Seed can implementation

Fork of SEEED_CAN by Sophie Dexter

Revision:
2:fd026fcfde94
Parent:
1:ad71faa09868
diff -r ad71faa09868 -r fd026fcfde94 seeed_can_api.h
--- a/seeed_can_api.h	Wed Nov 06 20:16:11 2013 +0000
+++ b/seeed_can_api.h	Tue Nov 12 20:54:16 2013 +0000
@@ -76,6 +76,7 @@
     };
     typedef struct MCP_CANMsg CANMsg;
 
+#ifndef MBED_CAN_HELPER_H                                               // These are already defined for some mbed family members
     enum CANFormat {
         CANStandard = 0,
         CANExtended = 1
@@ -96,39 +97,85 @@
         CANType        type;        // 0 - DATA FRAME, 1 - REMOTE FRAME
     };
     typedef struct CAN_Message CAN_Message;
+#endif
     
     enum MCP_Mode {
-        _NORMAL,
-        _SLEEP,
-        _LOOPBACK,
-        _MONITOR,
-        _CONFIG,
-        _RESET,
+        _M_NORMAL,
+        _M_SLEEP,
+        _M_LOOPBACK,
+        _M_MONITOR,
+        _M_CONFIG,
+        _M_RESET,
     };
     typedef MCP_Mode CANMode;
 
+    enum MCP_Error_Flags {
+        _E_ALL,
+        _E_ERRORS,
+        _E_WARNINGS,
+        _E_RX1OVR,
+        _E_RX0OVR,
+        _E_TXBO,
+        _E_TXEP,
+        _E_RXEP,
+        _E_TXWAR,
+        _E_RXWAR,
+        _E_EWARN
+    };
+    typedef MCP_Error_Flags CANFlags;
+
+    enum MCP_Interrupt_Flags {
+        _I_NONE,
+        _I_ANY,
+        _I_RX,
+        _I_TX,
+        _I_RX0,
+        _I_RX1,
+        _I_TX0,
+        _I_TX1,
+        _I_TX2,
+        _I_ERROR,
+        _I_WAKE,
+        _I_M_ERR
+    };
+    typedef MCP_Interrupt_Flags CANIrqs;
+
 /** CAN driver functions
  */
-    uint8_t mcpInit(can_t *obj, const uint32_t bitRate);                // Initialise the MCP2515 and set the bit rate
-    uint8_t mcpSetMode(can_t *obj, const uint8_t newmode);              // set the MCP2515's operation mode
-    uint8_t mcpSetBitRate(can_t *obj, const uint32_t bitRate);          // set bitrate
+    uint8_t mcpInit(mcp_can_t *obj,                                     // Initialise the MCP2515 and set the bit rate
+                    const uint32_t bitRate,
+                    const CANMode mode);
+    uint8_t mcpSetMode(mcp_can_t *obj, const uint8_t newmode);          // set the MCP2515's operation mode
+    uint8_t mcpSetBitRate(mcp_can_t *obj, const uint32_t bitRate);      // set bitrate
     
-    void mcpWriteId(can_t *obj,                                         // write a CAN id
+    void mcpWriteId(mcp_can_t *obj,                                     // write a CAN id
                     const uint8_t mcp_addr,
                     const uint8_t ext,
                     const uint32_t id );
-    uint8_t mcpCanRead(can_t *obj, CAN_Message *msg);                   // read a CAN message
-    uint8_t mcpCanWrite(can_t *obj, CAN_Message msg);                   // write a CAN message
+    uint8_t mcpCanRead(mcp_can_t *obj, CAN_Message *msg);               // read a CAN message
+    uint8_t mcpCanWrite(mcp_can_t *obj, CAN_Message msg);               // write a CAN message
     
-    uint8_t mcpInitMask(can_t *obj, uint8_t num, uint32_t ulData, bool ext);  // initialise an Acceptance Mask
-    uint8_t mcpInitFilter(can_t *obj, uint8_t num, uint32_t ulData, bool ext);  // initialise an Acceptance Filter
+    uint8_t mcpInitMask(mcp_can_t *obj,                                 // initialise an Acceptance Mask
+                        uint8_t num,
+                        uint32_t ulData,
+                        bool ext);
+    uint8_t mcpInitFilter(mcp_can_t *obj,                               // initialise an Acceptance Filter
+                          uint8_t num,
+                          uint32_t ulData,
+                          bool ext);
 
-    uint8_t mcpReceptionErrorCount(can_t *obj);                         // number of message reception errors
-    uint8_t mcpTransmissionErrorCount(can_t *obj);                      // number of message transmission errors
+    uint8_t mcpErrorType(mcp_can_t *obj, const CANFlags type);          // Report on the specified errors and warnings
+    uint8_t mcpErrorFlags(mcp_can_t *obj);                              // Return contents of the error and warning flags register
+    uint8_t mcpReceptionErrorCount(mcp_can_t *obj);                     // number of message reception errors
+    uint8_t mcpTransmissionErrorCount(mcp_can_t *obj);                  // number of message transmission errors
 
-    void mcpMonitor(can_t *obj, const bool silent);                     // Select between monitor (silent = 1) and normal (silent = 0) modes
-    uint8_t mcpMode(can_t *obj, const CANMode mode);                    // Change CAN operation to the specified mode
+    void mcpMonitor(mcp_can_t *obj, const bool silent);                 // Select between monitor (silent = 1) and normal (silent = 0) modes
+    uint8_t mcpMode(mcp_can_t *obj, const CANMode mode);                // Change CAN operation to the specified mode
 
+    void mcpSetInterrupts(mcp_can_t *obj, const CANIrqs irqSet);        // Configure interrupt sources
+    uint8_t mcpInterruptType(mcp_can_t *obj, const CANIrqs irqFlag);    // Report on the specified interrupt causes
+    uint8_t mcpInterruptFlags(mcp_can_t *obj);                          // Return contents of the interrupt flags register
+    
 #ifdef __cplusplus
 };
 #endif