title: Userspace Serial communication Library on Linux
body: <p>I need to develop a (userspace) library to handle serial communication on Linux (on Zynq-Zybo Board: UART, SPI, I2C).<br>
  I explored various websites and stuff, and investigated the xilinx-linux kernel, as well as some references on O'Reilly Linux Device Drivers book.<br>
  What I found so far is: Linux already includes its own kernel modules to handle the communication (for example: the UART kernel module handles the peripherals so that they show up in /dev/, and through that device file I can interact with the device from userspace using open, read, write, etc.).<br>
  I also read that, as a common pattern, interaction with the device driver is done through a character device driver, which is accessed in user-space and is responsible of the interaction with the device driver (details in the following image)<br>
  <a href="https://i.stack.imgur.com/XKK5d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XKK5d.png" alt="enter image description here"></a></p>
  
  <p>The ideas which came to my mind are: </p>
  
  <ul>
  <li>Writing a user-space library which simply interacts with the provided device file (in /dev/..) through the classic open, read, write</li>
  <li>Referring to the above image, develop a character device driver and include this module in the kernel, so that the userspace library just interacts with it through IOCTL (or similar) and then this new module will directly interact with the (pre-existent) device drivers<br>
  (This solution, however, doesn't sound too good to me: I read that using user-space stuff like open, read, write inside kernel modules is not a good idea -although it's possible-)</li>
  </ul>
  
  <p>My question is: which way should i pursue, and why?<br>
  Also, whatever article/book/link on the subject will be highly appreciated.<br>
  Thanks in advance!</p>