]> rtime.felk.cvut.cz Git - arc.git/blob - boards/mpc5516it/config/Spi_Cfg.h
Merge with hcs12_mcal
[arc.git] / boards / mpc5516it / config / Spi_Cfg.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\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
9  *\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
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 \r
18 \r
19 \r
20 \r
21 \r
22 \r
23 #ifndef SPI_CFG_H_\r
24 #define SPI_CFG_H_\r
25 \r
26 #include "Dma.h"\r
27 #include "mpc55xx.h"\r
28 #include "Mcu.h"\r
29 \r
30 #define DSPI_CTRL_A     0\r
31 #define DSPI_CTRL_B     1\r
32 #define DSPI_CTRL_C     2\r
33 #define DSPI_CTRL_D     3\r
34 \r
35 /*\r
36  * General configuration\r
37  */\r
38 \r
39 // Maximum amount of data that can be written/read in one go.\r
40 #define SPI_EB_MAX_LENGTH                                       64\r
41 \r
42 // Switches the Spi_Cancel function ON or OFF.\r
43 #define SPI_CANCEL_API                                          STD_OFF\r
44 \r
45 // Selects the SPI Handler/Driver Channel Buffers usage allowed and delivered.\r
46 // LEVEL 0 - Only Internal buffers\r
47 // LEVEL 1 - Only external buffers\r
48 // LEVEL 2 - Both internal/external buffers\r
49 #define SPI_CHANNEL_BUFFERS_ALLOWED     1\r
50 \r
51 #define SPI_DEV_ERROR_DETECT                    STD_ON\r
52 // Switches the Spi_GetHWUnitStatus function ON or OFF.\r
53 #define SPI_HW_STATUS_API                                       STD_ON\r
54 // Switches the Interruptible Sequences handling functionality ON or OFF.\r
55 #define SPI_INTERRUPTIBLE_SEQ_ALLOWED           STD_OFF\r
56 \r
57 // LEVEL 0 - Simple sync\r
58 // LEVEL 1 - Basic async\r
59 // LEVEL 2 - Enhanced mode\r
60 #define SPI_LEVEL_DELIVERED                             2\r
61 \r
62 #define SPI_VERSION_INFO_API                            STD_ON\r
63 \r
64 #if 0\r
65 #if SPI_LEVEL_DELIVERED>=1\r
66 #define SPI_INTERRUPTIBLE_SEQ_ALLOWED   STD_ON\r
67 #endif\r
68 #endif\r
69 \r
70 // M95256\r
71 #define E2_WREN   0x6           // Write Enable 0000 0110\r
72 #define E2_WRDI   0x4           // Write Disable 0000 0100\r
73 #define E2_RDSR   0x5           // Read Status Register  0000 0101\r
74                                                                                                         // 1 - Read data\r
75 #define E2_WRSR   0x1           // Write Status Register  0000 0001\r
76                                                                                                         // 1 - Write data\r
77 #define E2_READ   0x3           // Read from Memory Array 0000 0011\r
78                                                                                                         // 1  - Write 16-bit address\r
79                                                                                                         // n  - 8 -bit read data\r
80 #define E2_WRITE  0x2           // WRITE  Write to Memory Array  0000 0010\r
81                                                                                                         // 1  Write 16-bit address\r
82                                                                                                         // n  - 8-bit reads\r
83 \r
84 \r
85 #define FLASH_READ_25                   0x03\r
86 #define FLASH_READ_50                   0x0B\r
87 #define FLASH_RDSR                                      0x05\r
88 #define FLASH_JEDEC_ID                  0x9f\r
89 #define FLASH_RDID                                      0x90\r
90 #define FLASH_BYTE_WRITE        0x02\r
91 #define FLASH_AI_WORD_WRITE 0xad\r
92 #define FLASH_WREN                                      0x06\r
93 #define FLASH_WRDI                                      0x04\r
94 #define FLASH_WRSR                                      0x01\r
95 #define FLASH_ERASE_4K                  0x20\r
96 \r
97 \r
98 \r
99 typedef enum\r
100 {\r
101   SPI_EB = 0, // External Buffer\r
102   SPI_IB // Internal Buffer\r
103 } Spi_BufferType;\r
104 \r
105 typedef enum {\r
106         SPI_EXT_DEVICE_A_E2,\r
107         SPI_EXT_DEVICE_A_FLASH,\r
108         SPI_EXT_DEVICE_B_E2,\r
109 } Spi_ExternalDeviceTypeType;\r
110 \r
111 typedef enum\r
112 {\r
113         SPI_CH_E2_CMD = 0,\r
114         SPI_CH_E2_ADDR,\r
115         SPI_CH_E2_WREN,\r
116         SPI_CH_E2_DATA,\r
117 \r
118         SPI_CH_EEP_CMD,\r
119         SPI_CH_EEP_ADDR,\r
120         SPI_CH_EEP_WREN,\r
121         SPI_CH_EEP_DATA,\r
122 \r
123         SPI_CH_FLASH_CMD,\r
124         SPI_CH_FLASH_ADDR,\r
125         SPI_CH_FLASH_DATA,\r
126         SPI_CH_FLASH_WREN,\r
127         SPI_CH_FLASH_WRDI,\r
128         SPI_CH_FLASH_WRSR,\r
129 \r
130   SPI_MAX_CHANNEL,\r
131 } Spi_ChannelType;\r
132 \r
133 typedef enum\r
134 {\r
135         SPI_JOB_E2_CMD = 0,\r
136         SPI_JOB_E2_CMD2,\r
137         SPI_JOB_E2_DATA,\r
138         SPI_JOB_E2_WREN,\r
139 \r
140         SPI_JOB_EEP_CMD,\r
141         SPI_JOB_EEP_CMD2,\r
142         SPI_JOB_EEP_DATA,\r
143         SPI_JOB_EEP_WREN,\r
144 \r
145         SPI_JOB_FLASH_CMD,\r
146         SPI_JOB_FLASH_CMD2,\r
147         SPI_JOB_FLASH_CMD_DATA,\r
148         SPI_JOB_FLASH_READ,\r
149         SPI_JOB_FLASH_WREN,\r
150         SPI_JOB_FLASH_WRDI,\r
151         SPI_JOB_FLASH_DATA,\r
152         SPI_JOB_FLASH_WRSR,\r
153         SPI_JOB_FLASH_ADDR,\r
154 \r
155   SPI_MAX_JOB,\r
156 } Spi_JobType;\r
157 \r
158 #define SPI_MAX_CHANNELS        8\r
159 \r
160 typedef enum\r
161 {\r
162         SPI_SEQ_E2_CMD = 0,\r
163         SPI_SEQ_E2_CMD2,\r
164         SPI_SEQ_E2_READ,\r
165         SPI_SEQ_E2_WRITE,\r
166 \r
167         SPI_SEQ_EEP_CMD,\r
168         SPI_SEQ_EEP_CMD2,\r
169         SPI_SEQ_EEP_READ,\r
170         SPI_SEQ_EEP_WRITE,\r
171 \r
172         SPI_SEQ_FLASH_CMD,\r
173         SPI_SEQ_FLASH_CMD2,\r
174         SPI_SEQ_FLASH_CMD_DATA,\r
175         SPI_SEQ_FLASH_READ,\r
176         SPI_SEQ_FLASH_WRITE,\r
177         SPI_SEQ_FLASH_WRSR,\r
178         SPI_SEQ_FLASH_ERASE,\r
179 \r
180   SPI_MAX_SEQUENCE,\r
181 } Spi_SequenceType;\r
182 \r
183 typedef enum\r
184 {\r
185   SPI_ARC_TRANSFER_START_LSB,\r
186   SPI_ARC_TRANSFER_START_MSB,\r
187 } Spi_Arc_TransferStartType;\r
188 \r
189 \r
190 typedef enum {\r
191         SPI_EDGE_LEADING,\r
192         SPI_EDGE_TRAILING\r
193 } Spi_EdgeType;\r
194 \r
195 \r
196 \r
197 // All data needed to configure one SPI-channel\r
198 typedef struct\r
199 {\r
200   // Symbolic name\r
201   Spi_ChannelType SpiChannelId;\r
202   // Buffer usage with EB/IB channel\r
203   // TODO: The type is wrong...\r
204   unsigned SpiChannelType;\r
205 \r
206   // This parameter is the width of a transmitted data unit.\r
207   uint32 SpiDataWidth;\r
208   // This parameter is the default value to transmit.\r
209   uint32 SpiDefaultData;\r
210 \r
211   // This parameter contains the maximum size of data buffers in case of EB\r
212   // Channels and only.\r
213   Spi_NumberOfDataType SpiEbMaxLength;\r
214 \r
215   // This parameter contains the maximum number of data buffers in case of IB\r
216   // Channels and only.\r
217   Spi_NumberOfDataType SpiIbNBuffers;\r
218 \r
219   // This parameter defines the first starting bit for transmission.\r
220   Spi_Arc_TransferStartType SpiTransferStart;\r
221 \r
222   //\r
223   _Bool SpiDmaNoIncreaseSrc;\r
224 \r
225 } Spi_ChannelConfigType;\r
226 \r
227 // All data needed to configure one SPI-Job, amongst others the connection\r
228 // between the internal SPI unit and the special settings for an external de-\r
229 // vice is done.\r
230 typedef struct\r
231 {\r
232 \r
233   Spi_JobType SpiJobId;\r
234 \r
235   //    This parameter is the symbolic name to identify the HW SPI Hardware micro-\r
236   //    controller peripheral allocated to this Job.\r
237   uint32 SpiHwUnit;\r
238 \r
239   // This parameter is a reference to a notification function.\r
240   void (*SpiJobEndNotification)();\r
241 \r
242   // Priority of the Job\r
243   // range 0..3\r
244   unsigned SpiJobPriority;\r
245 \r
246   // A job references several channels.\r
247   uint32 ChannelAssignment[SPI_MAX_CHANNELS];\r
248 \r
249   // Reference to the external device used by this job\r
250   Spi_ExternalDeviceTypeType DeviceAssignment;\r
251 \r
252 //      unsigned        SPI_NUMBER_OF_CHANNELS;\r
253 //      unsigned        SPI_LIST_OF_CHANNELS[SPI_MAX_CHANNEL];\r
254 } Spi_JobConfigType;\r
255 \r
256 // The communication settings of an external device. Closely linked to Spi-\r
257 // Job.\r
258 typedef struct\r
259 {\r
260 \r
261   // This parameter is the communication baudrate - This parameter allows\r
262   // using a range of values, from the point of view of configuration tools, from\r
263   // Hz up to MHz.\r
264   // Note! Float in config case, not here\r
265   uint32 SpiBaudrate;\r
266 \r
267   // Symbolic name to identify the CS used for this job\r
268   uint32 SpiCsIdentifier;\r
269 \r
270   // This parameter defines the active polarity of Chip Select.\r
271   // STD_HIGH or STD_LOW\r
272   uint8 SpiCsPolarity;\r
273 \r
274   // This parameter defines the SPI data shift edge.\r
275   Spi_EdgeType SpiDataShiftEdge;\r
276 \r
277   // This parameter enables or not the Chip Select handling functions.\r
278   uint8 SpiEnableCs;\r
279 \r
280   // This parameter defines the SPI shift clock idle level.\r
281   uint8 SpiShiftClockIdleLevel;\r
282 \r
283   // Timing between clock and chip select - This parameter allows to use a\r
284   // range of values from 0 up to 100 microSec. the real configuration-value\r
285   // used in software BSW-SPI is calculated out of this by the generator-tools\r
286   // Note! Float in config case, not here. Unit ns\r
287   uint32 SpiTimeClk2Cs;\r
288 \r
289   // Timing between PCS and first edge of SCK. Unit ns.\r
290   uint32 SpiTimeCs2Clk;\r
291 \r
292   // ArcCore extension...\r
293   // The controller ID(0..3)\r
294   //uint32 SpiControllerId;\r
295 \r
296 } Spi_ExternalDeviceType;\r
297 \r
298 // All data needed to configure one SPI-sequence\r
299 typedef struct\r
300 {\r
301   // This parameter allows or not this Sequence to be suspended by another\r
302   // one.\r
303   unsigned SpiInterruptibleSequence;\r
304   // This parameter is a reference to a notification function.\r
305   void (*SpiSeqEndNotification)();\r
306   //\r
307   Spi_SequenceType SpiSequenceId;\r
308   //    unsigned                        SPI_NUMBER_OF_JOBS;\r
309   // A sequence references several jobs, which are executed during a commu-\r
310   // nication sequence\r
311   uint32 JobAssignment[SPI_MAX_JOB];\r
312 } Spi_SequenceConfigType;\r
313 \r
314 typedef struct\r
315 {\r
316   /* Interrupt priority level for this SPI channel. */\r
317   uint8 IsrPriority;\r
318 \r
319   /* This channel is to be activated for use. */\r
320   uint8 Activated;\r
321 \r
322   /* Receive DMA channel. */\r
323   Dma_ChannelType RxDmaChannel;\r
324 \r
325   /* Transmit DMA channel. */\r
326   Dma_ChannelType TxDmaChannel;\r
327 \r
328   /* Peripheral clock source. */\r
329   McuE_PeriperalClock_t PeripheralClock;\r
330 }Spi_HwConfigType;\r
331 \r
332 typedef struct\r
333 {\r
334   //    This parameter contains the number of Channels configured. It will be\r
335   //    gathered by tools during the configuration stage.\r
336   uint8 SpiMaxChannel;\r
337 \r
338   uint8 SpiMaxJob;\r
339 \r
340   uint8 SpiMaxSequence;\r
341 \r
342   // All data needed to configure one SPI-channel\r
343   const Spi_ChannelConfigType * SpiChannelConfig;\r
344 \r
345   // The communication settings of an external device. Closely\r
346   // linked to SpiJob.\r
347   const Spi_ExternalDeviceType * SpiExternalDevice;\r
348 \r
349   //    All data needed to configure one SPI-Job, amongst others the\r
350   //    connection between the internal SPI unit and the special set-\r
351   //    tings for an external device is done.\r
352   const Spi_JobConfigType * SpiJobConfig;\r
353 \r
354   // All data needed to configure one SPI-sequence\r
355   const Spi_SequenceConfigType * SpiSequenceConfig;\r
356 \r
357   const Spi_HwConfigType *SpiHwConfig;\r
358 } Spi_DriverType;\r
359 \r
360 typedef Spi_DriverType Spi_ConfigType;\r
361 \r
362 \r
363 #if 0\r
364 struct SpiDriverConfiguration_s\r
365 {\r
366   Spi_ChannelType SPI_MAX_CHANNEL;\r
367   Spi_JobType SPI_MAX_JOB;\r
368   Spi_SequenceType SPI_MAX_SEQUENCE;\r
369 };\r
370 #endif\r
371 \r
372 // This is implementation specific but not all values may be valid\r
373 // within the type.This type shall be chosen in order to have the\r
374 // most efficient implementation on a specific microcontroller\r
375 // platform.\r
376 // In-short: Type of application data buffer elements\r
377 // The 5516 TXDATA is 16-bit.. fits ?\r
378 \r
379 typedef uint8 Spi_DataType;\r
380 //typedef uint16 Spi_DataType;\r
381 \r
382 // Specifies the identification (ID) for a SPI Hardware microcontroller peripheral (unit).\r
383 // SPI140: This type is configurable (On / Off) at pre-compile time. The switch\r
384 // SPI_HW_STATUS_API shall activate or deactivate the declaration of this\r
385 // type.\r
386 typedef uint32 Spi_HWUnitType;\r
387 \r
388 #if 0\r
389 typedef struct\r
390 {\r
391   Spi_SequenceConfigType SpiSequenceConfig;\r
392   Spi_JobConfigType SpiJobConfig;\r
393   Spi_ChannelConfigType SpiChannelConfig;\r
394   Spi_ExternalDeviceType SpiExternalDevice;\r
395 }Spi_ConfigType;\r
396 #endif\r
397 \r
398 extern const Spi_ConfigType SpiConfigData;\r
399 \r
400 \r
401 uint32 Spi_GetJobCnt(void );\r
402 uint32 Spi_GetChannelCnt(void );\r
403 uint32 Spi_GetExternalDeviceCnt(void );\r
404 \r
405 \r
406 \r
407 #endif /*SPI_CFG_H_*/\r