Revision c53ef0b1 modules/LightRing_1-0/module.c
modules/LightRing_1-0/module.c | ||
---|---|---|
24 | 24 |
* @{ |
25 | 25 |
*/ |
26 | 26 |
|
27 |
#include "module.h" |
|
27 |
#include <amiroos.h> |
|
28 |
|
|
29 |
#include <string.h> |
|
28 | 30 |
|
29 | 31 |
/*===========================================================================*/ |
30 | 32 |
/** |
... | ... | |
244 | 246 |
*/ |
245 | 247 |
/*===========================================================================*/ |
246 | 248 |
|
249 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__) |
|
250 |
|
|
251 |
/* some local definitions */ |
|
252 |
// maximum number of bytes per CAN frame |
|
253 |
#define CAN_BYTES_PER_FRAME 8 |
|
254 |
// identifier (as dominant as possible) |
|
255 |
#define MSI_BCBMSG_CANID 0 |
|
256 |
|
|
257 |
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length) |
|
258 |
{ |
|
259 |
aosDbgCheck(buffer != NULL); |
|
260 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME); |
|
261 |
|
|
262 |
// local variables |
|
263 |
CANTxFrame frame; |
|
264 |
|
|
265 |
// setup the common parts of the message frame |
|
266 |
frame.DLC = (uint8_t)length; |
|
267 |
frame.RTR = CAN_RTR_DATA; |
|
268 |
frame.IDE = CAN_IDE_STD; |
|
269 |
frame.SID = MSI_BCBMSG_CANID; |
|
270 |
memcpy(frame.data8, buffer, length); |
|
271 |
|
|
272 |
// sent the frame and return |
|
273 |
return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR; |
|
274 |
} |
|
275 |
|
|
276 |
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length) |
|
277 |
{ |
|
278 |
aosDbgCheck(buffer != NULL); |
|
279 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME); |
|
280 |
|
|
281 |
// local variables |
|
282 |
CANRxFrame frame; |
|
283 |
|
|
284 |
// receive a frame and check for errors |
|
285 |
if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) { |
|
286 |
// a correct frame was received |
|
287 |
if (frame.DLC == length && |
|
288 |
frame.RTR == CAN_RTR_DATA && |
|
289 |
frame.IDE == CAN_IDE_STD && |
|
290 |
frame.SID == MSI_BCBMSG_CANID) { |
|
291 |
// success: fetch the data and return |
|
292 |
memcpy(buffer, frame.data8, length); |
|
293 |
return AOS_SSSP_BCB_SUCCESS; |
|
294 |
} |
|
295 |
// an unexpected frame was received |
|
296 |
else { |
|
297 |
return AOS_SSSP_BCB_INVALIDMSG; |
|
298 |
} |
|
299 |
} else { |
|
300 |
// failure: return with error |
|
301 |
return AOS_SSSP_BCB_ERROR; |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
#undef MSI_BCBMSG_CANID |
|
306 |
#undef CAN_BYTES_PER_FRAME |
|
307 |
|
|
308 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */ |
|
309 |
|
|
247 | 310 |
/** @} */ |
248 | 311 |
|
249 | 312 |
/*===========================================================================*/ |
Also available in: Unified diff