Embedded Wireless Framework
ewf_interface_lpc_uart.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_interface_lpc_uart__h__included__
10 #define __ewf_interface_lpc_uart__h__included__
11 
12 #include "ewf_interface.h"
13 
14 #if FSL_FEATURE_SOC_LPUART_COUNT > 0
15 #include "fsl_lpuart.h"
16 #elif FSL_FEATURE_SOC_USART_COUNT > 0
17 #include "fsl_usart.h"
18 #else
19 #error "Do not have a supported UART peripheral."
20 #endif
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /************************************************************************/
38 #define EWF_INTERFACE_LPC_UART_RING_BUFFER_SIZE (128U)
39 
40 
41 #ifndef EWF_INTERFACE_LPC_UART_CONFIG_UART_RX_QUEUE_SIZE
42 #define EWF_INTERFACE_LPC_UART_CONFIG_UART_RX_QUEUE_SIZE (32)
43 #endif
44 
45 #ifndef EWF_INTERFACE_LPC_UART_CONFIG_RESPONSE_QUEUE_SIZE
46 #define EWF_INTERFACE_LPC_UART_CONFIG_RESPONSE_QUEUE_SIZE (8)
47 #endif
48 
49 #ifndef EWF_INTERFACE_LPC_UART_CONFIG_URC_QUEUE_SIZE
50 #define EWF_INTERFACE_LPC_UART_CONFIG_URC_QUEUE_SIZE (8)
51 #endif
52 
59 {
60 #if FSL_FEATURE_SOC_LPUART_COUNT > 0
61  LPUART_Type *base;
62  lpuart_handle_t handle;
63  lpuart_transfer_t tx_transfer;
64  lpuart_transfer_t rx_transfer;
65 #elif FSL_FEATURE_SOC_USART_COUNT > 0
66  USART_Type *base;
67  usart_handle_t handle;
68  usart_transfer_t tx_transfer;
69  usart_transfer_t rx_transfer;
70 #endif
71 
72  uint32_t baud_rate;
73 
74  usart_config_t config;
75 
76  uint8_t ring_buffer[EWF_INTERFACE_LPC_UART_RING_BUFFER_SIZE];
77  uint32_t buffer_size;
79  ewf_platform_mutex* rx_mutex_ptr;
80 
81  usart_transfer_t xfer;
82 
84 
89 
94 
98 ewf_result ewf_interface_lpc_uart_hardware_send(ewf_interface* interface_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
99 
103 ewf_result ewf_interface_lpc_uart_hardware_receive(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr, bool wait);
104 
105 #ifdef EWF_PARAMETER_CHECKING
106 #define EWF_INTERFACE_LPC_UART_INITIALIZE_HEADER(interface_ptr) \
107 do { \
108 (interface_ptr)->struct_magic = EWF_INTERFACE_STRUCT_MAGIC; \
109 (interface_ptr)->struct_size = EWF_INTERFACE_STRUCT_SIZE; \
110 (interface_ptr)->struct_version = EWF_INTERFACE_VERSION; \
111 (interface_ptr)->struct_type = EWF_INTERFACE_TYPE_LPC_UART; \
112 } while(0)
113 #else
114 #define EWF_INTERFACE_LPC_UART_INITIALIZE_HEADER(interface_ptr)
115 #endif /* EWF_PARAMETER_CHECKING */
116 
122 #define EWF_INTERFACE_LPC_UART_STATIC_DECLARE(interface_ptr, interface_name_symb, uart_base_ptr_param, baud_rate_param) \
123 do { \
124 static ewf_interface_lpc_uart ewf_interface_lpc_uart__implementation__##interface_name_symb = {0}; \
125 static ewf_interface ewf_interface_lpc_uart__interface__##interface_name_symb = {0}; \
126 ewf_interface_lpc_uart__implementation__##interface_name_symb.base = uart_base_ptr_param; \
127 ewf_interface_lpc_uart__implementation__##interface_name_symb.buffer_size = EWF_INTERFACE_LPC_UART_RING_BUFFER_SIZE; \
128 ewf_interface_lpc_uart__implementation__##interface_name_symb.baud_rate = baud_rate_param; \
129 EWF_PLATFORM_MUTEX_STATIC_DECLARE( \
130  ewf_interface_lpc_uart__implementation__##interface_name_symb.rx_mutex_ptr, \
131  ewf_interface_lpc_uart__uart_rx_mutex__##interface_name_symb); \
132 EWF_PLATFORM_QUEUE_STATIC_DECLARE( \
133  ewf_interface_lpc_uart__interface__##interface_name_symb.response_queue_ptr, \
134  ewf_interface_lpc_uart__response_queue__##interface_name_symb, \
135  ewf_interface_message, \
136  EWF_INTERFACE_LPC_UART_CONFIG_RESPONSE_QUEUE_SIZE); \
137 EWF_PLATFORM_QUEUE_STATIC_DECLARE( \
138  ewf_interface_lpc_uart__interface__##interface_name_symb.urc_queue_ptr, \
139  ewf_interface_lpc_uart__urc_queue__##interface_name_symb, \
140  ewf_interface_message, \
141  EWF_INTERFACE_LPC_UART_CONFIG_URC_QUEUE_SIZE); \
142 ewf_interface_lpc_uart__interface__##interface_name_symb.hardware_start = ewf_interface_lpc_uart_hardware_start; \
143 ewf_interface_lpc_uart__interface__##interface_name_symb.hardware_stop = ewf_interface_lpc_uart_hardware_stop; \
144 ewf_interface_lpc_uart__interface__##interface_name_symb.hardware_send = ewf_interface_lpc_uart_hardware_send; \
145 ewf_interface_lpc_uart__interface__##interface_name_symb.hardware_receive = ewf_interface_lpc_uart_hardware_receive; \
146 ewf_interface_lpc_uart__interface__##interface_name_symb.implementation_ptr = &(ewf_interface_lpc_uart__implementation__##interface_name_symb); \
147 interface_ptr = &(ewf_interface_lpc_uart__interface__##interface_name_symb); \
148 EWF_INTERFACE_LPC_UART_INITIALIZE_HEADER(interface_ptr); \
149 } while(0)
150 
151 /************************************************************************/
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif /* __ewf_interface_lpc_uart__h__included__ */
The Embedded Wireless Framework host interface API.
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
ewf_result ewf_interface_lpc_uart_hardware_receive(ewf_interface *interface_ptr, uint8_t *buffer_ptr, uint32_t *buffer_length_ptr, bool wait)
Receive a buffer using the LPC UART hardware interface.
Definition: ewf_interface_lpc_uart.c:143
ewf_result ewf_interface_lpc_uart_hardware_stop(ewf_interface *interface_ptr)
Stop the LPC UART hardware interface.
Definition: ewf_interface_lpc_uart.c:109
struct _ewf_interface_lpc_uart ewf_interface_lpc_uart
The LPC UART host interface implementation data structure type.
ewf_result ewf_interface_lpc_uart_hardware_start(ewf_interface *interface_ptr)
Start the LPC UART hardware interface.
Definition: ewf_interface_lpc_uart.c:60
ewf_result ewf_interface_lpc_uart_hardware_send(ewf_interface *interface_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)
Send a buffer using the LPC UART hardware interface.
Definition: ewf_interface_lpc_uart.c:125
The LPC UART host interface implementation data structure type.
Definition: ewf_interface_lpc_uart.h:59
uint32_t buffer_size
Definition: ewf_interface_lpc_uart.h:77
uint8_t ring_buffer[EWF_INTERFACE_LPC_UART_RING_BUFFER_SIZE]
Definition: ewf_interface_lpc_uart.h:76
The interface structure definition.
Definition: ewf_interface.h:66