Skip to content

Commit

Permalink
refactoring of radio module.
Browse files Browse the repository at this point in the history
  • Loading branch information
anroOfCode committed Dec 23, 2012
1 parent a596473 commit e3431c6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
9 changes: 1 addition & 8 deletions cc2520.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <linux/workqueue.h>
#include <linux/spinlock.h>

#include 'radio.h'
#include "radio.h"

//////////////////////////////
// Configuration for driver
Expand Down Expand Up @@ -125,13 +125,6 @@ struct cc2520_state {
struct workqueue_struct *wq;
};

// Radio


// Radio Interrupt Callbacks
void cc2520_radio_sfd_occurred(u64 nano_timestamp);
void cc2520_radio_fifop_occurred(void);

// Platform
int cc2520_plat_gpio_init(void);
void cc2520_plat_gpio_free(void);
Expand Down
7 changes: 0 additions & 7 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ int init_module()
int err = 0;

memset(&state, 0, sizeof(struct cc2520_state));
state.short_addr = CC2520_DEF_SHORT_ADDR;
state.extended_addr = CC2520_DEF_EXT_ADDR;
state.pan_id = CC2520_DEF_PAN;
state.channel = CC2520_DEF_CHANNEL;


printk(KERN_INFO "loading CC2520 Kernel Module v0.01...\n");

sema_init(&state.radio_sem, 1);

err = cc2520_plat_gpio_init();
if (err) {
printk(KERN_INFO "[CC2520] - gpio driver error. aborting.");
Expand Down
33 changes: 0 additions & 33 deletions platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ int cc2520_plat_spi_init()
{
int result;

state.tx_buf = kmalloc(SPI_BUFF_SIZE, GFP_KERNEL | GFP_DMA);
if (!state.tx_buf) {
result = -EFAULT;
goto error;
}

state.rx_buf = kmalloc(SPI_BUFF_SIZE, GFP_KERNEL | GFP_DMA);
if (!state.rx_buf) {
result = -EFAULT;
goto error;
}

result = cc2520_spi_add_to_bus();
if (result < 0)
goto error;
Expand All @@ -133,17 +121,6 @@ int cc2520_plat_spi_init()

error:
spi_unregister_driver(&cc2520_spi_driver);

if (state.rx_buf) {
kfree(state.rx_buf);
state.rx_buf = 0;
}

if (state.tx_buf) {
kfree(state.tx_buf);
state.tx_buf = 0;
}

return result;
}

Expand All @@ -153,16 +130,6 @@ void cc2520_plat_spi_free()
spi_unregister_device(state.spi_device);

spi_unregister_driver(&cc2520_spi_driver);

if (state.rx_buf) {
kfree(state.rx_buf);
state.rx_buf = 0;
}

if (state.tx_buf) {
kfree(state.tx_buf);
state.tx_buf = 0;
}
}

//////////////////////////
Expand Down
40 changes: 38 additions & 2 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,26 @@ int cc2520_radio_init()
{
int result;

spinlock_init(&radio_sl);
short_addr = CC2520_DEF_SHORT_ADDR;
extended_addr = CC2520_DEF_EXT_ADDR;
pan_id = CC2520_DEF_PAN;
channel = CC2520_DEF_CHANNEL;

spin_lock_init(&radio_sl);
radio_state = CC2520_RADIO_STATE_IDLE;

tx_buf = kmalloc(SPI_BUFF_SIZE, GFP_KERNEL | GFP_DMA);
if (!tx_buf) {
result = -EFAULT;
goto error;
}

rx_buf = kmalloc(SPI_BUFF_SIZE, GFP_KERNEL | GFP_DMA);
if (!rx_buf) {
result = -EFAULT;
goto error;
}

tx_buf_r = kmalloc(PKT_BUFF_SIZE, GFP_KERNEL);
if (!tx_buf_r) {
result = -EFAULT;
Expand All @@ -85,6 +102,15 @@ int cc2520_radio_init()
tx_buf_r = 0;
}

if (rx_buf) {
kfree(rx_buf);
rx_buf = 0;
}

if (tx_buf) {
kfree(tx_buf);
tx_buf = 0;
}
return result;
}

Expand All @@ -99,6 +125,16 @@ void cc2520_radio_free()
kfree(tx_buf_r);
tx_buf_r = 0;
}

if (rx_buf) {
kfree(rx_buf);
rx_buf = 0;
}

if (tx_buf) {
kfree(tx_buf);
tx_buf = 0;
}
}

void cc2520_radio_start()
Expand Down Expand Up @@ -222,7 +258,7 @@ void cc2520_radio_reset()
/////////////////////////////

// context: process?
void cc2520_radio_tx(u8 *buf, u8 len)
int cc2520_radio_tx(u8 *buf, u8 len)
{
// capture exclusive radio rights to send
// build the transmit command seq
Expand Down

0 comments on commit e3431c6

Please sign in to comment.