Revision c53ef0b1 modules/PowerManagement_1-1/module.c
modules/PowerManagement_1-1/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 |
/** |
... | ... | |
535 | 537 |
*/ |
536 | 538 |
/*===========================================================================*/ |
537 | 539 |
|
540 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__) |
|
541 |
|
|
542 |
/* some local definitions */ |
|
543 |
// maximum number of bytes per CAN frame |
|
544 |
#define CAN_BYTES_PER_FRAME 8 |
|
545 |
// identifier (as dominant as possible) |
|
546 |
#define MSI_BCBMSG_CANID 0 |
|
547 |
|
|
548 |
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length) |
|
549 |
{ |
|
550 |
aosDbgCheck(buffer != NULL); |
|
551 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME); |
|
552 |
|
|
553 |
// local variables |
|
554 |
CANTxFrame frame; |
|
555 |
|
|
556 |
// setup the common parts of the message frame |
|
557 |
frame.DLC = (uint8_t)length; |
|
558 |
frame.RTR = CAN_RTR_DATA; |
|
559 |
frame.IDE = CAN_IDE_STD; |
|
560 |
frame.SID = MSI_BCBMSG_CANID; |
|
561 |
memcpy(frame.data8, buffer, length); |
|
562 |
|
|
563 |
// sent the frame and return |
|
564 |
return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR; |
|
565 |
} |
|
566 |
|
|
567 |
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length) |
|
568 |
{ |
|
569 |
aosDbgCheck(buffer != NULL); |
|
570 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME); |
|
571 |
|
|
572 |
// local variables |
|
573 |
CANRxFrame frame; |
|
574 |
|
|
575 |
// receive a frame and check for errors |
|
576 |
if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) { |
|
577 |
// a correct frame was received |
|
578 |
if (frame.DLC == length && |
|
579 |
frame.RTR == CAN_RTR_DATA && |
|
580 |
frame.IDE == CAN_IDE_STD && |
|
581 |
frame.SID == MSI_BCBMSG_CANID) { |
|
582 |
// success: fetch the data and return |
|
583 |
memcpy(buffer, frame.data8, length); |
|
584 |
return AOS_SSSP_BCB_SUCCESS; |
|
585 |
} |
|
586 |
// an unexpected frame was received |
|
587 |
else { |
|
588 |
return AOS_SSSP_BCB_INVALIDMSG; |
|
589 |
} |
|
590 |
} else { |
|
591 |
// failure: return with error |
|
592 |
return AOS_SSSP_BCB_ERROR; |
|
593 |
} |
|
594 |
} |
|
595 |
|
|
596 |
#undef MSI_BCBMSG_CANID |
|
597 |
#undef CAN_BYTES_PER_FRAME |
|
598 |
|
|
599 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */ |
|
600 |
|
|
538 | 601 |
/** @} */ |
539 | 602 |
|
540 | 603 |
/*===========================================================================*/ |
Also available in: Unified diff