Hardware Abstraction Layer for FreeRTOS
can_prv.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2018
5  */
6 #ifndef CAN_PRV_
7 #define CAN_PRV_
8 #ifndef CAN_PRV
9 # error "Never include this file out of a CAN driver"
10 #endif
11 #include <FreeRTOS.h>
12 #include <semphr.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <hal.h>
16 #define CAN_ALREDY_INITED 1
17 int32_t can_genericInit(struct can *can);
18 #ifdef CONFIG_CAN_THREAD_SAVE
19 # define can_lock(u, w, e) HAL_LOCK(u, w, e)
20 # define can_unlock(u, e) HAL_UNLOCK(u, e)
21 #else
22 # define can_lock(u, w, e)
23 # define can_unlock(u, e)
24 #endif
25 #define CAN_ADDDEV(ns, p) HAL_ADDDEV(can, ns, p)
27 #define CAN_GET_DEV(index) HAL_GET_DEV(can, index)
28 
37 struct can_bittiming {
38  uint32_t bitrate; /* Bit-rate in bits/second */
39  uint32_t sample_point; /* Sample point in one-tenth of a percent */
40  uint32_t tq; /* Time quanta (TQ) in nanoseconds */
41  uint32_t prop_seg; /* Propagation segment in TQs */
42  uint32_t phase_seg1; /* Phase buffer segment 1 in TQs */
43  uint32_t phase_seg2; /* Phase buffer segment 2 in TQs */
44  uint32_t sjw; /* Synchronisation jump width in TQs */
45  uint32_t brp; /* Bit-rate prescaler */
46 };
55  uint32_t tseg1_min; /* Time segment 1 = prop_seg + phase_seg1 */
56  uint32_t tseg1_max;
57  uint32_t tseg2_min; /* Time segment 2 = phase_seg2 */
58  uint32_t tseg2_max;
59  uint32_t sjw_max; /* Synchronisation jump width */
60  uint32_t brp_min; /* Bit-rate prescaler */
61  uint32_t brp_max;
62  uint32_t brp_inc;
63 };
64 int32_t can_calcBittiming(struct can_bittiming *bt, struct can_bittiming_const const *btc, int64_t clkFreq);
65 
66 #ifndef CONFIG_CAN_MULTI
67 # define CAN_OPS(ns)
68 # define CAN_INIT_DEV(ns)
69 # define CAN_INIT(ns, index, bitrate, pin, pinHigh, callback, data) struct can * can_init(uint32_t index, uint32_t bitrate, struct gpio_pin *pin, bool pinHigh, bool (*callback)(struct can *can, can_error_t error, can_errorData_t d, void *userData), void *data)
70 # define CAN_DEINIT(ns, c) int32_t can_deinit(struct can *c)
71 # define CAN_SET_CALLBACK(ns, c, filterID, callback, data) int32_t can_setCallback(struct can *c, int32_t filterID, bool (*callback)(struct can *can, struct can_msg *msg, void *data), void *data)
72 # define CAN_REGISTER_FILTER(ns, c, filter) int32_t can_registerFilter(struct can *c, struct can_filter *filter)
73 # define CAN_DEREGISTER_FILTER(ns, c, filterID) int32_t can_deregisterFilter(struct can *c, int32_t filterID)
74 # define CAN_SEND(ns, c, msg, waittime) int32_t can_send(struct can *c, struct can_msg *msg, TickType_t waittime)
75 # define CAN_RECV(ns, c, filterID, msg, waittime) int32_t can_recv(struct can *c, int32_t filterID, struct can_msg *msg, TickType_t waittime)
76 # define CAN_SEND_ISR(ns, c, msg) int32_t can_sendISR(struct can *c, struct can_msg *msg)
77 # define CAN_RECV_ISR(ns, c, filterID, msg) int32_t can_recvISR(struct can *c, int32_t filterID, struct can_msg *msg)
78 # define CAN_UP(ns, c) int32_t can_up(struct can *c)
79 # define CAN_DOWN(ns, c) int32_t can_down(struct can *c)
80 #else
81 # define CAN_OPS(ns) const struct can_ops ns##_can_ops = { \
82  .can_init = &ns##_can_init,\
83  .can_deinit = &ns##_can_deinit,\
84  .can_init = &ns##_can_init, \
85  .can_deinit = &ns##_can_deinit, \
86  .can_setCallback = &ns##_can_setCallback, \
87  .can_registerFilter = &ns##_can_registerFilter, \
88  .can_deregisterFilter = &ns##_can_deregisterFilter, \
89  .can_send = &ns##_can_send, \
90  .can_recv = &ns##_can_recv, \
91  .can_sendISR = &ns##_can_sendISR, \
92  .can_recvISR = &ns##_can_recvISR, \
93  .can_up = &ns##_can_up, \
94  .can_down = &ns##_can_down, \
95 }
96 # define CAN_INIT_DEV(ns) .gen.ops = &ns##_can_ops,
97 # define CAN_INIT(ns, index, bitrate, pin, pinHigh, callback, data) struct can * ns##_can_init(uint32_t index, uint32_t bitrate, struct gpio_pin *pin, bool pinHigh, bool (*callback)(struct can *can, can_error_t error, can_errorData_t d, void *userData), void *data)
98 # define CAN_DEINIT(ns, c) int32_t ns##_can_deinit(struct can *c)
99 # define CAN_SET_CALLBACK(ns, c, filterID, callback, data) int32_t ns##_can_setCallback(struct can *c, int32_t filterID, bool (*callback)(struct can *can, struct can_msg *msg, void *data), void *data)
100 # define CAN_REGISTER_FILTER(ns, c, filter) int32_t ns##_can_registerFilter(struct can *c, struct can_filter *filter)
101 # define CAN_DEREGISTER_FILTER(ns, c, filterID) int32_t ns##_can_deregisterFilter(struct can *c, int32_t filterID)
102 # define CAN_SEND(ns, c, msg, waittime) int32_t ns##_can_send(struct can *c, struct can_msg *msg, TickType_t waittime)
103 # define CAN_RECV(ns, c, filterID, msg, waittime) int32_t ns##_can_recv(struct can *c, int32_t filterID, struct can_msg *msg, TickType_t waittime)
104 # define CAN_SEND_ISR(ns, c, msg) int32_t ns##_can_sendISR(struct can *c, struct can_msg *msg)
105 # define CAN_RECV_ISR(ns, c, filterID, msg) int32_t ns##_can_recvISR(struct can *c, int32_t filterID, struct can_msg *msg)
106 # define CAN_UP(ns, c) int32_t ns##_can_up(struct can *c)
107 # define CAN_DOWN(ns, c) int32_t ns##_can_down(struct can *c)
108 #endif
109 #endif
can_bittiming_const::brp_inc
uint32_t brp_inc
Definition: can_prv.h:62
HAL_DEFINE_GLOBAL_ARRAY
HAL_DEFINE_GLOBAL_ARRAY(can)
can_bittiming_const::brp_max
uint32_t brp_max
Definition: can_prv.h:61
can_bittiming_const::sjw_max
uint32_t sjw_max
Definition: can_prv.h:59
hal.h
can_bittiming_const::tseg1_max
uint32_t tseg1_max
Definition: can_prv.h:56
can_bittiming::sample_point
uint32_t sample_point
Definition: can_prv.h:39
can_bittiming::phase_seg2
uint32_t phase_seg2
Definition: can_prv.h:43
can_bittiming_const::tseg2_min
uint32_t tseg2_min
Definition: can_prv.h:57
can_bittiming::prop_seg
uint32_t prop_seg
Definition: can_prv.h:41
can_bittiming_const
Definition: can_prv.h:54
can_genericInit
int32_t can_genericInit(struct can *can)
can_bittiming::tq
uint32_t tq
Definition: can_prv.h:40
can_bittiming_const::tseg2_max
uint32_t tseg2_max
Definition: can_prv.h:58
can_bittiming_const::tseg1_min
uint32_t tseg1_min
Definition: can_prv.h:55
can_bittiming::sjw
uint32_t sjw
Definition: can_prv.h:44
can_bittiming::phase_seg1
uint32_t phase_seg1
Definition: can_prv.h:42
can_calcBittiming
int32_t can_calcBittiming(struct can_bittiming *bt, struct can_bittiming_const const *btc, int64_t clkFreq)
can_bittiming
Definition: can_prv.h:37
can_bittiming::brp
uint32_t brp
Definition: can_prv.h:45
can_bittiming_const::brp_min
uint32_t brp_min
Definition: can_prv.h:60
can_bittiming::bitrate
uint32_t bitrate
Definition: can_prv.h:38