- Added RF address setup function (byte order may not be correct)

- Fixed the interrupt and read functions, now receiving one frame correctly
- Improved the send and read functions to work with sicslowmac.c
- TODO: Still a MAC interaction problem. Although the exact same payload is received and sent up to the MAC as is sent, the MAC doesn't do anything with it. Turn on DEBUG in sicslowmac.c to see the problem.
- Removed mtarch files, not used currently
This commit is contained in:
zdshelby 2009-09-11 08:07:12 +00:00
parent ec02eab6bc
commit d98026ae03
4 changed files with 62 additions and 311 deletions

View file

@ -74,6 +74,7 @@ uint8_t rf_channel = 0;
rf_address_mode_t rf_addr_mode; rf_address_mode_t rf_addr_mode;
uint16_t rf_manfid; uint16_t rf_manfid;
uint8_t rf_softack; uint8_t rf_softack;
uint16_t rf_panid;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(cc2430_rf_process, "CC2430 RF driver"); PROCESS(cc2430_rf_process, "CC2430 RF driver");
@ -115,7 +116,7 @@ cc2430_rf_init(void)
return; return;
} }
printf("cc2430_rf_init called\n"); PRINTF("cc2430_rf_init called\n");
RFPWR &= ~RREG_RADIO_PD; /*make sure it's powered*/ RFPWR &= ~RREG_RADIO_PD; /*make sure it's powered*/
while((RFPWR & ADI_RADIO_PD) == 1); while((RFPWR & ADI_RADIO_PD) == 1);
@ -125,7 +126,6 @@ cc2430_rf_init(void)
rf_flags = 0; rf_flags = 0;
rf_softack = 0; rf_softack = 0;
rf_addr_mode = RF_DECODER_NONE;
FSMTC1 = 1; /*don't abort reception, if enable called, accept ack, auto rx after tx*/ FSMTC1 = 1; /*don't abort reception, if enable called, accept ack, auto rx after tx*/
@ -147,6 +147,9 @@ cc2430_rf_init(void)
cc2430_rf_command(ISFLUSHTX); cc2430_rf_command(ISFLUSHTX);
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
cc2430_rf_set_addr(0xffff, 0x0000, NULL);
cc2430_rf_address_decoder_mode(RF_DECODER_NONE);
RFIM = IRQ_FIFOP; RFIM = IRQ_FIFOP;
RFIF &= ~(IRQ_FIFOP); RFIF &= ~(IRQ_FIFOP);
@ -171,8 +174,6 @@ cc2430_rf_send(const void *payload, unsigned short payload_len)
{ {
uint8_t i, counter; uint8_t i, counter;
/*PRINTF("cc2430_rf_send\n");*/
if(rf_flags & TX_ACK) { if(rf_flags & TX_ACK) {
return -1; return -1;
} }
@ -188,17 +189,16 @@ cc2430_rf_send(const void *payload, unsigned short payload_len)
RIMESTATS_ADD(lltx); RIMESTATS_ADD(lltx);
/* Add checksum to end of packet as in cc2420 driver? */
/* Send */ /* Send */
cc2430_rf_command(ISFLUSHTX); cc2430_rf_command(ISFLUSHTX);
RFD = (payload_len + 2); RFD = payload_len;
PRINTF("cc2430_rf: sent = ");
for(i = 0 ; i < payload_len; i++) { for(i = 0 ; i < payload_len; i++) {
RFD = ((unsigned char*)(payload))[i]; RFD = ((unsigned char*)(payload))[i];
PRINTF("%02X", ((unsigned char*)(payload))[i]);
} }
RFD = (0); PRINTF("\n");
RFD = (0);
if(cc2430_rf_cca_check(0,0) == -1) { if(cc2430_rf_cca_check(0,0) == -1) {
return -1; return -1;
@ -214,7 +214,7 @@ cc2430_rf_send(const void *payload, unsigned short payload_len)
} }
if(!(RFSTATUS & TX_ACTIVE)) { if(!(RFSTATUS & TX_ACTIVE)) {
printf("cc2430_rf: TX never active.\n"); PRINTF("cc2430_rf: TX never active.\n");
cc2430_rf_command(ISFLUSHTX); cc2430_rf_command(ISFLUSHTX);
return -1; return -1;
} else { } else {
@ -238,59 +238,55 @@ cc2430_rf_read(void *buf, unsigned short bufsize)
/* Check the length */ /* Check the length */
len = RFD; len = RFD;
len &= 0x7f; len &= 0x7f;
printf("cc2430_rf: received %d bytes\n", len); PRINTF("cc2430_rf: received %d bytes\n", len);
/* Check for validity */ /* Check for validity */
if(len > CC2430_MAX_PACKET_LEN) { if(len > CC2430_MAX_PACKET_LEN) {
/* Oops, we must be out of sync. */ /* Oops, we must be out of sync. */
printf("error: bad sync\n"); PRINTF("error: bad sync\n");
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
RIMESTATS_ADD(badsynch); RIMESTATS_ADD(badsynch);
return 0; return 0;
} }
if(len <= CC2430_MIN_PACKET_LEN) { if(len <= CC2430_MIN_PACKET_LEN) {
printf("error: too short\n"); PRINTF("error: too short\n");
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
RIMESTATS_ADD(tooshort); RIMESTATS_ADD(tooshort);
return 0; return 0;
} }
if(len - CHECKSUM_LEN > bufsize) { if(len - CHECKSUM_LEN > bufsize) {
printf("error: too long\n"); PRINTF("error: too long\n");
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
RIMESTATS_ADD(toolong); RIMESTATS_ADD(toolong);
return 0; return 0;
} }
/* Check the type */
type = RFD;
type &= 0x07;
if(type == 0x02) {
printf("cc2430_rf: ack\n");
} else {
/* Read the buffer */ /* Read the buffer */
printf("cc2430_rf: data = "); PRINTF("cc2430_rf: read = ");
for(i = 0; i < (len - 2 - CHECKSUM_LEN); i++) { for(i = 1; i < (len + 1 - CHECKSUM_LEN); i++) {
((unsigned char*)(buf))[i] = RFD; ((unsigned char*)(buf))[i] = RFD;
printf("%c", ((unsigned char*)(buf))[i]); PRINTF("%02X", ((unsigned char*)(buf))[i]);
} }
printf("\n"); PRINTF("\n");
#if CC2430_CONF_CHECKSUM #if CC2430_CONF_CHECKSUM
/* Deal with the checksum */ /* Deal with the checksum */
#endif /* CC2430_CONF_CHECKSUM */ #endif /* CC2430_CONF_CHECKSUM */
}
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, ((int8_t) RFD) - 45); packetbuf_set_attr(PACKETBUF_ATTR_RSSI, ((int8_t) RFD) - 45);
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, RFD); packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, RFD);
RFIF &= ~IRQ_FIFOP;
RFSTATUS &= ~FIFO;
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
cc2430_rf_command(ISFLUSHRX);
RF_RX_LED_OFF();
RIMESTATS_ADD(llrx); RIMESTATS_ADD(llrx);
RF_RX_LED_OFF(); return (len - CHECKSUM_LEN);
return (len - 2 - CHECKSUM_LEN);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
@ -428,7 +424,7 @@ cc2430_rf_power_set(uint8_t new_power)
int8_t int8_t
cc2430_rf_rx_enable(void) cc2430_rf_rx_enable(void)
{ {
printf("cc2430_rf_rx_enable called\n"); PRINTF("cc2430_rf_rx_enable called\n");
if(!(rf_flags & RX_ACTIVE)) { if(!(rf_flags & RX_ACTIVE)) {
IOCFG0 = 0x7f; // Set the FIFOP threshold 127 IOCFG0 = 0x7f; // Set the FIFOP threshold 127
RSSIH = 0xd2; /* -84dbm = 0xd2 default, 0xe0 -70 dbm */ RSSIH = 0xd2; /* -84dbm = 0xd2 default, 0xe0 -70 dbm */
@ -477,6 +473,36 @@ cc2430_rf_tx_enable(void)
return 1; return 1;
} }
/**
* Set MAC addresses
*
* \param pan The PAN address to set
* \param adde The short address to set
* \param ieee_addr The 64-bit IEEE address to set
*/
void
cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr)
{
uint8_t f;
__xdata unsigned char *ptr;
rf_panid = pan;
PANIDH = pan >> 8;
PANIDL = pan & 0xff;
SHORTADDRH = addr >> 8;
SHORTADDRL = addr & 0xff;
if(ieee_addr != NULL) {
ptr = &IEEE_ADDR0;
/* LSB first, MSB last for 802.15.4 addresses in CC2420 */
for (f = 0; f < 8; f++) {
*ptr++ = ieee_addr[f];
}
}
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Set address decoder on/off. * Set address decoder on/off.
@ -610,15 +636,12 @@ void
cc2430_rf_ISR( void ) __interrupt (RF_VECTOR) cc2430_rf_ISR( void ) __interrupt (RF_VECTOR)
{ {
EA = 0; EA = 0;
RF_TX_LED_ON();
if(RFIF & IRQ_TXDONE) { if(RFIF & IRQ_TXDONE) {
RF_TX_LED_OFF(); RF_TX_LED_OFF();
RFIF &= ~IRQ_TXDONE; RFIF &= ~IRQ_TXDONE;
cc2430_rf_command(ISFLUSHTX); cc2430_rf_command(ISFLUSHTX);
} }
if(RFIF & IRQ_FIFOP) { if(RFIF & IRQ_FIFOP) {
RF_TX_LED_OFF();
if(RFSTATUS & FIFO) { if(RFSTATUS & FIFO) {
RF_RX_LED_ON(); RF_RX_LED_ON();
/* Poll the RF process which calls cc2430_rf_read() */ /* Poll the RF process which calls cc2430_rf_read() */
@ -626,12 +649,10 @@ cc2430_rf_ISR( void ) __interrupt (RF_VECTOR)
} else { } else {
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX);
}
RFIF &= ~IRQ_FIFOP; RFIF &= ~IRQ_FIFOP;
} }
}
S1CON &= ~(RFIF_0 | RFIF_1); S1CON &= ~(RFIF_0 | RFIF_1);
RFIM |= IRQ_FIFOP;
EA = 1; EA = 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -23,21 +23,7 @@ typedef enum rf_address_mode_t
RF_SOFTACK_CLIENT, RF_SOFTACK_CLIENT,
RF_DECODER_ON RF_DECODER_ON
}rf_address_mode_t; }rf_address_mode_t;
typedef enum
{
MAC_NONE = 0,
MAC_RECEIVE=1,
MAC_ACK_RX=2,
MAC_TIMER_ACK=3,
MAC_TIMER_CCA=4,
MAC_TRANSMIT=5,
MAC_CONTROL=6,
MAC_TIMER_NONE=7,
MAC_LOOP=8,
MAC_ED_SCAN=9,
MAC_RSSI_CHECK=10,
MAC_GW_DIS = 11
}mac_event_t;
/*CSP command set*/ /*CSP command set*/
#define SSTOP 0xDF #define SSTOP 0xDF
/*this is not a real command but a way of having rf_command /*this is not a real command but a way of having rf_command
@ -94,6 +80,7 @@ int8_t cc2430_rf_address_decoder_mode(rf_address_mode_t mode);
int8_t cc2430_rf_analyze_rssi(void); int8_t cc2430_rf_analyze_rssi(void);
int8_t cc2430_rf_cca_check(uint8_t backoff_count, uint8_t slotted); int8_t cc2430_rf_cca_check(uint8_t backoff_count, uint8_t slotted);
void cc2430_rf_send_ack(uint8_t pending); void cc2430_rf_send_ack(uint8_t pending);
void cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr);
extern void cc2430_rf_ISR( void ) __interrupt (RF_VECTOR); extern void cc2430_rf_ISR( void ) __interrupt (RF_VECTOR);
extern void cc2430_rf_error_ISR( void ) __interrupt (RFERR_VECTOR); extern void cc2430_rf_error_ISR( void ) __interrupt (RFERR_VECTOR);

View file

@ -1,192 +0,0 @@
/*
* Copyright (c) 2007, Takahide Matsutsuka.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* \file
* Z80 machine-specific implementation for supporting multithread.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include "sys/mt.h"
#include "mtarch.h"
/*--------------------------------------------------------------------------*/
void
mtarch_init(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_start(struct mtarch_thread *t,
void (*function)(void *), void *data)
{
u16_t i;
for(i = 0; i < MTARCH_STACKSIZE; i++) {
t->stack[i] = i;
}
t->sp = &t->stack[MTARCH_STACKSIZE - 1];
/* A parameter for method for thread function. */
*t->sp = (u16_t)data;
--t->sp;
/* This will be a return address of thread function. */
*t->sp = (u16_t)mt_exit;
--t->sp;
/* The thread function, is used as a return address of mtarch_switch. */
*t->sp = (u16_t)function;
--t->sp;
/*
* Space for registers.
* af, bc, de, hl, ix, iy, af', bc', de', hl'
*/
/*
* Z80 stack basis:
* push stores the data AFTER decrementing sp.
* pop reads the data BEFORE incrementing sp.
*/
t->sp = t->sp - 9;
}
/*--------------------------------------------------------------------------*/
static struct mtarch_thread *running_thread;
static u16_t *sptmp;
static void
mtarch_switch()
{
__asm
di ; disable interrupt
; normal registers
push af
push bc
push de
push hl
push ix
push iy
; back registers
ex af,af'
push af
exx
push bc
push de
push hl
; swap between running_thread->sp and SP reg
; _running_thread in asembler below points running_thread->sp
; sptmp = sp;
ld (_sptmp),sp
; sp = *(running_thread->sp);
ld ix,(_running_thread)
ld l,0(ix)
ld h,1(ix)
ld sp,hl
; running_thread->sp = sptmp;
ld hl,(_sptmp)
ld 0(ix),l
ld 1(ix),h
; back registers
pop hl
pop de
pop bc
exx
pop af
ex af,af'
; normal registers
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ei ; enable interrupt
__endasm;
// here sp indicates the address that point the function
}
/*--------------------------------------------------------------------------*/
void
mtarch_exec(struct mtarch_thread *t)
{
running_thread = t;
mtarch_switch();
running_thread = NULL;
}
/*--------------------------------------------------------------------------*/
void
mtarch_remove()
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_yield()
{
if (running_thread == NULL) {
/* ERROR! we have no runnning thread. */
return;
}
mtarch_switch();
}
/*--------------------------------------------------------------------------*/
void mtarch_stop(struct mtarch_thread *thread)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstop()
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstart()
{
}
/*--------------------------------------------------------------------------*/
int
mtarch_stack_usage(struct mtarch_thread *t)
{
u16_t i;
for (i = 0; i < MTARCH_STACKSIZE; i++) {
if (t->stack[i] != i) {
return MTARCH_STACKSIZE - i;
}
}
return 0;
}
/*--------------------------------------------------------------------------*/

View file

@ -1,65 +0,0 @@
/*
* Copyright (c) 2007, Takahide Matsutsuka.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* \file
* Z80 machine-specific difinitions for supporting multithread.
*
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __MTARCH_H__
#define __MTARCH_H__
/* Unit of the stack is 2byte wide. */
#ifndef MTARCH_STACKSIZE
#define MTARCH_STACKSIZE 128
#endif /* MTARCH_STACKSIZE */
struct mtarch_thread {
/*
* On top of the mtarch_thread must be the address for the stack pointer.
* See details at mtarch_switch in mtarch.c
*/
u16_t *sp;
/*
* Stack is 2-byte wide, so please note that you need 2 * MTARCH_STACKSIZE
* bytes for the stack area for each thread.
*/
u16_t stack[MTARCH_STACKSIZE];
};
/*
* A function for debugging purpose, placed here by following other implementations.
*/
int mtarch_stack_usage(struct mtarch_thread *t);
#endif /* __MTARCH_H__ */