Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : 91x_can.h |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
||
5 | * Description : This file contains all the functions prototypes for the |
||
6 | * CAN bus software library. |
||
7 | ******************************************************************************** |
||
8 | * History: |
||
9 | * 05/22/2007 : Version 1.2 |
||
10 | * 05/24/2006 : Version 1.1 |
||
11 | * 05/18/2006 : Version 1.0 |
||
12 | ******************************************************************************** |
||
13 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
||
14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
||
15 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
||
16 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
||
17 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
18 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
19 | *******************************************************************************/ |
||
20 | |||
21 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
22 | #ifndef __91x_CAN_H |
||
23 | #define __91x_CAN_H |
||
24 | |||
25 | /* Includes ------------------------------------------------------------------*/ |
||
26 | #include "91x_map.h" |
||
27 | |||
28 | /* Exported types ------------------------------------------------------------*/ |
||
29 | |||
30 | /* CAN Init structure define */ |
||
31 | typedef struct |
||
32 | { |
||
33 | u8 CAN_ConfigParameters; |
||
34 | u32 CAN_Bitrate; |
||
35 | }CAN_InitTypeDef; |
||
36 | |||
37 | /* Exported constants --------------------------------------------------------*/ |
||
38 | /* Standard bitrates available*/ |
||
39 | enum |
||
40 | { |
||
41 | CAN_BITRATE_100K, |
||
42 | CAN_BITRATE_125K, |
||
43 | CAN_BITRATE_250K, |
||
44 | CAN_BITRATE_500K, |
||
45 | CAN_BITRATE_1M |
||
46 | }; |
||
47 | |||
48 | /* Control register*/ |
||
49 | #define CAN_CR_TEST 0x0080 |
||
50 | #define CAN_CR_CCE 0x0040 |
||
51 | #define CAN_CR_DAR 0x0020 |
||
52 | #define CAN_CR_EIE 0x0008 |
||
53 | #define CAN_CR_SIE 0x0004 |
||
54 | #define CAN_CR_IE 0x0002 |
||
55 | #define CAN_CR_INIT 0x0001 |
||
56 | |||
57 | /* Status register */ |
||
58 | #define CAN_SR_BOFF 0x0080 |
||
59 | #define CAN_SR_EWARN 0x0040 |
||
60 | #define CAN_SR_EPASS 0x0020 |
||
61 | #define CAN_SR_RXOK 0x0010 |
||
62 | #define CAN_SR_TXOK 0x0008 |
||
63 | #define CAN_SR_LEC 0x0007 |
||
64 | |||
65 | /* Test register*/ |
||
66 | #define CAN_TESTR_RX 0x0080 |
||
67 | #define CAN_TESTR_TX1 0x0040 |
||
68 | #define CAN_TESTR_TX0 0x0020 |
||
69 | #define CAN_TESTR_LBACK 0x0010 |
||
70 | #define CAN_TESTR_SILENT 0x0008 |
||
71 | #define CAN_TESTR_BASIC 0x0004 |
||
72 | |||
73 | /* IFn / Command Request register*/ |
||
74 | #define CAN_CRR_BUSY 0x8000 |
||
75 | |||
76 | /* IFn / Command Mask register*/ |
||
77 | #define CAN_CMR_WRRD 0x0080 |
||
78 | #define CAN_CMR_MASK 0x0040 |
||
79 | #define CAN_CMR_ARB 0x0020 |
||
80 | #define CAN_CMR_CONTROL 0x0010 |
||
81 | #define CAN_CMR_CLRINTPND 0x0008 |
||
82 | #define CAN_CMR_TXRQSTNEWDAT 0x0004 |
||
83 | #define CAN_CMR_DATAA 0x0002 |
||
84 | #define CAN_CMR_DATAB 0x0001 |
||
85 | |||
86 | /* IFn / Mask 2 register*/ |
||
87 | #define CAN_M2R_MXTD 0x8000 |
||
88 | #define CAN_M2R_MDIR 0x4000 |
||
89 | |||
90 | /* IFn / Arbitration 2 register*/ |
||
91 | #define CAN_A2R_MSGVAL 0x8000 |
||
92 | #define CAN_A2R_XTD 0x4000 |
||
93 | #define CAN_A2R_DIR 0x2000 |
||
94 | |||
95 | /* IFn / Message Control register*/ |
||
96 | #define CAN_MCR_NEWDAT 0x8000 |
||
97 | #define CAN_MCR_MSGLST 0x4000 |
||
98 | #define CAN_MCR_INTPND 0x2000 |
||
99 | #define CAN_MCR_UMASK 0x1000 |
||
100 | #define CAN_MCR_TXIE 0x0800 |
||
101 | #define CAN_MCR_RXIE 0x0400 |
||
102 | #define CAN_MCR_RMTEN 0x0200 |
||
103 | #define CAN_MCR_TXRQST 0x0100 |
||
104 | #define CAN_MCR_EOB 0x0080 |
||
105 | |||
106 | |||
107 | /* Wake-up modes*/ |
||
108 | enum |
||
109 | { |
||
110 | CAN_WAKEUP_ON_EXT, |
||
111 | CAN_WAKEUP_ON_CAN |
||
112 | }; |
||
113 | |||
114 | |||
115 | /* CAN message structure*/ |
||
116 | typedef struct |
||
117 | { |
||
118 | u32 IdType; |
||
119 | u32 Id; |
||
120 | u8 Dlc; |
||
121 | u8 Data[8]; |
||
122 | } canmsg; |
||
123 | |||
124 | /* Message ID types*/ |
||
125 | enum |
||
126 | { |
||
127 | CAN_STD_ID, |
||
128 | CAN_EXT_ID |
||
129 | }; |
||
130 | |||
131 | /* Message ID limits*/ |
||
132 | |||
133 | #define CAN_LAST_STD_ID ((1<<11) - 1) |
||
134 | #define CAN_LAST_EXT_ID ((1L<<29) - 1) |
||
135 | |||
136 | /* Exported functions ------------------------------------------------------- */ |
||
137 | |||
138 | void CAN_Init (CAN_InitTypeDef *CAN_InitStruct); |
||
139 | void CAN_DeInit (void); |
||
140 | void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct); |
||
141 | void CAN_SetBitrate(u32 bitrate); |
||
142 | void CAN_SetTiming(u32 tseg1, u32 tseg2, u32 sjw, u32 brp); |
||
143 | ErrorStatus CAN_SetUnusedMsgObj(u32 msgobj); |
||
144 | ErrorStatus CAN_SetTxMsgObj(u32 msgobj, u32 idType); |
||
145 | ErrorStatus CAN_SetRxMsgObj(u32 msgobj, u32 idType, u32 idLow, u32 idHigh, bool singleOrFifoLast); |
||
146 | void CAN_InvalidateAllMsgObj(void); |
||
147 | ErrorStatus CAN_ReleaseMessage(u32 msgobj); |
||
148 | ErrorStatus CAN_SendMessage(u32 msgobj, canmsg* pCanMsg); |
||
149 | ErrorStatus CAN_ReceiveMessage(u32 msgobj, bool release, canmsg* pCanMsg); |
||
150 | ErrorStatus CAN_WaitEndOfTx(void); |
||
151 | ErrorStatus CAN_BasicSendMessage(canmsg* pCanMsg); |
||
152 | ErrorStatus CAN_BasicReceiveMessage(canmsg* pCanMsg); |
||
153 | void CAN_EnterTestMode(u8 TestMask); |
||
154 | void CAN_EnterInitMode(u8 InitMask); |
||
155 | void CAN_LeaveInitMode(void); |
||
156 | void CAN_LeaveTestMode(void); |
||
157 | void CAN_ReleaseTxMessage(u32 msgobj); |
||
158 | void CAN_ReleaseRxMessage(u32 msgobj); |
||
159 | u32 CAN_IsMessageWaiting(u32 msgobj); |
||
160 | u32 CAN_IsTransmitRequested(u32 msgobj); |
||
161 | u32 CAN_IsInterruptPending(u32 msgobj); |
||
162 | u32 CAN_IsObjectValid(u32 msgobj); |
||
163 | |||
164 | #endif /* __91x_CAN_H */ |
||
165 | |||
166 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |