2010-11-24 11:20:27 +01:00
|
|
|
#include <stdio.h>
|
2010-11-26 17:06:54 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
#include <shell.h>
|
|
|
|
#include <board_uart0.h>
|
|
|
|
#include <posix_io.h>
|
|
|
|
#include <thread.h>
|
|
|
|
#include <board.h>
|
|
|
|
#include <hwtimer.h>
|
2010-11-27 19:27:05 +01:00
|
|
|
#include <swtimer.h>
|
2010-11-24 11:20:27 +01:00
|
|
|
#include <msg.h>
|
|
|
|
#include <transceiver.h>
|
2010-12-11 12:09:20 +01:00
|
|
|
#include <cc110x_ng.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-26 17:06:54 +01:00
|
|
|
#define SHELL_STACK_SIZE (2048)
|
|
|
|
#define RADIO_STACK_SIZE (2048)
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
#define SND_BUFFER_SIZE (100)
|
|
|
|
#define RCV_BUFFER_SIZE (64)
|
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
#define SENDING_DELAY (5 * 1000)
|
2010-11-27 19:27:05 +01:00
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
char shell_stack_buffer[SHELL_STACK_SIZE];
|
2010-11-24 11:20:27 +01:00
|
|
|
char radio_stack_buffer[RADIO_STACK_SIZE];
|
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH];
|
|
|
|
|
2011-03-08 10:54:40 +01:00
|
|
|
msg_t msg_q[RCV_BUFFER_SIZE];
|
2010-11-27 19:27:05 +01:00
|
|
|
|
2011-03-08 10:54:40 +01:00
|
|
|
static msg_t mesg;
|
2010-11-27 19:27:05 +01:00
|
|
|
static transceiver_command_t tcmd;
|
|
|
|
static radio_packet_t p;
|
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
static uint32_t sending_delay = SENDING_DELAY;
|
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
void sender(char *count);
|
|
|
|
void print_buffer(char *unused);
|
2010-12-02 15:38:28 +01:00
|
|
|
void switch2rx(char *unused);
|
|
|
|
void powerdown(char *unused);
|
|
|
|
void set_delay(char *delay);
|
2010-11-27 19:27:05 +01:00
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
shell_t shell;
|
2010-11-24 11:20:27 +01:00
|
|
|
const shell_command_t sc[] = {
|
2010-12-02 15:38:28 +01:00
|
|
|
{"on", "", switch2rx},
|
|
|
|
{"off", "", powerdown},
|
2010-11-27 19:27:05 +01:00
|
|
|
{"snd", "", sender},
|
2010-12-02 15:38:28 +01:00
|
|
|
{"delay", "", set_delay},
|
2010-11-27 19:27:05 +01:00
|
|
|
{"buffer", "", print_buffer},
|
2010-11-24 11:20:27 +01:00
|
|
|
{NULL, NULL, NULL}};
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
void shell_runner(void) {
|
|
|
|
shell_init(&shell, sc, uart0_readc, uart0_putc);
|
|
|
|
posix_open(uart0_handler_pid, 0);
|
|
|
|
shell_run(&shell);
|
|
|
|
}
|
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
void sender(char *count) {
|
|
|
|
unsigned int c, i;
|
|
|
|
|
|
|
|
mesg.type = SND_PKT;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
tcmd.data = &p;
|
|
|
|
|
|
|
|
p.length = CC1100_MAX_DATA_LENGTH;
|
|
|
|
p.dst = 0;
|
|
|
|
|
|
|
|
sscanf(count, "snd %u", &c);
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
puts(".");
|
|
|
|
p.data = snd_buffer[i % SND_BUFFER_SIZE];
|
|
|
|
msg_send(&mesg, transceiver_pid, 1);
|
2010-12-02 15:38:28 +01:00
|
|
|
swtimer_usleep(sending_delay);
|
2010-11-27 19:27:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_buffer(char *unused) {
|
|
|
|
uint8_t i;
|
|
|
|
extern radio_packet_t transceiver_buffer[];
|
|
|
|
for (i = 0; i < TRANSCEIVER_BUFFER_SIZE; i++) {
|
|
|
|
printf("[%u] %u # %u # %u\n", i, transceiver_buffer[i].processing, transceiver_buffer[i].length, transceiver_buffer[i].data[i]);
|
|
|
|
}
|
2010-12-11 12:09:20 +01:00
|
|
|
extern rx_buffer_t cc110x_rx_buffer[];
|
2010-11-27 19:27:05 +01:00
|
|
|
for (i = 0; i < TRANSCEIVER_BUFFER_SIZE; i++) {
|
2010-12-11 12:09:20 +01:00
|
|
|
printf("[%u] %u # %u \n", i, cc110x_rx_buffer[i].packet.length, cc110x_rx_buffer[i].packet.data[i]);
|
2010-11-27 19:27:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
void switch2rx(char *unused) {
|
|
|
|
mesg.type = SWITCH_RX;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
puts("Turning transceiver on");
|
|
|
|
if (msg_send(&mesg, transceiver_pid, 1)) {
|
|
|
|
puts("\tsuccess");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void powerdown(char *unused) {
|
|
|
|
mesg.type = POWERDOWN;
|
|
|
|
mesg.content.ptr = (char*) &tcmd;
|
|
|
|
|
|
|
|
tcmd.transceivers = TRANSCEIVER_CC1100;
|
|
|
|
puts("Turning transceiver off");
|
|
|
|
if (msg_send(&mesg, transceiver_pid, 1)) {
|
|
|
|
puts("\tsuccess");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_delay(char *delay) {
|
|
|
|
uint32_t d;
|
|
|
|
|
|
|
|
if (sscanf(delay, "delay %lu", &d) == 1) {
|
|
|
|
sending_delay = d;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Usage:\tdelay <µs>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
void radio(void) {
|
2011-03-08 10:54:40 +01:00
|
|
|
msg_t m;
|
2010-11-26 17:06:54 +01:00
|
|
|
radio_packet_t *p;
|
|
|
|
uint8_t i;
|
2010-11-24 11:20:27 +01:00
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
msg_init_queue(msg_q, RCV_BUFFER_SIZE);
|
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
while (1) {
|
|
|
|
msg_receive(&m);
|
2010-11-26 17:06:54 +01:00
|
|
|
if (m.type == PKT_PENDING) {
|
|
|
|
p = (radio_packet_t*) m.content.ptr;
|
2010-11-27 19:27:05 +01:00
|
|
|
printf("Packet waiting, process %p...\n", p);
|
2010-11-26 17:06:54 +01:00
|
|
|
printf("\tLength:\t%u\n", p->length);
|
|
|
|
printf("\tSrc:\t%u\n", p->src);
|
|
|
|
printf("\tDst:\t%u\n", p->dst);
|
2010-12-01 17:07:05 +01:00
|
|
|
printf("\tLQI:\t%u\n", p->lqi);
|
|
|
|
printf("\tRSSI:\t%u\n", p->rssi);
|
2010-11-26 17:06:54 +01:00
|
|
|
|
|
|
|
for (i = 0; i < p->length; i++) {
|
|
|
|
printf("%02X ", p->data[i]);
|
|
|
|
}
|
2010-11-27 19:27:05 +01:00
|
|
|
p->processing--;
|
2010-11-26 17:06:54 +01:00
|
|
|
printf("\n");
|
|
|
|
}
|
2010-11-27 19:27:05 +01:00
|
|
|
else if (m.type == ENOBUFFER) {
|
|
|
|
puts("Transceiver buffer full");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Unknown packet received");
|
|
|
|
}
|
2010-11-24 11:20:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
int main(void) {
|
2010-11-26 10:23:46 +01:00
|
|
|
int radio_pid;
|
2010-11-27 19:27:05 +01:00
|
|
|
uint8_t i;
|
|
|
|
for (i = 0; i < SND_BUFFER_SIZE; i++) {
|
|
|
|
memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
|
|
|
|
}
|
2010-11-26 10:23:46 +01:00
|
|
|
thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell");
|
2010-11-24 21:45:38 +01:00
|
|
|
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
|
2010-11-26 10:23:46 +01:00
|
|
|
transceiver_init(TRANSCEIVER_CC1100);
|
2010-11-27 11:09:42 +01:00
|
|
|
transceiver_start();
|
2010-11-26 10:23:46 +01:00
|
|
|
transceiver_register(TRANSCEIVER_CC1100, radio_pid);
|
2010-11-19 20:10:09 +01:00
|
|
|
|
|
|
|
while (1) {
|
2010-11-24 11:20:27 +01:00
|
|
|
// LED_GREEN_TOGGLE;
|
2010-11-19 20:10:09 +01:00
|
|
|
hwtimer_wait(1000 * 1000);
|
|
|
|
}
|
|
|
|
}
|