I am working on a Cortex-M4 microcontroller software in C ++. I have a lot of code (drivers, etc.), which is very machine dependent. And I have a higher-level code, which is closely dependent on low-level code, using drivers directly. Example: low-level part, for example. a UART driver, which is very specific to the hardware, and the higher-level part is a communication protocol based on UART. (This software runs on bare metal, meaning there is no operating system under it.)
This code is currently closely related, so it cannot be tested.
I would like this to be checked.
So, I decided that I would create an abstraction of the low-level parts and make the high-level parts depend only on the abstraction. Then I could create abstraction layouts that will be used by unit tests, and a real implementation that will be executed on the microcontroller.
- Is this the right approach?
- How to create such an abstraction? Most of the sources that I found strongly hinder the use of inheritance functions
virtualin embedded systems. What other methods exist?
So, in general, I would like to create a hardware abstraction layer (HAL), but I am asking how to do this? Should I use inheritance virtualin C ++, or is there another, better way?