* @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 */