Kinetis SDK v.1.2 Demo Applications User's Guide  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
freemaster_Kxx.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Freescale Semiconductor Inc.
4 * (c) Copyright 2004-2011 Freescale Semiconductor
5 * ALL RIGHTS RESERVED.
6 *
7 ****************************************************************************/
19 #ifndef __FREEMASTER_KXX_H
20 #define __FREEMASTER_KXX_H
21 
22 /******************************************************************************
23  * Supress warnings generated by IAR EWBARM compiler
24  ******************************************************************************/
25 //#pragma diag_suppress=Pe174
26 //#pragma diag_suppress=Pe177
27 //#pragma diag_suppress=Pe174
28 //#pragma diag_suppress=Pe550
29 
30 /******************************************************************************
31  * platform-specific default configuration
32  ******************************************************************************/
33 
34 /* use 32-bit (EX) commands by default */
35 #ifndef FMSTR_USE_EX_CMDS
36 #define FMSTR_USE_EX_CMDS 1
37 #endif
38 
39 /* do not use 16-bit (no-EX) commands by default */
40 #ifndef FMSTR_USE_NOEX_CMDS
41 #define FMSTR_USE_NOEX_CMDS 0
42 #endif
43 
44 /* at least one of EX or no-EX command handling must be enabled */
45 #if !FMSTR_USE_EX_CMDS && !FMSTR_USE_NOEX_CMDS
46  #error At least one of EX or no-EX command handling must be enabled (please set FMSTR_USE_EX_CMDS)
47  #undef FMSTR_USE_EX_CMDS
48  #define FMSTR_USE_EX_CMDS 1
49 #endif
50 
51 /*****************************************************************************
52 * Board configuration information
53 ******************************************************************************/
54 
55 #define FMSTR_PROT_VER 3 /* protocol version 3 */
56 #define FMSTR_CFG_FLAGS 0 /* board info flags */
57 #define FMSTR_CFG_BUS_WIDTH 1 /* data bus width */
58 #define FMSTR_GLOB_VERSION_MAJOR 2 /* driver version */
59 #define FMSTR_GLOB_VERSION_MINOR 0
60 #define FMSTR_IDT_STRING "Kxx FreeMASTER"
61 #define FMSTR_TSA_FLAGS 0
62 
63 /******************************************************************************
64 * platform-specific types
65 ******************************************************************************/
66 
67 typedef unsigned char FMSTR_U8; /* smallest memory entity */
68 typedef unsigned short FMSTR_U16; /* 16bit value */
69 typedef unsigned long FMSTR_U32; /* 32bit value */
70 
71 typedef signed char FMSTR_S8; /* signed 8bit value */
72 typedef signed short FMSTR_S16; /* signed 16bit value */
73 typedef signed long FMSTR_S32; /* signed 32bit value */
74 
75 #if FMSTR_REC_FLOAT_TRIG
76 typedef float FMSTR_FLOAT; /* float value */
77 #endif
78 
79 typedef unsigned char FMSTR_FLAGS; /* type to be union-ed with flags (at least 8 bits) */
80 typedef unsigned char FMSTR_SIZE8; /* one-byte size value */
81 typedef signed short FMSTR_INDEX; /* general for-loop index (must be signed) */
82 
83 typedef unsigned char FMSTR_BCHR; /* type of a single character in comm.buffer */
84 typedef unsigned char* FMSTR_BPTR; /* pointer within a communication buffer */
85 
86 typedef unsigned char FMSTR_SCISR; /* data type to store SCI status register */
87 
88 /******************************************************************************
89 * communication buffer access functions
90 ******************************************************************************/
91 
92 void FMSTR_CopyMemory(FMSTR_ADDR nDestAddr, FMSTR_ADDR nSrcAddr, FMSTR_SIZE8 nSize);
95 void FMSTR_CopyFromBufferWithMask(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR_SIZE8 nSize);
96 
97 /* mixed EX and non-EX commands may occur */
98 #if FMSTR_USE_EX_CMDS && FMSTR_USE_NOEX_CMDS || (FMSTR_BUFFER_ACCESS_BY_FUNCT)
99 void FMSTR_SetExAddr(FMSTR_BOOL bNextAddrIsEx);
100 #else
101 /* otherwise, we always know what addresses are used, (ignore FMSTR_SetExAddr) */
102 #define FMSTR_SetExAddr(bNextAddrIsEx)
103 #endif
104 
105 #if (FMSTR_BUFFER_ACCESS_BY_FUNCT)
110 #endif
111 
112 /*********************************************************************************
113 * communication buffer access functions. Most of them are trivial simple on KXX
114 *********************************************************************************/
115 
116 #define FMSTR_ValueFromBuffer8(pDest, pSrc) \
117  ( (*((FMSTR_U8*)(pDest)) = *(FMSTR_U8*)(pSrc)), (((FMSTR_BPTR)(pSrc))+1) )
118 
119 #if !(FMSTR_BUFFER_ACCESS_BY_FUNCT)
120 #define FMSTR_ValueFromBuffer16(pDest, pSrc) \
121  ( (*((FMSTR_U16*)(pDest)) = *(FMSTR_U16*)(pSrc)), (((FMSTR_BPTR)(pSrc))+2) )
122 
123 #define FMSTR_ValueFromBuffer32(pDest, pSrc) \
124  ( (*((FMSTR_U32*)(pDest)) = *(FMSTR_U32*)(pSrc)), (((FMSTR_BPTR)(pSrc))+4) )
125 #endif
126 
127 #define FMSTR_ValueToBuffer8(pDest, src) \
128  ( (*((FMSTR_U8*)(pDest)) = (FMSTR_U8)(src)), (((FMSTR_BPTR)(pDest))+1) )
129 
130 #if !(FMSTR_BUFFER_ACCESS_BY_FUNCT)
131 #define FMSTR_ValueToBuffer16(pDest, src) \
132  ( (*((FMSTR_U16*)(pDest)) = (FMSTR_U16)(src)), (((FMSTR_BPTR)(pDest))+2) )
133 
134 #define FMSTR_ValueToBuffer32(pDest, src) \
135  ( (*((FMSTR_U32*)(pDest)) = (FMSTR_U32)(src)), (((FMSTR_BPTR)(pDest))+4) )
136 #endif
137 
138 #define FMSTR_SkipInBuffer(pDest, nSize) \
139  ( ((FMSTR_BPTR)(pDest)) + (nSize) )
140 
141 
142 #define FMSTR_ConstToBuffer8 FMSTR_ValueToBuffer8
143 #define FMSTR_ConstToBuffer16 FMSTR_ValueToBuffer16
144 
145 /* EX address used only: fetching 32bit word */
146 #if FMSTR_USE_EX_CMDS && !FMSTR_USE_NOEX_CMDS && !(FMSTR_BUFFER_ACCESS_BY_FUNCT)
147  #define FMSTR_AddressFromBuffer(pDest, pSrc) \
148  FMSTR_ValueFromBuffer32(pDest, pSrc)
149  #define FMSTR_AddressToBuffer(pDest, nAddr) \
150  FMSTR_ValueToBuffer32(pDest, nAddr)
151 
152 /* no-EX address used only: fetching 16bit word */
153 #elif !FMSTR_USE_EX_CMDS && FMSTR_USE_NOEX_CMDS && !(FMSTR_BUFFER_ACCESS_BY_FUNCT)
154  #define FMSTR_AddressFromBuffer(pDest, pSrc) \
155  FMSTR_ValueFromBuffer16(pDest, pSrc)
156  #define FMSTR_AddressToBuffer(pDest, nAddr) \
157  FMSTR_ValueToBuffer16(pDest, nAddr)
158 
159 /* mixed addresses used, need to process it programatically */
160 #else
163 #endif
164 
165 #define FMSTR_GetS8(addr) ( *(FMSTR_S8*)(addr) )
166 #define FMSTR_GetU8(addr) ( *(FMSTR_U8*)(addr) )
167 #define FMSTR_GetS16(addr) ( *(FMSTR_S16*)(addr) )
168 #define FMSTR_GetU16(addr) ( *(FMSTR_U16*)(addr) )
169 #define FMSTR_GetS32(addr) ( *(FMSTR_S32*)(addr) )
170 #define FMSTR_GetU32(addr) ( *(FMSTR_U32*)(addr) )
171 
172 #if FMSTR_REC_FLOAT_TRIG
173 #define FMSTR_GetFloat(addr) ( *(FMSTR_FLOAT*)(addr) )
174 #endif
175 
176 /****************************************************************************************
177 * Other helper macros
178 *****************************************************************************************/
179 
180 /* This macro assigns C pointer to FMSTR_ADDR-typed variable */
181 #define FMSTR_PTR2ADDR(tmpAddr,ptr) ( tmpAddr = (FMSTR_ADDR) (FMSTR_U8*) ptr )
182 #define FMSTR_ARR2ADDR FMSTR_PTR2ADDR
183 
184 /****************************************************************************************
185 * Platform-specific configuration
186 *****************************************************************************************/
187 
188 /* FlexCAN functionality tested on KXX */
189 #define FMSTR_CANHW_FLEXCAN 1
190 
191 /****************************************************************************************
192 * General peripheral space access macros
193 *****************************************************************************************/
194 
195 #define FMSTR_SETREG8(base, offset, value) (*(volatile FMSTR_U8*)(((FMSTR_U32)(base))+(offset)) = value)
196 #define FMSTR_GETREG8(base, offset) (*(volatile FMSTR_U8*)(((FMSTR_U32)(base))+(offset)))
197 #define FMSTR_SETBIT8(base, offset, bit) (*(volatile FMSTR_U8*)(((FMSTR_U32)(base))+(offset)) |= bit)
198 #define FMSTR_CLRBIT8(base, offset, bit) (*(volatile FMSTR_U8*)(((FMSTR_U32)(base))+(offset)) &= (FMSTR_U16)~((FMSTR_U16)(bit)))
199 #define FMSTR_SETREG16(base, offset, value) (*(volatile FMSTR_U16*)(((FMSTR_U32)(base))+(offset)) = value)
200 #define FMSTR_GETREG16(base, offset) (*(volatile FMSTR_U16*)(((FMSTR_U32)(base))+(offset)))
201 #define FMSTR_SETBIT16(base, offset, bit) (*(volatile FMSTR_U16*)(((FMSTR_U32)(base))+(offset)) |= bit)
202 #define FMSTR_CLRBIT16(base, offset, bit) (*(volatile FMSTR_U16*)(((FMSTR_U32)(base))+(offset)) &= (FMSTR_U16)~((FMSTR_U16)(bit)))
203 #define FMSTR_TSTBIT16(base, offset, bit) (*(volatile FMSTR_U16*)(((FMSTR_U32)(base))+(offset)) & (bit))
204 #define FMSTR_SETREG32(base, offset, value) (*(volatile FMSTR_U32*)(((FMSTR_U32)(base))+(offset)) = value)
205 #define FMSTR_GETREG32(base, offset) (*(volatile FMSTR_U32*)(((FMSTR_U32)(base))+(offset)))
206 #define FMSTR_SETBIT32(base, offset, bit) ((*(volatile FMSTR_U32*)(((FMSTR_U32)(base))+(offset))) |= bit)
207 #define FMSTR_CLRBIT32(base, offset, bit) ((*(volatile FMSTR_U32*)(((FMSTR_U32)(base))+(offset))) &= ~(bit))
208 #define FMSTR_TSTBIT32(base, offset, bit) (*(volatile FMSTR_U32*)(((FMSTR_U32)(base))+(offset)) & (bit))
209 
210 /****************************************************************************************
211 * SCI module constants
212 *****************************************************************************************/
213 
214 /* SCI module registers */
215 #define FMSTR_SCIBDH_OFFSET 0
216 #define FMSTR_SCIBDL_OFFSET 1
217 #define FMSTR_SCIC1_OFFSET 2
218 #define FMSTR_SCIC2_OFFSET 3
219 #define FMSTR_SCIS1_OFFSET 4
220 #define FMSTR_SCIS2_OFFSET 5
221 #define FMSTR_SCIC3_OFFSET 6
222 #define FMSTR_SCIDR_OFFSET 7
223 
224 /* SCI Control Register bits */
225 #define FMSTR_SCIC1_LOOPS 0x80
226 #define FMSTR_SCIC1_SWAI 0x40
227 #define FMSTR_SCIC1_RSRC 0x20
228 #define FMSTR_SCIC1_M 0x10
229 #define FMSTR_SCIC1_WAKE 0x08
230 #define FMSTR_SCIC1_ILT 0x04
231 #define FMSTR_SCIC1_PE 0x02
232 #define FMSTR_SCIC1_PT 0x01
233 #define FMSTR_SCIC2_TIE 0x80
234 #define FMSTR_SCIC2_TCIE 0x40
235 #define FMSTR_SCIC2_RIE 0x20
236 #define FMSTR_SCIC2_ILIE 0x10
237 #define FMSTR_SCIC2_TE 0x08
238 #define FMSTR_SCIC2_RE 0x04
239 #define FMSTR_SCIC2_RWU 0x02
240 #define FMSTR_SCIC2_SBK 0x01
241 
242 /* SCI Status registers bits */
243 #define FMSTR_SCISR_TDRE 0x80
244 #define FMSTR_SCISR_TC 0x40
245 #define FMSTR_SCISR_RDRF 0x20
246 #define FMSTR_SCISR_IDLE 0x10
247 #define FMSTR_SCISR_OR 0x08
248 #define FMSTR_SCISR_NF 0x04
249 #define FMSTR_SCISR_FE 0x02
250 #define FMSTR_SCISR_PF 0x01
251 #define FMSTR_SCISR2_BRK13 0x04
252 #define FMSTR_SCISR2_TXDIR 0x02
253 #define FMSTR_SCISR2_RAF 0x01
254 
255 /*******************************************************************************************
256 * SCI access macros
257 *****************************************************************************************/
258 
259 /* transmitter enable/disable */
260 #define FMSTR_SCI_TE() FMSTR_SETBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_TE)
261 #define FMSTR_SCI_TD() FMSTR_CLRBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_TE)
262 
263 /* receiver enable/disable */
264 #define FMSTR_SCI_RE() FMSTR_SETBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_RE)
265 #define FMSTR_SCI_RD() FMSTR_CLRBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_RE)
266 
267 #define FMSTR_SCI_TE_RE() FMSTR_SETBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_RE | FMSTR_SCIC2_TE)
268 
269 /* Transmitter-empty interrupt enable/disable */
270 #define FMSTR_SCI_ETXI() FMSTR_SETBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_TIE)
271 #define FMSTR_SCI_DTXI() FMSTR_CLRBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_TIE)
272 
273 /* Receiver-full interrupt enable/disable */
274 #define FMSTR_SCI_ERXI() FMSTR_SETBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_RIE)
275 #define FMSTR_SCI_DRXI() FMSTR_CLRBIT8(FMSTR_SCI_BASE, FMSTR_SCIC2_OFFSET, FMSTR_SCIC2_RIE)
276 
277 /* Tranmsit character */
278 #define FMSTR_SCI_PUTCHAR(ch) FMSTR_SETREG8(FMSTR_SCI_BASE, FMSTR_SCIDR_OFFSET, ch)
279 
280 /* Get received character */
281 #define FMSTR_SCI_GETCHAR() FMSTR_GETREG8(FMSTR_SCI_BASE, FMSTR_SCIDR_OFFSET)
282 
283 /* read status register */
284 #define FMSTR_SCI_GETSR() FMSTR_GETREG8(FMSTR_SCI_BASE, FMSTR_SCIS1_OFFSET)
285 
286 /* read & clear status register */
287 #define FMSTR_SCI_RDCLRSR() FMSTR_GETREG8(FMSTR_SCI_BASE, FMSTR_SCIS1_OFFSET)
288 
289 /****************************************************************************************
290 * FCAN module constants
291 *****************************************************************************************/
292 
293 /* FCAN module MB CODEs */
294 #define FMSTR_FCANMB_CODE_MASK 0x0F /* defines mask of codes */
295 
296 #define FMSTR_FCANMB_CRXVOID 0x00 /* buffer void after received data read-out */
297 #define FMSTR_FCANMB_CRXEMPTY 0x04 /* active and empty */
298 
299 #define FMSTR_FCANMB_CTXTRANS_ONCE 0x0C /* Initialize transmitting data from buffer */
300 #define FMSTR_FCANMB_CTXREADY 0x08 /* Message buffer not ready for transmit */
301 
302 /* FCAN module registers offsets */
303 #define FMSTR_FCANTMR_OFFSET 0x08
304 #define FMSTR_FCANIER2_OFFSET 0x24
305 #define FMSTR_FCANIER1_OFFSET 0x28
306 #define FMSTR_FCANIFR2_OFFSET 0x2C
307 #define FMSTR_FCANIFR1_OFFSET 0x30
308 #define FMSTR_FCANRXFG_OFFSET (0x80 + ((FMSTR_FLEXCAN_RXMB) * 0x10))
309 #define FMSTR_FCANTXFG_OFFSET (0x80 + ((FMSTR_FLEXCAN_TXMB) * 0x10))
310 
311 /* FCAN MB registers offsets (must also add FCANxxFG_OFFSET) */
312 #define FMSTR_FCMBCSR 0x00
313 #define FMSTR_FCMBIDR0 0x04
314 #define FMSTR_FCMBIDR1 0x05
315 #define FMSTR_FCMBIDR2 0x06
316 #define FMSTR_FCMBIDR3 0x07
317 #define FMSTR_FCMBDSR0 0x0B
318 #define FMSTR_FCMBDSR1 0x0A
319 #define FMSTR_FCMBDSR2 0x09
320 #define FMSTR_FCMBDSR3 0x08
321 #define FMSTR_FCMBDSR4 0x0F
322 #define FMSTR_FCMBDSR5 0x0E
323 #define FMSTR_FCMBDSR6 0x0D
324 #define FMSTR_FCMBDSR7 0x0C
325 
326 /* FCAN CANMSCSR */
327 #define FMSTR_FCANCTRL_IDE 0x20
328 #define FMSTR_FCANCTRL_STD_RTR 0x10
329 #define FMSTR_FCANCTRL_EXT_RTR 0x10
330 #define FMSTR_FCANCTRL_EXT_SRR 0x40
331 
332 /* FCAN ID flags */
333 #define FMSTR_FCANID0_EXT_FLG 0x80
334 
335 /* FCAN: enable/disable CAN RX/TX interrupts */
336 #define FMSTR_FCAN_ETXI() ( ((FMSTR_FLEXCAN_TXMB)&0x20) ? \
337  FMSTR_SETBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER2_OFFSET, (1<<((FMSTR_FLEXCAN_TXMB)-32))):\
338  FMSTR_SETBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER1_OFFSET, (1<<(FMSTR_FLEXCAN_TXMB))) )
339 #define FMSTR_FCAN_DTXI() ( ((FMSTR_FLEXCAN_TXMB)&0x20) ? \
340  FMSTR_CLRBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER2_OFFSET, (1<<((FMSTR_FLEXCAN_TXMB)-32))):\
341  FMSTR_CLRBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER1_OFFSET, (1<<(FMSTR_FLEXCAN_TXMB))) )
342 #define FMSTR_FCAN_ERXI() ( ((FMSTR_FLEXCAN_RXMB)&0x20) ? \
343  FMSTR_SETBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER2_OFFSET, (1<<((FMSTR_FLEXCAN_RXMB)-32))):\
344  FMSTR_SETBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER1_OFFSET, (1<<(FMSTR_FLEXCAN_RXMB))) )
345 #define FMSTR_FCAN_DRXI() ( ((FMSTR_FLEXCAN_RXMB)&0x20) ? \
346  FMSTR_CLRBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER2_OFFSET, (1<<((FMSTR_FLEXCAN_RXMB)-32))):\
347  FMSTR_CLRBIT32(FMSTR_CAN_BASE, FMSTR_FCANIER1_OFFSET, (1<<(FMSTR_FLEXCAN_RXMB))) )
348 
349 /* FCAN: read RX status register */
350 #define FMSTR_FCAN_TEST_RXFLG() ( ((FMSTR_FLEXCAN_RXMB)&0x20) ? \
351  FMSTR_TSTBIT32(FMSTR_CAN_BASE, FMSTR_FCANIFR2_OFFSET, (1<<((FMSTR_FLEXCAN_RXMB)-32))):\
352  FMSTR_TSTBIT32(FMSTR_CAN_BASE, FMSTR_FCANIFR1_OFFSET, (1<<(FMSTR_FLEXCAN_RXMB))) )
353 #define FMSTR_FCAN_CLEAR_RXFLG() ( ((FMSTR_FLEXCAN_RXMB)&0x20) ? \
354  FMSTR_SETREG32(FMSTR_CAN_BASE, FMSTR_FCANIFR2_OFFSET, (1<<((FMSTR_FLEXCAN_RXMB)-32))):\
355  FMSTR_SETREG32(FMSTR_CAN_BASE, FMSTR_FCANIFR1_OFFSET, (1<<(FMSTR_FLEXCAN_RXMB))) )
356 
357 /* FCAN: read TX status register */
358 #define FMSTR_FCAN_TEST_TXFLG() ( ((FMSTR_FLEXCAN_TXMB)&0x20) ? \
359  FMSTR_TSTBIT32(FMSTR_CAN_BASE, FMSTR_FCANIFR2_OFFSET, (1<<((FMSTR_FLEXCAN_TXMB)-32))):\
360  FMSTR_TSTBIT32(FMSTR_CAN_BASE, FMSTR_FCANIFR1_OFFSET, (1<<(FMSTR_FLEXCAN_TXMB))) )
361 
362 /* FCAN: read TX MB status register */
363 #define FMSTR_FCAN_GET_MBSTATUS() (FMSTR_GETREG8(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET + FMSTR_FCMBCSR + 3)&FMSTR_FCANMB_CODE_MASK)
364 
365 /* FCAN: id to idr translation */
366 #define FMSTR_FCAN_MAKEIDR0(id) ((FMSTR_U8)( ((id)&FMSTR_CAN_EXTID) ? ((((id)>>24)&0x1f) | FMSTR_FCANID0_EXT_FLG) : (((id)>>6)&0x1f) ))
367 #define FMSTR_FCAN_MAKEIDR1(id) ((FMSTR_U8)( ((id)&FMSTR_CAN_EXTID) ? ((id)>>16) : ((id)<<2) ))
368 #define FMSTR_FCAN_MAKEIDR2(id) ((FMSTR_U8)( ((id)&FMSTR_CAN_EXTID) ? ((id)>>8) : 0 ))
369 #define FMSTR_FCAN_MAKEIDR3(id) ((FMSTR_U8)( ((id)&FMSTR_CAN_EXTID) ? (id) : 0 ))
370 
371 /* FCAN reception, configuring the buffer, just once at the initialization phase */
372 #define FMSTR_FCAN_RINIT(idr0, idr1, idr2, idr3) \
373  FMSTR_MACROCODE_BEGIN() \
374  (((idr0)&FMSTR_FCANID0_EXT_FLG) ? \
375  (FMSTR_SETREG16(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET + FMSTR_FCMBCSR + 2, (FMSTR_FCANMB_CRXVOID<<8 | FMSTR_FCANCTRL_IDE | FMSTR_FCANCTRL_EXT_SRR))) : \
376  (FMSTR_SETREG16(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET + FMSTR_FCMBCSR + 2, (FMSTR_FCANMB_CRXVOID<<8 | FMSTR_FCANCTRL_EXT_SRR))));\
377  FMSTR_SETREG32(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET + FMSTR_FCMBIDR0, ((idr0)<<24) | ((idr1)<<16) | ((idr2)<<8) | (idr3) );\
378  FMSTR_MACROCODE_END()
379 
380 /* FCAN transmission, configuring the buffer, just once at the initialization phase */
381 #define FMSTR_FCAN_TINIT(idr0, idr1, idr2, idr3) \
382  FMSTR_MACROCODE_BEGIN() \
383  (((idr0)&FMSTR_FCANID0_EXT_FLG) ? \
384  (FMSTR_SETREG16(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET + FMSTR_FCMBCSR + 2, (FMSTR_FCANMB_CTXREADY<<8 | FMSTR_FCANCTRL_IDE))) : \
385  (FMSTR_SETREG16(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET + FMSTR_FCMBCSR + 2, (FMSTR_FCANMB_CTXREADY<<8 ))));\
386  FMSTR_MACROCODE_END()
387 
388 /* FCAN reception, configuring the buffer for receiving (each time receiver is re-enabled) */
389 #define FMSTR_FCAN_RCFG() \
390  FMSTR_SETREG8(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET + FMSTR_FCMBCSR + 3, FMSTR_FCANMB_CRXEMPTY)
391 
392 /* FCAN: CAN transmission */
393 typedef struct
394 {
397 
398 /* FCAN transmission, put one data byte into buffer */
399 #define FMSTR_FCAN_TLEN(pctx, len) \
400  FMSTR_SETREG8(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET+FMSTR_FCMBCSR+2, (FMSTR_U8)((len & 0x0f) | \
401  (FMSTR_GETREG8(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET+FMSTR_FCMBCSR+2)&(FMSTR_FCANCTRL_IDE | FMSTR_FCANCTRL_EXT_SRR | FMSTR_FCANCTRL_EXT_RTR))))
402 
403 /* FCAN transmission, put one data byte into buffer */
404 #define FMSTR_FCAN_PUTBYTE(pctx, dataByte) \
405  FMSTR_MACROCODE_BEGIN() \
406  FMSTR_SETREG8(FMSTR_CAN_BASE, (FMSTR_FCANTXFG_OFFSET + FMSTR_FCMBDSR0) - (0x3&((pctx)->nDataIx)) + (0x4&((pctx)->nDataIx)), (dataByte) ); \
407  (pctx)->nDataIx++; \
408  FMSTR_MACROCODE_END()
409 
410 /* FCAN: CAN transmission, configuring the buffer before each transmission */
411 #define FMSTR_FCAN_TCFG(pctx) \
412  FMSTR_MACROCODE_BEGIN() \
413  (pctx)->nDataIx = 0; \
414  FMSTR_MACROCODE_END()
415 
416 /* FCAN: CAN transmission, preparing the buffer before each transmission */
417 #define FMSTR_FCAN_TID(pctx, idr0, idr1, idr2, idr3) \
418  FMSTR_MACROCODE_BEGIN() \
419  FMSTR_SETREG32(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET+FMSTR_FCMBIDR0, ((idr0)<<24) | ((idr1)<<16) | ((idr2)<<8) | (idr3) ); \
420  FMSTR_MACROCODE_END()
421 
422 /* FCAN transmission, set transmit priority */
423 #define FMSTR_FCAN_TPRI(pctx, txPri) /* in FCAN module is not implemented */
424 
425 /* FCAN transmission, final firing of the buffer */
426 #define FMSTR_FCAN_TX(pctx) \
427  FMSTR_SETREG8(FMSTR_CAN_BASE, FMSTR_FCANTXFG_OFFSET + FMSTR_FCMBCSR + 3, (FMSTR_FCANMB_CTXTRANS_ONCE & 0x0f) )
428 
429 /* FCAN reception */
430 typedef struct
431 {
434 
435 /* FCAN reception, lock frame */
436 #define FMSTR_FCAN_RX(pctx) \
437  (pctx)->nDataIx = 0;
438 
439 /* FCAN reception, test if received message ID matches the one given, TRUE if matching */
440 #define FMSTR_FCAN_TEST_RIDR(pctx, idr0, idr1, idr2, idr3) \
441  ( (idr0 & FMSTR_FCANID0_EXT_FLG) ? \
442  /* ext id compare */ \
443  ( ((((idr0)<<24) | ((idr1)<<16) | ((idr2)<<8) | (idr3))&0x1f000000)==((FMSTR_GETREG32(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET+FMSTR_FCMBIDR0))&0x1f000000) ) : \
444  /* std id compare */ \
445  ( (((idr0)<<8) | (idr1))==((FMSTR_GETREG16(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET+FMSTR_FCMBIDR0+2))&0x1ffc) ) )
446 
447 /* FCAN reception, get received frame length */
448 #define FMSTR_FCAN_RLEN(pctx) \
449  (FMSTR_GETREG8(FMSTR_CAN_BASE, FMSTR_FCANRXFG_OFFSET+FMSTR_FCMBCSR+2) & 0x0f)
450 
451 /* FCAN reception, get one received byte */
452 #define FMSTR_FCAN_GETBYTE(pctx) \
453  ((FMSTR_U8) (FMSTR_GETREG8(FMSTR_CAN_BASE, (FMSTR_FCANRXFG_OFFSET + FMSTR_FCMBDSR0) - (0x3&((pctx)->nDataIx)) + (0x4&((pctx)->nDataIx)) ))); \
454  (pctx)->nDataIx++
455 
456 /* FCAN reception, unlock the buffer */
457 #define FMSTR_FCAN_RFINISH(pctx) \
458  FMSTR_SETBIT16(FMSTR_CAN_BASE, FMSTR_FCANTMR_OFFSET, 0)
459 
460 #endif /* __FREEMASTER_KXX_H */
461 
FMSTR_U8 nDataIx
Definition: freemaster_Kxx.h:432
signed short FMSTR_S16
Definition: freemaster_Kxx.h:72
signed char FMSTR_S8
Definition: freemaster_Kxx.h:71
signed long FMSTR_S32
Definition: freemaster_Kxx.h:73
unsigned char FMSTR_BOOL
Definition: freemaster.h:40
FMSTR_BPTR FMSTR_CopyToBuffer(FMSTR_BPTR pDestBuff, FMSTR_ADDR nSrcAddr, FMSTR_SIZE8 nSize)
Write-into the communication buffer memory.
Definition: freemaster_Kxx.c:85
unsigned char FMSTR_BCHR
Definition: freemaster_Kxx.h:83
#define FMSTR_SetExAddr(bNextAddrIsEx)
Definition: freemaster_Kxx.h:102
#define FMSTR_ValueToBuffer16(pDest, src)
Definition: freemaster_Kxx.h:131
#define FMSTR_AddressToBuffer(pDest, nAddr)
Definition: freemaster_Kxx.h:149
#define FMSTR_ValueToBuffer32(pDest, src)
Definition: freemaster_Kxx.h:134
Definition: freemaster_Kxx.h:430
#define FMSTR_ValueFromBuffer16(pDest, pSrc)
Definition: freemaster_Kxx.h:120
unsigned char FMSTR_SIZE8
Definition: freemaster_Kxx.h:80
void FMSTR_CopyMemory(FMSTR_ADDR nDestAddr, FMSTR_ADDR nSrcAddr, FMSTR_SIZE8 nSize)
The &quot;memcpy&quot; used internally in FreeMASTER driver.
Definition: freemaster_Kxx.c:64
unsigned long FMSTR_U32
Definition: freemaster_Kxx.h:69
signed short FMSTR_INDEX
Definition: freemaster_Kxx.h:81
unsigned char * FMSTR_BPTR
Definition: freemaster_Kxx.h:84
unsigned char * FMSTR_ADDR
Definition: freemaster.h:38
#define FMSTR_AddressFromBuffer(pDest, pSrc)
Definition: freemaster_Kxx.h:147
unsigned short FMSTR_U16
Definition: freemaster_Kxx.h:68
#define FMSTR_ValueFromBuffer32(pDest, pSrc)
Definition: freemaster_Kxx.h:123
unsigned char FMSTR_SCISR
Definition: freemaster_Kxx.h:86
void FMSTR_CopyFromBufferWithMask(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR_SIZE8 nSize)
Read-out memory from communication buffer, perform AND-masking.
Definition: freemaster_Kxx.c:151
unsigned char FMSTR_FLAGS
Definition: freemaster_Kxx.h:79
Definition: freemaster_Kxx.h:393
FMSTR_U8 nDataIx
Definition: freemaster_Kxx.h:395
FMSTR_BPTR FMSTR_CopyFromBuffer(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR_SIZE8 nSize)
Read-out memory from communication buffer.
Definition: freemaster_Kxx.c:108
unsigned char FMSTR_U8
Definition: freemaster_Kxx.h:67