Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
40 #ifndef CASCODA_SPI_H
41 #define CASCODA_SPI_H
42 
44 #include "ca821x_api.h"
45 #include "mac_messages.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /****** Definitions for SPI Handling ******/
52 
53 #define SPI_T_TIMEOUT 500
54 #define SPI_T_BACKOFF 10
55 #define SPI_T_HOLD_8210 100
56 #define SPI_T_CSHOLD 50
57 
58 #define SPI_RX_FIFO_SIZE 7
59 #define SPI_RX_FIFO_RESV 4
60 
61 #if !(SPI_RX_FIFO_RESV < SPI_RX_FIFO_SIZE)
62 #error "SPI_RX_FIFO_RESV must be less than SPI_RX_FIFO_SIZE"
63 #endif
64 
65 /****** Function Declarations for cascoda_spi.c ******/
66 
82 ca_error SPI_Exchange(const struct MAC_Message *pTxBuffer, struct ca821x_dev *pDeviceRef);
83 
99 ca_error SPI_Send(const uint8_t *buf, u8_t *response, struct ca821x_dev *pDeviceRef);
100 
112 struct MAC_Message *SPI_PeekFullBuf(void);
113 
123 void SPI_DequeueFullBuf(void);
124 
135 bool SPI_IsFifoFull(void);
136 
149 bool SPI_IsFifoAlmostFull(void);
150 
159 bool SPI_IsFifoEmpty(void);
160 
171 
187 bool SPI_IsSyncChainInFlight(void);
188 
202 void SPI_StartSyncChain(struct ca821x_dev *pDeviceRef);
203 
211 void SPI_StopSyncChain(struct ca821x_dev *pDeviceRef);
212 
217 void SPI_Initialise(void);
218 
223 void SPI_ExchangeComplete(void);
224 
231 
232 #if CASCODA_EXTERNAL_FLASHCHIP_PRESENT
247 ca_error SPI_SetExternallyInUseStatus(bool status, void (*callback)(void));
248 #endif
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif // CASCODA_SPI_H
255 
The main ca821x-api include file.
Type definitions used by Cascoda baremetal drivers.
unsigned char u8_t
Definition: cascoda_types.h:46
bool SPI_GetExternallyInUseStatus(void)
Checks if the SPI is being used by something other than the RF chip.
Definition: cascoda_spi.c:607
struct MAC_Message * SPI_PeekFullBuf(void)
Get a MAC_Message buffer containing a received SPI Message.
Definition: cascoda_spi.c:218
void SPI_Initialise(void)
Initialise SPI buffers and call BSP SPI init.
Definition: cascoda_spi.c:598
bool SPI_IsSyncChainInFlight(void)
Query whether the SPI driver is currently locked in a Sync chain.
Definition: cascoda_spi.c:146
void SPI_StopSyncChain(struct ca821x_dev *pDeviceRef)
Stop the sync chain after starting with SPI_StartSyncChain.
Definition: cascoda_spi.c:161
void SPI_StartSyncChain(struct ca821x_dev *pDeviceRef)
Start a 'Sync Chain' For more efficient and safer chains of sync message communication with the CA821...
Definition: cascoda_spi.c:151
bool SPI_IsFifoFull(void)
Query whether the SPI message FIFO is full or not.
Definition: cascoda_spi.c:83
bool SPI_IsExchangeWithCA821xInProgress(void)
Query whether an SPI exchange operation with the CA821x is currently in progress.
Definition: cascoda_spi.c:141
ca_error SPI_Exchange(const struct MAC_Message *pTxBuffer, struct ca821x_dev *pDeviceRef)
Exchange Messages across SPI.
Definition: cascoda_spi.c:416
bool SPI_IsFifoEmpty(void)
Query whether the SPI message FIFO is empty or not.
Definition: cascoda_spi.c:94
void SPI_DequeueFullBuf(void)
Remove a processed Full Buffer from the SPI Queue.
Definition: cascoda_spi.c:230
bool SPI_IsFifoAlmostFull(void)
Query whether the SPI message FIFO is almost full or not.
Definition: cascoda_spi.c:123
ca_error SPI_Send(const uint8_t *buf, u8_t *response, struct ca821x_dev *pDeviceRef)
Send Request over SPI.
Definition: cascoda_spi.c:529
void SPI_ExchangeComplete(void)
Function to be called from the BSP when an exchange operation has been completed.
Definition: cascoda_spi.c:581
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
Definitions relating to MLME and MCPS API messages.
SPI Message Format Typedef.
Definition: mac_messages.h:1017
CA-821x Device reference struct.
Definition: ca821x_api.h:123