Hey folks;
In a lot of my development, we've used a standard set of functions to make very robust/flexible/understandable code. I'd like to propose we setup our modules (and code in general) to follow this outline.
I'm up for feedback/updates/ideas. I'd be glad to turn this into a cpp template if/when we get feedback that this semi-formal model of component/driver design matches our needs.
/*
* Sets up registers, initializes low-level hardware
*@param fReason: Reason flag, WAKEUP, BOOT, RESTORE,
* usuallly hardware platform specific.
* Very fast. very very fast
*/
void init_Hardware( uint8_t fReason )
/*
* Closes down registers, de-powers or stops low-level hardware
*@param fReason: Reason flag, SNOOZE, DEEP_SLEEP, REBOOT,
* usually hardware platform specific
* Very fast. very very fast
*/
void deinit_Hardware( uint8_t fReason )
/*
*Initalizes state machines, status, restores data from NVM/Disk
* /EEPROM
*/
void init_Software()
/*
*stops state machines, status, stores data from NVM/Disk
* /EEPROM
*/
void deinit_Software( uint8_t fReason )
/**
* Can be a 10ms or 100ms tick based on what the systems needs.
* very fast function for timer specific driver needs. In most
* drivers it's a nop.
* mostly or totally just sets flags, for the 'updateState' or 'processData' functions to use/dispatch during the next main loop
**/
void tick_10ms()
/**
* Effectively, this is where the work is done. This can take the
* time it needs to process data, sort things out, wait. etc. This
* function should make minimum state-machine changes, it should
* mostly process data (record/send/sort/whatever).
* Almost always called before 'updateState' in the main loop
**/
void processData( )
/**
* Effectively, the tick function for the state machine in a driver.
* Almost always called after 'updateState' in the main loop.
**/
void updateState( )
I think it adds clarity to steps/stages and helps build simple state machines out of what can be somewhat complex code. It also makes hardware abstraction using mocks a lot easier.
Any concerns about using this style, or suggestions of a better style?