[drivers cc110x]

* fixed cc110x driver (some references where broken due to renaming of spi  functions from cc1100_* to cc110x_*
This commit is contained in:
Oliver Hahm 2011-04-06 11:09:29 +02:00
parent 364905f0d6
commit 430bad0d69
7 changed files with 74 additions and 72 deletions

View File

@ -31,5 +31,5 @@ HDRS += $(TOP)/drivers/cc110x ;
Module cc110x : cc1100.c cc1100-csmaca-mac.c cc1100-defaultSettings.c
cc1100_phy.c cc1100_spi.c
: board_cc1100 swtimer protocol_multiplex gpioint ;
: board_cc110x swtimer protocol_multiplex gpioint ;

View File

@ -38,13 +38,13 @@ and the mailinglist (subscription via web site)
#include <stdint.h>
uint8_t cc1100_txrx(uint8_t c);
uint8_t cc110x_txrx(uint8_t c);
void cc1100_gdo0_enable(void);
void cc1100_gdo0_disable(void);
void cc1100_gdo2_enable(void);
void cc1100_gdo2_disable(void);
void cc1100_init_interrupts(void);
void cc110x_gdo0_enable(void);
void cc110x_gdo0_disable(void);
void cc110x_gdo2_enable(void);
void cc110x_gdo2_disable(void);
void cc110x_init_interrupts(void);
void cc1100_before_send(void);
void cc1100_after_send(void);
void cc110x_before_send(void);
void cc110x_after_send(void);

View File

@ -38,7 +38,7 @@ and the mailinglist (subscription via web site)
*/
#include <stdio.h>
//#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include "cc1100.h"
@ -47,6 +47,7 @@ and the mailinglist (subscription via web site)
#include "protocol-multiplex.h"
#include "hwtimer.h"
#include <swtimer.h>
/*---------------------------------------------------------------------------*/
@ -106,9 +107,9 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
collisions_per_sec = 0;
collision_state = COLLISION_STATE_MEASURE;
} else if (collision_state == COLLISION_STATE_MEASURE) {
uint64_t timespan = swtimer_now() - collision_measurement_start;
if (timespan > 1000000) {
collisions_per_sec = (collision_count * 1000000) / (double) timespan;
uint64_t timespan = swtimer_now() - collision_measurement_start;
if (timespan > 1000000) {
collisions_per_sec = (collision_count * 1000000) / (double) timespan;
if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) {
collision_measurement_start = swtimer_now();
collision_state = COLLISION_STATE_KEEP;
@ -120,8 +121,8 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
}
}
} else if (collision_state == COLLISION_STATE_KEEP) {
uint64_t timespan = swtimer_now() - collision_measurement_start;
if (timespan > 5000000) {
uint64_t timespan = swtimer_now() - collision_measurement_start;
if (timespan > 5000000) {
collision_state = COLLISION_STATE_INITIAL;
}
}

View File

@ -160,19 +160,19 @@ volatile int wor_hwtimer_id = -1;
void cc1100_disable_interrupts(void)
{
cc1100_gdo2_disable();
cc1100_gdo0_disable();
cc110x_gdo2_disable();
cc110x_gdo0_disable();
}
void cc1100_gdo0_irq(void)
void cc110x_gdo0_irq(void)
{
// Air was not free -> Clear CCA flag
rflags.CAA = false;
// Disable carrier sense detection (GDO0 interrupt)
cc1100_gdo0_disable();
cc110x_gdo0_disable();
}
void cc1100_gdo2_irq(void)
void cc110x_gdo2_irq(void)
{
cc1100_phy_rx_handler();
}
@ -251,9 +251,9 @@ bool cc1100_spi_receive_packet(uint8_t *rxBuffer, uint8_t length)
void cc1100_set_idle(void) {
if (radio_state == RADIO_WOR) {
// Wake up the chip from WOR/sleep
cc1100_spi_select();
cc110x_spi_select();
hwtimer_wait(RTIMER_TICKS(122));
cc1100_spi_unselect();
cc110x_spi_unselect();
radio_state = RADIO_IDLE;
// XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms)
hwtimer_wait(FS_CAL_TIME);
@ -292,9 +292,9 @@ static void wakeup_from_wor(void)
return;
}
// Wake up the chip from WOR/sleep
cc1100_spi_select();
cc110x_spi_select();
hwtimer_wait(RTIMER_TICKS(122));
cc1100_spi_unselect();
cc110x_spi_unselect();
radio_state = RADIO_IDLE;
// XOSC startup + FS calibration (300 + 809 us ~ 1.38 ms)
hwtimer_wait(FS_CAL_TIME);
@ -305,7 +305,7 @@ static void wakeup_from_wor(void)
*/
void switch_to_wor2(void)
{
if (cc1100_get_gdo2()) return; // If incoming packet, then don't go to WOR now
if (cc110x_get_gdo2()) return; // If incoming packet, then don't go to WOR now
cc1100_spi_strobe(CC1100_SIDLE); // Put CC1100 to IDLE
radio_state = RADIO_IDLE; // Radio state now IDLE
cc1100_spi_write_reg(CC1100_MCSM2,
@ -336,7 +336,7 @@ static void hwtimer_switch_to_wor2_wrapper(void* ptr)
static void switch_to_wor(void)
{
// Any incoming packet?
if (cc1100_get_gdo2())
if (cc110x_get_gdo2())
{
// Then don't go to WOR now
return;
@ -558,16 +558,16 @@ void cc1100_hwtimer_go_receive_wrapper(void *ptr)
static void reset(void)
{
cc1100_go_idle();
cc1100_spi_select();
cc110x_spi_select();
cc1100_spi_strobe(CC1100_SRES);
hwtimer_wait(RTIMER_TICKS(10));
}
static void power_up_reset(void)
{
cc1100_spi_unselect();
cc1100_spi_cs();
cc1100_spi_unselect();
cc110x_spi_unselect();
cc110x_spi_cs();
cc110x_spi_unselect();
hwtimer_wait(RESET_WAIT_TIME);
reset();
radio_state = RADIO_IDLE;
@ -587,7 +587,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
if (size > PACKET_LENGTH) return;
// Disables RX interrupt etc.
cc1100_before_send();
cc110x_before_send();
// But CC1100 in IDLE mode to flush the FIFO
cc1100_spi_strobe(CC1100_SIDLE);
@ -600,7 +600,7 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
unsigned int cpsr = disableIRQ();
cc1100_spi_strobe(CC1100_STX);
// Wait for GDO2 to be set -> sync word transmitted
while (cc1100_get_gdo2() == 0) {
while (cc110x_get_gdo2() == 0) {
abort_count++;
if (abort_count > CC1100_SYNC_WORD_TX_TIME) {
// Abort waiting. CC1100 maybe in wrong mode
@ -611,9 +611,9 @@ void cc1100_send_raw(uint8_t *tx_buffer, uint8_t size)
}
restoreIRQ(cpsr);
// Wait for GDO2 to be cleared -> end of packet
while (cc1100_get_gdo2() != 0);
while (cc110x_get_gdo2() != 0);
// Experimental - TOF Measurement
cc1100_after_send();
cc110x_after_send();
}
/*---------------------------------------------------------------------------*/
@ -742,7 +742,7 @@ rssi_2_dbm(uint8_t rssi)
void cc1100_init(void)
{
// Initialize SPI
cc1100_spi_init();
cc110x_spi_init();
// Set default mode (with default (energy optimized) RX interval)
cc1100_set_mode0(CC1100_RADIO_MODE, T_RX_INTERVAL);
@ -834,7 +834,7 @@ rd_set_mode(int mode)
switch (mode)
{
case RADIO_MODE_ON:
cc1100_init_interrupts(); // Enable interrupts
cc110x_init_interrupts(); // Enable interrupts
cc1100_setup_mode(); // Set chip to desired mode
break;
case RADIO_MODE_OFF:
@ -877,19 +877,19 @@ void cc1100_cs_set_enabled(bool enabled)
if (enabled)
{
// Enable carrier sense detection (GDO0 interrupt)
cc1100_gdo0_enable();
cc110x_gdo0_enable();
}
else
{
// Disable carrier sense detection (GDO0 interrupt)
cc1100_gdo0_disable();
cc110x_gdo0_disable();
}
}
int cc1100_cs_read(void)
{
/* GDO0 reflects CS (high: air not free, low: air free) */
return cc1100_get_gdo0();
return cc110x_get_gdo0();
}
int cc1100_cs_read_cca(void)

View File

@ -45,7 +45,7 @@ and the mailinglist (subscription via web site)
#include <string.h>
#include "hwtimer.h"
#include "swtimer.h"
#include <swtimer.h>
#include "cc1100.h"
#include "cc1100_spi.h"
@ -382,7 +382,7 @@ static bool contains_seq_entry(uint8_t src, uint8_t id)
{
// Check if time stamp is OK
cmp = (radio_mode == CC1100_MODE_WOR) ? cc1100_wor_config.rx_interval : 16000; // constant RX ~16ms
if ((now - seq_buffer[i].m_ticks) <= cmp)
if ((now - seq_buffer[i].m_ticks) <= cmp)
{
return true;
}
@ -412,7 +412,7 @@ static void add_seq_entry(uint8_t src, uint8_t id)
// Add new entry
seq_buffer[seq_buffer_pos].source = src;
seq_buffer[seq_buffer_pos].identification = id;
seq_buffer[seq_buffer_pos].m_ticks = swtimer_now();
seq_buffer[seq_buffer_pos].m_ticks = swtimer_now();
// Store 16 bit sequence number of layer 0 for speedup
last_seq_num = src;
@ -625,6 +625,7 @@ int cc1100_set_packet_handler(protocol_t protocol, packet_handler_t handler)
static void cc1100_event_handler_function(void)
{
msg_t m;
while (1)
{
if (cc1100_watch_dog_period != 0) {

View File

@ -61,13 +61,13 @@ cc1100_spi_writeburst_reg(uint8_t addr, char *src, uint8_t count)
{
int i = 0;
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
cc1100_txrx(addr | CC1100_WRITE_BURST);
cc110x_spi_select();
cc110x_txrx(addr | CC1100_WRITE_BURST);
while (i < count) {
cc1100_txrx(src[i]);
cc110x_txrx(src[i]);
i++;
}
cc1100_spi_unselect();
cc110x_spi_unselect();
restoreIRQ(cpsr);
return count;
}
@ -77,13 +77,13 @@ cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count)
{
int i = 0;
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
cc1100_txrx(addr | CC1100_READ_BURST);
cc110x_spi_select();
cc110x_txrx(addr | CC1100_READ_BURST);
while (i < count) {
buffer[i] = cc1100_txrx(NOBYTE);
buffer[i] = cc110x_txrx(NOBYTE);
i++;
}
cc1100_spi_unselect();
cc110x_spi_unselect();
restoreIRQ(cpsr);
}
@ -91,10 +91,10 @@ void
cc1100_spi_write_reg(uint8_t addr, uint8_t value)
{
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
cc1100_txrx(addr);
cc1100_txrx(value);
cc1100_spi_unselect();
cc110x_spi_select();
cc110x_txrx(addr);
cc110x_txrx(value);
cc110x_spi_unselect();
restoreIRQ(cpsr);
}
@ -102,10 +102,10 @@ uint8_t cc1100_spi_read_reg(uint8_t addr)
{
uint8_t result;
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
cc1100_txrx(addr | CC1100_READ_SINGLE);
result = cc1100_txrx(NOBYTE);
cc1100_spi_unselect();
cc110x_spi_select();
cc110x_txrx(addr | CC1100_READ_SINGLE);
result = cc110x_txrx(NOBYTE);
cc110x_spi_unselect();
restoreIRQ(cpsr);
return result;
}
@ -114,10 +114,10 @@ uint8_t cc1100_spi_read_status(uint8_t addr)
{
uint8_t result;
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
cc1100_txrx(addr | CC1100_READ_BURST);
result = cc1100_txrx(NOBYTE);
cc1100_spi_unselect();
cc110x_spi_select();
cc110x_txrx(addr | CC1100_READ_BURST);
result = cc110x_txrx(NOBYTE);
cc110x_spi_unselect();
restoreIRQ(cpsr);
return result;
}
@ -126,9 +126,9 @@ uint8_t cc1100_spi_strobe(uint8_t c)
{
uint8_t result;
unsigned int cpsr = disableIRQ();
cc1100_spi_select();
result = cc1100_txrx(c);
cc1100_spi_unselect();
cc110x_spi_select();
result = cc110x_txrx(c);
cc110x_spi_unselect();
restoreIRQ(cpsr);
return result;
}

View File

@ -44,14 +44,14 @@ and the mailinglist (subscription via web site)
#ifndef CC1100_SPI_H_
#define CC1100_SPI_H_
int cc1100_get_gdo0(void);
int cc1100_get_gdo1(void);
int cc1100_get_gdo2(void);
int cc110x_get_gdo0(void);
int cc110x_get_gdo1(void);
int cc110x_get_gdo2(void);
void cc1100_spi_init(void);
void cc1100_spi_cs(void);
void cc1100_spi_select(void);
void cc1100_spi_unselect(void);
void cc110x_spi_init(void);
void cc110x_spi_cs(void);
void cc110x_spi_select(void);
void cc110x_spi_unselect(void);
uint8_t cc1100_spi_writeburst_reg(uint8_t addr, char *buffer, uint8_t count);
void cc1100_spi_readburst_reg(uint8_t addr, char *buffer, uint8_t count);