Subversion Repositories HomeAutomation

Rev

Rev 693 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * High level functions for bus communication and standard node behaviour.
  3.  *
  4.  * @author  Andreas Fritiofson
  5.  *
  6.  * @date    2007-10-24
  7.  */
  8.  
  9. #error StdCan: For discussion only! Do not use in application code.
  10.  
  11. #ifndef STDCAN_H_
  12. #define STDCAN_H_
  13.  
  14. /**
  15.  * Return values.
  16.  * Most StdCan functions return one of these values.
  17.  */
  18. typedef enum {
  19.     StdCan_Ret_OK, /**< Operation completed successfully. */
  20.     StdCan_Ret_Full, /**< Failed to send because transmit queue was full. */
  21.     StdCan_Ret_Empty, /**< Failed to read because receive queue was empty. */
  22.     StdCan_Ret_Fail, /**< General error. */
  23.     StdCan_Ret_DataErr /**< Malformed data. */
  24. } StdCan_Ret_t;
  25.  
  26. /**
  27.  * Message structure.
  28.  * Stores a CAN message frame. Flags that are unused at this level have been
  29.  * excluded (RTR and standard id).
  30.  */
  31. typedef struct {
  32.     unsigned long Id; /**< CAN extended ID (29 bits). */
  33.     char Length; /**< Data length [0,8]. */
  34.     unsigned char Data[8]; /**< Data array. Only the first \c Length elements are valid. */
  35. } StdCan_Msg_t;
  36.  
  37. /**
  38.  * Node descriptor structure.
  39.  * Describes the node and the application running on it.
  40.  * TODO: Discuss the purpose and layout of Node_Desc_t.
  41.  */
  42. typedef struct {
  43.     unsigned short Type; /**< Application type (documented elsewhere). */
  44.     unsigned short Version; /**< Application version number (application defined). */
  45.     unsigned char Id; /**< Node ID. */
  46. } Node_Desc_t;
  47.  
  48. /**
  49.  * Initialize StdCan.
  50.  * Initializes the StdCan and lower layers and sends an Application Startup
  51.  * Message.
  52.  *
  53.  * @param node_desc
  54.  *      Pointer to node descriptor, containing information about the type and
  55.  *      version of the application that should be announced in startup and
  56.  *      heartbeat messages.
  57.  */
  58. StdCan_Ret_t StdCan_Init(Node_Desc_t* node_desc);
  59.  
  60. /**
  61.  * Get a message.
  62.  * Retrieves a message from the receive queue.
  63.  *
  64.  * @param[out] msg
  65.  *      Pointer to message stucture to be filled with the next message from
  66.  *      the queue.
  67.  */
  68. StdCan_Ret_t StdCan_Get(StdCan_Msg_t* msg);
  69.  
  70. /**
  71.  * Send a message.
  72.  * Puts a message on the transmit queue.
  73.  *
  74.  * @param[in] msg
  75.  *      Pointer to message to send.
  76.  */
  77. StdCan_Ret_t StdCan_Put(StdCan_Msg_t* msg);
  78.  
  79. /**
  80.  * Send a Heartbeat.
  81.  * Puts a Heartbeat message on the transmit queue. Takes an \c uint8_t and
  82.  * returns \c void in order to be able to use it as a \c Timer callback
  83.  * directly, i.e.
  84.  * \code
  85.  *      Timer_SetTimeout(APP_HEARTBEAT_TIMER, STDCAN_HEARTBEAT_PERIOD, TimerTypeFreeRunning, StdCan_SendHeartbeat);
  86.  * \endcode
  87.  * If the transmit queue is full this function will silently fail.
  88.  *
  89.  * @param n
  90.  *      Dummy value.
  91.  */
  92. void StdCan_SendHeartbeat(uint8_t n);
  93.  
  94. #endif /*STDCAN_H_*/
  95.