Revision c53ef0b1 modules/DiWheelDrive_1-2/module.c

View differences:

modules/DiWheelDrive_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
/**
......
349 351
 */
350 352
/*===========================================================================*/
351 353

  
354
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
355

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

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

  
367
  // local variables
368
  CANTxFrame frame;
369

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

  
377
  // sent the frame and return
378
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
379
}
380

  
381
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
382
{
383
  aosDbgCheck(buffer != NULL);
384
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
385

  
386
  // local variables
387
  CANRxFrame frame;
388

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

  
410
#undef MSI_BCBMSG_CANID
411
#undef CAN_BYTES_PER_FRAME
412

  
413
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
414

  
352 415
/** @} */
353 416

  
354 417
/*===========================================================================*/

Also available in: Unified diff