Apollo  6.0
Open source self driving car software
zynq_api.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include "bcan_defs.h"
20 
21 #define ZYNQ_MOD_VER "1.6.1.2"
22 
23 #define ZYNQ_DRV_NAME "zynq"
24 
25 #define ZYNQ_DEV_NAME_FW "zynq_fw"
26 #define ZYNQ_DEV_NAME_TRIGGER "zynq_trigger"
27 #define ZYNQ_DEV_NAME_GPS "zynq_gps"
28 #define ZYNQ_DEV_NAME_REG "zynq_reg"
29 #define ZYNQ_DEV_NAME_CAN "zynq_can"
30 
31 /*
32  * ioctl argument definition for CAN send/recv
33  */
34 typedef struct ioc_bcan_msg {
36  unsigned int ioc_msg_num;
37  unsigned int ioc_msg_num_done;
41 
42 /*
43  * CAN error and status
44  */
45 typedef struct ioc_bcan_status_err {
46  unsigned int bcan_status;
47  unsigned int bcan_err_status;
48  unsigned int bcan_err_count;
51 
52 /* ioctl command list */
53 #define ZYNQ_IOC_MAGIC ('z' << 12 | 'y' << 8 | 'n' << 4 | 'q')
55 
69 };
70 
74  IOC_FW_PL_UPDATE, /* PL FPGA FW image update */
75  IOC_FW_PS_UPDATE, /* PS OS image update */
76  IOC_FW_GET_VER, /* get the image version */
78 };
79 
81  IOC_CAN_TX_TIMEOUT_SET = IOC_FW_CMD_MAX, /* in milli-seconds */
82  IOC_CAN_RX_TIMEOUT_SET, /* in milli-seconds */
97 };
98 
106 };
107 
114 };
115 
116 /* GPS update ioctl cmds */
117 #define ZYNQ_GPS_VAL_SZ 12
118 #define ZYNQ_IOC_GPS_GET _IOR(ZYNQ_IOC_MAGIC, IOC_GPS_GET, unsigned char *)
119 #define ZYNQ_GPS_GPRMC_VAL_SZ 68
120 #define ZYNQ_IOC_GPS_GPRMC_GET \
121  _IOR(ZYNQ_IOC_MAGIC, IOC_GPS_GPRMC_GET, unsigned char *)
122 
123 /* Trigger ioctl cmds */
124 #define ZYNQ_IOC_TRIGGER_DISABLE \
125  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_DISABLE, unsigned long)
126 #define ZYNQ_IOC_TRIGGER_ENABLE_GPS \
127  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_GPS, unsigned long)
128 #define ZYNQ_IOC_TRIGGER_ENABLE_NOGPS \
129  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_NOGPS, unsigned long)
130 #define ZYNQ_IOC_TRIGGER_ENABLE_ONE_GPS \
131  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_ONE_GPS, unsigned long)
132 #define ZYNQ_IOC_TRIGGER_ENABLE_ONE_NOGPS \
133  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_ONE_NOGPS, unsigned long)
134 #define ZYNQ_IOC_TRIGGER_TIMESTAMP \
135  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_TIMESTAMP, unsigned long)
136 #define ZYNQ_IOC_TRIGGER_STATUS _IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS, int *)
137 #define ZYNQ_IOC_TRIGGER_STATUS_GPS \
138  _IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS_GPS, int *)
139 #define ZYNQ_IOC_TRIGGER_STATUS_PPS \
140  _IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS_PPS, int *)
141 #define ZYNQ_IOC_TRIGGER_FPS_SET \
142  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_FPS_SET, int *)
143 #define ZYNQ_IOC_TRIGGER_FPS_GET \
144  _IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_FPS_GET, int *)
145 
146 /* supported GrassHopper fps */
147 #define GH_FPS_30_DEFAULT 0 /* 30Hz */
148 #define GH_FPS_20 1 /* 20Hz */
149 #define GH_FPS_15 2 /* 15Hz */
150 #define GH_FPS_10 3 /* 10Hz */
151 /* supported Leopard Imaging fps */
152 #define LI_FPS_30_DEFAULT 0 /* 30Hz */
153 #define LI_FPS_20 1 /* 20Hz */
154 #define LI_FPS_15 2 /* 15Hz */
155 #define LI_FPS_10 3 /* 10Hz */
156 /* supported BumbleBee fps */
157 #define BB_FPS_15_DEFAULT 0 /* 15Hz */
158 #define BB_FPS_14 1 /* 14Hz */
159 #define BB_FPS_16 2 /* 16Hz */
160 /* supported LadyBug fps */
161 #define LD_FPS_5_DEFAULT 0 /* 5Hz */
162 #define LD_FPS_7 1 /* 7Hz */
163 #define LD_FPS_9 2 /* 9Hz */
164 /* adv_trigger specify fps in format of <GH><LI><BB><LD> */
165 #define ZYNQ_FPS_GH(fps) ((fps >> 12) & 0xf)
166 #define ZYNQ_FPS_LI(fps) ((fps >> 8) & 0xf)
167 #define ZYNQ_FPS_BB(fps) ((fps >> 4) & 0xf)
168 #define ZYNQ_FPS_LD(fps) (fps & 0xf)
169 #define ZYNQ_FPS_KEEP 0xf
170 #define ZYNQ_FPS_KEEP_ALL 0xffff
171 #define ZYNQ_FPS_ALL_DEFAULT 0
172 #define ZYNQ_FPS_LI_DEFAULT 0xf0ff
173 /* Set LI fps only and keep other fps unchanged: 0xf */
174 #define ZYNQ_FPS_SET_LI_ONLY(li_fps) (0xf0ff | (li_fps << 8))
175 #define ZYNQ_FPS_VALIDATE_FAIL(fps) \
176  ((ZYNQ_FPS_GH(fps) > 3 && ZYNQ_FPS_GH(fps) != ZYNQ_FPS_KEEP) || \
177  (ZYNQ_FPS_LI(fps) > 3 && ZYNQ_FPS_LI(fps) != ZYNQ_FPS_KEEP) || \
178  (ZYNQ_FPS_BB(fps) > 2 && ZYNQ_FPS_BB(fps) != ZYNQ_FPS_KEEP) || \
179  (ZYNQ_FPS_LD(fps) > 2 && ZYNQ_FPS_LD(fps) != ZYNQ_FPS_KEEP))
180 
181 /* FW update ioctl cmds */
182 #define ZYNQ_FW_PADDING 0x00000000
183 #define ZYNQ_FW_MSG_SZ 16
184 typedef struct ioc_zynq_fw_upload {
185  /*
186  * image data size must be multiple of 4 as each polling transfer is in
187  * 16-byte, so padding the data if needed.
188  */
189  unsigned int *ioc_zynq_fw_data;
190  unsigned int ioc_zynq_fw_num;
191  unsigned int ioc_zynq_fw_done;
194 
195 #define ZYNQ_IOC_FW_IMAGE_UPLOAD_START \
196  _IOW(ZYNQ_IOC_MAGIC, IOC_FW_IMAGE_UPLOAD_START, unsigned long)
197 #define ZYNQ_IOC_FW_IMAGE_UPLOAD \
198  _IOW(ZYNQ_IOC_MAGIC, IOC_FW_IMAGE_UPLOAD, ioc_zynq_fw_upload_t *)
199 #define ZYNQ_IOC_FW_PL_UPDATE \
200  _IOW(ZYNQ_IOC_MAGIC, IOC_FW_PL_UPDATE, unsigned long)
201 #define ZYNQ_IOC_FW_PS_UPDATE \
202  _IOW(ZYNQ_IOC_MAGIC, IOC_FW_PS_UPDATE, unsigned long)
203 #define ZYNQ_IOC_FW_GET_VER _IOW(ZYNQ_IOC_MAGIC, IOC_FW_GET_VER, unsigned int *)
204 
205 /* CAN channel ioctl cmds */
206 #define ZYNQ_IOC_CAN_TX_TIMEOUT_SET \
207  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_TX_TIMEOUT_SET, unsigned long)
208 
209 #define ZYNQ_IOC_CAN_RX_TIMEOUT_SET \
210  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_RX_TIMEOUT_SET, unsigned long)
211 
212 #define ZYNQ_IOC_CAN_DEV_START \
213  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_START, unsigned long)
214 
215 #define ZYNQ_IOC_CAN_DEV_STOP \
216  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_STOP, unsigned long)
217 
218 #define ZYNQ_IOC_CAN_DEV_RESET \
219  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_RESET, unsigned long)
220 
221 #define ZYNQ_IOC_CAN_ID_ADD _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_ID_ADD, unsigned long)
222 
223 #define ZYNQ_IOC_CAN_ID_DEL _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_ID_DEL, unsigned long)
224 
225 #define ZYNQ_IOC_CAN_BAUDRATE_SET \
226  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_BAUDRATE_SET, unsigned long)
227 
228 #define ZYNQ_IOC_CAN_BAUDRATE_GET \
229  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_BAUDRATE_GET, unsigned long)
230 
231 #define ZYNQ_IOC_CAN_LOOPBACK_SET \
232  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_LOOPBACK_SET, unsigned long)
233 
234 #define ZYNQ_IOC_CAN_LOOPBACK_UNSET \
235  _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_LOOPBACK_UNSET, unsigned long)
236 
237 #define ZYNQ_IOC_CAN_RECV _IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_RECV, ioc_bcan_msg_t *)
238 
239 #define ZYNQ_IOC_CAN_SEND _IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_SEND, ioc_bcan_msg_t *)
240 
241 #define ZYNQ_IOC_CAN_SEND_HIPRI \
242  _IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_SEND_HIPRI, ioc_bcan_msg_t *)
243 
244 #define ZYNQ_IOC_CAN_GET_STATUS_ERR \
245  _IOR(ZYNQ_IOC_MAGIC, IOC_CAN_GET_STATUS_ERR, ioc_bcan_status_err_t *)
246 
247 /* register read/write ioctl cmds */
248 typedef struct ioc_zynq_reg_acc {
249  unsigned int reg_bar;
250  unsigned int reg_offset;
251  unsigned int reg_data;
253 
254 /* I2C ID definitions */
255 #define ZYNQ_I2C_ID_JANUS 0x5c
256 #define ZYNQ_I2C_ID_MAX 0x7f /* 7-bit */
257 
258 typedef struct ioc_zynq_i2c_acc {
259  unsigned char i2c_id; /* 7-bit */
260  unsigned char i2c_addr;
261  unsigned char i2c_data;
263 
264 #define ZYNQ_IOC_REG_READ \
265  _IOR(ZYNQ_IOC_MAGIC, IOC_REG_READ, ioc_zynq_reg_acc_t *)
266 #define ZYNQ_IOC_REG_WRITE \
267  _IOW(ZYNQ_IOC_MAGIC, IOC_REG_WRITE, ioc_zynq_reg_acc_t *)
268 #define ZYNQ_IOC_REG_I2C_READ \
269  _IOR(ZYNQ_IOC_MAGIC, IOC_REG_I2C_READ, ioc_zynq_i2c_acc_t *)
270 #define ZYNQ_IOC_REG_I2C_WRITE \
271  _IOW(ZYNQ_IOC_MAGIC, IOC_REG_I2C_WRITE, ioc_zynq_i2c_acc_t *)
272 /* wait for GPS/PPS status change event notification */
273 #define ZYNQ_IOC_REG_GPSPPS_EVENT_WAIT \
274  _IOW(ZYNQ_IOC_MAGIC, IOC_REG_GPSPPS_EVENT_WAIT, unsigned long)
struct ioc_bcan_msg ioc_bcan_msg_t
Definition: zynq_api.h:54
struct ioc_zynq_i2c_acc ioc_zynq_i2c_acc_t
Definition: zynq_api.h:77
Definition: zynq_api.h:57
Definition: zynq_api.h:110
Definition: zynq_api.h:94
Definition: zynq_api.h:58
Definition: zynq_api.h:64
Definition: zynq_api.h:34
Definition: zynq_api.h:84
Definition: zynq_api.h:104
Definition: zynq_api.h:54
unsigned int reg_bar
Definition: zynq_api.h:249
Definition: zynq_api.h:65
Definition: zynq_api.h:103
Definition: zynq_api.h:62
unsigned int bcan_status
Definition: zynq_api.h:46
Definition: zynq_api.h:85
Definition: zynq_api.h:111
Definition: zynq_api.h:89
ZYNQ_IOC_REG_CMD
Definition: zynq_api.h:99
unsigned int bcan_err_status
Definition: zynq_api.h:47
Definition: zynq_api.h:258
Definition: zynq_api.h:248
unsigned int reg_data
Definition: zynq_api.h:251
Definition: zynq_api.h:100
Definition: zynq_api.h:87
unsigned int bcan_err_count
Definition: zynq_api.h:48
unsigned char i2c_id
Definition: zynq_api.h:259
Definition: zynq_api.h:81
struct ioc_zynq_reg_acc ioc_zynq_reg_acc_t
Definition: zynq_api.h:67
Definition: zynq_api.h:88
Definition: zynq_api.h:63
ZYNQ_IOC_TRIGGER_CMD
Definition: zynq_api.h:56
Definition: zynq_api.h:102
Definition: zynq_api.h:83
zynq_baudrate_val
Definition: zynq_api.h:108
Definition: zynq_api.h:76
unsigned int ioc_msg_num
Definition: zynq_api.h:36
unsigned char i2c_data
Definition: zynq_api.h:261
Definition: zynq_api.h:93
Definition: zynq_api.h:59
Definition: zynq_api.h:101
struct ioc_zynq_fw_upload ioc_zynq_fw_upload_t
Definition: zynq_api.h:95
unsigned int ioc_zynq_fw_done
Definition: zynq_api.h:191
Definition: zynq_api.h:92
Definition: zynq_api.h:73
Definition: zynq_api.h:60
Definition: zynq_api.h:184
bcan_msg_t * ioc_msgs
Definition: zynq_api.h:35
Definition: zynq_api.h:54
Definition: zynq_api.h:82
Definition: zynq_api.h:86
Definition: zynq_api.h:113
Definition: zynq_api.h:75
unsigned int reg_offset
Definition: zynq_api.h:250
int ioc_msg_rx_clear
Definition: zynq_api.h:39
Definition: zynq_api.h:74
unsigned int * ioc_zynq_fw_data
Definition: zynq_api.h:189
Definition: zynq_api.h:45
Definition: zynq_api.h:72
Definition: zynq_api.h:66
int bcan_ioc_err
Definition: zynq_api.h:49
Definition: zynq_api.h:61
Definition: zynq_api.h:91
Definition: bcan_defs.h:28
Definition: zynq_api.h:105
Definition: zynq_api.h:90
Definition: zynq_api.h:68
int ioc_zynq_fw_err
Definition: zynq_api.h:192
ZYNQ_IOC_GPS_CMD
Definition: zynq_api.h:54
unsigned char i2c_addr
Definition: zynq_api.h:260
int ioc_msg_err
Definition: zynq_api.h:38
Definition: zynq_api.h:96
ZYNQ_IOC_CAN_CMD
Definition: zynq_api.h:80
unsigned int ioc_zynq_fw_num
Definition: zynq_api.h:190
struct ioc_bcan_status_err ioc_bcan_status_err_t
ZYNQ_IOC_FW_CMD
Definition: zynq_api.h:71
Definition: zynq_api.h:112
unsigned int ioc_msg_num_done
Definition: zynq_api.h:37
Definition: zynq_api.h:109