Encapsulating modules in spite of PE

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Encapsulating modules in spite of PE

2,248 次查看
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
标签 (1)
0 项奖励
回复
2 回复数

823 次查看
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 项奖励
回复

823 次查看
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 项奖励
回复