library for C++ CANOpen implementation. mbed independant, but is easy to attach into with mbed.
Dependents: ppCANOpen_Example DISCO-F746NG_rtos_test
Example:
Import programppCANOpen_Example
I am no longer actively working on the ppCANOpen library, however, I want to publish this project so that anyone who wants to pick up any of the pieces can have a good example. This is a a project I was working on using the ppCANOpen library. It has a pretty in deep use of the object dictionary structure. And a number of functions to control high voltage pinball drivers, if you're into that sort of thing.
include/CanOpenMessage.h@5:22a337cdc0e3, 2016-02-13 (annotated)
- Committer:
- ptpaterson
- Date:
- Sat Feb 13 20:22:59 2016 +0000
- Revision:
- 5:22a337cdc0e3
- Parent:
- 4:2034b04c86d2
PDO receive complete
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ptpaterson | 4:2034b04c86d2 | 1 | /** |
| ptpaterson | 4:2034b04c86d2 | 2 | ****************************************************************************** |
| ptpaterson | 4:2034b04c86d2 | 3 | * @file |
| ptpaterson | 4:2034b04c86d2 | 4 | * @author Paul Paterson |
| ptpaterson | 4:2034b04c86d2 | 5 | * @version |
| ptpaterson | 4:2034b04c86d2 | 6 | * @date 2015-12-14 |
| ptpaterson | 4:2034b04c86d2 | 7 | * @brief CANOpen implementation library |
| ptpaterson | 4:2034b04c86d2 | 8 | ****************************************************************************** |
| ptpaterson | 4:2034b04c86d2 | 9 | * @attention |
| ptpaterson | 4:2034b04c86d2 | 10 | * |
| ptpaterson | 4:2034b04c86d2 | 11 | * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson |
| ptpaterson | 4:2034b04c86d2 | 12 | * |
| ptpaterson | 4:2034b04c86d2 | 13 | * All rights reserved. |
| ptpaterson | 4:2034b04c86d2 | 14 | |
| ptpaterson | 4:2034b04c86d2 | 15 | This program is free software: you can redistribute it and/or modify |
| ptpaterson | 4:2034b04c86d2 | 16 | it under the terms of the GNU General Public License as published by |
| ptpaterson | 4:2034b04c86d2 | 17 | the Free Software Foundation, either version 3 of the License, or |
| ptpaterson | 4:2034b04c86d2 | 18 | (at your option) any later version. |
| ptpaterson | 4:2034b04c86d2 | 19 | |
| ptpaterson | 4:2034b04c86d2 | 20 | This program is distributed in the hope that it will be useful, |
| ptpaterson | 4:2034b04c86d2 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| ptpaterson | 4:2034b04c86d2 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| ptpaterson | 4:2034b04c86d2 | 23 | GNU General Public License for more details. |
| ptpaterson | 4:2034b04c86d2 | 24 | |
| ptpaterson | 4:2034b04c86d2 | 25 | You should have received a copy of the GNU General Public License |
| ptpaterson | 4:2034b04c86d2 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| ptpaterson | 4:2034b04c86d2 | 27 | */ |
| ptpaterson | 4:2034b04c86d2 | 28 | |
| ptpaterson | 4:2034b04c86d2 | 29 | #ifndef PPCAN_CANOPEN_MESSAGE_H |
| ptpaterson | 4:2034b04c86d2 | 30 | #define PPCAN_CANOPEN_MESSAGE_H |
| ptpaterson | 4:2034b04c86d2 | 31 | |
| ptpaterson | 5:22a337cdc0e3 | 32 | #include "stdint.h" |
| ptpaterson | 5:22a337cdc0e3 | 33 | |
| ptpaterson | 4:2034b04c86d2 | 34 | #ifdef __cplusplus |
| ptpaterson | 4:2034b04c86d2 | 35 | extern "C" { |
| ptpaterson | 4:2034b04c86d2 | 36 | #endif |
| ptpaterson | 4:2034b04c86d2 | 37 | |
| ptpaterson | 4:2034b04c86d2 | 38 | /*========================================================================= |
| ptpaterson | 4:2034b04c86d2 | 39 | * CANOpen Message Structure |
| ptpaterson | 4:2034b04c86d2 | 40 | *========================================================================= |
| ptpaterson | 4:2034b04c86d2 | 41 | */ |
| ptpaterson | 4:2034b04c86d2 | 42 | |
| ptpaterson | 4:2034b04c86d2 | 43 | /** CANOpen Message Format */ |
| ptpaterson | 4:2034b04c86d2 | 44 | typedef enum { |
| ptpaterson | 4:2034b04c86d2 | 45 | CANOPEN_FORMAT_STANDARD = 0, |
| ptpaterson | 4:2034b04c86d2 | 46 | CANOPEN_FORMAT_EXTENDED, |
| ptpaterson | 4:2034b04c86d2 | 47 | CANOPEN_FORMAT_ANY |
| ptpaterson | 4:2034b04c86d2 | 48 | } CanOpenFormat; |
| ptpaterson | 4:2034b04c86d2 | 49 | |
| ptpaterson | 4:2034b04c86d2 | 50 | /** CANOpen Message Data Type */ |
| ptpaterson | 4:2034b04c86d2 | 51 | typedef enum { |
| ptpaterson | 4:2034b04c86d2 | 52 | CANOPEN_TYPE_DATA = 0, |
| ptpaterson | 4:2034b04c86d2 | 53 | CANOPEN_TYPE_REMOTE |
| ptpaterson | 4:2034b04c86d2 | 54 | } CanOpenType; |
| ptpaterson | 4:2034b04c86d2 | 55 | |
| ptpaterson | 4:2034b04c86d2 | 56 | |
| ptpaterson | 4:2034b04c86d2 | 57 | /** CANOpen Message */ |
| ptpaterson | 4:2034b04c86d2 | 58 | typedef struct CanOpenMessage { |
| ptpaterson | 5:22a337cdc0e3 | 59 | uint32_t id; |
| ptpaterson | 5:22a337cdc0e3 | 60 | uint8_t data[8]; |
| ptpaterson | 4:2034b04c86d2 | 61 | CanOpenFormat format; |
| ptpaterson | 4:2034b04c86d2 | 62 | CanOpenType type; |
| ptpaterson | 5:22a337cdc0e3 | 63 | uint8_t dataCount; |
| ptpaterson | 4:2034b04c86d2 | 64 | } CanOpenMessage; |
| ptpaterson | 4:2034b04c86d2 | 65 | |
| ptpaterson | 5:22a337cdc0e3 | 66 | |
| ptpaterson | 5:22a337cdc0e3 | 67 | /*========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 68 | * CANOpen Function Codes |
| ptpaterson | 5:22a337cdc0e3 | 69 | *========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 70 | */ |
| ptpaterson | 5:22a337cdc0e3 | 71 | |
| ptpaterson | 5:22a337cdc0e3 | 72 | /** CANOpen Function Codes */ |
| ptpaterson | 5:22a337cdc0e3 | 73 | typedef enum { |
| ptpaterson | 5:22a337cdc0e3 | 74 | CANOPEN_FUNCTION_CODE_NMT = 0x00, |
| ptpaterson | 5:22a337cdc0e3 | 75 | CANOPEN_FUNCTION_CODE_SYNC = 0x01, |
| ptpaterson | 5:22a337cdc0e3 | 76 | CANOPEN_FUNCTION_CODE_TIME = 0x02, |
| ptpaterson | 5:22a337cdc0e3 | 77 | CANOPEN_FUNCTION_CODE_PDO1T = 0x03, |
| ptpaterson | 5:22a337cdc0e3 | 78 | CANOPEN_FUNCTION_CODE_PDO1R = 0x04, |
| ptpaterson | 5:22a337cdc0e3 | 79 | CANOPEN_FUNCTION_CODE_PDO2T = 0x05, |
| ptpaterson | 5:22a337cdc0e3 | 80 | CANOPEN_FUNCTION_CODE_PDO2R = 0x06, |
| ptpaterson | 5:22a337cdc0e3 | 81 | CANOPEN_FUNCTION_CODE_PDO3T = 0x07, |
| ptpaterson | 5:22a337cdc0e3 | 82 | CANOPEN_FUNCTION_CODE_PDO3R = 0x08, |
| ptpaterson | 5:22a337cdc0e3 | 83 | CANOPEN_FUNCTION_CODE_PDO4T = 0x09, |
| ptpaterson | 5:22a337cdc0e3 | 84 | CANOPEN_FUNCTION_CODE_PDO4R = 0x0A, |
| ptpaterson | 5:22a337cdc0e3 | 85 | CANOPEN_FUNCTION_CODE_SDOT = 0x0B, |
| ptpaterson | 5:22a337cdc0e3 | 86 | CANOPEN_FUNCTION_CODE_SDOR = 0x0C, |
| ptpaterson | 5:22a337cdc0e3 | 87 | CANOPEN_FUNCTION_CODE_NODE_GUARD = 0x0E, |
| ptpaterson | 5:22a337cdc0e3 | 88 | CANOPEN_FUNCTION_CODE_LSS = 0x0F |
| ptpaterson | 5:22a337cdc0e3 | 89 | } CanOpenFunctionCodes; |
| ptpaterson | 5:22a337cdc0e3 | 90 | |
| ptpaterson | 5:22a337cdc0e3 | 91 | /* Message Constants */ |
| ptpaterson | 5:22a337cdc0e3 | 92 | #define MESSAGE_NODEID_BITS 0b00001111111 |
| ptpaterson | 5:22a337cdc0e3 | 93 | #define MESSAGE_COMMAND_BITS 0b11110000000 |
| ptpaterson | 5:22a337cdc0e3 | 94 | |
| ptpaterson | 5:22a337cdc0e3 | 95 | /* Message Macros -----------------------------------------------------------*/ |
| ptpaterson | 5:22a337cdc0e3 | 96 | #define MESSAGE_GET_NODEID(cobId) (cobId & MESSAGE_NODEID_BITS) |
| ptpaterson | 5:22a337cdc0e3 | 97 | #define MESSAGE_GET_COMMAND(cobId) ((cobId & MESSAGE_COMMAND_BITS) >> 7) |
| ptpaterson | 5:22a337cdc0e3 | 98 | |
| ptpaterson | 5:22a337cdc0e3 | 99 | /*========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 100 | * SDO MESSAGE PARAMETERS |
| ptpaterson | 5:22a337cdc0e3 | 101 | *========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 102 | */ |
| ptpaterson | 5:22a337cdc0e3 | 103 | |
| ptpaterson | 5:22a337cdc0e3 | 104 | /** SDO initiate protocol command specifiers */ |
| ptpaterson | 5:22a337cdc0e3 | 105 | typedef enum { |
| ptpaterson | 5:22a337cdc0e3 | 106 | SDO_CCS_DOWNLOAD_SEGMENT_REQUEST = 0x00, |
| ptpaterson | 5:22a337cdc0e3 | 107 | SDO_CCS_INITIATE_DOWNLOAD_REQUEST = 0x01, |
| ptpaterson | 5:22a337cdc0e3 | 108 | SDO_CCS_INITIATE_UPLOAD_REQUEST = 0x02, |
| ptpaterson | 5:22a337cdc0e3 | 109 | } SdoClientCommandSpecifier; |
| ptpaterson | 5:22a337cdc0e3 | 110 | |
| ptpaterson | 5:22a337cdc0e3 | 111 | /** SDO segment protocol command specifiers */ |
| ptpaterson | 5:22a337cdc0e3 | 112 | typedef enum { |
| ptpaterson | 5:22a337cdc0e3 | 113 | SDO_SCS_DOWNLOAD_SEGMENT_RESPONSE = 0x01, |
| ptpaterson | 5:22a337cdc0e3 | 114 | SDO_SCS_INITIATE_UPLOAD_RESPONSE = 0x02, |
| ptpaterson | 5:22a337cdc0e3 | 115 | SDO_SCS_INITIATE_DOWNLOAD_RESPONSE = 0x03, |
| ptpaterson | 5:22a337cdc0e3 | 116 | } SdoServerCommandSpecifier; |
| ptpaterson | 5:22a337cdc0e3 | 117 | |
| ptpaterson | 5:22a337cdc0e3 | 118 | /* SDO constants --------------------------------------------------------*/ |
| ptpaterson | 5:22a337cdc0e3 | 119 | #define SDO_SIZE_INDICATOR_BIT 0b00000001 |
| ptpaterson | 5:22a337cdc0e3 | 120 | #define SDO_TRANSFER_TYPE_BIT 0b00000010 |
| ptpaterson | 5:22a337cdc0e3 | 121 | #define SDO_DATA_COUNT_BITS 0b00001100 |
| ptpaterson | 5:22a337cdc0e3 | 122 | #define SDO_TOGGLE_BIT 0b00010000 |
| ptpaterson | 5:22a337cdc0e3 | 123 | #define SDO_CS_BITS 0b11100000 |
| ptpaterson | 5:22a337cdc0e3 | 124 | |
| ptpaterson | 5:22a337cdc0e3 | 125 | /* SDO macros -----------------------------------------------------------*/ |
| ptpaterson | 5:22a337cdc0e3 | 126 | #define SDO_GET_CS(data0) ((data0 & SDO_CS_BITS) >> 5) |
| ptpaterson | 5:22a337cdc0e3 | 127 | #define SDO_GET_DATA_COUNT(data0) ((data0 & SDO_DATA_COUNT_BITS) >> 2) |
| ptpaterson | 5:22a337cdc0e3 | 128 | |
| ptpaterson | 5:22a337cdc0e3 | 129 | |
| ptpaterson | 5:22a337cdc0e3 | 130 | /*========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 131 | * NMT MESSAGE PARAMETERS |
| ptpaterson | 5:22a337cdc0e3 | 132 | *========================================================================= |
| ptpaterson | 5:22a337cdc0e3 | 133 | */ |
| ptpaterson | 5:22a337cdc0e3 | 134 | |
| ptpaterson | 5:22a337cdc0e3 | 135 | /** NMT node control protocol command specifiers */ |
| ptpaterson | 5:22a337cdc0e3 | 136 | typedef enum { |
| ptpaterson | 5:22a337cdc0e3 | 137 | NMT_CS_START = 0x01, |
| ptpaterson | 5:22a337cdc0e3 | 138 | NMT_CS_STOP = 0x02, |
| ptpaterson | 5:22a337cdc0e3 | 139 | NMT_CS_ENTER_PREOP = 0x80, |
| ptpaterson | 5:22a337cdc0e3 | 140 | NMT_CS_RESET_NODE = 0x81, |
| ptpaterson | 5:22a337cdc0e3 | 141 | NMT_CS_RESET_COM = 0x82 |
| ptpaterson | 5:22a337cdc0e3 | 142 | } NmtCommandSpecifier; |
| ptpaterson | 5:22a337cdc0e3 | 143 | |
| ptpaterson | 4:2034b04c86d2 | 144 | #ifdef __cplusplus |
| ptpaterson | 4:2034b04c86d2 | 145 | }; |
| ptpaterson | 4:2034b04c86d2 | 146 | #endif |
| ptpaterson | 4:2034b04c86d2 | 147 | |
| ptpaterson | 4:2034b04c86d2 | 148 | #endif /* PPCAN_CANOPEN_MESSAGE_H */ |
