33 #include "dev/protobuf-handler.h"
38 #include "contiki-conf.h"
42 #ifdef SERIAL_TIMEOUT_DEBUG
43 #define PRINTF(...) printf(__VA_ARGS__)
45 #define PRINTF(...) do {} while (0)
49 #ifdef SERIAL_TIMEOUT_CONF_BUFSIZE
50 #define SER_BUFSIZE SERIAL_TIMEOUT_CONF_BUFSIZE
52 #define SER_BUFSIZE 128
55 #if (SER_BUFSIZE & (SER_BUFSIZE - 1)) != 0
56 #error SERIAL_TIMEOUT_CONF_BUFSIZE must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...).
57 #error Change SERIAL_TIMEOUT_CONF_BUFSIZE in contiki-conf.h.
61 static uint8_t rxbuf_data[SER_BUFSIZE];
62 static rtimer_clock_t ser_timer;
63 static uint8_t rxbytes;
65 PROCESS(serial_timeout_process,
"Serial timeout driver");
78 rxbuf_data[rxbytes++] = c;
81 if(rxbytes >= SER_BUFSIZE){
88 rxbuf_data[rxbytes++] = c;
104 printf(
"Serial timeout process started\n");
105 static uint8_t buf[SER_BUFSIZE];
106 static uint8_t bytes;
111 PRINTF(
"Rx bytes = 0\n");
115 while (RTIMER_CLOCK_LT(
RTIMER_NOW(), (ser_timer + SERIAL_TIMEOUT_VALUE)));
116 if (rxbytes > SER_BUFSIZE){
117 PRINTF(
"Serial recieve overflow");
119 #ifdef SERIAL_TIMEOUT_DEBUG
120 printf(
"Timeout reached\n");
121 printf(
"Recieved Bytes: %i\n", rxbytes);
123 while (i < SER_BUFSIZE){
124 printf(
"%i:", (
int)rxbuf_data[i++]);
128 memcpy( buf, rxbuf_data, rxbytes);
131 memset(rxbuf_data, 0, SER_BUFSIZE);
133 PRINTF(
"CALLING PROTOBUG\n");
134 protobuf_process_message(buf, bytes);
142 serial_timeout_init(
void)
145 memset(rxbuf_data, 0, SER_BUFSIZE);
void process_poll(struct process *p)
Request a process to be polled.
#define RTIMER_NOW()
Get the current clock time.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
int serial_timeout_input_byte(unsigned char c)
Get one byte of input from the serial driver.
#define NULL
The null pointer.
process_event_t serial_timeout_event_message
Event posted when a timeout has expired after the end of data recieving.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Generic serial I/O process header filer waits for timeout.
Header file for the ring buffer library
#define PROCESS_BEGIN()
Define the beginning of a process.