-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCANopen.hpp
More file actions
163 lines (146 loc) · 6.83 KB
/
Copy pathCANopen.hpp
File metadata and controls
163 lines (146 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Contains functions to make CANopen stack versions of drivers. The
* functions will take in an EVT-core driver which will be used for
* making the drivers.
*/
#ifndef _EVT_CANopen_
#define _EVT_CANopen_
#include "CANDevice.hpp"
#include "co_core.h"
#include <core/dev/RTC.hpp>
#include <core/dev/Timer.hpp>
#include <core/io/CAN.hpp>
#include <core/io/types/CANMessage.hpp>
#include <core/utils/types/FixedQueue.hpp>
// Allows for resizable CANOpen queue if needed
#ifndef CANOPEN_QUEUE_SIZE
#define CANOPEN_QUEUE_SIZE 150
#endif
namespace core::io {
typedef void (*csdo_callback_t)(CO_CSDO* csdo, uint32_t entry, uint32_t status, void* context);
/**
* Get an instance of the CAN driver that can be used with the CANopen
* stack. This will populate a struct with function pointers that can
* handle CAN operations.
*
* @param[in] can The CAN interface that will be used for the stack driver
* @param[in] messageQueue Queue that will be read from for receiving CAN messages
* @param[out] canDriver The CANopen stack driver to populate
*/
void getCANopenCANDriver(CAN* can, types::FixedQueue<CANOPEN_QUEUE_SIZE, io::CANMessage>* messageQueue,
CO_IF_CAN_DRV* canDriver);
/**
* Get an instance of the timer driver that can be used with the
* CANopen stack. This will populate a struct with function pointers
* that will handler timer operations.
*
* @param[in] timer The timer interface to use
* @param[out] timerDriver The timer driver to populate
*/
void getCANopenTimerDriver(dev::Timer* timer, CO_IF_TIMER_DRV* timerDriver);
/**
* Get an instance of the NVM (non-volitile memory) that can be used
* with the CANopen stack. This will populate a struct with
* function pointers that can handle CAN operations.
*
* CURRENTLY ONLY FOR TESTING USE ONLY, NOT ACTUALLY NVM.
*
* @param[out] nvmDriver The NVM driver to populate
*/
void getCANopenNVMDriver(CO_IF_NVM_DRV* nvmDriver);
/**
* Takes in a references to objects that will be populated
* with all of the needed CAN drivers. Once these drivers
* are populated, they are passed to the overall canDriver.
*
* @param canOpenQueue[in,out] the canOpen queue to give to the drivers.
* @param can[in,out] the can instance to initialize with.
* @param timer[in] the EVT Core timer to give to CANOpen.
* @param canStackDriver[in,out] the stack driver.
* @param nvmDriver[in,out] the nvm driver.
* @param timerDriver[in,out] the timer driver.
* @param canDriver[in,out] the general CAN driver.
*/
void initializeCANopenDriver(types::FixedQueue<CANOPEN_QUEUE_SIZE, io::CANMessage>* canOpenQueue, io::CAN* can,
core::dev::Timer* timer, CO_IF_DRV* canStackDriver, CO_IF_NVM_DRV* nvmDriver,
CO_IF_TIMER_DRV* timerDriver, CO_IF_CAN_DRV* canDriver);
/**
* This function initializes a CO_NODE by taking in the CANDevice,
* drivers, and buffers and using those to create a CO_NODE_SPEC and
* initializing it.
*
* @param canNode[in,out] the CO_NODE that is initialized.
* @param canDevice[in] the canDevice that the object dictionary is Getd from.
* @param canStackDriver[in] references to the drivers that will be used in initialization
* @param sdoBuffer[in] the sdoBuffer
* @param appTmrMem[in] the appTmrMem
*/
void initializeCANopenNode(CO_NODE* canNode, CANDevice* canDevice, CO_IF_DRV* canStackDriver,
uint8_t sdoBuffer[CO_SSDO_N * CO_SDO_BUF_BYTE], CO_TMR_MEM appTmrMem[16]);
/**
* Takes in a reference to a CO_NODE and processes events
* on that node.
*
* @param canNode[in,out] the node to process events on.
*/
void processCANopenNode(CO_NODE* canNode);
/**
* Alert a canOpen TPDO to send the TPDO's values.
* DISCLAIMER: Does not immediately send said TPDO, just flags it for the next time processCANopenNode() runs.
*
* @param canNode the can node
* @param tpdoNum the TPDO number to be sent
*/
void alertTPDO(CO_NODE* canNode, uint16_t tpdoNum);
/**
* This function starts an asynchronous SDO download (write) request to transfer data
* to the specified object dictionary entry on the target CANopen node.
*
* @param node[in] Reference to the CANopen node object
* @param data[in] Pointer to the data buffer that holds the data to send
* @param size[in] Size of the data to transfer in bytes
* @param entry[in] Object dictionary entry (index + subindex) to write to
* @param transferCallback[in] Callback function for the transfer operation
* @param transferContext[in] Context for the callback function
* @return CO_ERR Returns the result of scheduling the transfer operation
*/
CO_ERR SDOTransfer(CO_NODE& node, uint8_t* data, uint8_t size, uint32_t entry, csdo_callback_t transferCallback,
void* transferContext);
/**
* This function starts an asynchronous SDO upload (read) request to fetch data from
* the specified object dictionary entry on the target CANopen node
*
* @param node[in] Reference to the CANopen node object
* @param data[out] Pointer to the buffer where received data will be stored
* @param size[in] Size of the buffer provided to receive data
* @param entry[in] Object dictionary entry (index + subindex) to read from
* @param receiveCallback[in] Callback function for the receive operation
* @param receiveContext[in] Context for the callback function
* @return CO_ERR Returns the result of scheduling the receive operation
*/
CO_ERR SDOReceive(CO_NODE& node, uint8_t* data, uint8_t size, uint32_t entry, csdo_callback_t receiveCallback,
void* receiveContext);
/**
* This function performs a blocking SDO download (write) request to transfer data to the
* specified object dictionary entry on the target CANopen node and waits for the response.
*
* @param node[in] Reference to the CANopen node object
* @param data[in] Pointer to the data buffer that holds the data to send
* @param size[in] Size of the data to transfer in bytes
* @param entry[in] Object dictionary entry (index + subindex) to write to
* @return CO_ERR[out] Returns the result of the transfer operation
*/
uint32_t SDOTransferBlocking(CO_NODE& node, uint8_t* data, uint8_t size, uint32_t entry);
/**
* This function performs a blocking SDO upload (read) request to fetch data from
* the specified object dictionary entry on the target CANopen node.
*
* @param node[in] Reference to the CANopen node object
* @param data[out] Pointer to the buffer where received data will be stored
* @param size[in] Size of the buffer provided to receive data
* @param entry[in] Object dictionary entry (index + subindex) to read from
* @return CO_ERR Returns the result of the receive operation
*/
uint32_t SDOReceiveBlocking(CO_NODE& node, uint8_t* data, uint8_t size, uint32_t entry);
} // namespace core::io
#endif