Appiko
S2LP_Fifo.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "S2LP_Fifo.h"
26 #include "MCU_Interface.h"
27 
28 
65 #define IS_FIFO_THR(VAL) (VAL<=128)
66 
103 {
104  uint8_t tmp;
105  g_xStatus = S2LPSpiReadRegisters(RX_FIFO_STATUS_ADDR, 1, &tmp);
106  return tmp;
107 
108 }
109 
110 
117 {
118  uint8_t tmp;
119  g_xStatus = S2LPSpiReadRegisters(TX_FIFO_STATUS_ADDR, 1, &tmp);
120  return tmp;
121 
122 }
123 
124 
133 void S2LPFifoSetAlmostFullThresholdRx(uint8_t cThrRxFifo)
134 {
135  uint8_t tmp;
136 
137  s_assert_param(IS_FIFO_THR(cThrRxFifo));
138 
139  S2LPSpiReadRegisters(FIFO_CONFIG3_ADDR, 1, &tmp);
140 
141  tmp &= ~RX_AFTHR_REGMASK;
142  tmp |= cThrRxFifo;
143 
144  g_xStatus = S2LPSpiWriteRegisters(FIFO_CONFIG3_ADDR, 1, &tmp);
145 
146 }
147 
148 
157 {
158  uint8_t tmp;
159 
160  g_xStatus = S2LPSpiReadRegisters(FIFO_CONFIG3_ADDR, 1, &tmp);
161 
162  return (tmp & RX_AFTHR_REGMASK);
163 
164 }
165 
166 
173 void S2LPFifoSetAlmostEmptyThresholdRx(uint8_t cThrRxFifo)
174 {
175  uint8_t tmp;
176 
177  s_assert_param(IS_FIFO_THR(cThrRxFifo));
178 
179  S2LPSpiReadRegisters(FIFO_CONFIG2_ADDR, 1, &tmp);
180 
181  tmp &= ~RX_AETHR_REGMASK;
182  tmp |= cThrRxFifo;
183 
184  g_xStatus = S2LPSpiWriteRegisters(FIFO_CONFIG2_ADDR, 1, &tmp);
185 
186 }
187 
188 
195 {
196  uint8_t tmp;
197 
198  g_xStatus = S2LPSpiReadRegisters(FIFO_CONFIG2_ADDR, 1, &tmp);
199 
200  return (tmp & RX_AETHR_REGMASK);
201 
202 }
203 
204 
213 void S2LPFifoSetAlmostFullThresholdTx(uint8_t cThrTxFifo)
214 {
215  uint8_t tmp;
216 
217  s_assert_param(IS_FIFO_THR(cThrTxFifo));
218 
219  S2LPSpiReadRegisters(FIFO_CONFIG1_ADDR, 1, &tmp);
220 
221  tmp &= ~TX_AFTHR_REGMASK;
222  tmp |= cThrTxFifo;
223 
224  g_xStatus = S2LPSpiWriteRegisters(FIFO_CONFIG1_ADDR, 1, &tmp);
225 
226 }
227 
228 
237 {
238  uint8_t tmp;
239 
240  g_xStatus = S2LPSpiReadRegisters(FIFO_CONFIG1_ADDR, 1, &tmp);
241 
242  return (tmp & TX_AFTHR_REGMASK);
243 
244 }
245 
246 
253 void S2LPFifoSetAlmostEmptyThresholdTx(uint8_t cThrTxFifo)
254 {
255  uint8_t tmp;
256 
257  s_assert_param(IS_FIFO_THR(cThrTxFifo));
258 
259  S2LPSpiReadRegisters(FIFO_CONFIG0_ADDR, 1, &tmp);
260 
261  /* Build the register value */
262  tmp &= ~TX_AETHR_REGMASK;
263  tmp |= cThrTxFifo;
264 
265  /* Writes the Almost Empty threshold for Tx in the corresponding register */
266  g_xStatus = S2LPSpiWriteRegisters(FIFO_CONFIG0_ADDR, 1, &tmp);
267 
268 }
269 
270 
277 {
278  uint8_t tmp;
279 
280  g_xStatus = S2LPSpiReadRegisters(FIFO_CONFIG0_ADDR, 1, &tmp);
281 
282  return (tmp & TX_AETHR_REGMASK);
283 
284 }
285 
286 
293 {
294  /* default TX selection*/
295  uint8_t tmp;
296  s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
297 
298  S2LPSpiReadRegisters(PROTOCOL2_ADDR, 1, &tmp);
299 
300  if(xNewState == S_ENABLE) {
301  tmp |= FIFO_GPIO_OUT_MUX_SEL_REGMASK;
302  } else {
303  tmp &= ~FIFO_GPIO_OUT_MUX_SEL_REGMASK;
304  }
305  g_xStatus = S2LPSpiWriteRegisters(PROTOCOL2_ADDR, 1, &tmp);
306 }
307 
308 
324 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
uint8_t S2LPFifoGetAlmostFullThresholdRx(void)
Return the almost full threshold for RX FIFO.
Definition: S2LP_Fifo.c:156
#define PROTOCOL2_ADDR
PROTOCOL2 register.
Definition: S2LP_Regs.h:660
void S2LPFifoSetAlmostFullThresholdRx(uint8_t cThrRxFifo)
Set the almost full threshold for the Rx FIFO. When the number of elements in RX FIFO reaches this va...
Definition: S2LP_Fifo.c:133
SFunctionalState
S2LP Functional state. Used to enable or disable a specific option.
Definition: S2LP_Types.h:67
void S2LPFifoSetAlmostEmptyThresholdRx(uint8_t cThrRxFifo)
Set the almost empty threshold for the Rx FIFO. When the number of elements in RX FIFO reaches this v...
Definition: S2LP_Fifo.c:173
#define RX_FIFO_STATUS_ADDR
RX_FIFO_STATUS register.
Definition: S2LP_Regs.h:1513
uint8_t S2LPFifoGetAlmostFullThresholdTx(void)
Return the almost full threshold for Tx FIFO.
Definition: S2LP_Fifo.c:236
Configuration and management of S2-LP Fifo.
uint8_t S2LPFifoReadNumberBytesRxFifo(void)
Return the number of elements in the Rx FIFO.
Definition: S2LP_Fifo.c:102
#define FIFO_CONFIG2_ADDR
FIFO_CONFIG2 register.
Definition: S2LP_Regs.h:740
volatile S2LPStatus g_xStatus
S2LP Status global variable. This global variable of S2LPStatus type is updated on every SPI transact...
Definition: S2LP_Types.c:82
uint8_t S2LPFifoReadNumberBytesTxFifo(void)
Return the number of elements in the Tx FIFO.
Definition: S2LP_Fifo.c:116
void S2LPFifoSetAlmostFullThresholdTx(uint8_t cThrTxFifo)
Set the almost full threshold for the Tx FIFO. When the number of elements in TX FIFO reaches this va...
Definition: S2LP_Fifo.c:213
#define TX_FIFO_STATUS_ADDR
TX_FIFO_STATUS register.
Definition: S2LP_Regs.h:1499
Header file for low level S2LP SPI driver.
#define FIFO_CONFIG1_ADDR
FIFO_CONFIG1 register.
Definition: S2LP_Regs.h:754
uint8_t S2LPFifoGetAlmostEmptyThresholdTx(void)
Return the almost empty threshold for Tx FIFO.
Definition: S2LP_Fifo.c:276
#define FIFO_CONFIG3_ADDR
FIFO_CONFIG3 register.
Definition: S2LP_Regs.h:726
#define FIFO_CONFIG0_ADDR
FIFO_CONFIG0 register.
Definition: S2LP_Regs.h:768
uint8_t S2LPFifoGetAlmostEmptyThresholdRx(void)
Return the almost empty threshold for Rx FIFO.
Definition: S2LP_Fifo.c:194
void S2LPFifoSetAlmostEmptyThresholdTx(uint8_t cThrTxFifo)
Set the almost empty threshold for the Tx FIFO. When the number of elements in Tx FIFO reaches this v...
Definition: S2LP_Fifo.c:253
void S2LPFifoMuxRxFifoIrqEnable(SFunctionalState xNewState)
Enable the Mux for the Rx FIFO IRQ. To be enabled when RX FIFO THRESHOLD is used.
Definition: S2LP_Fifo.c:292