Reduce size to allow start
[romboot.git] / embedded_services.h
blobb73e1187535228eae1157c35230a93632b70e2f5
1 //*----------------------------------------------------------------------------
2 //* ATMEL Microcontroller Software Support - ROUSSET -
3 //*----------------------------------------------------------------------------
4 //* The software is delivered "AS IS" without warranty or condition of any
5 //* kind, either express, implied or statutory. This includes without
6 //* limitation any warranty or condition with respect to merchantability or
7 //* fitness for any particular purpose, or against the infringements of
8 //* intellectual property rights of others.
9 //*----------------------------------------------------------------------------
10 //* File Name : embedded_sevices.h
11 //* Object : Header File with all the embedded software services definitions
12 //*
13 //* 1.0 24 Jan 2003 FB : Creation
14 //*----------------------------------------------------------------------------
15 #ifndef embedded_sevices_h
16 #define embedded_sevices_h
17 ////////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////////
20 #include "AT91RM9200.h"
22 #define AT91C_BASE_ROM (char *)0x00100000
24 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25 // Buffer Structure
26 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 // Return values
28 #define AT91C_BUFFER_SUCCESS 0
29 #define AT91C_BUFFER_ERROR_SHIFT 16
30 #define AT91C_BUFFER_ERROR (0x0F << AT91C_BUFFER_ERROR_SHIFT)
32 #define AT91C_BUFFER_OVERFLOW (0x01 << AT91C_BUFFER_ERROR_SHIFT)
33 #define AT91C_BUFFER_UNDERRUN (0x02 << AT91C_BUFFER_ERROR_SHIFT)
35 typedef unsigned int AT91S_BufferStatus;
37 struct _AT91S_Pipe;
39 // This structure is a virtual object of a buffer
40 typedef struct _AT91S_Buffer
42 struct _AT91S_Pipe *pPipe;
43 void *pChild;
45 // Functions invoked by the pipe
46 AT91S_BufferStatus (*SetRdBuffer) (struct _AT91S_Buffer *pSBuffer, char *pBuffer, unsigned int Size);
47 AT91S_BufferStatus (*SetWrBuffer) (struct _AT91S_Buffer *pSBuffer, char const *pBuffer, unsigned int Size);
48 AT91S_BufferStatus (*RstRdBuffer) (struct _AT91S_Buffer *pSBuffer);
49 AT91S_BufferStatus (*RstWrBuffer) (struct _AT91S_Buffer *pSBuffer);
50 char (*MsgWritten) (struct _AT91S_Buffer *pSBuffer, char const *pBuffer);
51 char (*MsgRead) (struct _AT91S_Buffer *pSBuffer, char const *pBuffer);
52 // Functions invoked by the peripheral
53 AT91S_BufferStatus (*GetWrBuffer) (struct _AT91S_Buffer *pSBuffer, char const **pData, unsigned int *pSize);
54 AT91S_BufferStatus (*GetRdBuffer) (struct _AT91S_Buffer *pSBuffer, char **pData, unsigned int *pSize);
55 AT91S_BufferStatus (*EmptyWrBuffer) (struct _AT91S_Buffer *pSBuffer, unsigned int size);
56 AT91S_BufferStatus (*FillRdBuffer) (struct _AT91S_Buffer *pSBuffer, unsigned int size);
57 char (*IsWrEmpty) (struct _AT91S_Buffer *pSBuffer);
58 char (*IsRdFull) (struct _AT91S_Buffer *pSBuffer);
59 } AT91S_Buffer, *AT91PS_Buffer;
61 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 // End of Buffer Structure
63 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 // SBuffer Structure
67 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69 // ===========================================================================================
70 // SimpleBuffer definition
72 // This structure is pointed by pRealBuffer field in the SBuffer
73 // It contains usefull information for a real implementation of
74 // a SBuffer object.
75 // The application just create an instance of SSBUffer and SBuffer,
76 // call OpenSimpleBuffer, and continue using SBuffer instance
78 typedef struct _AT91S_SBuffer
80 AT91S_Buffer parent;
81 char *pRdBuffer;
82 char const *pWrBuffer;
83 unsigned int szRdBuffer;
84 unsigned int szWrBuffer;
85 unsigned int stRdBuffer;
86 unsigned int stWrBuffer;
87 } AT91S_SBuffer, *AT91PS_SBuffer;
89 typedef AT91PS_Buffer (*AT91PF_OpenSBuffer) (AT91PS_SBuffer);
91 // This function is called by the application
92 extern AT91PS_Buffer AT91F_OpenSBuffer(AT91PS_SBuffer pBuffer);
94 // Functions invoked by the pipe
95 extern AT91S_BufferStatus AT91F_SbSetRdBuffer (AT91PS_Buffer pBuffer, char *pData, unsigned int Size);
96 extern AT91S_BufferStatus AT91F_SbSetWrBuffer (AT91PS_Buffer pBuffer, char const *pData, unsigned int Size);
97 extern AT91S_BufferStatus AT91F_SbRstRdBuffer (AT91PS_Buffer pBuffer);
98 extern AT91S_BufferStatus AT91F_SbRstWrBuffer (AT91PS_Buffer pBuffer);
99 extern char AT91F_SbMsgWritten (AT91PS_Buffer pBuffer, char const *pMsg);
100 extern char AT91F_SbMsgRead (AT91PS_Buffer pBuffer, char const *pMsg);
101 // Functions invoked by the peripheral
102 extern AT91S_BufferStatus AT91F_SbGetWrBuffer (AT91PS_Buffer pBuffer, char const **pData, unsigned int *pSize);
103 extern AT91S_BufferStatus AT91F_SbGetRdBuffer (AT91PS_Buffer pBuffer, char **pData, unsigned int *pSize);
104 extern AT91S_BufferStatus AT91F_SbEmptyWrBuffer(AT91PS_Buffer pBuffer, unsigned int size);
105 extern AT91S_BufferStatus AT91F_SbFillRdBuffer (AT91PS_Buffer pBuffer, unsigned int size);
106 extern char AT91F_SbIsWrEmpty (AT91PS_Buffer pBuffer);
107 extern char AT91F_SbIsRdFull (AT91PS_Buffer pBuffer);
109 #ifdef DBG_DRV_BUFFER
110 extern char const *AT91F_SbGetError(AT91S_BufferStatus errorNumber);
111 #endif
112 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 // End of SBuffer Structure
114 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118 // Tempo service
119 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120 #define AT91C_OPEN_CTRLTEMPO_SUCCESS 0
121 #define AT91C_ERROR_OPEN_CTRLTEMPO 1
122 #define AT91C_START_OK 2
123 #define AT91C_STOP_OK 3
124 #define AT91C_TIMEOUT_REACHED 4
126 /************************************************************************************************************************/
127 typedef enum _AT91E_SvcTempo {
128 AT91E_SVCTEMPO_DIS,
129 AT91E_SVCTEMPO_EN
130 } AT91E_SvcTempo;
132 /************************************************************************************************************************/
133 typedef unsigned int AT91S_TempoStatus;
135 /************************************************************************************************************************/
136 // AT91S_SvcTempo
137 typedef struct _AT91S_SvcTempo
140 // Methods:
141 AT91S_TempoStatus (*Start) (
142 struct _AT91S_SvcTempo *pSvc,
143 unsigned int timeout,
144 unsigned int reload,
145 void (*callback) (AT91S_TempoStatus, void *),
146 void *pData);
147 AT91S_TempoStatus (*Stop) (struct _AT91S_SvcTempo *pSvc);
149 struct _AT91S_SvcTempo *pPreviousTempo;
150 struct _AT91S_SvcTempo *pNextTempo;
152 // Data
153 unsigned int TickTempo; //* timeout value
154 unsigned int ReloadTempo;//* Reload value for periodic execution
155 void (*TempoCallback)(AT91S_TempoStatus, void *);
156 void *pPrivateData;
157 AT91E_SvcTempo flag;
158 } AT91S_SvcTempo, *AT91PS_SvcTempo;
161 /************************************************************************************************************************/
162 // AT91S_CtrlTempo
163 typedef struct _AT91S_CtlTempo
165 // Members:
167 // Start and stop for Timer hardware
168 AT91S_TempoStatus (*CtlTempoStart) (void *pTimer);
169 AT91S_TempoStatus (*CtlTempoStop) (void *pTimer);
171 // Start and stop for Tempo service
172 AT91S_TempoStatus (*SvcTempoStart) (
173 struct _AT91S_SvcTempo *pSvc,
174 unsigned int timeout,
175 unsigned int reload,
176 void (*callback) (AT91S_TempoStatus, void *),
177 void *pData);
178 AT91S_TempoStatus (*SvcTempoStop) (struct _AT91S_SvcTempo *pSvc);
179 AT91S_TempoStatus (*CtlTempoSetTime)(struct _AT91S_CtlTempo *pCtrl, unsigned int NewTime);
180 AT91S_TempoStatus (*CtlTempoGetTime)(struct _AT91S_CtlTempo *pCtrl);
181 AT91S_TempoStatus (*CtlTempoIsStart)(struct _AT91S_CtlTempo *pCtrl);
182 AT91S_TempoStatus (*CtlTempoCreate) (
183 struct _AT91S_CtlTempo *pCtrl,
184 struct _AT91S_SvcTempo *pTempo);
185 AT91S_TempoStatus (*CtlTempoRemove) (
186 struct _AT91S_CtlTempo *pCtrl,
187 struct _AT91S_SvcTempo *pTempo);
188 AT91S_TempoStatus (*CtlTempoTick) (struct _AT91S_CtlTempo *pCtrl);
190 // Data:
192 void *pPrivateData; // Pointer to devived class
193 void const *pTimer; // hardware
194 AT91PS_SvcTempo pFirstTempo;
195 AT91PS_SvcTempo pNewTempo;
196 } AT91S_CtlTempo, *AT91PS_CtlTempo;
197 /************************************************************************************************************************/
198 typedef AT91S_TempoStatus (*AT91PF_OpenCtlTempo) ( AT91PS_CtlTempo, void const *);
200 /************************************************************************************************************************/
201 // This function is called by the application.
202 extern AT91S_TempoStatus AT91F_OpenCtlTempo( AT91PS_CtlTempo pCtrlTempo, void const *pTempoTimer );
204 extern AT91S_TempoStatus AT91F_STStart (void *);
205 extern AT91S_TempoStatus AT91F_STStop (void *);
206 extern AT91S_TempoStatus AT91F_STSetTime (AT91PS_CtlTempo, unsigned int);
207 extern AT91S_TempoStatus AT91F_STGetTime (AT91PS_CtlTempo);
208 extern AT91S_TempoStatus AT91F_STIsStart (AT91PS_CtlTempo);
209 extern AT91S_TempoStatus AT91F_CtlTempoCreate (AT91PS_CtlTempo, AT91PS_SvcTempo);
210 extern AT91S_TempoStatus AT91F_CtlTempoRemove (AT91PS_CtlTempo, AT91PS_SvcTempo);
211 extern AT91S_TempoStatus AT91F_CtlTempoTick (AT91PS_CtlTempo);
212 extern AT91S_TempoStatus AT91F_SvcTempoStart (
213 AT91PS_SvcTempo pSvc,
214 unsigned int timeout,
215 unsigned int reload,
216 void (*callback) (AT91S_TempoStatus, void *),
217 void *pData);
218 extern AT91S_TempoStatus AT91F_SvcTempoStop (AT91PS_SvcTempo);
219 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
220 // End of Tempo service
221 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
224 // Xmodem service
225 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227 // Following types are defined in another header files
228 struct _AT91S_Buffer;
230 /************************************************************************************************************************/
231 // Constants:
232 #define AT91C_COMMSVC_SUCCESS 0
233 #define AT91C_COMMSVC_ERROR_SHIFT 8
234 #define AT91C_COMMSVC_ERROR (0x0f << AT91C_COMMSVC_ERROR_SHIFT)
236 /************************************************************************************************************************/
237 typedef unsigned int AT91S_SvcCommStatus;
239 /************************************************************************************************************************/
240 // AT91S_Service definition
241 // This structure is an abstraction of a communication peripheral
242 typedef struct _AT91S_Service
244 // Methods:
245 AT91S_SvcCommStatus (*Reset) (struct _AT91S_Service *pService);
246 AT91S_SvcCommStatus (*StartTx)(struct _AT91S_Service *pService);
247 AT91S_SvcCommStatus (*StartRx)(struct _AT91S_Service *pService);
248 AT91S_SvcCommStatus (*StopTx) (struct _AT91S_Service *pService);
249 AT91S_SvcCommStatus (*StopRx) (struct _AT91S_Service *pService);
250 char (*TxReady)(struct _AT91S_Service *pService);
251 char (*RxReady)(struct _AT91S_Service *pService);
252 // Data:
253 struct _AT91S_Buffer *pBuffer; // Link to a buffer object
254 void *pChild;
255 } AT91S_SvcComm, *AT91PS_SvcComm;
257 /************************************************************************************************************************/
258 // Constants:
259 #define AT91C_XMODEM_SOH 0x01 /* Start of Heading for 128 bytes */
260 #define AT91C_XMODEM_STX 0x02 /* Start of heading for 1024 bytes */
261 #define AT91C_XMODEM_EOT 0x04 /* End of transmission */
262 #define AT91C_XMODEM_ACK 0x06 /* Acknowledge */
263 #define AT91C_XMODEM_NAK 0x15 /* Negative Acknowledge */
264 #define AT91C_XMODEM_CRCCHR 'C'
266 #define AT91C_XMODEM_PACKET_SIZE 2 // packet + packetCRC
267 #define AT91C_XMODEM_CRC_SIZE 2 // crcLSB + crcMSB
268 #define AT91C_XMODEM_DATA_SIZE_SOH 128 // data 128 corresponding to SOH header
269 #define AT91C_XMODEM_DATA_SIZE_STX 1024 // data 1024 corresponding to STX header
271 /************************************************************************************************************************/
272 //* Following structure is used by SPipe to refer to the USB device peripheral endpoint
273 typedef struct _AT91PS_SvcXmodem {
275 // Public Methods:
276 AT91S_SvcCommStatus (*Handler) (struct _AT91PS_SvcXmodem *, unsigned int);
277 AT91S_SvcCommStatus (*StartTx) (struct _AT91PS_SvcXmodem *, unsigned int);
278 AT91S_SvcCommStatus (*StopTx) (struct _AT91PS_SvcXmodem *, unsigned int);
280 // Private Methods:
281 AT91S_SvcCommStatus (*ReadHandler) (struct _AT91PS_SvcXmodem *, unsigned int csr);
282 AT91S_SvcCommStatus (*WriteHandler) (struct _AT91PS_SvcXmodem *, unsigned int csr);
283 unsigned short (*GetCrc) (char *ptr, unsigned int count);
284 char (*CheckHeader) (unsigned char currentPacket, char *packet);
285 char (*CheckData) (struct _AT91PS_SvcXmodem *);
287 AT91S_SvcComm parent; // Base class
288 AT91PS_USART pUsart;
290 AT91S_SvcTempo tempo; // Link to a AT91S_Tempo object
292 char *pData;
293 unsigned int dataSize; // = XMODEM_DATA_STX or XMODEM_DATA_SOH
294 char packetDesc[AT91C_XMODEM_PACKET_SIZE];
295 unsigned char packetId; // Current packet
296 char packetStatus;
297 char isPacketDesc;
298 char eot; // end of transmition
299 } AT91S_SvcXmodem, *AT91PS_SvcXmodem;
301 /************************************************************************************************************************/
302 typedef AT91PS_SvcComm (*AT91PF_OpenSvcXmodem) ( AT91PS_SvcXmodem, AT91PS_USART, AT91PS_CtlTempo);
304 /************************************************************************************************************************/
305 // This function is called by the application.
306 extern AT91PS_SvcComm AT91F_OpenSvcXmodem( AT91PS_SvcXmodem, AT91PS_USART, AT91PS_CtlTempo);
308 extern unsigned short AT91F_SvcXmodemGetCrc (char *ptr, unsigned int count);
309 extern char AT91F_SvcXmodemCheckHeader(unsigned char currentPacket, char *packet);
310 extern char AT91F_SvcXmodemCheckData (AT91PS_SvcXmodem pSvcXmodem);
311 extern AT91S_SvcCommStatus AT91F_SvcXmodemReadHandler(AT91PS_SvcXmodem pSvcXmodem, unsigned int csr);
312 extern AT91S_SvcCommStatus AT91F_SvcXmodemWriteHandler(AT91PS_SvcXmodem pSvcXmodem, unsigned int csr);
313 extern AT91S_SvcCommStatus AT91F_SvcXmodemStartTx(AT91PS_SvcComm pSvcComm);
314 extern AT91S_SvcCommStatus AT91F_SvcXmodemStopTx(AT91PS_SvcComm pSvcComm);
315 extern AT91S_SvcCommStatus AT91F_SvcXmodemStartRx(AT91PS_SvcComm pSvcComm);
316 extern AT91S_SvcCommStatus AT91F_SvcXmodemStopRx(AT91PS_SvcComm pSvcComm);
317 extern char AT91F_SvcXmodemTxReady(AT91PS_SvcComm pService);
318 extern char AT91F_SvcXmodemRxReady(AT91PS_SvcComm pSvcComm);
319 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320 // End of Xmodem service
321 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
324 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
325 // Pipe Structure
326 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
328 // Constants:
329 #define AT91C_PIPE_SUCCESS 0
330 #define AT91C_PIPE_ERROR_SHIFT 8
331 #define AT91C_PIPE_ERROR (0x0F << AT91C_PIPE_ERROR_SHIFT)
333 #define AT91C_PIPE_OPEN_FAILED (1 << AT91C_PIPE_ERROR_SHIFT)
334 #define AT91C_PIPE_WRITE_FAILED (2 << AT91C_PIPE_ERROR_SHIFT)
335 #define AT91C_PIPE_WRITE_ABORTED (3 << AT91C_PIPE_ERROR_SHIFT)
336 #define AT91C_PIPE_READ_FAILED (4 << AT91C_PIPE_ERROR_SHIFT)
337 #define AT91C_PIPE_READ_ABORTED (5 << AT91C_PIPE_ERROR_SHIFT)
338 #define AT91C_PIPE_ABORT_FAILED (6 << AT91C_PIPE_ERROR_SHIFT)
339 #define AT91C_PIPE_RESET_FAILED (7 << AT91C_PIPE_ERROR_SHIFT)
341 /* _AT91S_Pipe stucture */
342 typedef unsigned int AT91S_PipeStatus;
344 typedef struct _AT91S_Pipe
346 // A pipe is linked with a peripheral and a buffer
347 AT91PS_SvcComm pSvcComm;
348 AT91PS_Buffer pBuffer;
350 // Callback functions with their arguments
351 void (*WriteCallback) (AT91S_PipeStatus, void *);
352 void (*ReadCallback) (AT91S_PipeStatus, void *);
353 void *pPrivateReadData;
354 void *pPrivateWriteData;
356 // Pipe methods
357 AT91S_PipeStatus (*Write) (
358 struct _AT91S_Pipe *pPipe,
359 char const * pData,
360 unsigned int size,
361 void (*callback) (AT91S_PipeStatus, void *),
362 void *privateData);
363 AT91S_PipeStatus (*Read) (
364 struct _AT91S_Pipe *pPipe,
365 char *pData,
366 unsigned int size,
367 void (*callback) (AT91S_PipeStatus, void *),
368 void *privateData);
369 AT91S_PipeStatus (*AbortWrite) (
370 struct _AT91S_Pipe *pPipe);
371 AT91S_PipeStatus (*AbortRead) (
372 struct _AT91S_Pipe *pPipe);
373 AT91S_PipeStatus (*Reset) (
374 struct _AT91S_Pipe *pPipe);
375 char (*IsWritten) (
376 struct _AT91S_Pipe *pPipe,
377 char const *pVoid);
378 char (*IsReceived) (
379 struct _AT91S_Pipe *pPipe,
380 char const *pVoid);
381 } AT91S_Pipe, *AT91PS_Pipe;
383 // types used in AT91S_Pipe
384 typedef AT91PS_Pipe (*AT91PF_OpenPipe) (AT91PS_Pipe, AT91PS_SvcComm, AT91PS_Buffer);
385 typedef void (*AT91PF_PipeWriteCallBack) (AT91S_PipeStatus, void *);
386 typedef void (*AT91PF_PipeReadCallBack) (AT91S_PipeStatus, void *);
387 typedef AT91S_PipeStatus (*AT91PF_PipeWrite) (AT91PS_Pipe, char const *, unsigned int, void (*) (AT91S_PipeStatus, void *), void *);
388 typedef AT91S_PipeStatus (*AT91PF_PipeRead) (AT91PS_Pipe, char const *, unsigned int, void (*) (AT91S_PipeStatus, void *), void *);
389 typedef AT91S_PipeStatus (*AT91PF_PipeAbortWrite) (AT91PS_Pipe);
390 typedef AT91S_PipeStatus (*AT91PF_PipeAbortRead) (AT91PS_Pipe);
391 typedef AT91S_PipeStatus (*AT91PF_PipeReset) (AT91PS_Pipe);
392 typedef char (*AT91PF_PipeIsWritten) (AT91PS_Pipe, char const *);
393 typedef char (*AT91PF_PipeIsReceived) (AT91PS_Pipe, char const *);
395 // This function is called by the application
396 extern AT91PS_Pipe AT91F_OpenPipe(
397 AT91PS_Pipe pPipe,
398 AT91PS_SvcComm pSvcComm,
399 AT91PS_Buffer pBuffer);
401 // Following functions are called through AT91S_Pipe pointers
403 extern AT91S_PipeStatus AT91F_PipeWrite(
404 AT91PS_Pipe pPipe,
405 char const *pVoid,
406 unsigned int size,
407 AT91PF_PipeWriteCallBack callback,
408 void *privateData);
409 extern AT91S_PipeStatus AT91F_PipeRead(
410 AT91PS_Pipe pPipe,
411 char *pVoid,
412 unsigned int Size,
413 AT91PF_PipeReadCallBack callback,
414 void *privateData);
415 extern AT91S_PipeStatus AT91F_PipeAbortWrite(AT91PS_Pipe pPipe);
416 extern AT91S_PipeStatus AT91F_PipeAbortRead(AT91PS_Pipe pPipe);
417 extern AT91S_PipeStatus AT91F_PipeReset(AT91PS_Pipe pPipe);
418 extern char AT91F_PipeMsgWritten(AT91PS_Pipe pPipe, char const *pVoid);
419 extern char AT91F_PipeMsgReceived(AT91PS_Pipe pPipe, char const *pVoid);
421 #ifdef DBG_DRV_PIPE
422 // This function parse the error number and return a string
423 // describing the error message
424 extern char const *AT91F_PipeGetError(AT91S_PipeStatus msgId);
425 #endif
426 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
427 // End of Pipe structure
428 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
430 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
431 // CRC service
432 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
433 extern const unsigned char bit_rev[256];
435 extern void CalculateCrc32(const unsigned char *,unsigned int, unsigned int *);
436 extern void CalculateCrc16(const unsigned char *, unsigned int , unsigned short *);
437 extern void CalculateCrcHdlc(const unsigned char *, unsigned int, unsigned short *);
438 extern void CalculateCrc16ccitt(const unsigned char *, unsigned int , unsigned short *);
439 /************************************************************************************************************************/
440 typedef const unsigned char* AT91PS_SVC_CRC_BIT_REV ;
442 typedef void (*AT91PF_SVC_CRC32) (const unsigned char *, unsigned int, unsigned int *);
443 typedef void (*AT91PF_SVC_CRC16) (const unsigned char *, unsigned int, unsigned short *);
444 typedef void (*AT91PF_SVC_CRCHDLC) (const unsigned char *, unsigned int, unsigned short *);
445 typedef void (*AT91PF_SVC_CRCCCITT)(const unsigned char *, unsigned int , unsigned short *);
446 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
447 // End of CRC service
448 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
451 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
452 // Sinus service
453 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
454 typedef short (*AT91PF_Sinus) (int angle);
455 typedef const short * AT91PS_SINE_TAB;
457 /************************************************************************************************************************/
458 extern short AT91F_Sinus(int angle);
459 extern const short AT91C_SINUS180_TAB[256];
460 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
461 // End of Sinus service
462 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
465 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
466 // ROM Entry service
467 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
468 typedef void (TypeAICHandler) (void) ;
471 /************************************************************************************************************************/
472 // ROM BOOT Structure Element Definition (liv v2)
473 typedef struct _AT91S_MEMCDesc
475 AT91PS_MC memc_base ; /* Peripheral base */
476 unsigned char periph_id ; /* MC Peripheral Identifier */
477 } AT91S_MEMCDesc, *AT91PS_MEMCDesc ;
479 typedef struct _AT91S_Pio2Desc
481 AT91PS_PIO pio_base ; /* Base Address */
482 unsigned char periph_id ; /* Peripheral Identifier */
483 unsigned char pio_number ; /* Total Pin Number */
484 } AT91S_Pio2Desc, *AT91PS_Pio2Desc ;
486 typedef struct _AT91S_SPIDesc
488 AT91PS_SPI spi_base ;
489 const AT91PS_PIO pio_base ;
490 unsigned char periph_id ;
491 unsigned char pin_spck ;
492 unsigned char pin_miso ;
493 unsigned char pin_mosi ;
494 unsigned char pin_npcs[4] ;
495 } AT91S_SPIDesc, *AT91PS_SPIDesc ;
497 typedef struct _AT91S_USART2Desc
499 AT91PS_USART usart_base ; /* Peripheral base */
500 const AT91PS_PIO pio_base ; /* IO controller descriptor */
501 unsigned int pin_rxd ; /* RXD pin number in the PIO */
502 unsigned int pin_txd ; /* TXD pin number in the PIO */
503 unsigned int pin_sck ; /* SCK pin number in the PIO */
504 unsigned int pin_rts ; /* RTS pin number in the PIO */
505 unsigned int pin_cts ; /* CTS pin number in the PIO */
506 unsigned int pin_dtr ; /* DTR pin number in the PIO */
507 unsigned int pin_ri ; /* RI pin number in the PIO */
508 unsigned int pin_dsr ; /* DSR pin number in the PIO */
509 unsigned int pin_dcd ; /* DCD pin number in the PIO */
510 unsigned int periph_id ; /* USART Peripheral Identifier */
511 } AT91S_USART2Desc, *AT91PS_USART2Desc ;
513 typedef struct _AT91S_TWIDesc
515 AT91PS_TWI TWI_base ;
516 const AT91PS_PIO pio_base ;
517 unsigned int pin_sck ;
518 unsigned int pin_sda ;
519 unsigned int periph_id;
520 }AT91S_TWIDesc, *AT91PS_TWIDesc;
522 typedef struct _AT91S_STDesc
524 AT91PS_ST st_base ; /* Peripheral base address */
525 TypeAICHandler *AsmSTHandler ; /* Assembly interrupt handler */
526 unsigned char PeriphId ; /* Peripheral Identifier */
527 } AT91S_STDesc, *AT91PS_STDesc;
529 /************************************************************************************************************************/
530 typedef struct _AT91S_RomBoot {
531 const unsigned int version;
532 // Peripheral descriptors
533 const AT91S_MEMCDesc MEMC_DESC;
534 const AT91S_STDesc SYSTIMER_DESC;
535 const AT91S_Pio2Desc PIOA_DESC;
536 const AT91S_Pio2Desc PIOB_DESC;
537 const AT91S_USART2Desc DBGU_DESC;
538 const AT91S_USART2Desc USART0_DESC;
539 const AT91S_USART2Desc USART1_DESC;
540 const AT91S_USART2Desc USART2_DESC;
541 const AT91S_USART2Desc USART3_DESC;
542 const AT91S_TWIDesc TWI_DESC;
543 const AT91S_SPIDesc SPI_DESC;
545 // Objects entry
546 const AT91PF_OpenPipe OpenPipe;
547 const AT91PF_OpenSBuffer OpenSBuffer;
548 const unsigned int reserved1;
549 const AT91PF_OpenSvcXmodem OpenSvcXmodem;
550 const AT91PF_OpenCtlTempo OpenCtlTempo;
551 const unsigned int reserved2;
552 const unsigned int reserved3;
553 const unsigned int reserved4;
554 const AT91PF_SVC_CRC16 CRC16;
555 const AT91PF_SVC_CRCCCITT CRCCCITT;
556 const AT91PF_SVC_CRCHDLC CRCHDLC;
557 const AT91PF_SVC_CRC32 CRC32;
558 const AT91PS_SVC_CRC_BIT_REV Bit_Reverse_Array;
559 const AT91PS_SINE_TAB SineTab;
560 const AT91PF_Sinus Sine;
561 } AT91S_RomBoot, *AT91PS_RomBoot;
563 #define AT91C_ROM_BOOT_ADDRESS ((const AT91S_RomBoot *) ( *((unsigned int *) (AT91C_BASE_ROM + 0x20))) )
565 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
566 // End of ROM Entry Service
567 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
570 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
571 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
572 #endif