31 #include "contiki-lib.h" 32 #include "at-master.h" 47 #define PRINTF(...) printf(__VA_ARGS__) 53 process_event_t at_cmd_received_event;
55 static uint8_t at_uart = 0;
57 PROCESS(at_process,
"AT process");
71 pch = strstr(buf, a->cmd_header);
72 if((plen <= a->cmd_max_len) && (pch != NULL)) {
73 if(strncmp(a->cmd_header, pch, a->cmd_hdr_len) == 0) {
74 if((a->cmd_hdr_len == plen) || (a->cmd_max_len > a->cmd_hdr_len)) {
75 a->event_callback(a, plen, (
char *)pch);
76 process_post(a->app_process, at_cmd_received_event, NULL);
93 at_send(
char *s, uint8_t len)
107 at_init(uint8_t uart_sel)
109 static uint8_t inited = 0;
121 PRINTF(
"AT: Started (%u)\n", at_uart);
126 at_register(
struct at_cmd *cmd,
struct process *app_process,
127 const char *cmd_hdr,
const uint8_t hdr_len,
128 const uint8_t cmd_max_len, at_event_callback_t event_callback)
130 if((hdr_len < 1) || (cmd_max_len < 1) || (!strncmp(cmd_hdr,
"AT", 2) == 0) ||
131 (event_callback == NULL)) {
132 PRINTF(
"AT: Invalid argument\n");
133 return AT_STATUS_INVALID_ARGS_ERROR;
136 memset(cmd, 0,
sizeof(
struct at_cmd));
137 cmd->event_callback = event_callback;
138 cmd->cmd_header = cmd_hdr;
139 cmd->cmd_hdr_len = hdr_len;
140 cmd->cmd_max_len = cmd_max_len;
141 cmd->app_process = app_process;
143 PRINTF(
"AT: registered HDR %s LEN %u MAX %u\n", cmd->cmd_header,
Header file for the cc2538 UART driver.
#define PROCESS(name, strname)
Declare a process.
Header file for the cc2538 System Control driver.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
void uart_init(uint8_t uart)
Initialises the UART controller, configures I/O control and interrupts.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
void uart_write_byte(uint8_t uart, uint8_t b)
Sends a single character down the UART.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Linked list manipulation routines.
void * list_head(list_t list)
Get a pointer to the first element of a list.
void uart_set_input(uint8_t uart, int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
process_event_t process_alloc_event(void)
Allocate a global event number.
void list_add(list_t list, void *item)
Add an item at the end of a list.
void list_init(list_t list)
Initialize a list.
#define LIST(name)
Declare a linked list.
process_event_t serial_line_event_message
Event posted when a line of input has been received.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
Generic serial I/O process header filer.
Default definitions of C compiler quirk work-arounds.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
void * list_item_next(void *item)
Get the next item following this item.
void process_start(struct process *p, process_data_t data)
Start a process.