1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

[cc110x_ng]

* fuxed transceiver driver for chronos
* some more stuff
This commit is contained in:
Oliver Hahm 2010-12-10 18:00:31 +01:00
parent 830f17246c
commit ec6a794143
15 changed files with 111 additions and 76 deletions

View File

@ -8,9 +8,9 @@
#include <cc430_.h>
#include <msp430/rf1a.h>
#define CC1100_GDO0 IOCFG0
#define CC1100_GDO1 IOCFG1
#define CC1100_GDO2 IOCFG2
#define CC1100_GDO0 (RF1AIN & BIT0)
#define CC1100_GDO1 (RF1AIN & BIT1)
#define CC1100_GDO2 (RF1AIN & BIT2)
int cc1100_get_gdo0(void) {
return CC1100_GDO0;
@ -37,41 +37,44 @@ void cc1100_after_send(void)
}
void cc1100_gdo0_enable(void) {
RF1AIFG &= ~RF1AIV_RFIFG0;
RF1AIE |= RF1AIV_RFIFG0;
RF1AIFG &= ~BIT0;
RF1AIE |= BIT0;
}
void cc1100_gdo0_disable(void) {
RF1AIE &= ~RF1AIV_RFIFG0;
RF1AIFG &= ~RF1AIV_RFIFG0;
RF1AIE &= ~BIT0;
RF1AIFG &= ~BIT0;
}
void cc1100_gdo2_disable(void) {
RF1AIFG &= ~RF1AIV_RFIFG2;
RF1AIE &= ~RF1AIV_RFIFG2;
RF1AIFG &= ~BIT2; // Clear a pending interrupt
RF1AIE &= ~BIT2; // Disable the interrupt
}
void cc1100_gdo2_enable(void) {
RF1AIE &= ~RF1AIV_RFIFG2;
RF1AIFG |= RF1AIV_RFIFG2;
RF1AIFG &= ~BIT2; // Clear a pending interrupt
RF1AIE |= BIT2; // Enable the interrupt
}
void cc1100_init_interrupts(void) {
uint8_t state = disableIRQ(); /* Disable all interrupts */
cc1100_gdo2_enable();
cc1100_gdo0_disable();
restoreIRQ(state); /* Enable all interrupts */
}
interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){
__enter_isr();
/* Check IFG */
if (RF1AIFG & RF1AIV_RFIFG2) {
RF1AIFG &= ~RF1AIV_RFIFG2;
if (RF1AIV == RF1AIV_RFIFG2) {
while (RF1AIN & BIT2);
/* discard all further interrupts */
RF1AIV = 0;
cc1100_gdo2_irq();
}
if (RF1AIFG & RF1AIV_RFIFG0) {
RF1AIFG &= ~RF1AIV_RFIFG0;
RF1AIE &= ~RF1AIV_RFIFG0;
if (RF1AIV == RF1AIV_RFIFG0) {
cc1100_gdo0_irq();
RF1AIE &= ~BIT0;
}
__exit_isr();
}

View File

@ -128,8 +128,7 @@ void cc1100_spi_init(void)
}
}
uint8_t
cc1100_txrx(uint8_t c) {
uint8_t cc1100_txrx(uint8_t c) {
uint8_t result;
SSP0DR = c;
#ifdef DEBUG

View File

@ -38,8 +38,8 @@ and the mailinglist (subscription via web site)
#define KERNEL_CONF_STACKSIZE_IDLE 64
#define MSP430_ISR_STACK_SIZE 256
#define RX_BUF_SIZE (2)
#define TRANSCEIVER_BUFFER_SIZE (2)
#define RX_BUF_SIZE (3)
#define TRANSCEIVER_BUFFER_SIZE (3)
/** @} */
#endif /* CPUCONF_H_ */

View File

@ -38,6 +38,7 @@ void cc1100_rx_handler(void) {
}
cc1100_rx_buffer[rx_buffer_next].rssi = rflags._RSSI;
cc1100_rx_buffer[rx_buffer_next].lqi = rflags._LQI;
cc1100_strobe(CC1100_SFRX); // ...for flushing the RX FIFO
// Valid packet. After a wake-up, the radio should be in IDLE.
// So put CC1100 to RX for WOR_TIMEOUT (have to manually put
@ -109,6 +110,7 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) {
rxBuffer[0] = packetLength;
// Read the rest of the packet
// TODO: Offset + 2 here for cc430
cc1100_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength);
// Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI)

View File

@ -272,7 +272,7 @@ static void reset(void) {
cc1100_spi_select();
#endif
cc1100_strobe(CC1100_SRES);
hwtimer_wait(RTIMER_TICKS(10));
hwtimer_wait(RTIMER_TICKS(100));
}
static void power_up_reset(void) {

View File

@ -99,9 +99,16 @@ void cc1100_write_reg(uint8_t addr, uint8_t value) {
}
uint8_t cc1100_read_status(uint8_t addr) {
char status;
cc1100_readburst_reg(addr, &status, 1);
return status;
unsigned char x;
uint16_t int_state;
int_state = disableIRQ();
RF1AINSTR1B = (addr | RF_STATREGRD);
x = RF1ADOUT1B;
restoreIRQ(int_state);
return x;
}
// *************************************************************************************************

View File

@ -11,17 +11,16 @@
#include <transceiver.h>
#include <cc1100_ng.h>
#define RADIO_STACK_SIZE (1024)
#define RADIO_STACK_SIZE (512)
#define SEND_SIZE CC1100_MAX_DATA_LENGTH
#define SND_BUFFER_SIZE (3)
#define RCV_BUFFER_SIZE (4)
#define SENDING_DELAY (5 * 1000)
char radio_stack_buffer[RADIO_STACK_SIZE];
uint8_t snd_buffer[SND_BUFFER_SIZE][SEND_SIZE];
uint8_t snd_buffer[SEND_SIZE];
msg msg_q[RCV_BUFFER_SIZE];
@ -29,28 +28,20 @@ static msg mesg;
static transceiver_command_t tcmd;
static radio_packet_t p;
void sender(char *count);
void sender(char *count) {
unsigned int c = 3;
unsigned int i;
void send(radio_address_t dst, uint8_t len, uint8_t *data);
void send(radio_address_t dst, uint8_t len, uint8_t *data) {
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;
p.length = len;
p.dst = dst;
for (i = 0; i < c; i++) {
display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF);
display_chars(LCD_SEG_L1_3_0, (char*) itoa(i, 1, 0), SEG_ON);
p.data = snd_buffer[i % SND_BUFFER_SIZE];
msg_send(&mesg, transceiver_pid, 1);
hwtimer_wait(SENDING_DELAY);
}
p.data = data;
msg_send(&mesg, transceiver_pid, 1);
}
@ -64,7 +55,9 @@ void radio(void) {
msg_receive(&m);
if (m.type == PKT_PENDING) {
p = (radio_packet_t*) m.content.ptr;
display_chars(LCD_SEG_L2_5_0, (char*) itoa(p->length, 2, 0), SEG_ON);
display_chars(LCD_SEG_L2_5_0, "CC1100", SEG_OFF);
display_chars(LCD_SEG_L2_5_0, (char*) p->data, SEG_ON);
send(p->src, p->length, p->data);
p->processing--;
}
else if (m.type == ENOBUFFER) {
@ -76,11 +69,8 @@ void radio(void) {
int main(void) {
int radio_pid;
uint8_t addr = 43;
uint8_t i;
for (i = 0; i < SND_BUFFER_SIZE; i++) {
memset(snd_buffer[i], i, SEND_SIZE);
}
radio_address_t addr = 43;
memset(snd_buffer, 43, SEND_SIZE);
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
transceiver_init(TRANSCEIVER_CC1100);
transceiver_start();
@ -96,8 +86,11 @@ int main(void) {
tcmd.data = &addr;
msg_send(&mesg, transceiver_pid, 1);
sender(NULL);
send(0, SEND_SIZE, snd_buffer);
while (1) {
hwtimer_wait(SENDING_DELAY);
display_chars(LCD_SEG_L1_3_0, ".....", SEG_OFF);
display_chars(LCD_SEG_L1_3_0, (char*) itoa(TA0R, 6, 0), SEG_ON);
}
}

View File

@ -1,5 +1,5 @@
SubDir TOP projects hi_earth ;
Module hi_earth : main.c ;
Module hi_earth : main.c : board_display hwtimer auto_init ;
UseModule hi_earth ;

View File

@ -5,9 +5,10 @@
// Author: Felix Genicio
//******************************************************************************
#include "cc430x613x.h"
#include <cc430x613x.h>
#include <string.h>
#include <display.h>
#include <hwtimer.h>
void display1(void);
void display2(void);
@ -30,6 +31,11 @@ int main(void)
i = 1;
display2();
}
for (j = 1; j < 10; j++) {
hwtimer_wait(3333);
}
display_symbol(5, SEG_ON);
/*
for (j = 1; j != 0; j++) {
if (i) {
display_symbol(LCD_ICON_BEEPER1, SEG_ON);
@ -38,16 +44,18 @@ int main(void)
display_symbol(5, SEG_OFF);
}
}
*/
}
}
void display1(void) {
display_chars(LCD_SEG_L1_3_0, (uint8_t*) "HI", SEG_ON);
display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_OFF);
display_chars(LCD_SEG_L1_3_0, "HI", SEG_ON);
display_chars(LCD_SEG_L2_5_0, " EARTH", SEG_OFF);
}
void display2(void) {
display_chars(LCD_SEG_L1_3_0, (uint8_t*) "HI", SEG_OFF);
display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON);
display_chars(LCD_SEG_L1_3_0, "HI", SEG_OFF);
display_chars(LCD_SEG_L2_5_0, (char*) itoa(TA0R, 6, 0), SEG_ON);
// display_chars(LCD_SEG_L2_5_0, (uint8_t*) " EARTH", SEG_ON);
}

View File

@ -1,5 +1,5 @@
SubDir TOP projects msb430_cc110x_ng ;
Module msb430_cc110x_ng : main.c : cc110x_ng transceiver shell shell_commands ps posix_io uart0 auto_init ;
Module msb430_cc110x_ng : main.c : cc110x_ng transceiver swtimer shell shell_commands ps posix_io uart0 auto_init config ;
UseModule msb430_cc110x_ng ;

View File

@ -41,6 +41,22 @@ const shell_command_t sc[] = {
{NULL, NULL, NULL}
};
void send(radio_address_t dst, uint8_t len, uint8_t *data);
void send(radio_address_t dst, uint8_t len, uint8_t *data) {
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &p;
p.length = len;
p.dst = dst;
p.data = data;
msg_send(&mesg, transceiver_pid, 1);
}
void shell_runner(void) {
shell_init(&shell, sc, uart0_readc, uart0_putc);
posix_open(uart0_handler_pid, 0);
@ -102,6 +118,7 @@ void radio(void) {
for (i = 0; i < p->length; i++) {
printf("%02X ", p->data[i]);
}
send(p->src, p->length, p->data);
p->processing--;
printf("\n");
}

View File

@ -1,5 +1,5 @@
SubDir TOP projects test_cc110x_ng ;
Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer ;
Module test_cc110x_ng : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ;
UseModule test_cc110x_ng ;

View File

@ -4,7 +4,11 @@
#include <radio/types.h>
/* Stack size for transceiver thread */
#ifdef ENABLE_DEBUG
#define TRANSCEIVER_STACK_SIZE (2048)
#else
#define TRANSCEIVER_STACK_SIZE (512)
#endif
/* The maximum of threads to register */
#define TRANSCEIVER_MAX_REGISTERED (4)

View File

@ -50,27 +50,33 @@ void _cc1100_ng_get_set_channel_handler(char *chan) {
void _cc1100_ng_send_handler(char *pkt) {
radio_packet_t p;
uint32_t response;
uint16_t addr;
char *tok;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &p;
uint16_t addr;
addr = atoi(pkt+7);
memcpy(text_msg, "Text", 5);
tok = strtok(pkt+7, " ");
if (tok) {
addr = atoi(tok);
tok = strtok(NULL, " ");
if (tok) {
memset(text_msg, 0, TEXT_SIZE);
memcpy(text_msg, tok, strlen(tok));
/* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/
if (1 == 1) {
p.data = (uint8_t*) text_msg;
p.length = strlen(text_msg);
p.dst = addr;
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
printf("[cc1100] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data);
msg_send_receive(&mesg, &mesg, transceiver_pid);
response = mesg.content.value;
printf("[cc1100] Packet sent: %lu\n", response);
}
else {
puts("Usage:\ttxtsnd <ADDR> <MSG>");
p.data = (uint8_t*) text_msg;
p.length = strlen(text_msg) + 1;
p.dst = addr;
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
printf("[cc1100] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data);
msg_send_receive(&mesg, &mesg, transceiver_pid);
response = mesg.content.value;
printf("[cc1100] Packet sent: %lu\n", response);
return;
}
}
puts("Usage:\ttxtsnd <ADDR> <MSG>");
}
void _cc1100_ng_monitor_handler(char *mode) {

View File

@ -20,10 +20,6 @@
#endif
//#define ENABLE_DEBUG (1)
#ifdef ENABLE_DEBUG
#undef TRANSCEIVER_BUFFER_SIZE
#define TRANSCEIVER_BUFFER_SIZE (2048)
#endif
#include <debug.h>
/*------------------------------------------------------------------------------------*/