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