diff --git a/cc2520.h b/cc2520.h index f2b3d33..e25eb0a 100644 --- a/cc2520.h +++ b/cc2520.h @@ -9,8 +9,8 @@ // Used to prevent timing-critical // operations from being interfered with // by the printk function. -#define DBG(x) printk x -//#define DBG(x) do {} while (0) +//#define DBG(x) printk x +#define DBG(x) do {} while (0) ////////////////////////////// // Configuration for driver diff --git a/radio.c b/radio.c index e111146..fc45e78 100644 --- a/radio.c +++ b/radio.c @@ -553,23 +553,7 @@ static void cc2520_radio_finishRx(void *arg) radio_top->rx_done(rx_buf_r, len); spin_unlock(&rx_buf_sl); - DBG((KERN_INFO "[cc2520] - Read %d bytes from radio.", len)); - - // At this point we should schedule the system to move the - // RX into a different buffer. For now just print it. - /* - buff = kmalloc(len*5 + 1, GFP_ATOMIC); - if (buff) { - buff_ptr = buff; - for (i = 0; i < len; i++) - { - buff_ptr += sprintf(buff_ptr, " 0x%02X", rx_buf[i]); - } - *(buff_ptr) = '\0'; - printk(KERN_INFO "[cc2520] - %s\n", buff); - kfree(buff); - } - */ + DBG((KERN_INFO "[cc2520] - Read %d bytes from radio.\n", len)); } ////////////////////////////// diff --git a/reload.sh b/reload.sh new file mode 100644 index 0000000..0cf363a --- /dev/null +++ b/reload.sh @@ -0,0 +1,3 @@ +#!/bin/bash +rmmod cc2520 +insmod cc2520.ko diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..4ed4c52 --- /dev/null +++ b/setup.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mknod /dev/radio c 251 0 +chmod 777 /dev/radio diff --git a/tests/read.c b/tests/read.c new file mode 100644 index 0000000..190d12d --- /dev/null +++ b/tests/read.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include "ioctl.h" +#include + +int main(char ** argv, int argc) +{ + + int result = 0; + printf("Testing cc2520 driver...\n"); + int file_desc; + file_desc = open("/dev/radio", O_RDWR); + + printf("Setting channel\n"); + struct cc2520_set_channel_data chan_data; + chan_data.channel = 26; + ioctl(file_desc, CC2520_IO_RADIO_SET_CHANNEL, &chan_data); + + printf("Setting address\n"); + struct cc2520_set_address_data addr_data; + addr_data.short_addr = 0x0001; + addr_data.extended_addr = 0x0000000000000001; + addr_data.pan_id = 0x22; + ioctl(file_desc, CC2520_IO_RADIO_SET_ADDRESS, &addr_data); + + printf("Setting tx power\n"); + struct cc2520_set_txpower_data txpower_data; + txpower_data.txpower = CC2520_TXPOWER_0DBM; + ioctl(file_desc, CC2520_IO_RADIO_SET_TXPOWER, &txpower_data); + + printf("Turning on the radio...\n"); + ioctl(file_desc, CC2520_IO_RADIO_INIT, NULL); + ioctl(file_desc, CC2520_IO_RADIO_ON, NULL); + + int i = 0; + + char buf[256]; + char pbuf[1024]; + char *buf_ptr = NULL; + + for (i = 0; i < 100; i++) { + printf("Receiving a test message...\n"); + result = read(file_desc, buf, 127); + + printf("result %d\n", result); + if (result > 0) { + buf_ptr = pbuf; + for (i = 0; i < result; i++) + { + buf_ptr += sprintf(buf_ptr, " 0x%02X", buf[i]); + } + *(buf_ptr) = '\0'; + printf("read %s\n", pbuf); + } + } + + printf("Turning off the radio...\n"); + ioctl(file_desc, CC2520_IO_RADIO_OFF, NULL); + + close(file_desc); +} \ No newline at end of file diff --git a/tests/write.c b/tests/write.c new file mode 100644 index 0000000..82666bc --- /dev/null +++ b/tests/write.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include "ioctl.h" +#include + +int main(char ** argv, int argc) +{ + + int result = 0; + printf("Testing cc2520 driver...\n"); + int file_desc; + file_desc = open("/dev/radio", O_RDWR); + + printf("Setting channel\n"); + struct cc2520_set_channel_data chan_data; + chan_data.channel = 26; + ioctl(file_desc, CC2520_IO_RADIO_SET_CHANNEL, &chan_data); + + printf("Setting address\n"); + struct cc2520_set_address_data addr_data; + addr_data.short_addr = 0x0001; + addr_data.extended_addr = 0x0000000000000001; + addr_data.pan_id = 0x22; + ioctl(file_desc, CC2520_IO_RADIO_SET_ADDRESS, &addr_data); + + printf("Setting tx power\n"); + struct cc2520_set_txpower_data txpower_data; + txpower_data.txpower = CC2520_TXPOWER_0DBM; + ioctl(file_desc, CC2520_IO_RADIO_SET_TXPOWER, &txpower_data); + + printf("Turning on the radio...\n"); + ioctl(file_desc, CC2520_IO_RADIO_INIT, NULL); + ioctl(file_desc, CC2520_IO_RADIO_ON, NULL); + + int i = 0; + + for (i = 0; i < 100; i++) { + printf("Sending a test message...\n"); + + // 8 Byte Header, 6 Byte Payload. + char test_msg[] = {0x41, 0x88, (char) i, 0x22, 0x00, 0xFF, 0xFF, 0x01, 0x00, 0x3F, 0x06, 0x00, 0x01, 0x72, (char) i}; + result = write(file_desc, test_msg, 15); + + printf("result %d\n", result); + //usleep(250 * 1000); + } + + printf("Turning off the radio...\n"); + ioctl(file_desc, CC2520_IO_RADIO_OFF, NULL); + + close(file_desc); +} \ No newline at end of file