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
79 #define CAN_CTRL_ERROR_PROCESSING_INTERRUPT (1UL<<7)
\r
80 #define CAN_CTRL_ERROR_PROCESSING_POLLING 0
\r
84 #include "Std_Types.h"
\r
85 #include "CanIf_Types.h"
\r
86 #include "ComStack_Types.h"
\r
91 uint32 txSuccessCnt;
\r
92 uint32 rxSuccessCnt;
\r
96 uint32 fifoOverflow;
\r
98 } Can_Arc_StatisticsType;
\r
101 #if defined(CFG_CAN_TEST)
\r
108 // uint16: if only Standard IDs are used
\r
109 // uint32: if also Extended IDs are used
\r
110 typedef uint32 Can_IdType;
\r
112 /* Good things to know
\r
118 typedef struct Can_PduType_s {
\r
119 // the CAN ID, 29 or 11-bit
\r
121 // Length, max 8 bytes
\r
125 // private data for CanIf,just save and use for callback
\r
126 PduIdType swPduHandle;
\r
135 } Can_StateTransitionType;
\r
141 // CAN_WAKEUP, // Removed in 3.0
\r
144 /* Error from CAN controller */
\r
146 volatile uint32_t R;
\r
148 volatile uint32_t:24;
\r
149 volatile uint32_t BIT1ERR:1;
\r
150 volatile uint32_t BIT0ERR:1;
\r
151 volatile uint32_t ACKERR:1;
\r
152 volatile uint32_t CRCERR:1;
\r
153 volatile uint32_t FRMERR:1;
\r
154 volatile uint32_t STFERR:1;
\r
155 volatile uint32_t TXWRN:1;
\r
156 volatile uint32_t RXWRN:1;
\r
158 } Can_Arc_ErrorType;
\r
162 #if defined(CFG_PPC)
\r
166 CAN_ID_TYPE_EXTENDED,
\r
168 CAN_ID_TYPE_STANDARD
\r
172 CAN_ARC_HANDLE_TYPE_BASIC,
\r
173 CAN_ARC_HANDLE_TYPE_FULL
\r
177 typedef struct Can_Callback {
\r
178 void (*CancelTxConfirmation)( const Can_PduType *);
\r
179 void (*RxIndication)( uint8 ,Can_IdType ,uint8 , const uint8 * );
\r
180 void (*ControllerBusOff)(uint8);
\r
181 void (*TxConfirmation)(PduIdType);
\r
182 void (*ControllerWakeup)(uint8);
\r
183 void (*Arc_Error)(uint8,Can_Arc_ErrorType);
\r
184 } Can_CallbackType;
\r
187 #include "Can_Cfg.h"
\r
190 typedef struct Can_HardwareObjectStruct {
\r
191 /* PC/PB, Specifies the type (Full-CAN or Basic-CAN) of a hardware object. */
\r
192 Can_Arc_HohType CanHandleType;
\r
194 /* PC/PB, Specifies whether the IdValue is of type - standard identifier - extended
\r
195 * identifier - mixed mode ImplementationType: Can_IdType */
\r
196 Can_IdTypeType CanIdType;
\r
198 /* PC/PB Specifies (together with the filter mask) the identifiers range that passes
\r
199 * the hardware filter. */
\r
202 /* PC/PB Holds the handle ID of HRH or HTH. The value of this parameter is unique
\r
203 * in a given CAN Driver, and it should start with 0 and continue without any
\r
204 * gaps. The HRH and HTH Ids are defined under two different name-spaces.
\r
205 * Example: HRH0-0, HRH1-1, HTH0-2, HTH1-3 */
\r
206 uint32 CanObjectId;
\r
208 /* PC/PB, Specifies if the HardwareObject is used as Transmit or as Receive object */
\r
209 Can_ObjectTypeType CanObjectType;
\r
211 /* Reference to CAN Controller to which the HOH is associated to. */
\r
212 uint8 Can_ControllerRef;
\r
214 /* PC/PB Reference to the filter mask that is used for hardware filtering togerther
\r
215 * with the CAN_ID_VALUE */
\r
216 Can_FilterMaskType *CanFilterMaskRef;
\r
218 /* PC, See CAN_HOH_XX macros */
\r
219 uint32 Can_Arc_Flags;
\r
221 /* PC, Number of mailboxes that is owned by this HOH */
\r
222 // uint8 ArcCanNumMailboxes;
\r
223 uint64 ArcMailboxMask;
\r
224 } Can_HardwareObjectType;
\r
228 typedef struct Can_ControllerConfig {
\r
230 bool CanControllerActivation;
\r
232 // Specifies the buadrate of the controller in kbps.
\r
233 uint32 CanControllerBaudRate;
\r
235 // This parameter provides the controller ID which is unique in a given CAN
\r
236 // Driver. The value for this parameter starts with 0 and continue without any
\r
239 CanControllerIdType CanControllerId;
\r
241 // Specifies propagation delay in time quantas.
\r
242 uint8 CanControllerPropSeg;
\r
244 // Specifies phase segment 1 in time quantas.
\r
245 uint8 CanControllerSeg1;
\r
247 // Specifies phase segment 2 in time quantas.
\r
248 uint8 CanControllerSeg2;
\r
250 // Specifies the time quanta for the controller. The calculation of the resulting
\r
251 // prescaler value depending on module clocking and time quanta shall be
\r
252 // done offline Hardware specific.
\r
253 // uint32 CanControllerTimeQuanta;
\r
255 // Reference to the CPU clock configuration, which is set in the MCU driver
\r
257 uint32 CanCpuClockRef;
\r
259 // This parameter contains a reference to the Wakeup Source for this
\r
260 // controller as defined in the ECU State Manager. Implementation Type:
\r
261 // reference to EcuM_WakeupSourceType
\r
262 uint32 CanWakeupSourceRef;
\r
264 /* Flags, See CAN_CTRL_XX macros */
\r
265 uint32 Can_Arc_Flags;
\r
267 /* Number of FIFO MB in the HOH list */
\r
268 uint8 Can_Arc_HohFifoCnt;
\r
270 /* Total number of HOHs in Can_Arc_Hoh */
\r
271 uint8 Can_Arc_HohCnt;
\r
273 // List of Hoh id's that belong to this controller
\r
274 const Can_HardwareObjectType * const Can_Arc_Hoh;
\r
276 uint64 Can_Arc_RxMailBoxMask;
\r
277 uint64 Can_Arc_TxMailBoxMask;
\r
279 const uint8 * const Can_Arc_MailBoxToHrh;
\r
281 PduIdType * const Can_Arc_TxPduHandles;
\r
283 uint8 Can_Arc_TxMailboxStart;
\r
285 uint8 Can_Arc_MailboxMax;
\r
290 boolean Can_Arc_Loopback;
\r
292 // Set this to use the fifo
\r
293 boolean Can_Arc_Fifo;
\r
296 } Can_ControllerConfigType;
\r
300 #include "Can_Cfg.h"
\r
302 #endif /* defined(PPC) */
\r
304 // Each controller has 32 hth's, so the division of 32 will give the
\r
306 #define GET_CANCONTROLLER(a) (a / HTH_DIVIDER)
\r
309 void Can_Init( const Can_ConfigType *Config );
\r
310 void Can_DeInit(void);
\r
312 #if ( CAN_VERSION_INFO_API == STD_ON )
\r
313 #define Can_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CAN)
\r
316 void Can_InitController( uint8 controller, const Can_ControllerConfigType *config);
\r
317 Can_ReturnType Can_SetControllerMode( uint8 Controller, Can_StateTransitionType transition );
\r
318 void Can_DisableControllerInterrupts( uint8 controller );
\r
319 void Can_EnableControllerInterrupts( uint8 controller );
\r
320 // Hth - for Flexcan, the hardware message box number... .We don't care
\r
323 Can_ReturnType Can_Write( Can_Arc_HTHType hth, Can_PduType *pduInfo );
\r
325 void Can_Cbk_CheckWakeup( uint8 controller );
\r
326 void Can_MainFunction_Write( void );
\r
327 void Can_MainFunction_Read( void );
\r
328 void Can_MainFunction_BusOff( void );
\r
329 void Can_MainFunction_Error( void );
\r
330 void Can_MainFunction_Wakeup( void );
\r
332 void Can_Arc_GetStatistics( uint8 controller, Can_Arc_StatisticsType * stat);
\r
333 #if defined(CFG_CAN_TEST)
\r
334 Can_TestType *Can_Arc_GetTestInfo( void );
\r