]> rtime.felk.cvut.cz Git - arc.git/blob - include/Can.h
Merged with dem-dev
[arc.git] / include / Can.h
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16
17
18
19
20
21
22
23 #ifndef CAN_H_\r
24 #define CAN_H_\r
25 \r
26 #define CAN_VENDOR_ID                       1\r
27 #define CAN_MODULE_ID                       MODULE_ID_CAN\r
28 #define CAN_AR_MAJOR_VERSION  2\r
29 #define CAN_AR_MINOR_VERSION    2\r
30 #define CAN_AR_PATCH_VERSION    2
31 \r
32 #define CAN_SW_MAJOR_VERSION    1\r
33 #define CAN_SW_MINOR_VERSION    0\r
34 #define CAN_SW_PATCH_VERSION    0\r
35 \r
36 #define CAN_E_PARAM_POINTER     0x01\r
37 #define CAN_E_PARAM_HANDLE     0x02\r
38 #define CAN_E_PARAM_DLC         0x03\r
39 #define CAN_E_PARAM_CONTROLLER 0x04\r
40 // API service used without initialization\r
41 #define CAN_E_UNINIT           0x05\r
42 // Init transition for current mode\r
43 #define CAN_E_TRANSITION       0x06\r
44 \r
45 \r
46 #include "Std_Types.h"\r
47 #include "CanIf_Types.h"\r
48 #include "ComStack_Types.h"\r
49 #include "Mcu.h"\r
50 \r
51 typedef struct {\r
52         uint32 txSuccessCnt;\r
53         uint32 rxSuccessCnt;\r
54         uint32 txErrorCnt;\r
55         uint32 rxErrorCnt;\r
56         uint32 boffCnt;\r
57         uint32 fifoOverflow;\r
58         uint32 fifoWarning;\r
59 } Can_Arc_StatisticsType;\r
60 \r
61 \r
62 // uint16: if only Standard IDs are used\r
63 // uint32: if also Extended IDs are used\r
64 typedef uint32 Can_IdType;\r
65 \r
66 /* Good things to know\r
67  * L-PDU  - Link PDU\r
68  *\r
69  *\r
70  */\r
71 \r
72 typedef struct Can_PduType_s {\r
73         // the CAN ID, 29 or 11-bit\r
74         Can_IdType      id;\r
75         // Length, max 8 bytes\r
76         uint8           length;\r
77         // data ptr\r
78         uint8           *sdu;\r
79         // private data for CanIf,just save and use for callback\r
80         PduIdType   swPduHandle;\r
81 } Can_PduType;\r
82 \r
83 \r
84 typedef enum {\r
85         CAN_T_START,\r
86         CAN_T_STOP,\r
87         CAN_T_SLEEP,\r
88         CAN_T_WAKEUP\r
89 } Can_StateTransitionType;\r
90 \r
91 typedef enum {\r
92         CAN_OK,\r
93         CAN_NOT_OK,\r
94         CAN_BUSY,\r
95 //      CAN_WAKEUP,             // Removed in 3.0\r
96 } Can_ReturnType;\r
97 \r
98 /* Error from  CAN controller */\r
99 typedef union {\r
100         volatile uint32_t R;\r
101      struct {\r
102          volatile uint32_t:24;\r
103          volatile uint32_t BIT1ERR:1;\r
104          volatile uint32_t BIT0ERR:1;\r
105          volatile uint32_t ACKERR:1;\r
106          volatile uint32_t CRCERR:1;\r
107          volatile uint32_t FRMERR:1;\r
108          volatile uint32_t STFERR:1;\r
109          volatile uint32_t TXWRN:1;\r
110          volatile uint32_t RXWRN:1;\r
111      } B;\r
112  } Can_Arc_ErrorType;\r
113 \r
114 // Each controller has 32 hth's, so the division of 32 will give the\r
115 // controller.\r
116 #define GET_CANCONTROLLER(a) (a / HTH_DIVIDER)\r
117 \r
118 #include "Can_Cfg.h"\r
119 \r
120 void Can_Init( const Can_ConfigType *Config );\r
121 void Can_DeInit();\r
122 \r
123 #if ( CAN_VERSION_INFO_API == STD_ON )\r
124 #define Can_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CAN)\r
125 #endif\r
126 \r
127 void Can_InitController( uint8 controller, const Can_ControllerConfigType *config);\r
128 Can_ReturnType Can_SetControllerMode( uint8 Controller, Can_StateTransitionType transition );\r
129 void Can_DisableControllerInterrupts( uint8 controller );\r
130 void Can_EnableControllerInterrupts( uint8 controller );\r
131 // Hth - for Flexcan, the hardware message box number... .We don't care\r
132 \r
133 \r
134 Can_ReturnType Can_Write( Can_Arc_HTHType hth, Can_PduType *pduInfo );\r
135 \r
136 void Can_Cbk_CheckWakeup( uint8 controller );\r
137 void Can_MainFunction_Write( void );\r
138 void Can_MainFunction_Read( void );\r
139 void Can_MainFunction_BusOff( void );\r
140 void Can_MainFunction_Wakeup( void );\r
141 \r
142 void Can_Arc_GetStatistics( uint8 controller, Can_Arc_StatisticsType * stat);\r
143 \r
144 #endif /*CAN_H_*/\r