From 044616bf198b87ee10903ea9d8caf28438bb1c9c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 19 Nov 2010 20:10:09 +0100 Subject: [PATCH] * some work on rx handling in cc110x_ng * added first version of cc110x_ng test application * introduced a generic transceiver interface and module --- projects/test_cc110x_ng/Jamfile | 5 ++ projects/test_cc110x_ng/main.c | 28 ++++++++ projects/test_cc110x_ng/tests/hello-world | 13 ++++ sys/Jamfile | 2 + sys/include/radio/types.h | 19 ++++++ sys/include/transceiver.h | 28 ++++++++ sys/transceiver.c | 78 +++++++++++++++++++++++ 7 files changed, 173 insertions(+) create mode 100644 projects/test_cc110x_ng/Jamfile create mode 100644 projects/test_cc110x_ng/main.c create mode 100755 projects/test_cc110x_ng/tests/hello-world create mode 100644 sys/include/transceiver.h create mode 100644 sys/transceiver.c diff --git a/projects/test_cc110x_ng/Jamfile b/projects/test_cc110x_ng/Jamfile new file mode 100644 index 0000000000..29f79da92f --- /dev/null +++ b/projects/test_cc110x_ng/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_cc110x_ng ; + +Module test_cc110x_ng : main.c : cc110x_ng shell ps rtc posix_io uart0 ; + +UseModule test_cc110x_ng ; diff --git a/projects/test_cc110x_ng/main.c b/projects/test_cc110x_ng/main.c new file mode 100644 index 0000000000..25fbfdaa8b --- /dev/null +++ b/projects/test_cc110x_ng/main.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + +#define SHELL_STACK_SIZE (4096) + +char shell_stack_buffer[SHELL_STACK_SIZE]; + +shell_t shell; +const shell_command_t sc[] = {{NULL, NULL, NULL}}; + +void shell_runner(void) { + shell_init(&shell, sc, uart0_readc, uart0_putc); + posix_open(uart0_handler_pid, 0); + shell_run(&shell); +} + +int main(void) { + thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); + + while (1) { + LED_GREEN_TOGGLE; + hwtimer_wait(1000 * 1000); + } +} diff --git a/projects/test_cc110x_ng/tests/hello-world b/projects/test_cc110x_ng/tests/hello-world new file mode 100755 index 0000000000..acde8265fe --- /dev/null +++ b/projects/test_cc110x_ng/tests/hello-world @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "Hello World!" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" + diff --git a/sys/Jamfile b/sys/Jamfile index 0ae65f81c8..a8ff40a5c0 100644 --- a/sys/Jamfile +++ b/sys/Jamfile @@ -35,6 +35,8 @@ Module auto_init : auto_init.c ; Module chardev_thread : chardev_thread.c : ringbuffer ; Module uart0 : uart0.c : ringbuffer chardev_thread ; +Module transceiver : transceiver.c ; + SubInclude TOP sys net ; SubInclude TOP sys lib ; SubInclude TOP sys shell ; diff --git a/sys/include/radio/types.h b/sys/include/radio/types.h index 7018480f65..5c191e3805 100644 --- a/sys/include/radio/types.h +++ b/sys/include/radio/types.h @@ -73,6 +73,25 @@ typedef struct __attribute__ ((packed)) packet_info_t bool promiscuous; ///< Radio layer: whether network interface is in promiscuous mode } packet_info_t; + +typedef struct __attribute__ ((packed)) { + uint8_t rssi; ///< Radio layer: RSSI + uint8_t lqi; ///< Radio layer: LQI +} radio_info_t; + +/** + * @brief General link layer packet format + */ +typedef struct __attribute__ ((packed)) { + uint16_t src; ///< Radio source address + uint16_t dst; ///< Radio destination address + uint8_t rssi; ///< Radio Signal Strength Indication + uint8_t lqi; ///< Link Quality Indicator + uint8_t length; ///< Length of payload + uint8_t *data; ///< Payload +} radio_packet_t; + + /** * Packet handler (receive function) of all layers. * @param [in/out] payload Pointer to packet payload data diff --git a/sys/include/transceiver.h b/sys/include/transceiver.h new file mode 100644 index 0000000000..563f4669ad --- /dev/null +++ b/sys/include/transceiver.h @@ -0,0 +1,28 @@ +#ifndef TRANSCEIVER_H +#define TRANSCEIVER_H + +#define TRANSCEIVER_BUFFER_SIZE (10) +#define TRANSCEIVER_STACK_SIZE (4096) + +enum transceiver_msg_type_t { + RCV_PKT, + SND_PKT, + SND_ACK, + SWITCH_RX, + POWERDOWN, +}; + +enum transceiver_type_t { + NONE, + CC1100, + CC1020 +}; + +void transceiver_init(transceiver_type_t transceiver); + +void transceiver_start(void); + +extern int transceiver_pid; +extern void *transceiver_rx_buffer; + +#endif /* TRANSCEIVER_H */ diff --git a/sys/transceiver.c b/sys/transceiver.c new file mode 100644 index 0000000000..9c3c05b1d9 --- /dev/null +++ b/sys/transceiver.c @@ -0,0 +1,78 @@ +#include +#include + +#include + +/* supported transceivers */ +#include + +transceiver_type_t transceiver = NONE; +int transceiver_pid = EINVAL; +radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE]; + +static volatile uint8_t rx_buffer_pos = 0; +static volatile uint8_t transceiver_buffer_pos = 0; + +const char transceiver_stack[TRANSCEIVER_STACK_SIZE]; + +void run(void); +void receive_packet(void); + +void transceiver_init(transceiver_type_t t) { + switch (t) { + case CC110: + transceiver = t; + cc1100_init(); + break; + default: + puts("Invalid transceiver type"); + break; + } +} + +void transceiver_start(void) { + transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING, run, "Transceiver"); + if (transceiver < 0) { + puts("Error creating transceiver thread"); + } +} + +void run(void) { + msg m; + while (1) { + msg_receive(&m); + switch (m) { + case RCV_PKT: + receive_packet(); + break; + default: + DEBUG("Unknown message received\n"); + break; + } + } +} + + +void receive_packet(void) { + switch (transveiver) { + case CC1100: + dINT(); + rx_buffer_pos = cc1100_rx_buffer_next - 1; + cc1100_packet_t p = cc1100_rx_buffer[rx_buffer_pos].packet; + radio_info_t info = cc1100_rx_buffer[rx_buffer_pos].info; + radio_packet_t trans_p = transceiver_buffer[transceiver_buffer_pos]; + + trans_p.src = p.phy_src; + trans_p.dst = p.address; + trans_p.rssi = info.rssi; + trans_p.lqi = info.lqi; + trans_p.length = p.length; + + /* TODO: copy payload */ + eINT(); + break; + default: + puts("Invalid transceiver type"); + break; + } +}