テスト用
Fork of nRF51822 by
Diff: nordic/nrf-sdk/app_common/app_uart.h
- Revision:
- 37:c29c330d942c
- Parent:
- 0:eff01767de02
--- a/nordic/nrf-sdk/app_common/app_uart.h Thu Jul 03 10:01:02 2014 +0100 +++ b/nordic/nrf-sdk/app_common/app_uart.h Mon Jul 07 13:43:31 2014 +0100 @@ -24,41 +24,40 @@ #include <stdint.h> #include <stdbool.h> -#include "nordic_global.h" -#include "app_util.h" +#include "app_util_platform.h" -#define UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */ +#define UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */ /**@brief UART Flow Control modes for the peripheral. */ typedef enum { - APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */ - APP_UART_FLOW_CONTROL_ENABLED, /**< Standard UART Hw Flow Control is enabled. */ - APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the nRF51 to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the nRF51 to safe power by only using the UART module when it is needed by the remote site. */ + APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */ + APP_UART_FLOW_CONTROL_ENABLED, /**< Standard UART Hw Flow Control is enabled. */ + APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the nRF51 to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the nRF51 to safe power by only using the UART module when it is needed by the remote site. */ } app_uart_flow_control_t; /**@brief UART communication structure holding configuration settings for the peripheral. */ typedef struct { - uint8_t rx_pin_no; /**< RX pin number. */ - uint8_t tx_pin_no; /**< TX pin number. */ - uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */ - uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */ - app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */ - bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */ - uint32_t baud_rate; /**< Baud rate configuration. */ + uint8_t rx_pin_no; /**< RX pin number. */ + uint8_t tx_pin_no; /**< TX pin number. */ + uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */ + uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */ + app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */ + bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */ + uint32_t baud_rate; /**< Baud rate configuration. */ } app_uart_comm_params_t; /**@brief UART buffer for transmitting/receiving data. */ typedef struct { - uint8_t * rx_buf; /**< Pointer to the RX buffer. */ - uint32_t rx_buf_size; /**< Size of the RX buffer. */ - uint8_t * tx_buf; /**< Pointer to the TX buffer. */ - uint32_t tx_buf_size; /**< Size of the TX buffer. */ + uint8_t * rx_buf; /**< Pointer to the RX buffer. */ + uint32_t rx_buf_size; /**< Size of the RX buffer. */ + uint8_t * tx_buf; /**< Pointer to the TX buffer. */ + uint32_t tx_buf_size; /**< Size of the TX buffer. */ } app_uart_buffers_t; /**@brief Enumeration describing current state of the UART. @@ -74,8 +73,8 @@ */ typedef enum { - APP_UART_DISCONNECTED, /**< State indicating that the UART is disconnected and cannot receive or transmit bytes. */ - APP_UART_CONNECTED /**< State indicating that the UART is connected and ready to receive or transmit bytes. If flow control is disabled, the state will always be connected. */ + APP_UART_DISCONNECTED, /**< State indicating that the UART is disconnected and cannot receive or transmit bytes. */ + APP_UART_CONNECTED /**< State indicating that the UART is connected and ready to receive or transmit bytes. If flow control is disabled, the state will always be connected. */ } app_uart_connection_state_t; /**@brief Enumeration which defines events used by the UART module upon data reception or error. @@ -85,11 +84,11 @@ */ typedef enum { - APP_UART_DATA_READY, /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */ - APP_UART_FIFO_ERROR, /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */ - APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */ - APP_UART_TX_EMPTY, /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */ - APP_UART_DATA, /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */ + APP_UART_DATA_READY, /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */ + APP_UART_FIFO_ERROR, /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */ + APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */ + APP_UART_TX_EMPTY, /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */ + APP_UART_DATA, /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */ } app_uart_evt_type_t; /**@brief Struct containing events from the UART module. @@ -99,12 +98,12 @@ */ typedef struct { - app_uart_evt_type_t evt_type; /**< Type of event. */ + app_uart_evt_type_t evt_type; /**< Type of event. */ union { - uint32_t error_communication;/**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from @ref nrf51_bitfields.h can be used to parse the error code. See also the nRF51 Series Reference Manual for specification. */ - uint32_t error_code; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ - uint8_t value; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ + uint32_t error_communication; /**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from @ref nrf51_bitfields.h can be used to parse the error code. See also the nRF51 Series Reference Manual for specification. */ + uint32_t error_code; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ + uint8_t value; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ } data; } app_uart_evt_t; @@ -115,7 +114,9 @@ * * @param[in] p_app_uart_event Pointer to UART event. */ -typedef void (*app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event); + + +typedef void (* app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event); /**@brief Macro for safe initialization of the UART module in a single user instance when using * a FIFO together with UART. @@ -132,7 +133,7 @@ * @note Since this macro allocates a buffer and registers the module as a GPIOTE user when flow * control is enabled, it must only be called once. */ -#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE)\ +#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \ do \ { \ uint16_t APP_UART_UID = 0; \ @@ -141,9 +142,9 @@ static uint8_t tx_buf[TX_BUF_SIZE]; \ \ buffers.rx_buf = rx_buf; \ - buffers.rx_buf_size = sizeof(rx_buf); \ + buffers.rx_buf_size = sizeof (rx_buf); \ buffers.tx_buf = tx_buf; \ - buffers.tx_buf_size = sizeof(tx_buf); \ + buffers.tx_buf_size = sizeof (tx_buf); \ ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO, &APP_UART_UID); \ } while (0) @@ -203,15 +204,15 @@ * @retval NRF_ERROR_NO_MEM GPIOTE module has reached the maximum number of users. */ uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params, - app_uart_buffers_t * p_buffers, - app_uart_event_handler_t error_handler, - app_irq_priority_t irq_priority, - uint16_t * p_uart_uid); + app_uart_buffers_t * p_buffers, + app_uart_event_handler_t error_handler, + app_irq_priority_t irq_priority, + uint16_t * p_uart_uid); /**@brief Function for getting a byte from the UART. * * @details This function will get the next byte from the RX buffer. If the RX buffer is empty - * an error code will be returned and the app_uart module will generate an event upon + * an error code will be returned and the app_uart module will generate an event upon * reception of the first byte which is added to the RX buffer. * * @param[out] p_byte Pointer to an address where next byte received on the UART will be copied. @@ -238,10 +239,10 @@ * * @details If flow control is disabled, the state is assumed to always be APP_UART_CONNECTED. * - * When using flow control the state will be controlled by the CTS. If CTS is set active + * When using flow control the state will be controlled by the CTS. If CTS is set active * by the remote side, or the app_uart module is in the process of transmitting a byte, * app_uart is in APP_UART_CONNECTED state. If CTS is set inactive by remote side app_uart - * will not get into APP_UART_DISCONNECTED state until the last byte in the TXD register + * will not get into APP_UART_DISCONNECTED state until the last byte in the TXD register * is fully transmitted. * * Internal states in the state machine are mapped to the general connected/disconnected @@ -280,6 +281,6 @@ uint32_t app_uart_close(uint16_t app_uart_id); -#endif // APP_UART_H__ +#endif //APP_UART_H__ /** @} */