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@2:c724ff3a4e4d, 2015-12-30 (annotated)
- Committer:
- ptpaterson
- Date:
- Wed Dec 30 13:33:41 2015 +0000
- Revision:
- 2:c724ff3a4e4d
- Child:
- 3:12b3c25bdeba
Implement simple Object Dictionary and derived class.
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 | 2:c724ff3a4e4d | 29 | #ifndef CANOPEN_PROTOCOL_H |
| ptpaterson | 2:c724ff3a4e4d | 30 | #define CANOPEN_PROTOCOL_H |
| ptpaterson | 2:c724ff3a4e4d | 31 | |
| ptpaterson | 2:c724ff3a4e4d | 32 | |
| ptpaterson | 2:c724ff3a4e4d | 33 | #ifdef __cplusplus |
| ptpaterson | 2:c724ff3a4e4d | 34 | extern "C" { |
| ptpaterson | 2:c724ff3a4e4d | 35 | #endif |
| ptpaterson | 2:c724ff3a4e4d | 36 | |
| ptpaterson | 2:c724ff3a4e4d | 37 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 38 | * MESSAGES |
| ptpaterson | 2:c724ff3a4e4d | 39 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 40 | */ |
| ptpaterson | 2:c724ff3a4e4d | 41 | |
| ptpaterson | 2:c724ff3a4e4d | 42 | /** CANOpen Message Format */ |
| ptpaterson | 2:c724ff3a4e4d | 43 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 44 | CANOPEN_FORMAT_STANDARD = 0, |
| ptpaterson | 2:c724ff3a4e4d | 45 | CANOPEN_FORMAT_EXTENDED, |
| ptpaterson | 2:c724ff3a4e4d | 46 | CANOPEN_FORMAT_ANY |
| ptpaterson | 2:c724ff3a4e4d | 47 | } CanOpenFormat; |
| ptpaterson | 2:c724ff3a4e4d | 48 | |
| ptpaterson | 2:c724ff3a4e4d | 49 | /** CANOpen Message Data Type */ |
| ptpaterson | 2:c724ff3a4e4d | 50 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 51 | CANOPEN_TYPE_DATA = 0, |
| ptpaterson | 2:c724ff3a4e4d | 52 | CANOPEN_TYPE_REMOTE |
| ptpaterson | 2:c724ff3a4e4d | 53 | } CanOpenType; |
| ptpaterson | 2:c724ff3a4e4d | 54 | |
| ptpaterson | 2:c724ff3a4e4d | 55 | /** CANOpen Message */ |
| ptpaterson | 2:c724ff3a4e4d | 56 | typedef struct { |
| ptpaterson | 2:c724ff3a4e4d | 57 | unsigned int id; |
| ptpaterson | 2:c724ff3a4e4d | 58 | char data[8]; |
| ptpaterson | 2:c724ff3a4e4d | 59 | CanOpenFormat format; |
| ptpaterson | 2:c724ff3a4e4d | 60 | CanOpenType type; |
| ptpaterson | 2:c724ff3a4e4d | 61 | unsigned char dataCount; |
| ptpaterson | 2:c724ff3a4e4d | 62 | } CanOpenMessage; |
| ptpaterson | 2:c724ff3a4e4d | 63 | |
| ptpaterson | 2:c724ff3a4e4d | 64 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 65 | * SDO MESSAGE PARAMETERS |
| ptpaterson | 2:c724ff3a4e4d | 66 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 67 | */ |
| ptpaterson | 2:c724ff3a4e4d | 68 | |
| ptpaterson | 2:c724ff3a4e4d | 69 | /** SDO initiate protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 70 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 71 | SDO_CCS_DOWNLOAD_SEGMENT_REQUEST = 0x00, |
| ptpaterson | 2:c724ff3a4e4d | 72 | SDO_CCS_INITIATE_DOWNLOAD_REQUEST = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 73 | SDO_CCS_INITIATE_UPLOAD_REQUEST = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 74 | } SdoClientCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 75 | |
| ptpaterson | 2:c724ff3a4e4d | 76 | /** SDO segment protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 77 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 78 | SDO_SCS_DOWNLOAD_SEGMENT_RESPONSE = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 79 | SDO_SCS_INITIATE_UPLOAD_RESPONSE = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 80 | SDO_SCS_INITIATE_DOWNLOAD_RESPONSE = 0x03, |
| ptpaterson | 2:c724ff3a4e4d | 81 | } SdoServerCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 82 | |
| ptpaterson | 2:c724ff3a4e4d | 83 | /* SDO constants --------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 84 | #define SDO_SIZE_INDICATOR_BIT 0b00000001 |
| ptpaterson | 2:c724ff3a4e4d | 85 | #define SDO_TRANSFER_TYPE_BIT 0b00000010 |
| ptpaterson | 2:c724ff3a4e4d | 86 | #define SDO_DATA_COUNT_BITS 0b00001100 |
| ptpaterson | 2:c724ff3a4e4d | 87 | #define SDO_TOGGLE_BIT 0b00010000 |
| ptpaterson | 2:c724ff3a4e4d | 88 | #define SDO_CS_BITS 0b11100000 |
| ptpaterson | 2:c724ff3a4e4d | 89 | |
| ptpaterson | 2:c724ff3a4e4d | 90 | /* SDO macros -----------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 91 | #define SDO_GET_CS(data0) ((data0 & SDO_CS_BITS) >> 5) |
| ptpaterson | 2:c724ff3a4e4d | 92 | #define SDO_GET_DATA_COUNT(data0) ((data0 & SDO_DATA_COUNT_BITS) >> 2) |
| ptpaterson | 2:c724ff3a4e4d | 93 | |
| ptpaterson | 2:c724ff3a4e4d | 94 | |
| ptpaterson | 2:c724ff3a4e4d | 95 | /*========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 96 | * NMT MESSAGE PARAMETERS |
| ptpaterson | 2:c724ff3a4e4d | 97 | *========================================================================= |
| ptpaterson | 2:c724ff3a4e4d | 98 | */ |
| ptpaterson | 2:c724ff3a4e4d | 99 | |
| ptpaterson | 2:c724ff3a4e4d | 100 | /** Node network management state */ |
| ptpaterson | 2:c724ff3a4e4d | 101 | typedef enum NmtState { |
| ptpaterson | 2:c724ff3a4e4d | 102 | NMT_STATE_INITIALIZED = 0x00, |
| ptpaterson | 2:c724ff3a4e4d | 103 | NMT_STATE_DISCONNECTED = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 104 | NMT_STATE_CONNECTING = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 105 | NMT_STATE_PREPARING = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 106 | NMT_STATE_STOPPED = 0x04, |
| ptpaterson | 2:c724ff3a4e4d | 107 | NMT_STATE_OPERATIONAL = 0x05, |
| ptpaterson | 2:c724ff3a4e4d | 108 | NMT_STATE_PREOPERATIONAL = 0x7F, |
| ptpaterson | 2:c724ff3a4e4d | 109 | NMT_STATE_UNKNOWN = 0x0F |
| ptpaterson | 2:c724ff3a4e4d | 110 | } NmtState; |
| ptpaterson | 2:c724ff3a4e4d | 111 | |
| ptpaterson | 2:c724ff3a4e4d | 112 | /** NMT node control protocol command specifiers */ |
| ptpaterson | 2:c724ff3a4e4d | 113 | typedef enum { |
| ptpaterson | 2:c724ff3a4e4d | 114 | NMT_CS_START = 0x01, |
| ptpaterson | 2:c724ff3a4e4d | 115 | NMT_CS_STOP = 0x02, |
| ptpaterson | 2:c724ff3a4e4d | 116 | NMT_CS_ENTER_PREOP = 0x80, |
| ptpaterson | 2:c724ff3a4e4d | 117 | NMT_CS_RESET_NODE = 0x81, |
| ptpaterson | 2:c724ff3a4e4d | 118 | NMT_CS_RESET_COM = 0x82 |
| ptpaterson | 2:c724ff3a4e4d | 119 | } NmtCommandSpecifier; |
| ptpaterson | 2:c724ff3a4e4d | 120 | |
| ptpaterson | 2:c724ff3a4e4d | 121 | /* NMT Constants --------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 122 | #define NMT_STATE_TOGGLE_BIT 0x80 |
| ptpaterson | 2:c724ff3a4e4d | 123 | |
| ptpaterson | 2:c724ff3a4e4d | 124 | /* NMT Macros -----------------------------------------------------------*/ |
| ptpaterson | 2:c724ff3a4e4d | 125 | #define NMT_SET_STATE(curState, newState) (curState) = (((curState) & NMT_STATE_TOGGLE_BIT) | ((newState) & (~NMT_STATE_TOGGLE_BIT)))) |
| ptpaterson | 2:c724ff3a4e4d | 126 | |
| ptpaterson | 2:c724ff3a4e4d | 127 | #ifdef __cplusplus |
| ptpaterson | 2:c724ff3a4e4d | 128 | }; |
| ptpaterson | 2:c724ff3a4e4d | 129 | #endif |
| ptpaterson | 2:c724ff3a4e4d | 130 | |
| ptpaterson | 2:c724ff3a4e4d | 131 | #endif /* CANOPEN_PROTOCOL */ |