EVE 1.0
uart_nrf.h
Go to the documentation of this file.
1 #ifndef NRF_UART_H
2 #define NRF_UART_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2013-2017, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief Driver for the NRF's UART block(s).
36  *
37  * This driver provides interface to the NRF's UART block(s).
38  *
39  * @author PE, DT, SE, Jetro AS
40  */ /******************************************************************/
41 
42 #include <hal/nrf_uarte.h>
43 #include <dev/uart.h>
44 
45 /**
46  * \defgroup nrf_uart nRF52 UART driver
47  * \ingroup uart
48  * \ingroup nrf52
49  * \{
50  *
51  * This driver provides interface to the NRF's UART block(s).
52  */
53 
54 /***********************************************************************
55  * Global defines
56 ***********************************************************************/
57 extern const struct uart_api_t NrfUartFunc;
58 
59 
60 /** Interrupt sources */
62 {
63  UART_INTERRUPT_SOURCE_UART, //!< UART interrupt
64  UART_INTERRUPT_SOURCE_ACTIVITY, //!< Activity on RX pin detected
65  UART_INTERRUPT_SOURCE_TIMEOUT, //!< Timeout after last word received
66 };
67 
68 /**
69  * UART driver run-time state
70  */
72 {
73 };
74 
75 /**
76  * UART driver configuration data
77  */
78 struct nrf_uart_t
79 {
80  NRF_UARTE_Type *Dev; /**< Address to UART device to use. */
81  uint32_t IrqPriority; /**< HW IRQ priority (see enum EVE_IRQ_PRIORITIES) */
82  struct nrf_uart_state_t *State; /**< Address to struct with RAM variables used by the uart driver */
83  NRF_TIMER_Type *Timer; /**< Timer used for detection of timeouts */
84  uint8_t PPI_ID; /**< PPI ID used for detection of timeouts */
85  uint8_t GPIOTE_ID; /**< GPIOTE ID used for detection of timeouts */
86 
87  struct
88  {
89  uint8_t Rts; /**< Location of the Rts pin */
90  uint8_t Txd; /**< Location of the Txd pin */
91  uint8_t Cts; /**< Location of the Cts pin */
92  uint8_t Rxd; /**< Location of the Rxd pin */
93  } Location;
94 };
95 
96 /******************************************************************************
97  * PUBLIC FUNCTIONS
98  ******************************************************************************/
99 
100 void NrfUartInit(const struct uart_t *Uart);
101 void NrfUartDisable(const struct uart_t *Uart);
102 void NrfUartStartBasicTx(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, uart_tx_callback_t Callback, void *CallbackData);
103 void NrfUartStartPingPongTx(const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize, uart_tx_callback_t Callback, void *CallbackData);
104 void NrfUartRefreshPingPongTx(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, bool Stop);
105 void NrfUartCancelTx(const struct uart_t *Uart);
106 bool NrfUartIsBusyTx(const struct uart_t *Uart);
107 void NrfUartStartBasicRx(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, uart_rx_callback_t Callback, void *CallbackData);
108 void NrfUartStartPingPongRx(const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize,uart_rx_callback_t Callback, void *CallbackData);
109 void NrfUartRefreshPingPongRx(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, bool Stop);
110 void NrfUartCancelRx(const struct uart_t *Uart);
111 bool NrfUartIsBusyRx(const struct uart_t *Uart);
112 void NrfUartSetBaudrate(const struct uart_t *Uart);
113 void NrfUartSetRxTimeouts(const struct uart_t *Uart, uint32_t RxStartTimeoutUs, uint32_t RxStopTimeoutUs);
114 void NrfUartSendBreak(const struct uart_t *Uart, uart_break_callback_t Callback, void *CallbackData);
115 void NrfUartSetRts(const struct uart_t *Uart, bool Active);
116 void NrfUartInterruptHandler(const struct uart_t *Uart, enum nrf_uart_interrupt_source_t Source);
117 
118 
119 /** @} nrf_uart */
120 
121 #endif //NRF_UART
uint8_t PPI_ID
Definition: uart_nrf.h:84
Abstract UART driver header.
NRF_TIMER_Type * Timer
Definition: uart_nrf.h:83
void(* uart_rx_callback_t)(const struct uart_t *Uart, void *CallbackData, enum uart_rx_status_t RxStatus)
Definition: uart.h:129
Activity on RX pin detected.
Definition: uart_nrf.h:64
uint8_t Rts
Definition: uart_nrf.h:89
Definition: uart.h:222
UART interrupt.
Definition: uart_nrf.h:63
nrf_uart_interrupt_source_t
Definition: uart_nrf.h:61
NRF_UARTE_Type * Dev
Definition: uart_nrf.h:80
uint8_t Rxd
Definition: uart_nrf.h:92
Timeout after last word received.
Definition: uart_nrf.h:65
uint32_t IrqPriority
Definition: uart_nrf.h:81
void(* uart_tx_callback_t)(const struct uart_t *Uart, void *CallbackData)
Definition: uart.h:137
uint8_t Cts
Definition: uart_nrf.h:91
struct nrf_uart_state_t * State
Definition: uart_nrf.h:82
uint8_t Txd
Definition: uart_nrf.h:90
uint8_t GPIOTE_ID
Definition: uart_nrf.h:85
void(* uart_break_callback_t)(const struct uart_t *Uart, void *CallbackData)
Definition: uart.h:145