Altera HWLIB  16.0
The Altera HW Manager API Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator 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: //depot/embedded/rel/15.0/ip/hps/altera_hps/hwlib/include/alt_can.h#1 $
35  */
36 
41 #ifndef __ALT_CAN_H__
42 #define __ALT_CAN_H__
43 
44 #include "hwlib.h"
45 #include "alt_clock_manager.h"
46 #include "socal/alt_can.h"
47 #include "socal/alt_rstmgr.h"
48 #include "socal/hps.h"
49 #include "socal/socal.h"
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif /* __cplusplus */
55 
56 /******************************************************************************/
98 typedef enum ALT_CAN_TMOD_e
99 {
103 
108 {
128 
132 typedef struct ALT_CAN_MAILBOX_PARAM_s
133 {
134  uint32_t id;
135  uint32_t mask;
138  uint32_t dlc;
140  bool init_done;
143  bool extend;
149  bool remote;
157 }
159 
160 
164 #define ALT_CAN_MAILBOXES_COUNT (128)
165 
169 #define ALT_CAN_DEFAULT_BAUDRATE (100000)
170 
171 /******************************************************************************/
172 /*
173  * A pointer or handle to the CAN controller device instance. The ALT_CAN_DEV_t is
174  * initialized by a call to alt_can_init() and subsequently used by the other CAN
175  * controller API functions as a reference to a specified device.
176  *
177  * \internal
178  * ALT_CAN_DEV_t may be a struct or reference to an opaque data
179  * structure. Whatever "internal" type is suited to the needs of the
180  * implementation.
181  * \endinternal
182  */
183 typedef struct ALT_CAN_DEV_s
184 {
185  void * location;
187 }
188 ALT_CAN_DEV_t;
189 
193 typedef enum ALT_CAN_CTLR_e
194 {
195  ALT_CAN_CAN0 = (int)ALT_CAN0_OFST,
196  ALT_CAN_CAN1 = (int)ALT_CAN1_OFST,
198 
203 {
204  ALT_CAN_INTERFACE_READ = (int)ALT_CAN_MSGIF_IF1CMR_OFST,
205  ALT_CAN_INTERFACE_WRITE = (int)ALT_CAN_MSGIF_IF2CMR_OFST,
207 
212 {
213  ALT_CAN_TEST_SILENT = 0,
214  ALT_CAN_TEST_LOOP_BACK = 1,
215  ALT_CAN_TEST_MIXED = 2,
217 
222 {
271 
275 typedef struct ALT_CAN_STATUS_s
276 {
283  bool tx_success;
289  bool rx_success;
295  bool err_passive;
298  bool warning;
301  bool bus_off;
302  bool par_error;
306 }
308 
312 typedef struct ALT_CAN_BITTIME_s {
313  uint32_t brp;
317  uint32_t sjw;
321  uint32_t tseg1;
323  uint32_t tseg2;
325  uint32_t brpe;
331 }
333 
337 typedef struct ALT_CAN_MSG_PARAM_s
338 {
339  bool auto_inc;
353  bool DMA_active;
355  bool data_B;
363  bool data_A;
388  bool clr_int_pnd;
399  bool control;
409  bool arbitration;
419  bool mask;
429  bool write;
435 }
437 
441 typedef struct ALT_CAN_MSG_MSK_s
442 {
443  uint32_t mask;
447  bool direction;
451  bool extended;
455 }
457 
461 typedef struct ALT_CAN_MSG_ARB_s
462 {
463  uint32_t id;
467  bool direction;
474  bool extended;
480  bool valid;
488 }
490 
494 typedef struct ALT_CAN_MSG_IFMCTR_s
495 {
496  uint32_t data_len;
506  bool block_end;
510  bool tx_rqst;
514  bool remote;
517  bool rx_int;
521  bool tx_int;
525  bool accept_mask;
536  bool int_pending;
542  bool msg_lost;
547  bool new_data;
551 }
553 
558 {
589 
594 {
595  uint32_t tx_error_counter;
598  uint32_t rx_error_counter;
604 }
606 
629 ALT_STATUS_CODE alt_can_init(const ALT_CAN_CTLR_t can, ALT_CAN_DEV_t *can_dev);
630 
647 ALT_STATUS_CODE alt_can_reset(ALT_CAN_DEV_t * can_dev);
648 
666 ALT_STATUS_CODE alt_can_disable(ALT_CAN_DEV_t *can_dev);
667 
686 ALT_STATUS_CODE alt_can_enable(ALT_CAN_DEV_t *can_dev);
687 
700 ALT_STATUS_CODE alt_can_is_enabled(ALT_CAN_DEV_t *can_dev);
701 
717 ALT_STATUS_CODE alt_can_baudrate_set(ALT_CAN_DEV_t * can_dev, const uint32_t bitrate);
718 
735 ALT_STATUS_CODE alt_can_uninit(ALT_CAN_DEV_t *can_dev);
736 
764 ALT_STATUS_CODE alt_can_int_disable(ALT_CAN_DEV_t *can_dev, const uint8_t mask);
765 
793 ALT_STATUS_CODE alt_can_int_enable(ALT_CAN_DEV_t *can_dev, const uint8_t mask);
794 
811 ALT_STATUS_CODE alt_can_int_ident_get(ALT_CAN_DEV_t *can_dev, uint32_t * interrupt);
812 
830 ALT_STATUS_CODE alt_can_int_status_get(ALT_CAN_DEV_t *can_dev);
831 
848 ALT_STATUS_CODE alt_can_bit_timing_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_BITTIME_t * params);
849 
866 ALT_STATUS_CODE alt_can_bit_timing_set(ALT_CAN_DEV_t * can_dev,ALT_CAN_BITTIME_t * bittime);
867 
886 ALT_STATUS_CODE alt_can_rate_to_bittime(ALT_CAN_DEV_t *can_dev, uint32_t bitrate,
887  ALT_CAN_BITTIME_t * bittime);
900 ALT_STATUS_CODE alt_can_test_mode_disable(ALT_CAN_DEV_t *can_dev);
901 
918 ALT_STATUS_CODE alt_can_test_mode_enable(ALT_CAN_DEV_t *can_dev, ALT_CAN_TEST_TYPE_t type);
919 
935 ALT_STATUS_CODE alt_can_test_mode_is_enabled(ALT_CAN_DEV_t *can_dev, ALT_CAN_TEST_TYPE_t * type);
936 
953 ALT_STATUS_CODE alt_can_error_counter_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_ERROR_COUNTER_t* counter);
954 
971 ALT_STATUS_CODE alt_can_status_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_STATUS_t * status);
972 
996 ALT_STATUS_CODE alt_can_if_cmd_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
997  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
998 
1018 ALT_STATUS_CODE alt_can_if_mask_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1019  ALT_CAN_MSG_MSK_t * mask_param);
1020 
1040 ALT_STATUS_CODE alt_can_if_mask_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1041  ALT_CAN_MSG_MSK_t * mask_param);
1042 
1062 ALT_STATUS_CODE alt_can_if_arb_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1063  ALT_CAN_MSG_ARB_t * arb_param);
1064 
1084 ALT_STATUS_CODE alt_can_if_arb_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1085  ALT_CAN_MSG_ARB_t * arb_param);
1086 
1106 ALT_STATUS_CODE alt_can_if_msg_ctrl_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1107  ALT_CAN_MSG_IFMCTR_t * ctrl);
1108 
1128 ALT_STATUS_CODE alt_can_if_msg_ctrl_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1129  ALT_CAN_MSG_IFMCTR_t * ctrl);
1130 
1152 ALT_STATUS_CODE alt_can_if_data_set(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1153  uint32_t dataA, uint32_t dataB);
1154 
1178 ALT_STATUS_CODE alt_can_if_data_get(ALT_CAN_DEV_t * can_dev, ALT_CAN_INTERFACE_t if_index,
1179  uint32_t * dataA, uint32_t * dataB);
1180 
1199 ALT_STATUS_CODE alt_can_mailbox_reset(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1200  uint32_t msg_obj_num);
1201 
1218 ALT_STATUS_CODE alt_can_message_is_busy(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index);
1219 
1242 ALT_STATUS_CODE alt_can_message_put(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1243  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
1244 
1267 ALT_STATUS_CODE alt_can_message_get(ALT_CAN_DEV_t *can_dev, ALT_CAN_INTERFACE_t if_index,
1268  uint32_t msg_obj_num, ALT_CAN_MSG_PARAM_t * cmd_params);
1269 
1301 ALT_STATUS_CODE alt_can_mailbox_init(ALT_CAN_DEV_t *can_dev,
1302  uint32_t msg_obj_num,
1303  uint32_t id,
1304  uint32_t id_mask,
1305  ALT_CAN_TMOD_t transfer_mode,
1306  ALT_CAN_FIFO_MODE_t fifo_mode);
1307 
1323 ALT_STATUS_CODE alt_can_mailbox_uninit(ALT_CAN_DEV_t *can_dev, uint32_t msg_obj_num);
1324 
1337 ALT_STATUS_CODE alt_can_mailboxes_reset(ALT_CAN_DEV_t *can_dev);
1338 
1360 ALT_STATUS_CODE alt_can_frame_read(ALT_CAN_DEV_t *can_dev,
1361  uint32_t msg_obj_num,
1362  void * buffer,
1363  uint32_t *frame_size);
1364 
1383 ALT_STATUS_CODE alt_can_frame_write(ALT_CAN_DEV_t *can_dev,
1384  uint32_t msg_obj_num,
1385  void * buffer);
1386 
1413 ALT_STATUS_CODE alt_can_data_read(ALT_CAN_DEV_t *can_dev,
1414  uint32_t msg_obj_num,
1415  void * buffer,
1416  uint32_t size,
1417  uint32_t * bytes_read);
1418 
1440 ALT_STATUS_CODE alt_can_data_write(ALT_CAN_DEV_t *can_dev,
1441  uint32_t msg_obj_num,
1442  void * buffer,
1443  uint32_t size);
1444 
1449 #ifdef __cplusplus
1450 }
1451 #endif /* __cplusplus */
1452 #endif /* __ALT_CAN_H__ */