]> rtime.felk.cvut.cz Git - arc.git/blob - include/Spi.h
Initial commit.
[arc.git] / include / Spi.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_H_
24 #define SPI_H_
25
26 #include "Std_Types.h"
27
28 /* Standard info */
29 #define SPI_VENDOR_ID             1
30 #define SPI_MODULE_ID                    MODULE_ID_SPI
31 #define SPI_SW_MAJOR_VERSION      1
32 #define SPI_SW_MINOR_VERSION      0
33 #define SPI_SW_PATCH_VERSION      2
34 #define SPI_AR_MAJOR_VERSION      2
35 #define SPI_AR_MINOR_VERSION      2
36 #define SPI_AR_PATCH_VERSION      2
37
38
39 /* --- Service IDs --- */
40 #define SPI_INIT_SERVICE_ID               0x00
41 #define SPI_DEINIT_SERVICE_ID             0x01
42 #define SPI_WRITEIB_SERVICE_ID            0x02
43 #define SPI_ASYNCTRANSMIT_SERVICE_ID      0x03
44 #define SPI_READIB_SERVICE_ID             0x04
45 #define SPI_SETUPEB_SERVICE_ID            0x05
46 #define SPI_GETSTATUS_SERVICE_ID          0x06
47 #define SPI_GETJOBRESULT_SERVICE_ID       0x07
48 #define SPI_GETSEQUENCERESULT_SERVICE_ID  0x08
49 #define SPI_GETVERSIONINFO_SERVICE_ID     0x09
50 #define SPI_SYNCTRANSMIT_SERVICE_ID       0x0A
51 #define SPI_GETHWUNITSTATUS_SERVICE_ID    0x0B
52 #define SPI_CANCEL_SERVICE_ID             0x0C
53 #define SPI_SETASYNCMODE_SERVICE_ID       0x0D
54
55 /* --- Error codes --- */
56 #define SPI_E_PARAM_CHANNEL               0x0A
57 #define SPI_E_PARAM_JOB                   0x0B
58 #define SPI_E_PARAM_SEQ                   0x0C
59 #define SPI_E_PARAM_LENGTH                0x0D
60 #define SPI_E_PARAM_UNIT                  0x0E
61 #define SPI_E_UNINIT                      0x1A
62 #define SPI_E_SEQ_PENDING                 0x2A
63 #define SPI_E_SEQ_IN_PROCESS              0x3A
64 #define SPI_E_ALREADY_INITIALIZED         0x4A
65
66 typedef enum {
67         SPI_UNINIT=0, // The SPI Handler/Driver is not initialized or not usable.
68                                 // SPI011: This shall be the default value after reset. This
69                         // status shall have the value 0.
70
71         SPI_IDLE,       // The SPI Handler/Driver is not currently transmitting any
72                         // Job.
73
74         SPI_BUSY,       // The SPI Handler/Driver is performing a SPI Job( transmit )
75 } Spi_StatusType;
76
77 typedef enum {
78         SPI_JOB_OK=0,           // The last transmission of the Job has been finished
79                                         // successfully.
80                                         // SPI012: This shall be the default value after reset.
81                                         // This status shall have the value 0.
82
83         SPI_JOB_PENDING,        // The SPI Handler/Driver is performing a SPI Job.
84                                                 // The meaning of this status is equal to SPI_BUSY.
85
86         SPI_JOB_FAILED,         // The last transmission of the Job has failed.
87 } Spi_JobResultType;
88
89 typedef enum {
90
91         SPI_SEQ_OK,     //      The last transmission of the Sequence has been
92                                         //    finished successfully.
93                                         //    SPI017: This shall be the default value after reset.
94                                         //    This status shall have the value 0.
95
96         SPI_SEQ_PENDING, // The SPI Handler/Driver is performing a SPI
97                         // Sequence. The meaning of this status is equal to
98                         // SPI_BUSY.
99
100         SPI_SEQ_FAILED,         // The last transmission of the Sequence has failed.
101
102         SPI_SEQ_CANCELLED,      // The last transmission of the Sequence has been
103                                         //    cancelled by user.
104 } Spi_SeqResultType;
105
106
107 // Type for defining the number of data elements of the type Spi_DataType to
108 // send and / or receive by Channel
109 typedef uint16 Spi_NumberOfDataType;
110
111
112 // Specifies the asynchronous mechanism mode for SPI busses handled
113 // asynchronously in LEVEL 2.
114 // SPI150: This type is available or not accordint to the pre compile time parameter:
115 // SPI_LEVEL_DELIVERED. This is only relevant for LEVEL 2.
116
117 typedef enum {
118
119         //      The asynchronous mechanism is ensured by
120         //    polling, so interrupts related to SPI busses
121         //    handled asynchronously are disabled.
122         SPI_POLLING_MODE,
123
124         //    The asynchronous mechanism is ensured by
125         //    interrupt, so interrupts related to SPI busses
126         //    handled asynchronously are enabled.
127
128         SPI_INTERRUPT_MODE,
129 } Spi_AsyncModeType;
130
131
132 #include "Spi_Cfg.h"
133
134 void Spi_Init( const Spi_ConfigType *ConfigPtr );
135 Std_ReturnType Spi_DeInit( void );
136 Std_ReturnType Spi_WriteIB( Spi_ChannelType Channel, const Spi_DataType *DataBufferPtr );
137 Std_ReturnType Spi_AsyncTransmit( Spi_SequenceType Sequence );
138 Std_ReturnType Spi_ReadIB( Spi_ChannelType Channel, Spi_DataType *const DataBufferPtr ) ;
139 Std_ReturnType Spi_SetupEB( Spi_ChannelType Channel,
140                                                         const Spi_DataType*  SrcDataBufferPtr,
141                                                 Spi_DataType* DesDataBufferPtr,
142                                                 Spi_NumberOfDataType Length );
143
144 Spi_StatusType Spi_GetStatus( void );
145 Spi_JobResultType Spi_GetJobResult ( Spi_JobType       Job );
146 Spi_SeqResultType Spi_GetSequenceResult(Spi_SequenceType Sequence );
147
148 #if ( SPI_VERSION_INFO_API == STD_ON  )
149 #define Spi_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,SPI)
150 #endif
151
152 Std_ReturnType Spi_SyncTransmit( Spi_SequenceType        Sequence );
153 Spi_StatusType Spi_GetHWUnitStatus(Spi_HWUnitType        HWUnit);
154
155 #if (SPI_CANCEL_API == STD_ON )
156 void Spi_Cancel( Spi_SequenceType Sequence );
157 #endif
158
159 Std_ReturnType Spi_SetAsyncMode( Spi_AsyncModeType        Mode );
160 void Spi_MainFunction_Handling( void );
161 void Spi_MainFunction_Driving( void );
162
163 #endif /*SPI_H_*/