Embedded Wireless Framework
ewf_interface.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_interface__h__included__
10 #define __ewf_interface__h__included__
11 
12 #include "ewf.h"
13 #include "ewf_platform.h"
14 #include "ewf_allocator.h"
15 #include "ewf_tokenizer.h"
16 #include "ewf_message.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /************************************************************************/
48 
53 
57 typedef ewf_result(*ewf_interface_response_callback)(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t length);
58 
62 typedef ewf_result(*ewf_interface_urc_callback)(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t length);
63 
66 {
67 #ifdef EWF_PARAMETER_CHECKING
68  uint32_t struct_magic;
69  uint32_t struct_size;
70  uint32_t struct_version;
71  uint32_t struct_type;
72 #endif /* EWF_PARAMETER_CHECKING */
73 
74 #ifdef EWF_PLATFORM_HAS_THREADING
76  ewf_platform_mutex global_mutex;
77 #endif /* EWF_PLATFORM_HAS_THREADING */
78 
80  volatile bool command_mode;
81 
83  volatile bool sync_urc_processing;
84 
85  /* *** Pointers to other related structures *** */
86 
89 
92 
98  ewf_interface_message current_message;
99 
100  /* *** Pointers to interface callbacks */
101 
104 
107 
109  ewf_interface_urc_callback user_urc_callback;
110 
111  /* *** Allocators *** */
112 
115 
117  ewf_allocator* data_allocator_ptr;
118 
119  /* *** Queues *** */
120 
123 
125  ewf_platform_queue* urc_queue_ptr;
126 
127  /* *** Timeout parameters *** */
128 
130  volatile uint32_t default_timeout;
131 
132  /* *** Tokenizer data *** */
133 
136 
139 
142 
144  ewf_interface_tokenizer_pattern* urc_tokenizer_pattern_ptr;
145 
146  /* *** Hardware interface *** */
147 
150 
153 
155  ewf_result(*hardware_send)(ewf_interface* interface_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
156 
158  ewf_result(*hardware_receive)(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr, bool wait);
159 };
160 
161 #define EWF_INTERFACE_STRUCT_MAGIC (0x017eface) /* ~~ i(n)te(r)face */
162 #define EWF_INTERFACE_STRUCT_SIZE (sizeof(struct _ewf_interface))
163 #define EWF_INTERFACE_VERSION (EWF_DEVELOPER_MICROSOFT | 0x0001)
164 
165 #ifdef EWF_PARAMETER_CHECKING
166 #define EWF_INTERFACE_VALIDATE_POINTER(interface_ptr) \
167 do { \
168  if ((interface_ptr == NULL) || \
169  (interface_ptr->struct_magic != EWF_INTERFACE_STRUCT_MAGIC) || \
170  (interface_ptr->struct_size != EWF_INTERFACE_STRUCT_SIZE) || \
171  (interface_ptr->struct_version != EWF_INTERFACE_VERSION) || \
172  (interface_ptr->implementation_ptr == NULL)) \
173  { \
174  EWF_LOG_ERROR("The interface pointer is invalid."); \
175  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
176  } \
177 } while(0)
178 #else
179 #define EWF_INTERFACE_VALIDATE_POINTER(interface_ptr) \
180 do { \
181  if ((interface_ptr == NULL) || \
182  (interface_ptr->implementation_ptr == NULL)) \
183  { \
184  EWF_LOG_ERROR("The interface pointer is invalid."); \
185  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
186  } \
187 } while(0)
188 #endif /* EWF_PARAMETER_CHECKING */
189 
190 #ifdef EWF_PARAMETER_CHECKING
191 #define EWF_INTERFACE_VALIDATE_POINTER_TYPE(interface_ptr, interface_type) \
192 do { \
193  if ((interface_ptr == NULL) || \
194  (interface_ptr->struct_type != interface_type) || \
195  (interface_ptr->implementation_ptr == NULL)) \
196  { \
197  EWF_LOG_ERROR("The interface type is invalid."); \
198  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
199  } \
200 } while(0)
201 #else
202 #define EWF_INTERFACE_VALIDATE_POINTER_TYPE(interface_ptr, interface_type)
203 #endif
204 
205 /************************************************************************/
220 
229 
236 
243 
251 ewf_result ewf_interface_send(ewf_interface* interface_ptr, const uint8_t * buffer_ptr, uint32_t buffer_length);
252 
261 ewf_result ewf_interface_receive_response(ewf_interface* interface_ptr, uint8_t** buffer_ptr_ptr, uint32_t* buffer_length_ptr, uint32_t wait_time);
262 
271 ewf_result ewf_interface_receive_urc(ewf_interface* interface_ptr, uint8_t** buffer, uint32_t * buffer_length_ptr, uint32_t wait_time);
272 
279 
286 
294 /* TODO: global rename ewf_interface_release -> ewf_interface_release_buffer */
295 
303 
304 /************************************************************************/
308 /************************************************************************/
321 
329 
330 /************************************************************************/
334 /************************************************************************/
347 
355 
363 
371 
379 
387 
395 
403 
404 /************************************************************************/
408 /************************************************************************/
424 
435 ewf_result ewf_interface_process_buffer(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
436 
437 /************************************************************************/
441 /************************************************************************/
454 
459 ewf_result ewf_interface_urc_process_message(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
460 
461 /************************************************************************/
465 /************************************************************************/
472 
473 ewf_result ewf_interface_receive_poll(ewf_interface* interface_ptr);
474 
475 ewf_result ewf_interface_process_poll(ewf_interface* interface_ptr);
476 
477 /************************************************************************/
481 /************************************************************************/
492 
498 
504 
505 /************************************************************************/
509 /************************************************************************/
521 
529 ewf_result ewf_interface_send_commands(ewf_interface* interface_ptr, const char* command_str, ...);
530 
536 
542 
549 
558 
566 ewf_result ewf_interface_verify_responses(ewf_interface* interface_ptr, uint32_t response_count, const char** expected_str_arr);
567 
576 
585 
586 /************************************************************************/
590 /************************************************************************/
594 #ifdef __cplusplus
595 }
596 #endif
597 
598 #endif /* __ewf_interface__h__included__ */
The Embedded Wireless Framework.
The Embedded Wireless Framework Software Platform API.
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
ewf_result ewf_interface_set_user_urc_callback(ewf_interface *interface_ptr, ewf_interface_urc_callback callback)
register a user callback for URC
Definition: ewf_interface.c:963
ewf_result ewf_interface_set_urc_callback(ewf_interface *interface_ptr, ewf_interface_urc_callback callback)
register a callback for URC
Definition: ewf_interface.c:954
ewf_result ewf_interface_set_response_callback(ewf_interface *interface_ptr, ewf_interface_response_callback callback)
register a user callback for responses
Definition: ewf_interface.c:945
ewf_result ewf_interface_stop(ewf_interface *interface_ptr)
Stops the interface.
Definition: ewf_interface.c:147
ewf_result ewf_interface_release(ewf_interface *interface_ptr, void *buffer_ptr)
Release a message buffer returned by the interface.
Definition: ewf_interface.c:313
ewf_result ewf_interface_receive_response(ewf_interface *interface_ptr, uint8_t **buffer_ptr_ptr, uint32_t *buffer_length_ptr, uint32_t wait_time)
Read a response message from the interface.
Definition: ewf_interface.c:287
ewf_result ewf_interface_message_allocator_set(ewf_interface *interface_ptr, ewf_allocator *allocator_ptr)
Set the interface message allocator.
Definition: ewf_interface.c:299
ewf_result ewf_interface_clean(ewf_interface *interface_ptr)
Cleanup the interface This is called after the interface has been stopped It releases resources used ...
Definition: ewf_interface.c:65
ewf_result ewf_interface_release_data(ewf_interface *interface_ptr, void *buffer_ptr)
Release a data buffer returned by the interface.
Definition: ewf_interface.c:320
ewf_result ewf_interface_start(ewf_interface *interface_ptr)
Starts the interface.
Definition: ewf_interface.c:82
ewf_result ewf_interface_send(ewf_interface *interface_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)
Sends data to the interface.
Definition: ewf_interface.c:187
ewf_result ewf_interface_receive_urc(ewf_interface *interface_ptr, uint8_t **buffer, uint32_t *buffer_length_ptr, uint32_t wait_time)
Receive a message from the URC queue.
Definition: ewf_interface.c:293
ewf_result ewf_interface_data_allocator_set(ewf_interface *interface_ptr, ewf_allocator *allocator_ptr)
Set the interface data allocator.
Definition: ewf_interface.c:306
ewf_result ewf_interface_init(ewf_interface *interface_ptr)
Initialize the interface This initializes the internal status of the control structure This doesn't s...
Definition: ewf_interface.c:34
ewf_result ewf_interface_process_byte(ewf_interface *interface_ptr, uint8_t b)
Called by the hardware code to process an incoming byte When the hardware interface receives a byte i...
Definition: ewf_interface.c:698
ewf_result ewf_interface_process_buffer(ewf_interface *interface_ptr, uint8_t *buffer_ptr, uint32_t buffer_length)
Called by the hardware code to process a buffer When the hardware interface receives a byte it used t...
ewf_result ewf_interface_send_command(ewf_interface *interface_ptr, const char *command_str)
Send a command.
Definition: ewf_interface.c:978
ewf_result ewf_interface_send_commands(ewf_interface *interface_ptr, const char *command_str,...)
Send a command.
Definition: ewf_interface.c:987
ewf_result ewf_interface_verify_response_ends_with(ewf_interface *interface_ptr, const char *expected_end_str)
Verify if interface response starts with expected string.
Definition: ewf_interface.c:1190
ewf_result ewf_interface_verify_response(ewf_interface *interface_ptr, const char *expected_str)
Verify an interface response, compare against a string.
Definition: ewf_interface.c:1079
ewf_result ewf_interface_verify_responses(ewf_interface *interface_ptr, uint32_t response_count, const char **expected_str_arr)
Verify an interface response, compare agains an array of strings.
Definition: ewf_interface.c:1116
ewf_result ewf_interface_get_response(ewf_interface *interface_ptr, uint8_t **response_out)
Get a response from the interface.
Definition: ewf_interface.c:1052
ewf_result ewf_interface_verify_response_starts_with(ewf_interface *interface_ptr, const char *expected_start_str)
Verify if interface response starts with expected string.
Definition: ewf_interface.c:1153
ewf_result ewf_interface_drop_all_responses(ewf_interface *interface_ptr)
Drop all responses from the interface.
Definition: ewf_interface.c:1009
ewf_result ewf_interface_drop_response(ewf_interface *interface_ptr)
Drop a single response from the interface.
Definition: ewf_interface.c:1026
ewf_result ewf_interface_poll(ewf_interface *interface_ptr)
Definition: ewf_interface.c:876
ewf_result ewf_interface_default_timeout_get(ewf_interface *interface_ptr, uint32_t *timeout_ptr)
Get the current interface default timeout value.
Definition: ewf_interface.c:334
ewf_result ewf_interface_default_timeout_set(ewf_interface *interface_ptr, uint32_t timeout)
Set the interface default timeout value.
Definition: ewf_interface.c:327
ewf_result ewf_interface_tokenizer_command_response_end_pattern_get(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern **tokenizer_patter_ptr_ptr)
Get the interface command response end tokenizer pattern.
Definition: ewf_interface.c:402
ewf_result ewf_interface_tokenizer_message_pattern_get(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern **tokenizer_patter_ptr_ptr)
Get the interface message tokenizer pattern.
Definition: ewf_interface.c:368
ewf_result ewf_interface_tokenizer_command_response_pattern_set(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern *tokenizer_patter_ptr)
Set the interface command response tokenizer pattern.
Definition: ewf_interface.c:410
ewf_result ewf_interface_tokenizer_urc_pattern_get(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern **tokenizer_patter_ptr_ptr)
Get the interface URC tokenizer pattern.
Definition: ewf_interface.c:470
ewf_result ewf_interface_tokenizer_command_response_pattern_get(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern **tokenizer_patter_ptr_ptr)
Get the interface command response tokenizer pattern.
Definition: ewf_interface.c:436
ewf_result ewf_interface_tokenizer_message_pattern_set(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern *tokenizer_patter_ptr)
Set the interface message tokenizer pattern.
Definition: ewf_interface.c:342
ewf_result ewf_interface_tokenizer_urc_pattern_set(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern *tokenizer_patter_ptr)
Set the interface URC tokenizer pattern.
Definition: ewf_interface.c:444
ewf_result ewf_interface_tokenizer_command_response_end_pattern_set(ewf_interface *interface_ptr, ewf_interface_tokenizer_pattern *tokenizer_patter_ptr)
Set the interface command response end tokenizer pattern.
Definition: ewf_interface.c:376
ewf_result ewf_interface_urc_process_message(ewf_interface *interface_ptr, uint8_t *buffer_ptr, uint32_t buffer_length)
Process a URC message.
Definition: ewf_interface.c:605
ewf_result ewf_interface_urc_processing(ewf_interface *interface_ptr)
Call periodically to process URCs This is called internally by the URC thread. Call manually if there...
Definition: ewf_interface.c:567
ewf_result(* ewf_interface_response_callback)(ewf_interface *interface_ptr, uint8_t *buffer_ptr, uint32_t length)
a function pointer type for response callbacks
Definition: ewf_interface.h:57
ewf_tokenizer_pattern ewf_interface_tokenizer_pattern
Legacy type for tokenizer patters.
Definition: ewf_interface.h:52
ewf_result(* ewf_interface_urc_callback)(ewf_interface *interface_ptr, uint8_t *buffer_ptr, uint32_t length)
a function pointer type for URC callbacks
Definition: ewf_interface.h:62
ewf_message ewf_interface_message
Legacy type for messages.
Definition: ewf_interface.h:47
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
ewf_interface * interface_ptr
Definition: ewf_adapter.h:73
The allocator structure definition.
Definition: ewf_allocator.h:27
The interface structure definition.
Definition: ewf_interface.h:66
ewf_result(* hardware_send)(ewf_interface *interface_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)
Definition: ewf_interface.h:155
ewf_result(* hardware_stop)(ewf_interface *interface_ptr)
Definition: ewf_interface.h:152
volatile bool command_mode
Definition: ewf_interface.h:80
ewf_platform_queue * response_queue_ptr
Definition: ewf_interface.h:122
struct _ewf_adapter * adapter_ptr
Definition: ewf_interface.h:88
void * implementation_ptr
Definition: ewf_interface.h:91
ewf_allocator * message_allocator_ptr
Definition: ewf_interface.h:114
ewf_interface_response_callback response_callback
Definition: ewf_interface.h:103
volatile uint32_t default_timeout
Definition: ewf_interface.h:130
ewf_interface_urc_callback urc_callback
Definition: ewf_interface.h:106
ewf_interface_tokenizer_pattern * message_tokenizer_pattern_ptr
Definition: ewf_interface.h:135
ewf_interface_tokenizer_pattern * command_response_tokenizer_pattern_ptr
Definition: ewf_interface.h:141
ewf_interface_tokenizer_pattern * command_response_end_tokenizer_pattern_ptr
Definition: ewf_interface.h:138
ewf_result(* hardware_start)(ewf_interface *interface_ptr)
Definition: ewf_interface.h:149
The interface message structure definition.
Definition: ewf_message.h:27
The platform queue structure.
Definition: ewf_platform_bare_metal.h:74
The interface tokenizer pattern structure definition.
Definition: ewf_tokenizer.h:27