Encapsulating modules in spite of PE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Encapsulating modules in spite of PE

1,820 Views
eliben
Contributor I
Hello,
 
While the Processor Expert allows to conveniently initialize and use peripherals, I have a problem with its coding convention. PE doesn't exactly encourage code modularity and encapsulation. For example, suppose that I want to write a higher-level serial communication module that knows how to send and receive blocks of data. To send more than one byte I have to use interrupts, but those appear in Events.c in PE's generated code. This means I have to break my module into two, one part being in Events.c, which at least recognizes the module and directs output to it.
 
How is this handled ? Can someone provide tips on writing large scale, modular software, with PE at its base ?
Thanks in avance
Labels (1)
0 Kudos
2 Replies

395 Views
bigmac
Specialist III
Hello,
 
I do not use PE, and I could quite possibly be missing your point.
 
My interpretation of your specific issue is that you wish to keep the code for the MCU derivative specific component completely separate from the serial protocol component.  Since circular (FIFO) buffers are commonly used with interrupt driven SCI communications, I might consider that these global buffers would provide a suitable common interface.
 
The ISR code would know how to write to the receive buffer and read from the send buffer.  Conversely, the serial protocol code would read from the receive buffer, and write to the send buffer.  Is this what you mean by "encapsulation"?
 
I guess it depends on whether PE can handle buffered communications using global arrays.
 
Regards,
Mac
 
0 Kudos

395 Views
LarryBr
Contributor I
You could write your modularized source, gizmo_driver.c, thusly:

// File: gizmo_driver.c
// Common stuff
// ...
#ifdef EXTRACT_EVENT_HANDLER_GIZMO
// Event handler for the gizmo device ...
// ...
#else
// Code for gizmo device other than event handler
// ...
#endif

Then, in Events.c, where the particular event handler would
be placed if modularization was not much of a concern:

#define EXTRACT_EVENT_HANDLER_GIZMO
#include "gizmo_driver.c"
#undef EXTRACT_EVENT_HANDLER_GIZMO

0 Kudos