1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
19 #include "Std_Types.h"
\r
22 /* STD container : SpiGeneral
\r
23 * SPI_CANCEL_API 1 Bool
\r
24 * SPI_CHANNEL_BUFFERS_ALLOWED 1 Int 0..2
\r
25 * SPI_DEV_ERROR_DETECT 1 Bool
\r
26 * SPI_HW_STATUS_API 1 Bool
\r
27 * SPI_INTERRUPTABLE_SEQ_ALLOWED 1 Bool
\r
28 * SPI_LEVEL_DELIVERED 1 Int 0..2
\r
29 * SPI_VERSION_INFO_API 1 Bool
\r
32 /* SPI container: SpiSequence
\r
33 * SpiInterruptableSequence 1 Bool
\r
34 * SpiSeqEndNotification 1 Func
\r
35 * SpiSequenceId 1 Int (name of the sequence)
\r
36 * JobAssignment 1..* Ref to SpiJob
\r
39 /* SPI container: SpiChannel
\r
40 * SpiChannelId 1 Int ( name of the channel )
\r
41 * SpiChannelType 1 enum IB, EB
\r
42 * SpiDataWidth 1 Int, 1..32
\r
43 * SpiDefaultData 1 Int
\r
44 * SpiEbMaxLength 1 Int
\r
45 * SpiHwUnitSynchronous 0..1 [New in 4.0]
\r
46 * SpiIbNBuffers 1 Int
\r
47 * SpiTransferStart 1 Enum LSB, MSB
\r
50 /* SPI container: SpiJob
\r
51 * SpiHwUnit 1 Enum, CSIB0,CSIB1,CSIB2,CSIB3
\r
52 * SpiJobEndNotification 1 Func
\r
53 * SpiJobId 1 Int ( name of job )
\r
54 * SpiJobPriority 1 Int 0..3
\r
55 * ChannelAssignment 1..* Ref to channel
\r
56 * DeviceAssignment 1 Ref to exteral device
\r
59 /* SPI container: SpiExternalDevice
\r
60 * SpiBaudrate 1 float
\r
61 * SpiCsIdentifier 1 String
\r
62 * SpiCsPolarity 1 enum, HIGH, LOW
\r
63 * SpiDataShiftEdge 1 enum LEADING, TRAILING
\r
64 * SpiEnableCs 1 Bool
\r
65 * SpiShiftClockIdleLevel 1 Enum, HIGH, LOW
\r
66 * SpiTimeClk2Cs 1 float
\r
69 /* SPI container: SpiDriver
\r
70 * SpiMaxChannel 0..1 Int
\r
71 * SpiMaxJob 0..1 Int
\r
72 * SpiMaxSequence 0..1 Int
\r
73 * SpiChannel[c] 1..* Channel Data
\r
74 * SpiExternalDevice[c] 1..* External device data
\r
75 * SpiJob[c] 1..* Job data
\r
76 * SpiSequence[c] 1..* Sequence data.
\r
81 #define SPI_VENDOR_ID 1
\r
82 #define SPI_MODULE_ID MODULE_ID_SPI
\r
83 #define SPI_SW_MAJOR_VERSION 1
\r
84 #define SPI_SW_MINOR_VERSION 0
\r
85 #define SPI_SW_PATCH_VERSION 2
\r
86 /* Part of release 3.0 rev 0001 */
\r
87 #define SPI_AR_MAJOR_VERSION 3
\r
88 #define SPI_AR_MINOR_VERSION 0
\r
89 #define SPI_AR_PATCH_VERSION 0
\r
92 /* --- Service IDs --- */
\r
93 #define SPI_INIT_SERVICE_ID 0x00
\r
94 #define SPI_DEINIT_SERVICE_ID 0x01
\r
95 #define SPI_WRITEIB_SERVICE_ID 0x02
\r
96 #define SPI_ASYNCTRANSMIT_SERVICE_ID 0x03
\r
97 #define SPI_READIB_SERVICE_ID 0x04
\r
98 #define SPI_SETUPEB_SERVICE_ID 0x05
\r
99 #define SPI_GETSTATUS_SERVICE_ID 0x06
\r
100 #define SPI_GETJOBRESULT_SERVICE_ID 0x07
\r
101 #define SPI_GETSEQUENCERESULT_SERVICE_ID 0x08
\r
102 #define SPI_GETVERSIONINFO_SERVICE_ID 0x09
\r
103 #define SPI_SYNCTRANSMIT_SERVICE_ID 0x0A
\r
104 #define SPI_GETHWUNITSTATUS_SERVICE_ID 0x0B
\r
105 #define SPI_CANCEL_SERVICE_ID 0x0C
\r
106 #define SPI_SETASYNCMODE_SERVICE_ID 0x0D
\r
108 /* --- Error codes --- */
\r
109 #define SPI_E_PARAM_CHANNEL 0x0A
\r
110 #define SPI_E_PARAM_JOB 0x0B
\r
111 #define SPI_E_PARAM_SEQ 0x0C
\r
112 #define SPI_E_PARAM_LENGTH 0x0D
\r
113 #define SPI_E_PARAM_UNIT 0x0E
\r
114 #define SPI_E_UNINIT 0x1A
\r
115 #define SPI_E_SEQ_PENDING 0x2A
\r
116 #define SPI_E_SEQ_IN_PROCESS 0x3A
\r
117 #define SPI_E_ALREADY_INITIALIZED 0x4A
\r
122 #define CH_NOT_VALID (0xff)
\r
123 #define JOB_NOT_VALID (0xffff)
\r
124 #define SEQ_NOT_VALID (0xff)
\r
126 /* Types according to standard */
\r
127 typedef uint8_t Spi_ChannelType ;
\r
128 typedef uint16_t Spi_JobType;
\r
129 typedef uint8_t Spi_SequenceType;
\r
132 #define CH_NOT_VALID (-1)
\r
133 #define JOB_NOT_VALID (-1)
\r
134 #define SEQ_NOT_VALID (-1)
\r
136 typedef uint8_t Spi_ChannelType ;
\r
137 typedef uint16_t Spi_JobType;
\r
138 typedef uint8_t Spi_SequenceType;
\r
142 #define SPI_SIMPLE 0 /* Not implemented, NOT TESTED */
\r
146 #define SPI_EB_MAX_LENGTH 64
\r
154 SPI_UNINIT=0, // The SPI Handler/Driver is not initialized or not usable.
\r
155 // SPI011: This shall be the default value after reset. This
\r
156 // status shall have the value 0.
\r
158 SPI_IDLE, // The SPI Handler/Driver is not currently transmitting any
\r
161 SPI_BUSY, // The SPI Handler/Driver is performing a SPI Job( transmit )
\r
165 SPI_JOB_OK=0, // The last transmission of the Job has been finished
\r
167 // SPI012: This shall be the default value after reset.
\r
168 // This status shall have the value 0.
\r
170 SPI_JOB_PENDING, // The SPI Handler/Driver is performing a SPI Job.
\r
171 // The meaning of this status is equal to SPI_BUSY.
\r
173 SPI_JOB_FAILED, // The last transmission of the Job has failed.
\r
174 } Spi_JobResultType;
\r
178 SPI_SEQ_OK, // The last transmission of the Sequence has been
\r
179 // finished successfully.
\r
180 // SPI017: This shall be the default value after reset.
\r
181 // This status shall have the value 0.
\r
183 SPI_SEQ_PENDING, // The SPI Handler/Driver is performing a SPI
\r
184 // Sequence. The meaning of this status is equal to
\r
187 SPI_SEQ_FAILED, // The last transmission of the Sequence has failed.
\r
189 SPI_SEQ_CANCELLED, // The last transmission of the Sequence has been
\r
190 // cancelled by user.
\r
191 } Spi_SeqResultType;
\r
194 // Type for defining the number of data elements of the type Spi_DataType to
\r
195 // send and / or receive by Channel
\r
196 typedef uint16 Spi_NumberOfDataType;
\r
199 // Specifies the asynchronous mechanism mode for SPI busses handled
\r
200 // asynchronously in LEVEL 2.
\r
201 // SPI150: This type is available or not accordint to the pre compile time parameter:
\r
202 // SPI_LEVEL_DELIVERED. This is only relevant for LEVEL 2.
\r
206 // The asynchronous mechanism is ensured by
\r
207 // polling, so interrupts related to SPI busses
\r
208 // handled asynchronously are disabled.
\r
211 // The asynchronous mechanism is ensured by
\r
212 // interrupt, so interrupts related to SPI busses
\r
213 // handled asynchronously are enabled.
\r
215 SPI_INTERRUPT_MODE,
\r
216 } Spi_AsyncModeType;
\r
220 SPI_EB = 0, // External Buffer
\r
221 SPI_IB // Internal Buffer
\r
226 SPI_TRANSFER_START_LSB,
\r
227 SPI_TRANSFER_START_MSB,
\r
228 } Spi_TransferStartType;
\r
237 #include "Spi_Cfg.h"
\r
238 #if (SPI_IMPLEMENTATION==SPI_DMA)
\r
242 // All data needed to configure one SPI-channel
\r
243 typedef struct Spi_ChannelConfig
\r
246 Spi_ChannelType SpiChannelId;
\r
247 // Buffer usage with EB/IB channel
\r
248 Spi_BufferType SpiChannelType;
\r
250 // This parameter is the width of a transmitted data unit.
\r
251 uint32 SpiDataWidth;
\r
252 // This parameter is the default value to transmit.
\r
253 uint32 SpiDefaultData;
\r
255 // This parameter contains the maximum size of data buffers in case of EB
\r
256 // Channels and only.
\r
257 Spi_NumberOfDataType SpiEbMaxLength;
\r
259 // This parameter contains the maximum number of data buffers in case of IB
\r
260 // Channels and only.
\r
261 Spi_NumberOfDataType SpiIbNBuffers;
\r
263 // This parameter defines the first starting bit for transmission.
\r
264 Spi_TransferStartType SpiTransferStart;
\r
267 // _Bool SpiDmaNoIncreaseSrc;
\r
269 } Spi_ChannelConfigType;
\r
271 // All data needed to configure one SPI-Job, amongst others the connection
\r
272 // between the internal SPI unit and the special settings for an external de-
\r
274 typedef struct Spi_JobConfig
\r
277 Spi_JobType SpiJobId;
\r
279 // This parameter is the symbolic name to identify the HW SPI Hardware micro-
\r
280 // controller peripheral allocated to this Job.
\r
283 // This parameter is a reference to a notification function.
\r
284 void (*SpiJobEndNotification)();
\r
286 // Priority of the Job
\r
288 unsigned SpiJobPriority;
\r
290 // A job references several channels. TODO: Optimize this...
\r
291 Spi_ChannelType ChannelAssignment[SPI_MAX_CHANNEL+1];
\r
293 // Reference to the external device used by this job
\r
294 Spi_ExternalDeviceTypeType DeviceAssignment;
\r
296 // unsigned SPI_NUMBER_OF_CHANNELS;
\r
297 // unsigned SPI_LIST_OF_CHANNELS[SPI_MAX_CHANNEL];
\r
298 } Spi_JobConfigType;
\r
300 // The communication settings of an external device. Closely linked to Spi-
\r
302 typedef struct Spi_ExternalDevice
\r
305 // This parameter is the communication baudrate - This parameter allows
\r
306 // using a range of values, from the point of view of configuration tools, from
\r
308 // Note! Float in config case, not here
\r
309 uint32 SpiBaudrate;
\r
311 // Symbolic name to identify the CS used for this job
\r
312 uint32 SpiCsIdentifier;
\r
314 // This parameter defines the active polarity of Chip Select.
\r
315 // STD_HIGH or STD_LOW
\r
316 uint8 SpiCsPolarity;
\r
318 // This parameter defines the SPI data shift edge.
\r
319 Spi_EdgeType SpiDataShiftEdge;
\r
321 // This parameter enables or not the Chip Select handling functions.
\r
324 // This parameter defines the SPI shift clock idle level.
\r
325 uint8 SpiShiftClockIdleLevel;
\r
327 // Timing between clock and chip select - This parameter allows to use a
\r
328 // range of values from 0 up to 100 microSec. the real configuration-value
\r
329 // used in software BSW-SPI is calculated out of this by the generator-tools
\r
330 // Note! Float in config case, not here. Unit ns
\r
331 uint32 SpiTimeClk2Cs;
\r
333 // Timing between PCS and first edge of SCK. Unit ns.
\r
334 uint32 SpiTimeCs2Clk;
\r
336 // ArcCore extension...
\r
337 // The controller ID(0..3)
\r
338 //uint32 SpiControllerId;
\r
339 void (*SpiCsCallback)(int);
\r
341 } Spi_ExternalDeviceType;
\r
343 // All data needed to configure one SPI-sequence
\r
344 typedef struct Spi_SequenceConfig
\r
346 // This parameter allows or not this Sequence to be suspended by another
\r
348 unsigned SpiInterruptibleSequence;
\r
349 // This parameter is a reference to a notification function.
\r
350 void (*SpiSeqEndNotification)();
\r
352 Spi_SequenceType SpiSequenceId;
\r
353 // unsigned SPI_NUMBER_OF_JOBS;
\r
354 // A sequence references several jobs, which are executed during a commu-
\r
355 // nication sequence
\r
356 Spi_JobType JobAssignment[SPI_MAX_JOB+1];
\r
357 } Spi_SequenceConfigType;
\r
359 typedef struct Spi_HwConfig
\r
361 /* Interrupt priority level for this SPI channel. */
\r
362 // uint8 IsrPriority;
\r
364 /* This channel is to be activated for use. */
\r
367 /* Receive DMA channel. */
\r
368 #if (SPI_IMPLEMENTATION==SPI_DMA)
\r
369 Dma_ChannelType RxDmaChannel;
\r
371 /* Transmit DMA channel. */
\r
372 Dma_ChannelType TxDmaChannel;
\r
375 /* Peripheral clock source. */
\r
376 // McuE_PeriperalClock_t PeripheralClock;
\r
381 struct SpiDriverConfiguration_s
\r
383 Spi_ChannelType SPI_MAX_CHANNEL;
\r
384 Spi_JobType SPI_MAX_JOB;
\r
385 Spi_SequenceType SPI_MAX_SEQUENCE;
\r
389 // This is implementation specific but not all values may be valid
\r
390 // within the type.This type shall be chosen in order to have the
\r
391 // most efficient implementation on a specific microcontroller
\r
393 // In-short: Type of application data buffer elements
\r
394 // The 5516 TXDATA is 16-bit.. fits ?
\r
396 typedef uint8 Spi_DataType;
\r
397 //typedef uint16 Spi_DataType;
\r
399 // Specifies the identification (ID) for a SPI Hardware microcontroller peripheral (unit).
\r
400 // SPI140: This type is configurable (On / Off) at pre-compile time. The switch
\r
401 // SPI_HW_STATUS_API shall activate or deactivate the declaration of this
\r
403 typedef uint8 Spi_HWUnitType;
\r
408 Spi_SequenceConfigType SpiSequenceConfig;
\r
409 Spi_JobConfigType SpiJobConfig;
\r
410 Spi_ChannelConfigType SpiChannelConfig;
\r
411 Spi_ExternalDeviceType SpiExternalDevice;
\r
416 typedef struct Spi_Driver
\r
418 // This parameter contains the number of Channels configured. It will be
\r
419 // gathered by tools during the configuration stage.
\r
420 uint8 SpiMaxChannel;
\r
424 uint8 SpiMaxSequence;
\r
426 // All data needed to configure one SPI-channel
\r
427 const struct Spi_ChannelConfig * SpiChannelConfig;
\r
429 // The communication settings of an external device. Closely
\r
430 // linked to SpiJob.
\r
431 const struct Spi_ExternalDevice * SpiExternalDevice;
\r
433 // All data needed to configure one SPI-Job, amongst others the
\r
434 // connection between the internal SPI unit and the special set-
\r
435 // tings for an external device is done.
\r
436 const struct Spi_JobConfig * SpiJobConfig;
\r
438 // All data needed to configure one SPI-sequence
\r
439 const struct Spi_SequenceConfig * SpiSequenceConfig;
\r
441 // const struct Spi_HwConfig *SpiHwConfig;
\r
444 typedef Spi_DriverType Spi_ConfigType;
\r
447 void Spi_Init( const Spi_ConfigType *ConfigPtr );
\r
448 Std_ReturnType Spi_DeInit( void );
\r
449 Std_ReturnType Spi_WriteIB( Spi_ChannelType Channel, const Spi_DataType *DataBufferPtr );
\r
450 Std_ReturnType Spi_AsyncTransmit( Spi_SequenceType Sequence );
\r
451 Std_ReturnType Spi_ReadIB( Spi_ChannelType Channel, Spi_DataType *const DataBufferPtr ) ;
\r
452 Std_ReturnType Spi_SetupEB( Spi_ChannelType Channel,
\r
453 const Spi_DataType* SrcDataBufferPtr,
\r
454 Spi_DataType* DesDataBufferPtr,
\r
455 Spi_NumberOfDataType Length );
\r
457 Spi_StatusType Spi_GetStatus( void );
\r
458 Spi_JobResultType Spi_GetJobResult ( Spi_JobType Job );
\r
459 Spi_SeqResultType Spi_GetSequenceResult(Spi_SequenceType Sequence );
\r
461 #if ( SPI_VERSION_INFO_API == STD_ON )
\r
462 #define Spi_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,SPI)
\r
465 Std_ReturnType Spi_SyncTransmit( Spi_SequenceType Sequence );
\r
466 Spi_StatusType Spi_GetHWUnitStatus(Spi_HWUnitType HWUnit);
\r
468 #if (SPI_CANCEL_API == STD_ON )
\r
469 void Spi_Cancel( Spi_SequenceType Sequence );
\r
472 Std_ReturnType Spi_SetAsyncMode( Spi_AsyncModeType Mode );
\r
473 void Spi_MainFunction_Handling( void );
\r
474 void Spi_MainFunction_Driving( void );
\r
476 extern const Spi_ConfigType SpiConfigData;
\r