]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/commitdiff
Added CAN API proposal
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 22 Jul 2013 13:47:06 +0000 (15:47 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 22 Jul 2013 13:47:06 +0000 (15:47 +0200)
rpp/lib/rpp/include/rpp/can.h

index c57f5febcd2783dd21a8362c748f4090f9d9a421..25d36351eb9cb0ceb0cb3a35072e07d768bf974f 100644 (file)
@@ -6,12 +6,28 @@
  * @copyright Copyright (C) 2013 Czech Technical University in Prague
  *
  * @author Carlos Jenkins <carlos@jenkins.co.cr>
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
  */
 
 
 #ifndef __RPP_CAN_H
 #define __RPP_CAN_H
 
+
+/**
+ * Message object identifier.
+ */
+typedef uint16_t rpp_can_msg_obj;
+
+/**
+ * CAN frame
+ */
+struct rpp_can_pdu {
+       uint32_t id;
+       uint8_t dlc;
+       uint8_t data[8];
+};
+
 /**
  * CAN module initialization.
  *
  */
 int8_t rpp_can_init();
 
+/**
+ * Setup a CAN message for transmission.
+ *
+ * Data pointed by @a pdu is copied to the given message box for
+ * transmission. A successful call to this function also clears the TX
+ * confirmation that can be retrieved with rpp_can_check_tx_con()
+ * until the written message is transmitted to the bus.
+ *
+ * @param[in] msg_obj Message object to use for transmission.
+ * @param[in] pdu Message to send.
+ *
+ * @return SUCCESS if the message was succesfully prepared for transmission,\n
+ *        FAILURE if an error was detected.
+ */
+int8_t rpp_can_write(rpp_can_msg_obj msg_obj, const struct rpp_can_pdu *pdu);
 
-#endif /* __RPP_CAN_H */
+/**
+ * Checks whether a message was transmitted.
+ *
+ * Call this function to check whether a message previously set for
+ * transmission with rpp_can_write() was already transmitted to the
+ * bus.
+ *
+ * @param[in] msg_obj Message object to be checked.
+ * @param[inout] tx_con Where to store the TX confirmation flag.
+ *
+ * @return SUCCESS if tx_con was updated with the requested value,\n
+ *        FAILURE if an error was detected.
+ */
+int8_t rpp_can_check_tx_con(rpp_can_msg_obj msg_obj, bool *tx_con);
 
+/**
+ * Read a message from a message object.
+ *
+ * Data in the given message object is copied to @a pdu. A successful
+ * call to this function also clears the indication that can be
+ * retrieved with rpp_can_check_rx_ind() until the next message is
+ * received by that message object.
+ *
+ * @param[in] msg_obj Message object to be read.
+ * @param[inout] pdu Where to store the read message.
+ *
+ * @return SUCCESS if the message was succesfully copied out from the message object,\n
+ *        FAILURE if an error was detected.
+ */
+int8_t rpp_can_read(rpp_can_msg_obj msg_obj, struct rpp_can_pdu *pdu);
+
+/**
+ * Checks whether a message was received by the message object.
+ *
+ * @param[in] msg_obj Message object to be checked.
+ * @param[inout] rx_ind Where to store the RX indication flag.
+ *
+ * @return SUCCESS if rx_ind was updated with the requested value,\n
+ *        FAILURE if an error was detected.
+ */
+int8_t rpp_can_check_rx_ind(rpp_can_msg_obj msg_obj, bool *rx_ind);
+
+#endif /* __RPP_CAN_H */