In embedded, is there any difference between a device driver and a library

embedded-systemslibrariesphilosophy

Assuming a platform with no kernel mode, such as Atmel AVR, is there any difference between a device driver and a library, given that everything is user mode anyway?

I ask because I'm thinking about how I want to layer my code. It's like this:

+----------------+
| Business logic |
+----------------+
|   CAN library  |
+----------------+
| MCP2515 driver |
+----------------+
|   SPI driver   |
+----------------+

The SPI "driver" has an interrupt handler, and it talks directly to the microcontroller's SPI peripheral, which sounds like a driver, but other than that, I don't see how it's any different to, say, the CAN library, which has high-level functions like "send this message".

Best Answer

The main difference between a device driver and a library is that the purpose of a device driver is to control some hardware component.

Device drivers can either directly control I/O pins of the processor (like the SPI driver in your example is likely doing), or they can use the services of a lower-layer device driver to communicate over a communication channel with their device (like the MCP2515 driver).

What sets the latter kind of device driver apart from a library that implements a communication protocol is that the communication partner is a hardware chip that can only perform some dedicated function and that the communication protocol is very low level.

Related Topic