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
164
165
166
167
168
169
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <stdint.h>
#include "hal/CANAPITypes.h"
#include "hal/Types.h"
/**
* @defgroup hal_canapi CAN API Functions
* @ingroup hal_capi
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Reads the current value of the millisecond-resolution timer that the CAN API
* functions use as a time base.
*
* @return Current value of timer used as a base time by the CAN API in
* milliseconds.
*/
uint32_t HAL_GetCANPacketBaseTime(void);
/**
* Initializes a CAN device.
*
* These follow the FIRST standard CAN layout.
* https://docs.wpilib.org/en/stable/docs/software/can-devices/can-addressing.html
*
* @param[in] manufacturer the can manufacturer
* @param[in] deviceId the device ID (0-63)
* @param[in] deviceType the device type
* @param[out] status Error status variable. 0 on success.
* @return the created CAN handle
*/
HAL_CANHandle HAL_InitializeCAN(HAL_CANManufacturer manufacturer,
int32_t deviceId, HAL_CANDeviceType deviceType,
int32_t* status);
/**
* Frees a CAN device
*
* @param handle the CAN handle
*/
void HAL_CleanCAN(HAL_CANHandle handle);
/**
* Writes a packet to the CAN device with a specific ID.
*
* This ID is 10 bits.
*
* @param[in] handle the CAN handle
* @param[in] data the data to write (0-8 bytes)
* @param[in] length the length of data (0-8)
* @param[in] apiId the ID to write (0-1023 bits)
* @param[out] status Error status variable. 0 on success.
*/
void HAL_WriteCANPacket(HAL_CANHandle handle, const uint8_t* data,
int32_t length, int32_t apiId, int32_t* status);
/**
* Writes a repeating packet to the CAN device with a specific ID.
*
* This ID is 10 bits.
*
* The RoboRIO will automatically repeat the packet at the specified interval
*
* @param[in] handle the CAN handle
* @param[in] data the data to write (0-8 bytes)
* @param[in] length the length of data (0-8)
* @param[in] apiId the ID to write (0-1023)
* @param[in] repeatMs the period to repeat in ms
* @param[out] status Error status variable. 0 on success.
*/
void HAL_WriteCANPacketRepeating(HAL_CANHandle handle, const uint8_t* data,
int32_t length, int32_t apiId,
int32_t repeatMs, int32_t* status);
/**
* Writes an RTR frame of the specified length to the CAN device with the
* specific ID.
*
* By spec, the length must be equal to the length sent by the other device,
* otherwise behavior is unspecified.
*
* @param[in] handle the CAN handle
* @param[in] length the length of data to request (0-8)
* @param[in] apiId the ID to write (0-1023)
* @param[out] status Error status variable. 0 on success.
*/
void HAL_WriteCANRTRFrame(HAL_CANHandle handle, int32_t length, int32_t apiId,
int32_t* status);
/**
* Stops a repeating packet with a specific ID.
*
* This ID is 10 bits.
*
* @param[in] handle the CAN handle
* @param[in] apiId the ID to stop repeating (0-1023)
* @param[out] status Error status variable. 0 on success.
*/
void HAL_StopCANPacketRepeating(HAL_CANHandle handle, int32_t apiId,
int32_t* status);
/**
* Reads a new CAN packet.
*
* This will only return properly once per packet received. Multiple calls
* without receiving another packet will return an error code.
*
* @param[in] handle the CAN handle
* @param[in] apiId the ID to read (0-1023)
* @param[out] data the packet data (8 bytes)
* @param[out] length the received length (0-8 bytes)
* @param[out] receivedTimestamp the packet received timestamp in ms (based off
* of CLOCK_MONOTONIC)
* @param[out] status Error status variable. 0 on success.
*/
void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
int32_t* length, uint64_t* receivedTimestamp,
int32_t* status);
/**
* Reads a CAN packet. The will continuously return the last packet received,
* without accounting for packet age.
*
* @param[in] handle the CAN handle
* @param[in] apiId the ID to read (0-1023)
* @param[out] data the packet data (8 bytes)
* @param[out] length the received length (0-8 bytes)
* @param[out] receivedTimestamp the packet received timestamp in ms (based off
* of CLOCK_MONOTONIC)
* @param[out] status Error status variable. 0 on success.
*/
void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
int32_t* length, uint64_t* receivedTimestamp,
int32_t* status);
/**
* Reads a CAN packet. The will return the last packet received until the
* packet is older then the requested timeout. Then it will return an error
* code.
*
* @param[in] handle the CAN handle
* @param[in] apiId the ID to read (0-1023)
* @param[out] data the packet data (8 bytes)
* @param[out] length the received length (0-8 bytes)
* @param[out] receivedTimestamp the packet received timestamp in ms (based off
* of CLOCK_MONOTONIC)
* @param[out] timeoutMs the timeout time for the packet
* @param[out] status Error status variable. 0 on success.
*/
void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId,
uint8_t* data, int32_t* length,
uint64_t* receivedTimestamp, int32_t timeoutMs,
int32_t* status);
#ifdef __cplusplus
} // extern "C"
#endif
/** @} */