13
13
#include <hal/nrf_gpio.h>
14
14
15
15
16
+ static NRF_UART_Type * const uart0_addr = (NRF_UART_Type * )CONFIG_UART_0_BASE ;
17
+
16
18
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
17
19
18
20
static uart_irq_callback_t irq_callback ; /**< Callback function pointer */
@@ -29,7 +31,7 @@ static volatile u8_t uart_sw_event_txdrdy;
29
31
30
32
static bool event_txdrdy_check (void )
31
33
{
32
- return (nrf_uart_event_check (NRF_UART0 , NRF_UART_EVENT_TXDRDY )
34
+ return (nrf_uart_event_check (uart0_addr , NRF_UART_EVENT_TXDRDY )
33
35
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
34
36
|| uart_sw_event_txdrdy
35
37
#endif
@@ -38,7 +40,7 @@ static bool event_txdrdy_check(void)
38
40
39
41
static void event_txdrdy_clear (void )
40
42
{
41
- nrf_uart_event_clear (NRF_UART0 , NRF_UART_EVENT_TXDRDY );
43
+ nrf_uart_event_clear (uart0_addr , NRF_UART_EVENT_TXDRDY );
42
44
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
43
45
uart_sw_event_txdrdy = 0 ;
44
46
#endif
@@ -127,7 +129,7 @@ static int baudrate_set(struct device *dev, u32_t baudrate)
127
129
return - EINVAL ;
128
130
}
129
131
130
- nrf_uart_baudrate_set (NRF_UART0 , nrf_baudrate );
132
+ nrf_uart_baudrate_set (uart0_addr , nrf_baudrate );
131
133
132
134
return 0 ;
133
135
}
@@ -143,15 +145,15 @@ static int baudrate_set(struct device *dev, u32_t baudrate)
143
145
144
146
static int uart_nrfx_poll_in (struct device * dev , unsigned char * c )
145
147
{
146
- if (!nrf_uart_event_check (NRF_UART0 , NRF_UART_EVENT_RXDRDY )) {
148
+ if (!nrf_uart_event_check (uart0_addr , NRF_UART_EVENT_RXDRDY )) {
147
149
return -1 ;
148
150
}
149
151
150
152
/* Clear the interrupt */
151
- nrf_uart_event_clear (NRF_UART0 , NRF_UART_EVENT_RXDRDY );
153
+ nrf_uart_event_clear (uart0_addr , NRF_UART_EVENT_RXDRDY );
152
154
153
155
/* got a character */
154
- * c = nrf_uart_rxd_get (NRF_UART0 );
156
+ * c = nrf_uart_rxd_get (uart0_addr );
155
157
156
158
return 0 ;
157
159
}
@@ -182,7 +184,7 @@ static unsigned char uart_nrfx_poll_out(struct device *dev,
182
184
event_txdrdy_clear ();
183
185
184
186
/* send a character */
185
- nrf_uart_txd_set (NRF_UART0 , (u8_t )c );
187
+ nrf_uart_txd_set (uart0_addr , (u8_t )c );
186
188
187
189
/* Wait for transmitter to be ready */
188
190
while (!event_txdrdy_check ()) {
@@ -196,9 +198,9 @@ static int uart_nrfx_err_check(struct device *dev)
196
198
{
197
199
u32_t error = 0 ;
198
200
199
- if (nrf_uart_event_check (NRF_UART0 , NRF_UART_EVENT_ERROR )) {
201
+ if (nrf_uart_event_check (uart0_addr , NRF_UART_EVENT_ERROR )) {
200
202
/* register bitfields maps to the defines in uart.h */
201
- error = nrf_uart_errorsrc_get_and_clear (NRF_UART0 );
203
+ error = nrf_uart_errorsrc_get_and_clear (uart0_addr );
202
204
}
203
205
204
206
return error ;
@@ -221,7 +223,7 @@ static int uart_nrfx_fifo_fill(struct device *dev,
221
223
event_txdrdy_clear ();
222
224
223
225
/* Send a character */
224
- nrf_uart_txd_set (NRF_UART0 , (u8_t )tx_data [num_tx ++ ]);
226
+ nrf_uart_txd_set (uart0_addr , (u8_t )tx_data [num_tx ++ ]);
225
227
}
226
228
227
229
return (int )num_tx ;
@@ -235,12 +237,12 @@ static int uart_nrfx_fifo_read(struct device *dev,
235
237
u8_t num_rx = 0 ;
236
238
237
239
while ((size - num_rx > 0 ) &&
238
- nrf_uart_event_check (NRF_UART0 , NRF_UART_EVENT_RXDRDY )) {
240
+ nrf_uart_event_check (uart0_addr , NRF_UART_EVENT_RXDRDY )) {
239
241
/* Clear the interrupt */
240
- nrf_uart_event_clear (NRF_UART0 , NRF_UART_EVENT_RXDRDY );
242
+ nrf_uart_event_clear (uart0_addr , NRF_UART_EVENT_RXDRDY );
241
243
242
244
/* Receive a character */
243
- rx_data [num_rx ++ ] = (u8_t )nrf_uart_rxd_get (NRF_UART0 );
245
+ rx_data [num_rx ++ ] = (u8_t )nrf_uart_rxd_get (uart0_addr );
244
246
}
245
247
246
248
return num_rx ;
@@ -251,7 +253,7 @@ static void uart_nrfx_irq_tx_enable(struct device *dev)
251
253
{
252
254
u32_t key ;
253
255
254
- nrf_uart_int_enable (NRF_UART0 , NRF_UART_INT_MASK_TXDRDY );
256
+ nrf_uart_int_enable (uart0_addr , NRF_UART_INT_MASK_TXDRDY );
255
257
256
258
/* Critical section is used to avoid any UART related interrupt which
257
259
* can occur after the if statement and before call of the function
@@ -262,27 +264,27 @@ static void uart_nrfx_irq_tx_enable(struct device *dev)
262
264
/* Due to HW limitation first TXDRDY interrupt shall be
263
265
* triggered by the software.
264
266
*/
265
- NVIC_SetPendingIRQ (NRFX_IRQ_NUMBER_GET ( NRF_UART0 ) );
267
+ NVIC_SetPendingIRQ (CONFIG_UART_0_IRQ_NUM );
266
268
}
267
269
irq_unlock (key );
268
270
}
269
271
270
272
/** Interrupt driven transfer disabling function */
271
273
static void uart_nrfx_irq_tx_disable (struct device * dev )
272
274
{
273
- nrf_uart_int_disable (NRF_UART0 , NRF_UART_INT_MASK_TXDRDY );
275
+ nrf_uart_int_disable (uart0_addr , NRF_UART_INT_MASK_TXDRDY );
274
276
}
275
277
276
278
/** Interrupt driven receiver enabling function */
277
279
static void uart_nrfx_irq_rx_enable (struct device * dev )
278
280
{
279
- nrf_uart_int_enable (NRF_UART0 , NRF_UART_INT_MASK_RXDRDY );
281
+ nrf_uart_int_enable (uart0_addr , NRF_UART_INT_MASK_RXDRDY );
280
282
}
281
283
282
284
/** Interrupt driven receiver disabling function */
283
285
static void uart_nrfx_irq_rx_disable (struct device * dev )
284
286
{
285
- nrf_uart_int_disable (NRF_UART0 , NRF_UART_INT_MASK_RXDRDY );
287
+ nrf_uart_int_disable (uart0_addr , NRF_UART_INT_MASK_RXDRDY );
286
288
}
287
289
288
290
/** Interrupt driven transfer empty function */
@@ -294,29 +296,29 @@ static int uart_nrfx_irq_tx_ready_complete(struct device *dev)
294
296
/** Interrupt driven receiver ready function */
295
297
static int uart_nrfx_irq_rx_ready (struct device * dev )
296
298
{
297
- return nrf_uart_event_check (NRF_UART0 , NRF_UART_EVENT_RXDRDY );
299
+ return nrf_uart_event_check (uart0_addr , NRF_UART_EVENT_RXDRDY );
298
300
}
299
301
300
302
/** Interrupt driven error enabling function */
301
303
static void uart_nrfx_irq_err_enable (struct device * dev )
302
304
{
303
- nrf_uart_int_enable (NRF_UART0 , NRF_UART_INT_MASK_ERROR );
305
+ nrf_uart_int_enable (uart0_addr , NRF_UART_INT_MASK_ERROR );
304
306
}
305
307
306
308
/** Interrupt driven error disabling function */
307
309
static void uart_nrfx_irq_err_disable (struct device * dev )
308
310
{
309
- nrf_uart_int_disable (NRF_UART0 , NRF_UART_INT_MASK_ERROR );
311
+ nrf_uart_int_disable (uart0_addr , NRF_UART_INT_MASK_ERROR );
310
312
}
311
313
312
314
/** Interrupt driven pending status function */
313
315
static int uart_nrfx_irq_is_pending (struct device * dev )
314
316
{
315
- return ((nrf_uart_int_enable_check (NRF_UART0 ,
317
+ return ((nrf_uart_int_enable_check (uart0_addr ,
316
318
NRF_UART_INT_MASK_TXDRDY ) &&
317
319
event_txdrdy_check ())
318
320
||
319
- (nrf_uart_int_enable_check (NRF_UART0 ,
321
+ (nrf_uart_int_enable_check (uart0_addr ,
320
322
NRF_UART_INT_MASK_RXDRDY ) &&
321
323
uart_nrfx_irq_rx_ready (dev )));
322
324
}
@@ -378,7 +380,7 @@ static int uart_nrfx_init(struct device *dev)
378
380
379
381
nrf_gpio_cfg_input (CONFIG_UART_0_NRF_RX_PIN , NRF_GPIO_PIN_NOPULL );
380
382
381
- nrf_uart_txrx_pins_set (NRF_UART0 ,
383
+ nrf_uart_txrx_pins_set (uart0_addr ,
382
384
CONFIG_UART_0_NRF_TX_PIN ,
383
385
CONFIG_UART_0_NRF_RX_PIN );
384
386
@@ -391,12 +393,12 @@ static int uart_nrfx_init(struct device *dev)
391
393
392
394
nrf_gpio_cfg_input (CONFIG_UART_0_NRF_CTS_PIN , NRF_GPIO_PIN_NOPULL );
393
395
394
- nrf_uart_hwfc_pins_set (NRF_UART0 ,
396
+ nrf_uart_hwfc_pins_set (uart0_addr ,
395
397
CONFIG_UART_0_NRF_RTS_PIN ,
396
398
CONFIG_UART_0_NRF_CTS_PIN );
397
399
#endif /* CONFIG_UART_0_NRF_FLOW_CONTROL */
398
400
399
- nrf_uart_configure (NRF_UART0 ,
401
+ nrf_uart_configure (uart0_addr ,
400
402
#ifdef CONFIG_UART_0_NRF_PARITY_BIT
401
403
NRF_UART_PARITY_INCLUDED ,
402
404
#else
@@ -415,12 +417,12 @@ static int uart_nrfx_init(struct device *dev)
415
417
}
416
418
417
419
/* Enable receiver and transmitter */
418
- nrf_uart_enable (NRF_UART0 );
420
+ nrf_uart_enable (uart0_addr );
419
421
420
- nrf_uart_event_clear (NRF_UART0 , NRF_UART_EVENT_RXDRDY );
422
+ nrf_uart_event_clear (uart0_addr , NRF_UART_EVENT_RXDRDY );
421
423
422
- nrf_uart_task_trigger (NRF_UART0 , NRF_UART_TASK_STARTTX );
423
- nrf_uart_task_trigger (NRF_UART0 , NRF_UART_TASK_STARTRX );
424
+ nrf_uart_task_trigger (uart0_addr , NRF_UART_TASK_STARTTX );
425
+ nrf_uart_task_trigger (uart0_addr , NRF_UART_TASK_STARTRX );
424
426
425
427
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
426
428
@@ -429,12 +431,12 @@ static int uart_nrfx_init(struct device *dev)
429
431
*/
430
432
uart_sw_event_txdrdy = 1 ;
431
433
432
- IRQ_CONNECT (NRFX_IRQ_NUMBER_GET ( NRF_UART0 ) ,
434
+ IRQ_CONNECT (CONFIG_UART_0_IRQ_NUM ,
433
435
CONFIG_UART_0_IRQ_PRI ,
434
436
uart_nrfx_isr ,
435
437
DEVICE_GET (uart_nrfx_uart0 ),
436
438
0 );
437
- irq_enable (NRFX_IRQ_NUMBER_GET ( NRF_UART0 ) );
439
+ irq_enable (CONFIG_UART_0_IRQ_NUM );
438
440
#endif
439
441
440
442
return 0 ;
@@ -474,3 +476,4 @@ DEVICE_AND_API_INIT(uart_nrfx_uart0,
474
476
PRE_KERNEL_1 ,
475
477
CONFIG_KERNEL_INIT_PRIORITY_DEVICE ,
476
478
& uart_nrfx_uart_driver_api );
479
+
0 commit comments