Skip to content

Commit

Permalink
added test programs and SUPER basic shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
anroOfCode committed Dec 26, 2012
1 parent 7dd1b5e commit db83f2e
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cc2520.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

//////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
rmmod cc2520
insmod cc2520.ko
3 changes: 3 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
mknod /dev/radio c 251 0
chmod 777 /dev/radio
63 changes: 63 additions & 0 deletions tests/read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "ioctl.h"
#include <unistd.h>

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);
}
54 changes: 54 additions & 0 deletions tests/write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "ioctl.h"
#include <unistd.h>

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);
}

0 comments on commit db83f2e

Please sign in to comment.