Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ppCANOpen_Example DISCO-F746NG_rtos_test
include/canopen_protocol.h@3:12b3c25bdeba, 2016-01-04 (annotated)
- Committer:
- ptpaterson
- Date:
- Mon Jan 04 06:10:49 2016 +0000
- Revision:
- 3:12b3c25bdeba
- Parent:
- 2:c724ff3a4e4d
Echo communication verified
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ptpaterson | 2:c724ff3a4e4d | 1 | /** |
| ptpaterson | 2:c724ff3a4e4d | 2 | ****************************************************************************** |
| ptpaterson | 2:c724ff3a4e4d | 3 | * @file |
| ptpaterson | 2:c724ff3a4e4d | 4 | * @author Paul Paterson |
| ptpaterson | 2:c724ff3a4e4d | 5 | * @version |
| ptpaterson | 2:c724ff3a4e4d | 6 | * @date 2015-12-17 |
| ptpaterson | 2:c724ff3a4e4d | 7 | * @brief CANOpen implementation library |
| ptpaterson | 2:c724ff3a4e4d | 8 | ****************************************************************************** |
| ptpaterson | 2:c724ff3a4e4d | 9 | * @attention |
| ptpaterson | 2:c724ff3a4e4d | 10 | * |
| ptpaterson | 2:c724ff3a4e4d | 11 | * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson |
| ptpaterson | 2:c724ff3a4e4d | 12 | * |
| ptpaterson | 2:c724ff3a4e4d | 13 | * All rights reserved. |
| ptpaterson | 2:c724ff3a4e4d | 14 | |
| ptpaterson | 2:c724ff3a4e4d | 15 | This program is free software: you can redistribute it and/or modify |
| ptpaterson | 2:c724ff3a4e4d | 16 | it under the terms of the GNU General Public License as published by |
| ptpaterson | 2:c724ff3a4e4d | 17 | the Free Software Foundation, either version 3 of the License, or |
| ptpaterson | 2:c724ff3a4e4d | 18 | (at your option) any later version. |
| ptpaterson | 2:c724ff3a4e4d | 19 | |
| ptpaterson | 2:c724ff3a4e4d | 20 | This program is distributed in the hope that it will be useful, |
| ptpaterson | 2:c724ff3a4e4d | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| ptpaterson | 2:c724ff3a4e4d | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| ptpaterson | 2:c724ff3a4e4d | 23 | GNU General Public License for more details. |
| ptpaterson | 2:c724ff3a4e4d | 24 | |
| ptpaterson | 2:c724ff3a4e4d | 25 | You should have received a copy of the GNU General Public License |
| ptpaterson | 2:c724ff3a4e4d | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| ptpaterson | 2:c724ff3a4e4d | 27 | */ |
| ptpaterson | 2:c724ff3a4e4d | 28 | |
| ptpaterson | 3:12b3c25bdeba | 29 | #ifndef PPCAN_CANOPEN_PROTOCOL_H |
| ptpaterson | 3:12b3c25bdeba | 30 | #define PPCAN_CANOPEN_PROTOCOL_H |
| ptpaterson | 2:c724ff3a4e4d | 31 | |
| ptpaterson | 3:12b3c25bdeba | 32 | #include "CanOpenHandle.h" |
| ptpaterson | 2:c724ff3a4e4d | 33 | |
| ptpaterson | 2:c724ff3a4e4d | 34 | #ifdef __cplusplus |
| ptpaterson | 2:c724ff3a4e4d | 35 | extern "C" { |
| ptpaterson | 2:c724ff3a4e4d | 36 | #endif |
| ptpaterson | 2:c724ff3a4e4d | 37 | |
| ptpaterson | 2:c724ff3a4e4d | 38 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 39 | * MESSAGES |
| ptpaterson | 2:c724ff3a4e4d | 40 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 41 | */ |
| ptpaterson | 2:c724ff3a4e4d | 42 | |
| ptpaterson | 2:c724ff3a4e4d | 43 | /** CANOpen Message Format */ |
| ptpaterson | 2:c724ff3a4e4d | 44 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 45 | CANOPEN_FORMAT_STANDARD = 0, |
| ptpaterson | 2:c724ff3a4e4d | 46 | CANOPEN_FORMAT_EXTENDED, |
| ptpaterson | 2:c724ff3a4e4d | 47 | CANOPEN_FORMAT_ANY |
| ptpaterson | 2:c724ff3a4e4d | 48 | } CanOpenFormat; |
| ptpaterson | 2:c724ff3a4e4d | 49 | |
| ptpaterson | 2:c724ff3a4e4d | 50 | /** CANOpen Message Data Type */ |
| ptpaterson | 2:c724ff3a4e4d | 51 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 52 | CANOPEN_TYPE_DATA = 0, |
| ptpaterson | 2:c724ff3a4e4d | 53 | CANOPEN_TYPE_REMOTE |
| ptpaterson | 2:c724ff3a4e4d | 54 | } CanOpenType; |
| ptpaterson | 2:c724ff3a4e4d | 55 | |
| ptpaterson | 3:12b3c25bdeba | 56 | /** CANOpen Function Codes */ |
| ptpaterson | 3:12b3c25bdeba | 57 | typedef enum { |
| ptpaterson | 3:12b3c25bdeba | 58 | CANOPEN_FUNCTION_CODE_NMT = 0x00, |
| ptpaterson | 3:12b3c25bdeba | 59 | CANOPEN_FUNCTION_CODE_SYNC = 0x01, |
| ptpaterson | 3:12b3c25bdeba | 60 | CANOPEN_FUNCTION_CODE_TIME = 0x02, |
| ptpaterson | 3:12b3c25bdeba | 61 | CANOPEN_FUNCTION_CODE_PDO1T = 0x03, |
| ptpaterson | 3:12b3c25bdeba | 62 | CANOPEN_FUNCTION_CODE_PD01R = 0x04, |
| ptpaterson | 3:12b3c25bdeba | 63 | CANOPEN_FUNCTION_CODE_PD02T = 0x05, |
| ptpaterson | 3:12b3c25bdeba | 64 | CANOPEN_FUNCTION_CODE_PD02R = 0x06, |
| ptpaterson | 3:12b3c25bdeba | 65 | CANOPEN_FUNCTION_CODE_PD03T = 0x07, |
| ptpaterson | 3:12b3c25bdeba | 66 | CANOPEN_FUNCTION_CODE_PD03R = 0x08, |
| ptpaterson | 3:12b3c25bdeba | 67 | CANOPEN_FUNCTION_CODE_PD04T = 0x09, |
| ptpaterson | 3:12b3c25bdeba | 68 | CANOPEN_FUNCTION_CODE_PD04R = 0x0A, |
| ptpaterson | 3:12b3c25bdeba | 69 | CANOPEN_FUNCTION_CODE_SD0T = 0x0B, |
| ptpaterson | 3:12b3c25bdeba | 70 | CANOPEN_FUNCTION_CODE_SD0R = 0x0C, |
| ptpaterson | 3:12b3c25bdeba | 71 | CANOPEN_FUNCTION_CODE_NODE_GUARD = 0x0E, |
| ptpaterson | 3:12b3c25bdeba | 72 | CANOPEN_FUNCTION_CODE_LSS = 0x0F |
| ptpaterson | 3:12b3c25bdeba | 73 | } CanOpenFunctionCodes; |
| ptpaterson | 3:12b3c25bdeba | 74 | |
| ptpaterson | 2:c724ff3a4e4d | 75 | /** CANOpen Message */ |
| ptpaterson | 2:c724ff3a4e4d | 76 | typedef struct { |
| ptpaterson | 2:c724ff3a4e4d | 77 | unsigned int id; |
| ptpaterson | 2:c724ff3a4e4d | 78 | char data[8]; |
| ptpaterson | 2:c724ff3a4e4d | 79 | CanOpenFormat format; |
| ptpaterson | 2:c724ff3a4e4d | 80 | CanOpenType type; |
| ptpaterson | 2:c724ff3a4e4d | 81 | unsigned char dataCount; |
| ptpaterson | 2:c724ff3a4e4d | 82 | } CanOpenMessage; |
| ptpaterson | 2:c724ff3a4e4d | 83 | |
| ptpaterson | 3:12b3c25bdeba | 84 | |
| ptpaterson | 3:12b3c25bdeba | 85 | |
| ptpaterson | 3:12b3c25bdeba | 86 | /* Message Constants */ |
| ptpaterson | 3:12b3c25bdeba | 87 | #define MESSAGE_NODEID_BITS 0b00001111111 |
| ptpaterson | 3:12b3c25bdeba | 88 | #define MESSAGE_COMMAND_BITS 0b11110000000 |
| ptpaterson | 3:12b3c25bdeba | 89 | |
| ptpaterson | 3:12b3c25bdeba | 90 | /* Message Macros -----------------------------------------------------------*/ |
| ptpaterson | 3:12b3c25bdeba | 91 | #define MESSAGE_GET_NODEID(cobId) (cobId & MESSAGE_NODEID_BITS) |
| ptpaterson | 3:12b3c25bdeba | 92 | #define MESSAGE_GET_COMMAND(cobId) ((cobId & MESSAGE_COMMAND_BITS) >> 7) |
| ptpaterson | 3:12b3c25bdeba | 93 | |
| ptpaterson | 2:c724ff3a4e4d | 94 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 95 | * SDO MESSAGE PARAMETERS |
| ptpaterson | 2:c724ff3a4e4d | 96 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 97 | */ |
| ptpaterson | 2:c724ff3a4e4d | 98 | |
| ptpaterson | 2:c724ff3a4e4d | 99 | /** SDO initiate protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 100 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 101 | SDO_CCS_DOWNLOAD_SEGMENT_REQUEST = 0x00, |
| ptpaterson | 2:c724ff3a4e4d | 102 | SDO_CCS_INITIATE_DOWNLOAD_REQUEST = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 103 | SDO_CCS_INITIATE_UPLOAD_REQUEST = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 104 | } SdoClientCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 105 | |
| ptpaterson | 2:c724ff3a4e4d | 106 | /** SDO segment protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 107 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 108 | SDO_SCS_DOWNLOAD_SEGMENT_RESPONSE = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 109 | SDO_SCS_INITIATE_UPLOAD_RESPONSE = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 110 | SDO_SCS_INITIATE_DOWNLOAD_RESPONSE = 0x03, |
| ptpaterson | 2:c724ff3a4e4d | 111 | } SdoServerCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 112 | |
| ptpaterson | 2:c724ff3a4e4d | 113 | /* SDO constants --------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 114 | #define SDO_SIZE_INDICATOR_BIT 0b00000001 |
| ptpaterson | 2:c724ff3a4e4d | 115 | #define SDO_TRANSFER_TYPE_BIT 0b00000010 |
| ptpaterson | 2:c724ff3a4e4d | 116 | #define SDO_DATA_COUNT_BITS 0b00001100 |
| ptpaterson | 2:c724ff3a4e4d | 117 | #define SDO_TOGGLE_BIT 0b00010000 |
| ptpaterson | 2:c724ff3a4e4d | 118 | #define SDO_CS_BITS 0b11100000 |
| ptpaterson | 2:c724ff3a4e4d | 119 | |
| ptpaterson | 2:c724ff3a4e4d | 120 | /* SDO macros -----------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 121 | #define SDO_GET_CS(data0) ((data0 & SDO_CS_BITS) >> 5) |
| ptpaterson | 2:c724ff3a4e4d | 122 | #define SDO_GET_DATA_COUNT(data0) ((data0 & SDO_DATA_COUNT_BITS) >> 2) |
| ptpaterson | 2:c724ff3a4e4d | 123 | |
| ptpaterson | 2:c724ff3a4e4d | 124 | |
| ptpaterson | 2:c724ff3a4e4d | 125 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 126 | * NMT MESSAGE PARAMETERS |
| ptpaterson | 2:c724ff3a4e4d | 127 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 128 | */ |
| ptpaterson | 2:c724ff3a4e4d | 129 | |
| ptpaterson | 2:c724ff3a4e4d | 130 | /** Node network management state */ |
| ptpaterson | 2:c724ff3a4e4d | 131 | typedef enum NmtState { |
| ptpaterson | 2:c724ff3a4e4d | 132 | NMT_STATE_INITIALIZED = 0x00, |
| ptpaterson | 2:c724ff3a4e4d | 133 | NMT_STATE_DISCONNECTED = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 134 | NMT_STATE_CONNECTING = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 135 | NMT_STATE_PREPARING = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 136 | NMT_STATE_STOPPED = 0x04, |
| ptpaterson | 2:c724ff3a4e4d | 137 | NMT_STATE_OPERATIONAL = 0x05, |
| ptpaterson | 2:c724ff3a4e4d | 138 | NMT_STATE_PREOPERATIONAL = 0x7F, |
| ptpaterson | 2:c724ff3a4e4d | 139 | NMT_STATE_UNKNOWN = 0x0F |
| ptpaterson | 2:c724ff3a4e4d | 140 | } NmtState; |
| ptpaterson | 2:c724ff3a4e4d | 141 | |
| ptpaterson | 2:c724ff3a4e4d | 142 | /** NMT node control protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 143 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 144 | NMT_CS_START = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 145 | NMT_CS_STOP = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 146 | NMT_CS_ENTER_PREOP = 0x80, |
| ptpaterson | 2:c724ff3a4e4d | 147 | NMT_CS_RESET_NODE = 0x81, |
| ptpaterson | 2:c724ff3a4e4d | 148 | NMT_CS_RESET_COM = 0x82 |
| ptpaterson | 2:c724ff3a4e4d | 149 | } NmtCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 150 | |
| ptpaterson | 2:c724ff3a4e4d | 151 | /* NMT Constants --------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 152 | #define NMT_STATE_TOGGLE_BIT 0x80 |
| ptpaterson | 2:c724ff3a4e4d | 153 | |
| ptpaterson | 2:c724ff3a4e4d | 154 | /* NMT Macros -----------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 155 | #define NMT_SET_STATE(curState, newState) (curState) = (((curState) & NMT_STATE_TOGGLE_BIT) | ((newState) & (~NMT_STATE_TOGGLE_BIT)))) |
| ptpaterson | 2:c724ff3a4e4d | 156 | |
| ptpaterson | 2:c724ff3a4e4d | 157 | #ifdef __cplusplus |
| ptpaterson | 2:c724ff3a4e4d | 158 | }; |
| ptpaterson | 2:c724ff3a4e4d | 159 | #endif |
| ptpaterson | 2:c724ff3a4e4d | 160 | |
| ptpaterson | 3:12b3c25bdeba | 161 | #endif /* PPCAN_CANOPEN_PROTOCOL */ |