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.

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?

UserRevisionLine numberNew 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-22
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>&copy; 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 PPCAN_SERVICE_PROVIDER_H
ptpaterson 2:c724ff3a4e4d 30 #define PPCAN_SERVICE_PROVIDER_H
ptpaterson 2:c724ff3a4e4d 31
ptpaterson 4:2034b04c86d2 32 #include "CanOpenMessage.h"
ptpaterson 4:2034b04c86d2 33 #include <queue>
ptpaterson 4:2034b04c86d2 34
ptpaterson 4:2034b04c86d2 35 /*=========================================================================
ptpaterson 4:2034b04c86d2 36 * Forward declarations
ptpaterson 4:2034b04c86d2 37 *=========================================================================
ptpaterson 4:2034b04c86d2 38 */
ptpaterson 4:2034b04c86d2 39
ptpaterson 4:2034b04c86d2 40 struct CanOpenHandle;
ptpaterson 2:c724ff3a4e4d 41
ptpaterson 2:c724ff3a4e4d 42 namespace ppCANOpen
ptpaterson 2:c724ff3a4e4d 43 {
ptpaterson 2:c724ff3a4e4d 44
ptpaterson 2:c724ff3a4e4d 45 /* Avoid circular reference */
ptpaterson 2:c724ff3a4e4d 46 class Node;
ptpaterson 2:c724ff3a4e4d 47
ptpaterson 2:c724ff3a4e4d 48 /** Node Class to implement feature of a CANOpen NMT node
ptpaterson 2:c724ff3a4e4d 49 */
ptpaterson 2:c724ff3a4e4d 50 class ServiceProvider
ptpaterson 2:c724ff3a4e4d 51 {
ptpaterson 2:c724ff3a4e4d 52 public:
ptpaterson 2:c724ff3a4e4d 53
ptpaterson 2:c724ff3a4e4d 54 ServiceProvider (void);
ptpaterson 3:12b3c25bdeba 55 ~ServiceProvider (void);
ptpaterson 2:c724ff3a4e4d 56
ptpaterson 5:22a337cdc0e3 57 /* ========================================================================
ptpaterson 5:22a337cdc0e3 58 * Public Methods
ptpaterson 5:22a337cdc0e3 59 * ========================================================================
ptpaterson 5:22a337cdc0e3 60 */
ptpaterson 5:22a337cdc0e3 61
ptpaterson 5:22a337cdc0e3 62 /* Main application -----------------------------------------------------*/
ptpaterson 4:2034b04c86d2 63 /** Main loop */
ptpaterson 2:c724ff3a4e4d 64 void Run (void);
ptpaterson 2:c724ff3a4e4d 65
ptpaterson 5:22a337cdc0e3 66 /** Iterate through Nodes and update */
ptpaterson 5:22a337cdc0e3 67 void UpdateNodes(void);
ptpaterson 5:22a337cdc0e3 68
ptpaterson 5:22a337cdc0e3 69 /** C helper function to pass to API */
ptpaterson 5:22a337cdc0e3 70 static void UpdateNodes_CWrapper(void *pServiceObject);
ptpaterson 5:22a337cdc0e3 71
ptpaterson 5:22a337cdc0e3 72 /* Node Management ------------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 73 /** Register a node to get messages and get update calls */
ptpaterson 2:c724ff3a4e4d 74 int AddNode (Node * node);
ptpaterson 2:c724ff3a4e4d 75
ptpaterson 5:22a337cdc0e3 76 // TODO: remove node (swap pointers to fill in nicely
ptpaterson 5:22a337cdc0e3 77
ptpaterson 4:2034b04c86d2 78
ptpaterson 5:22a337cdc0e3 79 /* CanMessage Transmission ----------------------------------------------*/
ptpaterson 5:22a337cdc0e3 80 /** Add a message to the message queue outbox */
ptpaterson 5:22a337cdc0e3 81 void PostMessage (int nodeId, CanOpenMessage * msg);
ptpaterson 5:22a337cdc0e3 82
ptpaterson 5:22a337cdc0e3 83 /** quick way to create and send an NMT Control message
ptpaterson 5:22a337cdc0e3 84 * @note Make posting a message easier!
ptpaterson 4:2034b04c86d2 85 */
ptpaterson 5:22a337cdc0e3 86 void PostNmtControl (char targetNodeId, NmtCommandSpecifier cs);
ptpaterson 5:22a337cdc0e3 87
ptpaterson 5:22a337cdc0e3 88 /* Elapsed Time ---------------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 89 /** A way for the the Nodes to get elapsed time when they want it */
ptpaterson 5:22a337cdc0e3 90 uint32_t GetTime(void);
ptpaterson 4:2034b04c86d2 91
ptpaterson 2:c724ff3a4e4d 92 private:
ptpaterson 5:22a337cdc0e3 93 /* ========================================================================
ptpaterson 5:22a337cdc0e3 94 * Private Constants
ptpaterson 5:22a337cdc0e3 95 * ========================================================================
ptpaterson 5:22a337cdc0e3 96 */
ptpaterson 2:c724ff3a4e4d 97
ptpaterson 5:22a337cdc0e3 98 /** Define size of arrays in one place */
ptpaterson 4:2034b04c86d2 99 static const int SERVICE_MAX_NODES = 8;
ptpaterson 2:c724ff3a4e4d 100
ptpaterson 2:c724ff3a4e4d 101 /* ========================================================================
ptpaterson 5:22a337cdc0e3 102 * Private Methods
ptpaterson 2:c724ff3a4e4d 103 * ========================================================================
ptpaterson 2:c724ff3a4e4d 104 */
ptpaterson 2:c724ff3a4e4d 105
ptpaterson 5:22a337cdc0e3 106 /* CanMessage Reading ---------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 107 /** Function to be called on every CAN read interrupt */
ptpaterson 5:22a337cdc0e3 108 void ReadIT(void);
ptpaterson 5:22a337cdc0e3 109
ptpaterson 5:22a337cdc0e3 110 /** C helper function used to pass ReadIT() to API */
ptpaterson 5:22a337cdc0e3 111 static void ReadIT_CWrapper(void *pServiceObject);
ptpaterson 5:22a337cdc0e3 112
ptpaterson 5:22a337cdc0e3 113 /** Helper function that utilizes backup message inbox when the main one
ptpaterson 5:22a337cdc0e3 114 * is locked by the application.
ptpaterson 4:2034b04c86d2 115 */
ptpaterson 5:22a337cdc0e3 116 void ReadIT_clearBuffer(void);
ptpaterson 4:2034b04c86d2 117
ptpaterson 5:22a337cdc0e3 118 /* Elapsed Time ---------------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 119 /** Synchronize elapsed time*/
ptpaterson 5:22a337cdc0e3 120 void HandleTimeMessage(CanOpenMessage *canOpenMsg);
ptpaterson 5:22a337cdc0e3 121
ptpaterson 5:22a337cdc0e3 122
ptpaterson 5:22a337cdc0e3 123 /* ========================================================================
ptpaterson 5:22a337cdc0e3 124 * Private Member Variables
ptpaterson 5:22a337cdc0e3 125 * ========================================================================
ptpaterson 2:c724ff3a4e4d 126 */
ptpaterson 5:22a337cdc0e3 127
ptpaterson 5:22a337cdc0e3 128 /* Node Management -------------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 129 /** array of nodes to cycle through. */
ptpaterson 2:c724ff3a4e4d 130 Node * nodes[SERVICE_MAX_NODES];
ptpaterson 2:c724ff3a4e4d 131
ptpaterson 5:22a337cdc0e3 132 /** Keeps count of current number of nodes. */
ptpaterson 5:22a337cdc0e3 133 int nodeCount;
ptpaterson 5:22a337cdc0e3 134
ptpaterson 5:22a337cdc0e3 135 /* CanMessage Reading ---------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 136 /** array of messages in a queue */
ptpaterson 5:22a337cdc0e3 137 std::queue<CanOpenMessage> inbox;
ptpaterson 5:22a337cdc0e3 138
ptpaterson 5:22a337cdc0e3 139 /** Extra buffer only handled by ISR. Used if inbox is locked */
ptpaterson 5:22a337cdc0e3 140 std::queue<CanOpenMessage> inboxBuffer;
ptpaterson 5:22a337cdc0e3 141
ptpaterson 5:22a337cdc0e3 142 /** boolean to lock and unlock inbox */
ptpaterson 5:22a337cdc0e3 143 int bInboxUnlocked;
ptpaterson 5:22a337cdc0e3 144
ptpaterson 5:22a337cdc0e3 145 /** Data to keep track of internal messages. Node ID allows SP to avoid
ptpaterson 5:22a337cdc0e3 146 * dispatching message to the one who sent it
ptpaterson 2:c724ff3a4e4d 147 */
ptpaterson 5:22a337cdc0e3 148 struct InternalMessage {
ptpaterson 5:22a337cdc0e3 149 int nodeId;
ptpaterson 5:22a337cdc0e3 150 CanOpenMessage message;
ptpaterson 5:22a337cdc0e3 151
ptpaterson 5:22a337cdc0e3 152 InternalMessage(uint8_t n, CanOpenMessage m):
ptpaterson 5:22a337cdc0e3 153 nodeId(n),
ptpaterson 5:22a337cdc0e3 154 message(m)
ptpaterson 5:22a337cdc0e3 155 {}
ptpaterson 5:22a337cdc0e3 156 };
ptpaterson 5:22a337cdc0e3 157
ptpaterson 5:22a337cdc0e3 158 /** array of messages in a queue */
ptpaterson 5:22a337cdc0e3 159 std::queue<InternalMessage> outbox;
ptpaterson 3:12b3c25bdeba 160
ptpaterson 5:22a337cdc0e3 161 /* Elapsed Time ---------------------------------------------------------*/
ptpaterson 5:22a337cdc0e3 162 /** Elapsed time offset used for synchronization*/
ptpaterson 5:22a337cdc0e3 163 int32_t elapsedTimeOffset;
ptpaterson 5:22a337cdc0e3 164
ptpaterson 2:c724ff3a4e4d 165 };
ptpaterson 2:c724ff3a4e4d 166
ptpaterson 2:c724ff3a4e4d 167 } /* namspace ppCANOpen */
ptpaterson 2:c724ff3a4e4d 168
ptpaterson 2:c724ff3a4e4d 169 #endif /* PPCAN_SERVICE_PROVIDER_H */
ptpaterson 2:c724ff3a4e4d 170