1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
21 #define CAN_VENDOR_ID 1
\r
22 #define CAN_MODULE_ID MODULE_ID_CAN
\r
23 #define CAN_AR_MAJOR_VERSION 2
\r
24 #define CAN_AR_MINOR_VERSION 2
\r
25 #define CAN_AR_PATCH_VERSION 2
\r
27 #define CAN_SW_MAJOR_VERSION 1
\r
28 #define CAN_SW_MINOR_VERSION 0
\r
29 #define CAN_SW_PATCH_VERSION 0
\r
31 #define CAN_E_PARAM_POINTER 0x01
\r
32 #define CAN_E_PARAM_HANDLE 0x02
\r
33 #define CAN_E_PARAM_DLC 0x03
\r
34 #define CAN_E_PARAM_CONTROLLER 0x04
\r
35 // API service used without initialization
\r
36 #define CAN_E_UNINIT 0x05
\r
37 // Init transition for current mode
\r
38 #define CAN_E_TRANSITION 0x06
\r
40 #define CAN_E_DATALOST 0x07 /** @req 4.0.3/CAN395 */
\r
42 /** @name Service id's */
\r
44 #define CAN_INIT_SERVICE_ID 0x00
\r
45 #define CAN_MAINFUNCTION_WRITE_SERVICE_ID 0x01
\r
46 #define CAN_INITCONTROLLER_SERVICE_ID 0x02
\r
47 #define CAN_SETCONTROLLERMODE_SERVICE_ID 0x03
\r
48 #define CAN_DISABLECONTROLLERINTERRUPTS_SERVICE_ID 0x04
\r
49 #define CAN_ENABLECONTROLLERINTERRUPTS_SERVICE_ID 0x05
\r
50 #define CAN_WRITE_SERVICE_ID 0x06
\r
51 #define CAN_GETVERSIONINFO_SERVICE_ID 0x07
\r
52 #define CAN_MAINFUNCTION_READ_SERVICE_ID 0x08
\r
53 #define CAN_MAINFUNCTION_BUSOFF_SERVICE_ID 0x09
\r
54 #define CAN_MAINFUNCTION_WAKEUP_SERVICE_ID 0x0a
\r
55 #define CAN_CBK_CHECKWAKEUP_SERVICE_ID 0x0b
\r
59 #if defined(CFG_PPC)
\r
62 #define CAN_HOH_FIFO_MASK (1UL<<0)
\r
63 //#define CAN_HOH_EOL_MASK (1<<9)
\r
65 /* Controller flags */
\r
66 #define CAN_CTRL_RX_PROCESSING_INTERRUPT (1UL<<0)
\r
67 #define CAN_CTRL_RX_PROCESSING_POLLING 0
\r
68 #define CAN_CTRL_TX_PROCESSING_INTERRUPT (1UL<<1)
\r
69 #define CAN_CTRL_TX_PROCESSING_POLLING 0
\r
70 #define CAN_CTRL_WAKEUP_PROCESSING_INTERRUPT (1UL<<2)
\r
71 #define CAN_CTRL_WAKEUP_PROCESSING_POLLING 0
\r
72 #define CAN_CTRL_BUSOFF_PROCESSING_INTERRUPT (1UL<<3)
\r
73 #define CAN_CTRL_BUSOFF_PROCESSING_POLLING 0
\r
74 #define CAN_CTRL_ACTIVATION (1UL<<4)
\r
76 #define CAN_CTRL_LOOPBACK (1UL<<5)
\r
77 #define CAN_CTRL_FIFO (1UL<<6)
\r
81 #include "Std_Types.h"
\r
82 #include "CanIf_Types.h"
\r
83 #include "ComStack_Types.h"
\r
88 uint32 txSuccessCnt;
\r
89 uint32 rxSuccessCnt;
\r
93 uint32 fifoOverflow;
\r
95 } Can_Arc_StatisticsType;
\r
98 // uint16: if only Standard IDs are used
\r
99 // uint32: if also Extended IDs are used
\r
100 typedef uint32 Can_IdType;
\r
102 /* Good things to know
\r
108 typedef struct Can_PduType_s {
\r
109 // the CAN ID, 29 or 11-bit
\r
111 // Length, max 8 bytes
\r
115 // private data for CanIf,just save and use for callback
\r
116 PduIdType swPduHandle;
\r
125 } Can_StateTransitionType;
\r
131 // CAN_WAKEUP, // Removed in 3.0
\r
134 /* Error from CAN controller */
\r
136 volatile uint32_t R;
\r
138 volatile uint32_t:24;
\r
139 volatile uint32_t BIT1ERR:1;
\r
140 volatile uint32_t BIT0ERR:1;
\r
141 volatile uint32_t ACKERR:1;
\r
142 volatile uint32_t CRCERR:1;
\r
143 volatile uint32_t FRMERR:1;
\r
144 volatile uint32_t STFERR:1;
\r
145 volatile uint32_t TXWRN:1;
\r
146 volatile uint32_t RXWRN:1;
\r
148 } Can_Arc_ErrorType;
\r
152 #if defined(CFG_PPC)
\r
156 CAN_ID_TYPE_EXTENDED,
\r
158 CAN_ID_TYPE_STANDARD
\r
162 CAN_ARC_HANDLE_TYPE_BASIC,
\r
163 CAN_ARC_HANDLE_TYPE_FULL
\r
167 typedef struct Can_Callback {
\r
168 void (*CancelTxConfirmation)( const Can_PduType *);
\r
169 void (*RxIndication)( uint8 ,Can_IdType ,uint8 , const uint8 * );
\r
170 void (*ControllerBusOff)(uint8);
\r
171 void (*TxConfirmation)(PduIdType);
\r
172 void (*ControllerWakeup)(uint8);
\r
173 void (*Arc_Error)(uint8,Can_Arc_ErrorType);
\r
174 } Can_CallbackType;
\r
177 #include "Can_Cfg.h"
\r
180 typedef struct Can_HardwareObjectStruct {
\r
181 /* PC/PB, Specifies the type (Full-CAN or Basic-CAN) of a hardware object. */
\r
182 Can_Arc_HohType CanHandleType;
\r
184 /* PC/PB, Specifies whether the IdValue is of type - standard identifier - extended
\r
185 * identifier - mixed mode ImplementationType: Can_IdType */
\r
186 Can_IdTypeType CanIdType;
\r
188 /* PC/PB Specifies (together with the filter mask) the identifiers range that passes
\r
189 * the hardware filter. */
\r
192 /* PC/PB Holds the handle ID of HRH or HTH. The value of this parameter is unique
\r
193 * in a given CAN Driver, and it should start with 0 and continue without any
\r
194 * gaps. The HRH and HTH Ids are defined under two different name-spaces.
\r
195 * Example: HRH0-0, HRH1-1, HTH0-2, HTH1-3 */
\r
196 uint32 CanObjectId;
\r
198 /* PC/PB, Specifies if the HardwareObject is used as Transmit or as Receive object */
\r
199 Can_ObjectTypeType CanObjectType;
\r
201 /* Reference to CAN Controller to which the HOH is associated to. */
\r
202 uint8 Can_ControllerRef;
\r
204 /* PC/PB Reference to the filter mask that is used for hardware filtering togerther
\r
205 * with the CAN_ID_VALUE */
\r
206 Can_FilterMaskType *CanFilterMaskRef;
\r
208 /* PC, See CAN_HOH_XX macros */
\r
209 uint32 Can_Arc_Flags;
\r
211 /* PC, Number of mailboxes that is owned by this HOH */
\r
212 // uint8 ArcCanNumMailboxes;
\r
213 uint64 ArcMailboxMask;
\r
214 } Can_HardwareObjectType;
\r
218 typedef struct Can_ControllerConfig {
\r
220 bool CanControllerActivation;
\r
222 // Specifies the buadrate of the controller in kbps.
\r
223 uint32 CanControllerBaudRate;
\r
225 // This parameter provides the controller ID which is unique in a given CAN
\r
226 // Driver. The value for this parameter starts with 0 and continue without any
\r
229 CanControllerIdType CanControllerId;
\r
231 // Specifies propagation delay in time quantas.
\r
232 uint8 CanControllerPropSeg;
\r
234 // Specifies phase segment 1 in time quantas.
\r
235 uint8 CanControllerSeg1;
\r
237 // Specifies phase segment 2 in time quantas.
\r
238 uint8 CanControllerSeg2;
\r
240 // Specifies the time quanta for the controller. The calculation of the resulting
\r
241 // prescaler value depending on module clocking and time quanta shall be
\r
242 // done offline Hardware specific.
\r
243 // uint32 CanControllerTimeQuanta;
\r
245 // Reference to the CPU clock configuration, which is set in the MCU driver
\r
247 uint32 CanCpuClockRef;
\r
249 // This parameter contains a reference to the Wakeup Source for this
\r
250 // controller as defined in the ECU State Manager. Implementation Type:
\r
251 // reference to EcuM_WakeupSourceType
\r
252 uint32 CanWakeupSourceRef;
\r
254 /* Flags, See CAN_CTRL_XX macros */
\r
255 uint32 Can_Arc_Flags;
\r
257 /* Number of FIFO MB in the HOH list */
\r
258 uint8 Can_Arc_HohFifoCnt;
\r
260 /* Total number of HOHs in Can_Arc_Hoh */
\r
261 uint8 Can_Arc_HohCnt;
\r
263 // List of Hoh id's that belong to this controller
\r
264 const Can_HardwareObjectType * const Can_Arc_Hoh;
\r
266 uint64 Can_Arc_RxMailBoxMask;
\r
267 uint64 Can_Arc_TxMailBoxMask;
\r
269 const uint8 * const Can_Arc_MailBoxToHrh;
\r
271 PduIdType * const Can_Arc_TxPduHandles;
\r
273 uint8 Can_Arc_TxMailboxStart;
\r
275 uint8 Can_Arc_MailboxMax;
\r
280 boolean Can_Arc_Loopback;
\r
282 // Set this to use the fifo
\r
283 boolean Can_Arc_Fifo;
\r
286 } Can_ControllerConfigType;
\r
290 #include "Can_Cfg.h"
\r
292 #endif /* defined(PPC) */
\r
294 // Each controller has 32 hth's, so the division of 32 will give the
\r
296 #define GET_CANCONTROLLER(a) (a / HTH_DIVIDER)
\r
299 void Can_Init( const Can_ConfigType *Config );
\r
300 void Can_DeInit(void);
\r
302 #if ( CAN_VERSION_INFO_API == STD_ON )
\r
303 #define Can_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CAN)
\r
306 void Can_InitController( uint8 controller, const Can_ControllerConfigType *config);
\r
307 Can_ReturnType Can_SetControllerMode( uint8 Controller, Can_StateTransitionType transition );
\r
308 void Can_DisableControllerInterrupts( uint8 controller );
\r
309 void Can_EnableControllerInterrupts( uint8 controller );
\r
310 // Hth - for Flexcan, the hardware message box number... .We don't care
\r
313 Can_ReturnType Can_Write( Can_Arc_HTHType hth, Can_PduType *pduInfo );
\r
315 void Can_Cbk_CheckWakeup( uint8 controller );
\r
316 void Can_MainFunction_Write( void );
\r
317 void Can_MainFunction_Read( void );
\r
318 void Can_MainFunction_BusOff( void );
\r
319 void Can_MainFunction_Wakeup( void );
\r
321 void Can_Arc_GetStatistics( uint8 controller, Can_Arc_StatisticsType * stat);
\r