Hardware Libraries  20.1
Arria 10 SoC Hardware Manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
alt_can.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright 2014 Altera Corporation. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************/
32 
33 /*
34  * $Id: //acds/rel/20.1/embedded/ip/hps/altera_hps/hwlib/include/alt_can.h#1 $
35  */
36 
41 /* Only include this code for Cyclone V / Arria V */
42 #if defined(soc_cv_av)
43 
44 #ifndef __ALT_CAN_H__
45 #define __ALT_CAN_H__
46 
47 #include "hwlib.h"
48 #include "alt_clock_manager.h"
49 #include "socal/alt_can.h"
50 #include "socal/alt_rstmgr.h"
51 #include "socal/hps.h"
52 #include "socal/socal.h"
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif /* __cplusplus */
58 
59 /******************************************************************************/
101 typedef enum ALT_CAN_TMOD_e
102 {
103  ALT_CAN_TMOD_TX = 0,
104  ALT_CAN_TMOD_RX = 1
105 } ALT_CAN_TMOD_t;
106 
110 typedef enum ALT_CAN_FIFO_MODE_e
111 {
112  ALT_CAN_FIFO_MODE_SINGLE_MSG,
118  ALT_CAN_FIFO_MODE_BUFFER_NOT_LAST,
124  ALT_CAN_FIFO_MODE_BUFFER_LAST
130 } ALT_CAN_FIFO_MODE_t;
131 
135 typedef struct ALT_CAN_MAILBOX_PARAM_s
136 {
137  uint32_t id;
138  uint32_t mask;
141  uint32_t dlc;
142  ALT_CAN_TMOD_t transfer_mode;
143  bool init_done;
146  bool extend;
152  bool remote;
158  ALT_CAN_FIFO_MODE_t fifo_mode;
160 }
161 ALT_CAN_MAILBOX_PARAM_t;
162 
163 
167 #define ALT_CAN_MAILBOXES_COUNT (128)
168 
172 #define ALT_CAN_DEFAULT_BAUDRATE (100000)
173 
174 /******************************************************************************/
175 /*
176  * A pointer or handle to the CAN controller device instance. The ALT_CAN_DEV_t is
177  * initialized by a call to alt_can_init() and subsequently used by the other CAN
178  * controller API functions as a reference to a specified device.
179  *
180  * \internal
181  * ALT_CAN_DEV_t may be a struct or reference to an opaque data
182  * structure. Whatever "internal" type is suited to the needs of the
183  * implementation.
184  * \endinternal
185  */
186 typedef struct ALT_CAN_DEV_s
187 {
188  void * location;
189  ALT_CAN_MAILBOX_PARAM_t mailboxes[ALT_CAN_MAILBOXES_COUNT];
190 }
191 ALT_CAN_DEV_t;
192 
196 typedef enum ALT_CAN_CTLR_e
197 {
198  ALT_CAN_CAN0 = (int)ALT_CAN0_OFST,
199  ALT_CAN_CAN1 = (int)ALT_CAN1_OFST
200 } ALT_CAN_CTLR_t;
201 
205 typedef enum ALT_CAN_INTERFACE_e
206 {
207  ALT_CAN_INTERFACE_READ = (int)ALT_CAN_MSGIF_IF1CMR_OFST,
208  ALT_CAN_INTERFACE_WRITE = (int)ALT_CAN_MSGIF_IF2CMR_OFST
209 } ALT_CAN_INTERFACE_t;
210 
214 typedef enum ALT_CAN_TEST_TYPE_e
215 {
216  ALT_CAN_TEST_SILENT = 0,
217  ALT_CAN_TEST_LOOP_BACK = 1,
218  ALT_CAN_TEST_MIXED = 2
219 } ALT_CAN_TEST_TYPE_t;
220 
224 typedef enum ALT_CAN_LAST_ERROR_e
225 {
226  ALT_CAN_STAT_ERROR_NOERROR,
229  ALT_CAN_STAT_ERROR_STUFF,
234  ALT_CAN_STAT_ERROR_FORM,
238  ALT_CAN_STAT_ERROR_ACK,
242  ALT_CAN_STAT_ERROR_BIT1,
249  ALT_CAN_STAT_ERROR_BIT0,
262  ALT_CAN_STAT_ERROR_CRC,
267  ALT_CAN_STAT_ERROR_NOCNG
273 } ALT_CAN_LAST_ERROR_t;
274 
278 typedef struct ALT_CAN_STATUS_s
279 {
280  ALT_CAN_LAST_ERROR_t last_err_code;
286  bool tx_success;
292  bool rx_success;
298  bool err_passive;
301  bool warning;
304  bool bus_off;
305  bool par_error;
309 }
310 ALT_CAN_STATUS_t;
311 
315 typedef struct ALT_CAN_BITTIME_s {
316  uint32_t brp;
320  uint32_t sjw;
324  uint32_t tseg1;
326  uint32_t tseg2;
328  uint32_t brpe;
334 }
335 ALT_CAN_BITTIME_t;
336 
340 typedef struct ALT_CAN_MSG_PARAM_s
341 {
342  bool auto_inc;
356  bool DMA_active;
358  bool data_B;
366  bool data_A;
374  bool tx_rqst_new_dat;
391  bool clr_int_pnd;
402  bool control;
412  bool arbitration;
422  bool mask;
432  bool write;
435  bool clr_auto_inc;
438 } __attribute__((aligned(4))) ALT_CAN_MSG_PARAM_t;
439 
443 typedef struct ALT_CAN_MSG_MSK_s
444 {
445  uint32_t mask;
449  bool direction;
453  bool extended;
457 }
458 ALT_CAN_MSG_MSK_t;
459 
463 typedef struct ALT_CAN_MSG_ARB_s
464 {
465  uint32_t id;
469  bool direction;
476  bool extended;
482  bool valid;
490 } __attribute__((aligned(4))) ALT_CAN_MSG_ARB_t;
491 
495 typedef struct ALT_CAN_MSG_IFMCTR_s
496 {
497  uint32_t data_len;
507  bool block_end;
511  bool tx_rqst;
515  bool remote;
518  bool rx_int;
522  bool tx_int;
526  bool accept_mask;
537  bool int_pending;
543  bool msg_lost;
548  bool new_data;
552 } __attribute__((aligned(4))) ALT_CAN_MSG_IFMCTR_t;
553 
557 typedef enum ALT_CAN_INT_GROUP_e
558 {
559  ALT_CAN_INT_GROUP_MOD_LINE = 1UL << 0,
567  ALT_CAN_INT_GROUP_STATUS = 1UL << 1,
574  ALT_CAN_INT_GROUP_ERROR = 1UL << 2,
580  ALT_CAN_INT_GROUP_MSG_LINE = 1UL << 3,
585  ALT_CAN_INT_GROUP_ALL = 0xF
588 } ALT_CAN_INT_GROUP_t;
589 
593 typedef struct ALT_CAN_ERROR_COUNTER_s
594 {
595  uint32_t tx_error_counter;
598  uint32_t rx_error_counter;
601  bool rx_above_passive;
604 } __attribute__((aligned(4))) ALT_CAN_ERROR_COUNTER_t;
605 
628 ALT_STATUS_CODE alt_can_init(const ALT_CAN_CTLR_t can, ALT_CAN_DEV_t *can_dev);
629 
646 ALT_STATUS_CODE alt_can_reset(ALT_CAN_DEV_t * can_dev);
647 
665 ALT_STATUS_CODE alt_can_disable(ALT_CAN_DEV_t *can_dev);
666 
685 ALT_STATUS_CODE alt_can_enable(ALT_CAN_DEV_t *can_dev);
686 
699 ALT_STATUS_CODE alt_can_is_enabled(ALT_CAN_DEV_t *can_dev);
700 
716 ALT_STATUS_CODE alt_can_baudrate_set(ALT_CAN_DEV_t * can_dev, const uint32_t bitrate);
717 
734 ALT_STATUS_CODE alt_can_uninit(ALT_CAN_DEV_t *can_dev);
735 
763 ALT_STATUS_CODE alt_can_int_disable(ALT_CAN_DEV_t *can_dev, const uint8_t mask);
764 
792 ALT_STATUS_CODE alt_can_int_enable(ALT_CAN_DEV_t *can_dev, const uint8_t mask);
793 
810 ALT_STATUS_CODE alt_can_int_ident_get(ALT_CAN_DEV_t *can_dev, uint32_t * interrupt);
811 
829 ALT_STATUS_CODE alt_can_int_status_get(ALT_CAN_DEV_t *can_dev);
830 
847 ALT_STATUS_CODE alt_can_bit_timing_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_BITTIME_t * params);
848 
865 ALT_STATUS_CODE alt_can_bit_timing_set(ALT_CAN_DEV_t * can_dev,ALT_CAN_BITTIME_t * bittime);
866 
885 ALT_STATUS_CODE alt_can_rate_to_bittime(ALT_CAN_DEV_t *can_dev, uint32_t bitrate,
886  ALT_CAN_BITTIME_t * bittime);
899 ALT_STATUS_CODE alt_can_test_mode_disable(ALT_CAN_DEV_t *can_dev);
900 
917 ALT_STATUS_CODE alt_can_test_mode_enable(ALT_CAN_DEV_t *can_dev, ALT_CAN_TEST_TYPE_t type);
918 
934 ALT_STATUS_CODE alt_can_test_mode_is_enabled(ALT_CAN_DEV_t *can_dev, ALT_CAN_TEST_TYPE_t * type);
935 
952 ALT_STATUS_CODE alt_can_error_counter_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_ERROR_COUNTER_t* counter);
953 
970 ALT_STATUS_CODE alt_can_status_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_STATUS_t * status);
971 
995 ALT_STATUS_CODE alt_can_if_cmd_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
996  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
997 
1017 ALT_STATUS_CODE alt_can_if_mask_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1018  ALT_CAN_MSG_MSK_t * mask_param);
1019 
1039 ALT_STATUS_CODE alt_can_if_mask_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1040  ALT_CAN_MSG_MSK_t * mask_param);
1041 
1061 ALT_STATUS_CODE alt_can_if_arb_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1062  ALT_CAN_MSG_ARB_t * arb_param);
1063 
1083 ALT_STATUS_CODE alt_can_if_arb_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1084  ALT_CAN_MSG_ARB_t * arb_param);
1085 
1105 ALT_STATUS_CODE alt_can_if_msg_ctrl_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1106  ALT_CAN_MSG_IFMCTR_t * ctrl);
1107 
1127 ALT_STATUS_CODE alt_can_if_msg_ctrl_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1128  ALT_CAN_MSG_IFMCTR_t * ctrl);
1129 
1151 ALT_STATUS_CODE alt_can_if_data_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1152  uint32_t dataA, uint32_t dataB);
1153 
1177 ALT_STATUS_CODE alt_can_if_data_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1178  uint32_t * dataA, uint32_t * dataB);
1179 
1198 ALT_STATUS_CODE alt_can_mailbox_reset(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1199  uint32_t msg_obj_num);
1200 
1217 ALT_STATUS_CODE alt_can_message_is_busy(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index);
1218 
1241 ALT_STATUS_CODE alt_can_message_put(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1242  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
1243 
1266 ALT_STATUS_CODE alt_can_message_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1267  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
1268 
1300 ALT_STATUS_CODE alt_can_mailbox_init(ALT_CAN_DEV_t *can_dev,
1301  uint32_t msg_obj_num,
1302  uint32_t id,
1303  uint32_t id_mask,
1304  ALT_CAN_TMOD_t transfer_mode,
1305  ALT_CAN_FIFO_MODE_t fifo_mode);
1306 
1338 ALT_STATUS_CODE alt_can_mailbox_ext_id_init(ALT_CAN_DEV_t *can_dev,
1339  uint32_t msg_obj_num,
1340  uint32_t id,
1341  uint32_t id_mask,
1342  ALT_CAN_TMOD_t transfer_mode,
1343  ALT_CAN_FIFO_MODE_t fifo_mode);
1344 
1360 ALT_STATUS_CODE alt_can_mailbox_uninit(ALT_CAN_DEV_t *can_dev, uint32_t msg_obj_num);
1361 
1374 ALT_STATUS_CODE alt_can_mailboxes_reset(ALT_CAN_DEV_t *can_dev);
1375 
1397 ALT_STATUS_CODE alt_can_frame_read(ALT_CAN_DEV_t *can_dev,
1398  uint32_t msg_obj_num,
1399  void * buffer,
1400  uint32_t *frame_size);
1401 
1420 ALT_STATUS_CODE alt_can_frame_write(ALT_CAN_DEV_t *can_dev,
1421  uint32_t msg_obj_num,
1422  void * buffer);
1423 
1450 ALT_STATUS_CODE alt_can_data_read(ALT_CAN_DEV_t *can_dev,
1451  uint32_t msg_obj_num,
1452  void * buffer,
1453  uint32_t size,
1454  uint32_t * bytes_read);
1455 
1477 ALT_STATUS_CODE alt_can_data_write(ALT_CAN_DEV_t *can_dev,
1478  uint32_t msg_obj_num,
1479  void * buffer,
1480  uint32_t size);
1481 
1486 #ifdef __cplusplus
1487 }
1488 #endif /* __cplusplus */
1489 #endif /* __ALT_CAN_H__ */
1490 
1491 #endif /* defined soc_cv_av */
1492