Keep peripheral microcontroller drivers independent

This is a question I've been asking myself for a while. I've tried looking for good readings about this, but I can't seem to find a solution that suits the way I think it should be.

I believe that for portability and maintenance reasons, drivers should preferably be independent of each other. However, sometimes one driver may require functionality provided by another driver. For example, an I²C bus might have a timeout that depends on the timer driver.

The way I've done it so far is to simply # include the drivers in other drivers, but this is not a desirable solution. I feel like there must be a better way to do this.

I'm going to add another layer, a kind of abstraction between the main application and all the drivers. However, it looks like it just moves the problem somewhere else and doesn't solve it.

I've used function pointers, but that makes the maintenance null too.

Are there any good sources or ideas on driver interdependencies and how can this problem be solved?

+3


source to share


1 answer


On large controllers, Cortex M3 / 4 and the like, it's perfectly normal to have countless layers. For example, the LPC1822 SD card interface consists of an "sdif" driver that controls the basic communication and pin switching of the card interface. In addition, there is the "sdmmc" driver, which provides more advanced functionality. On top of that could be the FAT system (using real time clock), and on and on ...

In contrast, a tiny 8-bit controller may not have any layers at all. These 3 registers you must set up for i2c communication are manageable. Don't write hundreds of lines of code to do something trivial. In this case, it is quite normal to include the timer directly in the I2C routines. If you want your program to be clearer for your colleagues, use your time to write good comments and documentation, rather than encapsulate everything and everything in functions and abstraction layers.



If you are constrained by the registry and your program is not that big, don't put too much overhead on yourself to get solid layers. Layers are something for a lot of complex software. In embedded computing, you are sometimes better off maintaining your side dependencies rather than writing huge libraries that don't fit in flash space.

+3


source







All Articles