ESOS32
ESOSOn32-bitProcessors
esos_spi.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
28 
29 #ifndef _ESOS_SPI_H
30 #define _ESOS_SPI_H
31 
32 
39 // Documentation for this file. If the \file tag isn't present,
40 // this file won't be documented.
46 /* I N C L U D E S **********************************************************/
47 #include "esos.h"
48 
49 /* D E F I N I T I O N S ****************************************************/
50 
51 /* E X T E R N S ************************************************************/
52 extern struct stTask __stChildTaskSPI; // req'd child task for hw SPI functions
53 extern uint16_t __esos_spi_u16s[2]; // used to store arguments
54 
55 /* M A C R O S **************************************************************/
66 #define ESOS_TASK_WAIT_ON_AVAILABLE_SPI() \
67  do { \
68  ESOS_TASK_WAIT_UNTIL(ESOS_IS_SPI_AVAILABLE()); \
69  __esos_SetSystemFlag(__ESOS_SYS_SPI_IN_USE); \
70  }while(0)
71 
83 #define ESOS_SIGNAL_AVAILABLE_SPI() __esos_ClearSystemFlag(__ESOS_SYS_SPI_IN_USE)
84 
99 #define ESOS_IS_SPI_AVAILABLE() (__esos_IsSystemFlagClear(__ESOS_SYS_SPI_IN_USE))
100 
116 #define ESOS_TASK_WAIT_ON_WRITE1SPI1(u16_d1 ) \
117  do{ \
118  __esos_spi_u16s[0] = (uint16_t) (u16_d1); \
119  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, &__esos_spi_u16s[0], NULLPTR, 1 ); \
120  }while(0)
121 
122 
123 // We need a 2-byte array to be able to use the buffer.
124 // Otherwise, we'd need two writeN calls, which require
125 // child tasks, i.e. code size grows
126 
143 #define ESOS_TASK_WAIT_ON_WRITE2SPI1(u16_d1, u16_d2 ) \
144  do{ \
145  __esos_spi_u16s[0] = (uint16_t) (u16_d1); \
146  __esos_spi_u16s[1] = (uint16_t) (u16_d2); \
147  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, &__esos_spi_u16s[0], NULLPTR, 2 ); \
148  }while(0)
149 
166 #define ESOS_TASK_WAIT_ON_WRITENSPI1( pu16_out, u16_cnt ) \
167  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, (pu16_out), NULLPTR, (u16_cnt) )
168 
190 #define ESOS_TASK_WAIT_ON_XFERNSPI1( pu16_out, pu16_in, u16_cnt ) \
191  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, (pu16_out), (pu16_in), (u16_cnt) )
192 
209 #define ESOS_TASK_WAIT_ON_READ1SPI1(u16_d1 ) \
210  do{ \
211  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, NULLPTR, &__esos_spi_u16s[0], 1 ); \
212  (u16_d1) = __esos_spi_u16s[0]; \
213  }while(0)
214 
232 #define ESOS_TASK_WAIT_ON_READ2SPI1(u16_d1, u16_d2) \
233  do{ \
234  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, NULLPTR, &__esos_spi_u16s[0], 2 ); \
235  (u16_d1) = __esos_spi_u16s[0]; \
236  (u16_d2) = __esos_spi_u16s[1]; \
237  }while(0)
238 
256 #define ESOS_TASK_WAIT_ON_READNSPI1( pu16_in, u16_cnt ) \
257  ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskSPI, __esos_spi_hw_xferNSPI1, NULLPTR, (pu16_in), (u16_cnt) )
258 
259 
260 /* P U B L I C P R O T O T Y P E S *****************************************/
261 void __esos_spi_config(uint32_t u32_spibps);
262 
263 /* P R O T O T Y P E S HARDWARE-SPECIFIC ********************************/
264 extern void __esos_spi_hw_config(uint32_t u32_spibps);
265 ESOS_CHILD_TASK( __esos_spi_hw_xferNSPI1, uint16_t* pu16_out, uint16_t* pu16_in, uint16_t u16_cnt);
266 
268 #endif // end ESOS_SPI_H
__esos_spi_config
void __esos_spi_config(uint32_t u32_spibps)
Definition: esos_spi.c:70
esos.h
ESOS_CHILD_TASK
#define ESOS_CHILD_TASK(taskname,...)
Definition: esos_task.h:246
stTask
Definition: esos_task.h:54