-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.h
70 lines (45 loc) · 2.81 KB
/
interface.h
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
/**
* CAN Driver Interface
*
* Authors: Michael Rouse
*/
#ifndef __CAN_INTERFACE__
#define __CAN_INTERFACE__
#include "../datatypes.h"
#include "config.h"
/* Used to configure CAN filters and Masks */
#define can_accept(...) CAT(__can_accept_, NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
/* can_setup should be called by the user to setup the library and CAN Controller */
void can_setup(spi_bus bus, io_pin cs_pin, io_pin int_pin);
/* can_receive should be called when retrieving the most recent messages */
/* NO_MESSAGE is returned if no messages are available */
can_message* can_receive(void);
/* can_transmit should be called after populating a message and it's ready to send */
void can_transmit(void);
/* This variable should be used in the user's program to populate a message before */
/* calling can_transmit(). MUST call can_transmit() in-order for this variable */
/* to point to a brand new and empty CAN message */
extern can_message can_new_msg;
/* This function is for the CAN Controller to pass received messages to the CAN Drivers */
extern void __can_add_to_receive_queue(can_message* msg);
/* Do not use this function unless you really want to, otherwise use can_accept() */
void __can_accept(
uint16_t filter1, uint16_t filter2, uint16_t filter3,
uint16_t mask
);
/* This function is for initializing the CAN drivers, and should not be called */
/* by the user unless in a unit test */
void __can_initialization(
void(*can_setup_func)(spi_bus, io_pin, io_pin, uint16_t[], uint16_t[]),
void(*can_poll_func)(void),
void(*can_transmit_func)(can_message*)
);
/* Allows for an optional number of parameters on can_accept */
#define __can_accept_0() /* Nothing */
#define __can_accept_1(filter1) __can_accept((uint16_t)filter1, CAN_DEFAULT_FILTER, CAN_DEFAULT_FILTER, CAN_DEFAULT_MASK);
#define __can_accept_2(filter1, filter2) __can_accept((uint16_t)filter1, (uint16_t)filter2, CAN_DEFAULT_FILTER, CAN_DEFAULT_MASK)
#define __can_accept_3(filter1, filter2, filter3) __can_accept((uint16_t)filter1, (uint16_t)filter2, (uint16_t)filter3, CAN_DEFAULT_MASK)
#define __can_accept_4(filter1, filter2, filter3, mask) __can_accept((uint16_t)filter1, (uint16_t)filter2, (uint16_t)filter3, (uint16_t)mask)
#define __can_accept_6(filter1, filter2, filter3, filter4, filter5, filter6) __can_accept_3(filter1, filter2, filter3); __can_accept_3(filter4, filter5, filter6)
#define __can_accept_7(filter1, filter2, filter3, filter4, filter5, filter6, mask) __can_accept_4(filter1, filter2, filter3, mask); __can_accept_4(filter4, filter5, filter6, mask)
#endif