Revision c53ef0b1 modules/DiWheelDrive_1-1/module.c

View differences:

modules/DiWheelDrive_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
/**
......
352 354
 */
353 355
/*===========================================================================*/
354 356

  
357
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
358

  
359
/* some local definitions */
360
// maximum number of bytes per CAN frame
361
#define CAN_BYTES_PER_FRAME                     8
362
// identifier (as dominant as possible)
363
#define MSI_BCBMSG_CANID                        0
364

  
365
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
366
{
367
  aosDbgCheck(buffer != NULL);
368
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
369

  
370
  // local variables
371
  CANTxFrame frame;
372

  
373
  // setup the common parts of the message frame
374
  frame.DLC = (uint8_t)length;
375
  frame.RTR = CAN_RTR_DATA;
376
  frame.IDE = CAN_IDE_STD;
377
  frame.SID = MSI_BCBMSG_CANID;
378
  memcpy(frame.data8, buffer, length);
379

  
380
  // sent the frame and return
381
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
382
}
383

  
384
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
385
{
386
  aosDbgCheck(buffer != NULL);
387
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
388

  
389
  // local variables
390
  CANRxFrame frame;
391

  
392
  // receive a frame and check for errors
393
  if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
394
    // a correct frame was received
395
    if (frame.DLC == length &&
396
        frame.RTR == CAN_RTR_DATA &&
397
        frame.IDE == CAN_IDE_STD &&
398
        frame.SID == MSI_BCBMSG_CANID) {
399
      // success: fetch the data and return
400
      memcpy(buffer, frame.data8, length);
401
      return AOS_SSSP_BCB_SUCCESS;
402
    }
403
    // an unexpected frame was received
404
    else {
405
      return AOS_SSSP_BCB_INVALIDMSG;
406
    }
407
  } else {
408
    // failure: return with error
409
    return AOS_SSSP_BCB_ERROR;
410
  }
411
}
412

  
413
#undef MSI_BCBMSG_CANID
414
#undef CAN_BYTES_PER_FRAME
415

  
416
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
417

  
355 418
/** @} */
356 419

  
357 420
/*===========================================================================*/

Also available in: Unified diff