15
15
*
16
16
******************************************************************************/
17
17
18
- #include "FreeRTOS.h"
19
18
#include "cmsis_os2.h"
20
19
#include "dmadrv.h"
21
20
#include "em_cmu.h"
37
36
#include "sl_power_manager.h"
38
37
#endif
39
38
39
+ #define USART_INITSYNC_BAUDRATE 12500000
40
+
40
41
static bool dma_callback (unsigned int channel , unsigned int sequenceNo , void * userParam );
41
42
42
43
unsigned int rx_ldma_channel ;
43
44
unsigned int tx_ldma_channel ;
44
- osMutexId_t spi_transfer_mutex = 0 ;
45
+ osMutexId_t ncp_transfer_mutex = 0 ;
45
46
46
47
static uint32_t dummy_buffer ;
48
+ static sl_si91x_host_init_configuration init_config = { 0 };
47
49
48
50
// LDMA descriptor and transfer configuration structures for USART TX channel
49
51
LDMA_Descriptor_t ldmaTXDescriptor ;
@@ -70,33 +72,22 @@ static bool dma_callback(unsigned int channel, unsigned int sequenceNo, void * u
70
72
static void gpio_interrupt (uint8_t interrupt_number )
71
73
{
72
74
UNUSED_PARAMETER (interrupt_number );
73
- sl_si91x_host_set_bus_event (NCP_HOST_BUS_RX_EVENT );
74
- // GPIO_IntClear(0xAAAA);
75
- }
76
-
77
- void sl_si91x_host_set_sleep_indicator (void )
78
- {
79
- GPIO_PinOutSet (SLEEP_CONFIRM_PIN .port , SLEEP_CONFIRM_PIN .pin );
80
- }
81
75
82
- void sl_si91x_host_clear_sleep_indicator (void )
83
- {
84
- GPIO_PinOutClear (SLEEP_CONFIRM_PIN .port , SLEEP_CONFIRM_PIN .pin );
76
+ if (NULL != init_config .rx_irq )
77
+ {
78
+ init_config .rx_irq ();
79
+ }
85
80
}
86
81
87
- uint32_t sl_si91x_host_get_wake_indicator (void )
82
+ static void efx32_spi_init (void )
88
83
{
89
- return GPIO_PinInGet ( WAKE_INDICATOR_PIN . port , WAKE_INDICATOR_PIN . pin );
90
- }
84
+ // Default asynchronous initializer (master mode, 1 Mbps, 8-bit data)
85
+ USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT ;
91
86
92
- sl_status_t sl_si91x_host_init (void )
93
- {
94
- // Enable clock (not needed on xG21)
95
- CMU_ClockEnable (cmuClock_GPIO , true);
87
+ init .msbf = true; // MSB first transmission for SPI compatibility
88
+ init .autoCsEnable = true; // Allow the USART to assert CS
89
+ init .baudrate = USART_INITSYNC_BAUDRATE ;
96
90
97
- #if SL_SPICTRL_MUX
98
- spi_board_init ();
99
- #endif
100
91
// Configure SPI bus pins
101
92
GPIO_PinModeSet (SPI_MISO_PIN .port , SPI_MISO_PIN .pin , gpioModeInput , 0 );
102
93
GPIO_PinModeSet (SPI_MOSI_PIN .port , SPI_MOSI_PIN .pin , gpioModePushPull , 0 );
@@ -105,12 +96,6 @@ sl_status_t sl_si91x_host_init(void)
105
96
// Enable clock (not needed on xG21)
106
97
CMU_ClockEnable (SPI_USART_CMU_CLOCK , true);
107
98
108
- // Default asynchronous initializer (master mode, 1 Mbps, 8-bit data)
109
- USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT ;
110
-
111
- init .msbf = true; // MSB first transmission for SPI compatibility
112
- init .autoCsEnable = true; // Allow the USART to assert CS
113
- init .baudrate = 12500000 ;
114
99
/*
115
100
* Route USART RX, TX, and CLK to the specified pins. Note that CS is
116
101
* not controlled by USART so there is no write to the corresponding
@@ -139,33 +124,64 @@ sl_status_t sl_si91x_host_init(void)
139
124
SPI_USART -> TIMING |= /*USART_TIMING_TXDELAY_ONE | USART_TIMING_CSSETUP_ONE |*/ USART_TIMING_CSHOLD_ONE ;
140
125
141
126
// SPI_USART->CTRL_SET |= USART_CTRL_SMSDELAY;
127
+
128
+ // configure packet pending interrupt priority
129
+ NVIC_SetPriority (GPIO_ODD_IRQn , PACKET_PENDING_INT_PRI );
130
+ GPIOINT_CallbackRegister (INTERRUPT_PIN .pin , gpio_interrupt );
131
+ GPIO_PinModeSet (INTERRUPT_PIN .port , INTERRUPT_PIN .pin , gpioModeInputPullFilter , 0 );
132
+ GPIO_ExtIntConfig (INTERRUPT_PIN .port , INTERRUPT_PIN .pin , INTERRUPT_PIN .pin , true, false, true);
133
+ }
134
+
135
+ void sl_si91x_host_set_sleep_indicator (void )
136
+ {
137
+ GPIO_PinOutSet (SLEEP_CONFIRM_PIN .port , SLEEP_CONFIRM_PIN .pin );
138
+ }
139
+
140
+ void sl_si91x_host_clear_sleep_indicator (void )
141
+ {
142
+ GPIO_PinOutClear (SLEEP_CONFIRM_PIN .port , SLEEP_CONFIRM_PIN .pin );
143
+ }
144
+
145
+ uint32_t sl_si91x_host_get_wake_indicator (void )
146
+ {
147
+ return GPIO_PinInGet (WAKE_INDICATOR_PIN .port , WAKE_INDICATOR_PIN .pin );
148
+ }
149
+
150
+ sl_status_t sl_si91x_host_init (sl_si91x_host_init_configuration * config )
151
+ {
152
+ init_config .rx_irq = config -> rx_irq ;
153
+ init_config .rx_done = config -> rx_done ;
154
+
155
+ // Enable clock (not needed on xG21)
156
+ CMU_ClockEnable (cmuClock_GPIO , true);
157
+
158
+ #if SL_SPICTRL_MUX
159
+ spi_board_init ();
160
+ #endif
161
+
142
162
if (transfer_done_semaphore == NULL )
143
163
{
144
164
transfer_done_semaphore = osSemaphoreNew (1 , 0 , NULL );
145
165
}
146
166
147
- if (spi_transfer_mutex == 0 )
167
+ if (ncp_transfer_mutex == 0 )
148
168
{
149
- spi_transfer_mutex = osMutexNew (NULL );
169
+ ncp_transfer_mutex = osMutexNew (NULL );
150
170
}
151
171
152
- DMADRV_Init ();
153
- DMADRV_AllocateChannel (& rx_ldma_channel , NULL );
154
- DMADRV_AllocateChannel (& tx_ldma_channel , NULL );
172
+ efx32_spi_init ();
155
173
156
174
// Start reset line low
157
175
GPIO_PinModeSet (RESET_PIN .port , RESET_PIN .pin , gpioModePushPull , 0 );
158
176
159
- // configure packet pending interrupt priority
160
- NVIC_SetPriority (GPIO_ODD_IRQn , PACKET_PENDING_INT_PRI );
161
-
162
177
// Configure interrupt, sleep and wake confirmation pins
163
- GPIOINT_CallbackRegister (INTERRUPT_PIN .pin , gpio_interrupt );
164
- GPIO_PinModeSet (INTERRUPT_PIN .port , INTERRUPT_PIN .pin , gpioModeInputPullFilter , 0 );
165
- GPIO_ExtIntConfig (INTERRUPT_PIN .port , INTERRUPT_PIN .pin , INTERRUPT_PIN .pin , true, false, true);
166
178
GPIO_PinModeSet (SLEEP_CONFIRM_PIN .port , SLEEP_CONFIRM_PIN .pin , gpioModeWiredOrPullDown , 1 );
167
179
GPIO_PinModeSet (WAKE_INDICATOR_PIN .port , WAKE_INDICATOR_PIN .pin , gpioModeWiredOrPullDown , 0 );
168
180
181
+ DMADRV_Init ();
182
+ DMADRV_AllocateChannel (& rx_ldma_channel , NULL );
183
+ DMADRV_AllocateChannel (& tx_ldma_channel , NULL );
184
+
169
185
return SL_STATUS_OK ;
170
186
}
171
187
@@ -174,11 +190,7 @@ sl_status_t sl_si91x_host_deinit(void)
174
190
return SL_STATUS_OK ;
175
191
}
176
192
177
- void sl_si91x_host_enable_high_speed_bus ()
178
- {
179
- // SPI_USART->CTRL_SET |= USART_CTRL_SMSDELAY | USART_CTRL_SSSEARLY;
180
- // USART_BaudrateSyncSet(SPI_USART, 0, 20000000);
181
- }
193
+ void sl_si91x_host_enable_high_speed_bus () {}
182
194
183
195
/*==================================================================*/
184
196
/**
@@ -194,7 +206,7 @@ void sl_si91x_host_enable_high_speed_bus()
194
206
*/
195
207
sl_status_t sl_si91x_host_spi_transfer (const void * tx_buffer , void * rx_buffer , uint16_t buffer_length )
196
208
{
197
- osMutexAcquire (spi_transfer_mutex , 0xFFFFFFFFUL );
209
+ osMutexAcquire (ncp_transfer_mutex , 0xFFFFFFFFUL );
198
210
199
211
#if SL_SPICTRL_MUX
200
212
sl_wfx_host_spi_cs_assert ();
@@ -268,7 +280,7 @@ sl_status_t sl_si91x_host_spi_transfer(const void * tx_buffer, void * rx_buffer,
268
280
}
269
281
}
270
282
271
- osMutexRelease (spi_transfer_mutex );
283
+ osMutexRelease (ncp_transfer_mutex );
272
284
#if SL_SPICTRL_MUX
273
285
sl_wfx_host_spi_cs_deassert ();
274
286
#endif // SL_SPICTRL_MUX
@@ -288,6 +300,7 @@ void sl_si91x_host_release_from_reset(void)
288
300
289
301
void sl_si91x_host_enable_bus_interrupt (void )
290
302
{
303
+ NVIC_ClearPendingIRQ (GPIO_ODD_IRQn );
291
304
NVIC_EnableIRQ (GPIO_ODD_IRQn );
292
305
}
293
306
0 commit comments