Added Rime support to Cooja

This commit is contained in:
adamdunkels 2007-03-20 20:08:51 +00:00
parent 4bd8cd32ac
commit f18d88a2e0
2 changed files with 74 additions and 45 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: radio-arch.c,v 1.13 2007/03/18 19:31:36 fros4943 Exp $ * $Id: radio-arch.c,v 1.14 2007/03/20 20:10:34 adamdunkels Exp $
*/ */
#include "dev/radio-arch.h" #include "dev/radio-arch.h"
@ -63,6 +63,11 @@ int simSignalStrength = -200;
char simPower = 100; char simPower = 100;
int simRadioChannel = 1; int simRadioChannel = 1;
enum {
UIP,
RIME,
};
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void void
radio_set_channel(int channel) radio_set_channel(int channel)
@ -76,8 +81,10 @@ radio_sstrength(void)
return simSignalStrength; return simSignalStrength;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void radio_set_txpower(unsigned char power) { void
// 1 - 100: Number indicating output power radio_set_txpower(unsigned char power)
{
/* 1 - 100: Number indicating output power */
simPower = power; simPower = power;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -108,18 +115,25 @@ doInterfaceActionsBeforeTick(void)
} }
// ** Good place to add explicit manchester/gcr-encoding // ** Good place to add explicit manchester/gcr-encoding
if(simInDataBuffer[0] == UIP) {
// Hand over new packet to uIP // Hand over new packet to uIP
uip_len = simInSize; uip_len = simInSize - 1;
memcpy(&uip_buf[UIP_LLH_LEN], &simInDataBuffer[0], simInSize); memcpy(&uip_buf[UIP_LLH_LEN], &simInDataBuffer[1], simInSize - 1);
if (simNoYield) if(simNoYield) {
simDoTcpipInput = 1; simDoTcpipInput = 1;
else } else {
tcpip_input(); tcpip_input();
simInSize = 0; }
} else if(simInDataBuffer[0] == RIME) {
/* If we are not configured to use uIP, we use Rime instead. */
rimebuf_copyfrom(&simInDataBuffer[1], simInSize - 1);
/* log_message("rime input", "");*/
rime_input();
} }
simInSize = 0;
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static void static void
doInterfaceActionsAfterTick(void) doInterfaceActionsAfterTick(void)
@ -131,8 +145,8 @@ doInterfaceActionsAfterTick(void)
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
u8_t static u8_t
simDoLLSend(unsigned char *buf, int len) simDoLLSend(unsigned char *buf, int len, int uip_or_rime)
{ {
/* If radio is turned off, do nothing */ /* If radio is turned off, do nothing */
if(!simRadioHWOn) { if(!simRadioHWOn) {
@ -152,23 +166,24 @@ simDoLLSend(unsigned char *buf, int len)
/* ** Good place to add explicit manchester/gcr-decoding */ /* ** Good place to add explicit manchester/gcr-decoding */
/* Copy packet data to temporary storage */ /* Copy packet data to temporary storage */
memcpy(&simOutDataBuffer[0], &buf[UIP_LLH_LEN], len); simOutDataBuffer[0] = uip_or_rime;
simOutSize = len; memcpy(&simOutDataBuffer[1], buf, len);
simOutSize = len + 1;
/* Busy-wait until both radio HW and ether is ready */ /* Busy-wait until both radio HW and ether is ready */
{
int retries = 0; int retries = 0;
while(retries < MAX_RETRIES && !simNoYield && while(retries < MAX_RETRIES && !simNoYield &&
(simSignalStrength > SS_INTERFERENCE || simReceiving)) (simSignalStrength > SS_INTERFERENCE || simReceiving)) {
{
retries++; retries++;
cooja_mt_yield(); cooja_mt_yield();
if(!(simSignalStrength > SS_INTERFERENCE || simReceiving)) {
if (!(simSignalStrength > SS_INTERFERENCE || simReceiving)) /* Wait one extra tick before transmission starts */
{
// Wait one extra tick before transmission starts
cooja_mt_yield(); cooja_mt_yield();
} }
} }
}
if(simSignalStrength > SS_INTERFERENCE || simReceiving) { if(simSignalStrength > SS_INTERFERENCE || simReceiving) {
return UIP_FW_DROPPED; return UIP_FW_DROPPED;
} }
@ -184,6 +199,13 @@ simDoLLSend(unsigned char *buf, int len)
return UIP_FW_OK; return UIP_FW_OK;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void
rime_driver_send(void)
{
/* log_message("rime driver send", "");*/
simDoLLSend(rimebuf_hdrptr(), rimebuf_totlen(), RIME);
}
/*-----------------------------------------------------------------------------------*/
u8_t u8_t
simDoSend() simDoSend()
{ {
@ -200,7 +222,7 @@ simDoSend()
return UIP_FW_ZEROLEN; return UIP_FW_ZEROLEN;
} }
return simDoLLSend(uip_buf, uip_len); return simDoLLSend(&uip_buf[UIP_LLH_LEN], uip_len, UIP);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/** /**
@ -209,7 +231,8 @@ simDoSend()
* This function turns the radio hardware on. * This function turns the radio hardware on.
*/ */
void void
radio_on(void) { radio_on(void)
{
simRadioHWOn = 1; simRadioHWOn = 1;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -218,7 +241,9 @@ radio_on(void) {
* *
* This function turns the radio hardware off. * This function turns the radio hardware off.
*/ */
void radio_off(void) { void
radio_off(void)
{
simRadioHWOn = 0; simRadioHWOn = 0;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: code_main_template,v 1.12 2006/10/23 16:09:15 fros4943 Exp $ * $Id: code_main_template,v 1.13 2007/03/20 20:08:51 adamdunkels Exp $
*/ */
/** /**
@ -68,6 +68,7 @@
#include "lib/simEnvChange.h" #include "lib/simEnvChange.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "net/rime.h"
#include "net/uip.h" #include "net/uip.h"
#include "dev/radio-arch.h" #include "dev/radio-arch.h"
#include "cfs/cfs-cooja.h" #include "cfs/cfs-cooja.h"
@ -159,6 +160,9 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_init(JNIEnv *env, jobject obj)
/* Start Contiki processes */ /* Start Contiki processes */
procinit_init(); procinit_init();
/* Initialize Rime. */
rime_init();
/* Initialize uIP */ /* Initialize uIP */
uip_init(); uip_init();
uip_fw_init(); uip_fw_init();