Revision c53ef0b1 modules/PowerManagement_1-2/module.c

View differences:

modules/PowerManagement_1-2/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
/**
......
550 552
 */
551 553
/*===========================================================================*/
552 554

  
555
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
556

  
557
/* some local definitions */
558
// maximum number of bytes per CAN frame
559
#define CAN_BYTES_PER_FRAME                     8
560
// identifier (as dominant as possible)
561
#define MSI_BCBMSG_CANID                        0
562

  
563
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
564
{
565
  aosDbgCheck(buffer != NULL);
566
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
567

  
568
  // local variables
569
  CANTxFrame frame;
570

  
571
  // setup the common parts of the message frame
572
  frame.DLC = (uint8_t)length;
573
  frame.RTR = CAN_RTR_DATA;
574
  frame.IDE = CAN_IDE_STD;
575
  frame.SID = MSI_BCBMSG_CANID;
576
  memcpy(frame.data8, buffer, length);
577

  
578
  // sent the frame and return
579
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
580
}
581

  
582
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
583
{
584
  aosDbgCheck(buffer != NULL);
585
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
586

  
587
  // local variables
588
  CANRxFrame frame;
589

  
590
  // receive a frame and check for errors
591
  if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
592
    // a correct frame was received
593
    if (frame.DLC == length &&
594
        frame.RTR == CAN_RTR_DATA &&
595
        frame.IDE == CAN_IDE_STD &&
596
        frame.SID == MSI_BCBMSG_CANID) {
597
      // success: fetch the data and return
598
      memcpy(buffer, frame.data8, length);
599
      return AOS_SSSP_BCB_SUCCESS;
600
    }
601
    // an unexpected frame was received
602
    else {
603
      return AOS_SSSP_BCB_INVALIDMSG;
604
    }
605
  } else {
606
    // failure: return with error
607
    return AOS_SSSP_BCB_ERROR;
608
  }
609
}
610

  
611
#undef MSI_BCBMSG_CANID
612
#undef CAN_BYTES_PER_FRAME
613

  
614
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
615

  
553 616
/** @} */
554 617

  
555 618
/*===========================================================================*/

Also available in: Unified diff