Paul Paterson / ppCANOpen

Dependents:   ppCANOpen_Example DISCO-F746NG_rtos_test

Revision:
2:c724ff3a4e4d
Child:
3:12b3c25bdeba
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/canopen_protocol.h	Wed Dec 30 13:33:41 2015 +0000
@@ -0,0 +1,131 @@
+/**
+ ******************************************************************************
+ * @file
+ * @author  Paul Paterson
+ * @version
+ * @date    2015-12-17
+ * @brief   CANOpen implementation library
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2015 Paul Paterson
+ *
+ * All rights reserved.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CANOPEN_PROTOCOL_H
+#define CANOPEN_PROTOCOL_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    /*=========================================================================
+     * MESSAGES
+     *=========================================================================
+     */
+
+    /** CANOpen Message Format */
+    typedef enum {
+        CANOPEN_FORMAT_STANDARD = 0,
+        CANOPEN_FORMAT_EXTENDED,
+        CANOPEN_FORMAT_ANY
+    } CanOpenFormat;
+
+    /** CANOpen Message Data Type */
+    typedef enum {
+        CANOPEN_TYPE_DATA = 0,
+        CANOPEN_TYPE_REMOTE
+    } CanOpenType;
+
+    /** CANOpen Message */
+    typedef struct {
+        unsigned int    id;
+        char   data[8];
+        CanOpenFormat   format;
+        CanOpenType     type;
+        unsigned char   dataCount;
+    } CanOpenMessage;
+
+    /*=========================================================================
+     * SDO MESSAGE PARAMETERS
+     *=========================================================================
+     */
+    
+    /** SDO initiate protocol command specifiers */
+    typedef enum {
+         SDO_CCS_DOWNLOAD_SEGMENT_REQUEST   = 0x00, 
+         SDO_CCS_INITIATE_DOWNLOAD_REQUEST  = 0x01,
+         SDO_CCS_INITIATE_UPLOAD_REQUEST    = 0x02,
+    } SdoClientCommandSpecifier;
+    
+    /** SDO segment protocol command specifiers */
+    typedef enum {
+         SDO_SCS_DOWNLOAD_SEGMENT_RESPONSE  = 0x01,
+         SDO_SCS_INITIATE_UPLOAD_RESPONSE   = 0x02,
+         SDO_SCS_INITIATE_DOWNLOAD_RESPONSE = 0x03,
+    } SdoServerCommandSpecifier;
+    
+    /* SDO constants --------------------------------------------------------*/
+    #define SDO_SIZE_INDICATOR_BIT  0b00000001
+    #define SDO_TRANSFER_TYPE_BIT   0b00000010
+    #define SDO_DATA_COUNT_BITS     0b00001100
+    #define SDO_TOGGLE_BIT          0b00010000
+    #define SDO_CS_BITS             0b11100000
+    
+    /* SDO macros -----------------------------------------------------------*/ 
+    #define SDO_GET_CS(data0)           ((data0 & SDO_CS_BITS) >> 5)
+    #define SDO_GET_DATA_COUNT(data0)   ((data0 & SDO_DATA_COUNT_BITS) >> 2)
+    
+    
+    /*=========================================================================
+     * NMT MESSAGE PARAMETERS
+     *=========================================================================
+     */
+
+    /** Node network management state */
+    typedef enum NmtState {
+        NMT_STATE_INITIALIZED     = 0x00,
+        NMT_STATE_DISCONNECTED    = 0x01,
+        NMT_STATE_CONNECTING      = 0x02,
+        NMT_STATE_PREPARING       = 0x02,
+        NMT_STATE_STOPPED         = 0x04,
+        NMT_STATE_OPERATIONAL     = 0x05,
+        NMT_STATE_PREOPERATIONAL  = 0x7F,
+        NMT_STATE_UNKNOWN         = 0x0F
+    } NmtState;
+    
+    /** NMT node control protocol command specifiers */
+    typedef enum {
+         NMT_CS_START       = 0x01,
+         NMT_CS_STOP        = 0x02,
+         NMT_CS_ENTER_PREOP = 0x80,
+         NMT_CS_RESET_NODE  = 0x81,
+         NMT_CS_RESET_COM   = 0x82
+    } NmtCommandSpecifier;
+    
+    /* NMT Constants --------------------------------------------------------*/
+    #define NMT_STATE_TOGGLE_BIT      0x80
+    
+    /* NMT Macros -----------------------------------------------------------*/
+    #define NMT_SET_STATE(curState, newState) (curState) = (((curState) & NMT_STATE_TOGGLE_BIT) | ((newState) & (~NMT_STATE_TOGGLE_BIT))))
+    
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* CANOPEN_PROTOCOL */