CANopenADI
CANopenNode on Analog Devices Inc. MAX32xxx microcontrollers
Loading...
Searching...
No Matches
CO_driver_target.h
1/*
2 * Device and application specific definitions for CANopenNode.
3 *
4 * @file CO_driver_target.h
5 * @author Janez Paternoster
6 * @copyright 2021 Janez Paternoster
7 *
8 * This file is part of CANopenNode, an opensource CANopen Stack.
9 * Project home page is <https://github.com/CANopenNode/CANopenNode>.
10 * For more information on CANopen see <http://www.can-cia.org/>.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24
25
26#ifndef CO_DRIVER_TARGET_H
27#define CO_DRIVER_TARGET_H
28
29/* This file contains device and application specific definitions.
30 * It is included from CO_driver.h, which contains documentation
31 * for common definitions below. */
32
33#include <stddef.h>
34#include <stdbool.h>
35#include <stdint.h>
36
37#ifdef CO_DRIVER_CUSTOM
38#include "CO_driver_custom.h"
39#endif
40
41/* Disable storage */
42#define CO_CONFIG_STORAGE 0x00
43
44#ifndef CO_CONFIG_SDO_SRV
45#define CO_CONFIG_SDO_SRV (CO_CONFIG_SDO_SRV_SEGMENTED | \
46 CO_CONFIG_SDO_SRV_BLOCK)
47#endif
48#ifndef CO_CONFIG_SDO_SRV_BUFFER_SIZE
49#define CO_CONFIG_SDO_SRV_BUFFER_SIZE 900
50#endif
51#ifndef CO_CONFIG_CRC16
52#define CO_CONFIG_CRC16 (CO_CONFIG_CRC16_ENABLE)
53#endif
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/* Stack configuration override default values.
60 * For more information see file CO_config.h. */
61
62
63/* Basic definitions. If big endian, CO_SWAP_xx macros must swap bytes. */
64#define CO_LITTLE_ENDIAN
65#define CO_SWAP_16(x) x
66#define CO_SWAP_32(x) x
67#define CO_SWAP_64(x) x
68/* NULL is defined in stddef.h */
69/* true and false are defined in stdbool.h */
70/* int8_t to uint64_t are defined in stdint.h */
71typedef uint_fast8_t bool_t;
72typedef float float32_t;
73typedef double float64_t;
74
75typedef struct {
76 uint32_t ident;
77 uint8_t DLC;
78 uint8_t data[8];
79} CO_CANrxMsg_t;
80
81/* Access to received CAN message */
82#define CO_CANrxMsg_readIdent(msg) ((uint16_t)(((CO_CANrxMsg_t*)(msg)))->ident)
83#define CO_CANrxMsg_readDLC(msg) ((uint8_t)(((CO_CANrxMsg_t*)(msg)))->DLC)
84#define CO_CANrxMsg_readData(msg) ((uint8_t*)(((CO_CANrxMsg_t*)(msg)))->data)
85
86/* Received message object */
87typedef struct {
88 uint16_t ident;
89 uint16_t mask;
90 void *object;
91 void (*CANrx_callback)(void *object, void *message);
93
94/* Transmit message object */
95typedef struct {
96 uint32_t ident;
97 uint8_t DLC;
98 uint8_t data[8];
99 volatile bool_t bufferFull;
100 volatile bool_t syncFlag;
101} CO_CANtx_t;
102
103/* CAN module object */
104typedef struct {
105 void *CANptr;
106 CO_CANrx_t *rxArray;
107 uint16_t rxSize;
108 CO_CANtx_t *txArray;
109 uint16_t txSize;
110 uint16_t CANerrorStatus;
111 volatile bool_t CANnormal;
112 volatile bool_t useCANrxFilters;
113 volatile bool_t bufferInhibitFlag;
114 volatile bool_t firstCANtxMessage;
115 volatile uint16_t CANtxCount;
116 uint32_t errOld;
117 uint32_t txLock;
118 uint32_t emcyLock;
119 uint32_t odLock;
121
122
123/* Data storage object for one entry */
124typedef struct {
125 void *addr;
126 size_t len;
127 uint8_t subIndexOD;
128 uint8_t attr;
129 /* Additional variables (target specific) */
130 void *addrNV;
132
140void CO_CANModule_Lock(uint32_t *lock);
141
142
148void CO_CANModule_Unlock(uint32_t *lock);
149
150/* (un)lock critical section in CO_CANsend() */
151#define CO_LOCK_CAN_SEND(CAN_MODULE) CO_CANModule_Lock(&((CO_CANmodule_t *) CAN_MODULE)->txLock)
152#define CO_UNLOCK_CAN_SEND(CAN_MODULE) CO_CANModule_Unlock(&((CO_CANmodule_t *) CAN_MODULE)->txLock)
153
154/* (un)lock critical section in CO_errorReport() or CO_errorReset() */
155#define CO_LOCK_EMCY(CAN_MODULE) CO_CANModule_Lock(&((CO_CANmodule_t *) CAN_MODULE)->emcyLock)
156#define CO_UNLOCK_EMCY(CAN_MODULE) CO_CANModule_Unlock(&((CO_CANmodule_t *) CAN_MODULE)->emcyLock)
157
158/* (un)lock critical section when accessing Object Dictionary */
159#define CO_LOCK_OD(CAN_MODULE) CO_CANModule_Lock(&((CO_CANmodule_t *) CAN_MODULE)->odLock)
160#define CO_UNLOCK_OD(CAN_MODULE) CO_CANModule_Unlock(&((CO_CANmodule_t *) CAN_MODULE)->odLock)
161
162/* Synchronization between CAN receive and message processing threads. */
163#define CO_MemoryBarrier()
164#define CO_FLAG_READ(rxNew) ((rxNew) != NULL)
165#define CO_FLAG_SET(rxNew) {CO_MemoryBarrier(); rxNew = (void*)1L;}
166#define CO_FLAG_CLEAR(rxNew) {CO_MemoryBarrier(); rxNew = NULL;}
167
168
169#ifdef __cplusplus
170}
171#endif /* __cplusplus */
172
173#endif /* CO_DRIVER_TARGET_H */
unsigned int uint16_t
unsigned long int uint32_t
float float32_t
uint_fast8_t bool_t
unsigned char uint8_t
double float64_t