Peripherals
Last updated
Was this helpful?
Last updated
Was this helpful?
It this chapter I will describe and give multiple examples of how to drive and control multiple hardware peripherals while using model in conjunction with .
All the generic, platform independent code provided here is implemented as part of library while platform (Raspberry Pi) specific code is taken from project.
All the platform specific peripheral control classes reside in directory.
The directory contains several simple applications, such as flashing the led or responding to button presses.
There are also common Component classes shared between the applications. They reside in directory.
In order to compile all the applications please follow the instructions described in .
In ARM platform every pin needs to be configured as either gpio input, gpio output or having one of several alternative functions the microcontroller supports. The device::Function
class defined in and implements simple interface which allows every Device class configure the pins it uses.
Every implemented Device class will receive reference to Function
object in its constructor and will have to use it to configure the pins as required.
The interface of the device::InterruptMgr
is defined as following:
Every Driver will use registerHandler()
member function to register its member function as the handler for its IrqId
. The enableInterrupt()
and disableInterrupt()
are also used by the Device objects to control their interrupts on global level.
In order to use the Interrupt Manager described above every application has to implement proper interrupt handler that will retrieve the reference to device::InterruptMgr
object (via global/static variables) and invoke its handleInterrupt()
function, which in turn check the appropriate status register(s) and invoke registered handler(s). Please note, that the handler will be executed in interrupt context.
The code will look something like this:
There is one more componenet that every Device will use. It's device::InterruptMgr
defined in . The main responsibility of the object of this class is to control global level interrupts, register interrupt handlers from various Devices and invoke the appropriate handler when interrupt occurs.
There may also be a need to enable/disable all the interrupts by toggling i
flag in CPS
register. The same file provides two function for this purpose: