Revision c53ef0b1 modules/LightRing_1-2/module.c

View differences:

modules/LightRing_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
/**
......
522 524
 */
523 525
/*===========================================================================*/
524 526

  
527
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
528

  
529
/* some local definitions */
530
// maximum number of bytes per CAN frame
531
#define CAN_BYTES_PER_FRAME                     8
532
// identifier (as dominant as possible)
533
#define MSI_BCBMSG_CANID                        0
534

  
535
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
536
{
537
  aosDbgCheck(buffer != NULL);
538
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
539

  
540
  // local variables
541
  CANTxFrame frame;
542

  
543
  // setup the common parts of the message frame
544
  frame.DLC = (uint8_t)length;
545
  frame.RTR = CAN_RTR_DATA;
546
  frame.IDE = CAN_IDE_STD;
547
  frame.SID = MSI_BCBMSG_CANID;
548
  memcpy(frame.data8, buffer, length);
549

  
550
  // sent the frame and return
551
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
552
}
553

  
554
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
555
{
556
  aosDbgCheck(buffer != NULL);
557
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
558

  
559
  // local variables
560
  CANRxFrame frame;
561

  
562
  // receive a frame and check for errors
563
  if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
564
    // a correct frame was received
565
    if (frame.DLC == length &&
566
        frame.RTR == CAN_RTR_DATA &&
567
        frame.IDE == CAN_IDE_STD &&
568
        frame.SID == MSI_BCBMSG_CANID) {
569
      // success: fetch the data and return
570
      memcpy(buffer, frame.data8, length);
571
      return AOS_SSSP_BCB_SUCCESS;
572
    }
573
    // an unexpected frame was received
574
    else {
575
      return AOS_SSSP_BCB_INVALIDMSG;
576
    }
577
  } else {
578
    // failure: return with error
579
    return AOS_SSSP_BCB_ERROR;
580
  }
581
}
582

  
583
#undef MSI_BCBMSG_CANID
584
#undef CAN_BYTES_PER_FRAME
585

  
586
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
587

  
525 588
/** @} */
526 589

  
527 590
/*===========================================================================*/

Also available in: Unified diff