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

[drivers/cc110x_ng sys/transceiver]

* updated interface to switch transceiver off and back to rx mode
* removed some debugging stuff
This commit is contained in:
Oliver Hahm 2010-12-02 15:38:28 +01:00
parent 0b515b4063
commit 4a2c58bbba
10 changed files with 361 additions and 289 deletions

View File

@ -167,7 +167,6 @@ void bl_config_init(void) {
extern char configmem[]; extern char configmem[];
if (*((uint16_t*) configmem) == CONFIG_KEY) { if (*((uint16_t*) configmem) == CONFIG_KEY) {
memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig));
LED_GREEN_TOGGLE;
} }
else { else {
config_save(); config_save();

View File

@ -1,277 +1,277 @@
/* iap driver /* iap driver
* *
* based on iap driver for LPC2148 Controller made by Andreas Weschenfelder, 2008 * based on iap driver for LPC2148 Controller made by Andreas Weschenfelder, 2008
* see: * see:
* *
*/ */
#include <irq.h> #include <irq.h>
#include <flashrom.h> #include <flashrom.h>
#include <lpc2387.h> #include <lpc2387.h>
#define ENABLE_DEBUG //#define ENABLE_DEBUG
#include <debug.h> #include <debug.h>
/* pointer to reserved flash rom section for configuration data */ /* pointer to reserved flash rom section for configuration data */
__attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem"))); __attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem")));
static unsigned int iap_command[5]; // contains parameters for IAP command static unsigned int iap_command[5]; // contains parameters for IAP command
static unsigned int iap_result[2]; // contains results static unsigned int iap_result[2]; // contains results
typedef void (*IAP) (unsigned int[],unsigned int[]); // typedefinition for IAP entry function typedef void (*IAP) (unsigned int[],unsigned int[]); // typedefinition for IAP entry function
IAP IAP_Entry; IAP IAP_Entry;
/* some function prototypes */ /* some function prototypes */
static uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2); static uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2);
static uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2); static uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2);
static uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2); static uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2);
static uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size); static uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size);
static uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size); static uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size);
static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4); static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
/****************************************************************************** /******************************************************************************
* P U B L I C F U N C T I O N S * P U B L I C F U N C T I O N S
*****************************************************************************/ *****************************************************************************/
uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) { uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
char err; char err;
unsigned intstate; unsigned intstate;
uint8_t sec; uint8_t sec;
//buffer_vic = VICIntEnable; // save interrupt enable //buffer_vic = VICIntEnable; // save interrupt enable
//VICIntEnClr = 0xFFFFFFFF; // clear vic //VICIntEnClr = 0xFFFFFFFF; // clear vic
sec = flashrom_get_sector(dst); sec = flashrom_get_sector(dst);
if (sec == INVALID_ADDRESS) { if (sec == INVALID_ADDRESS) {
DEBUG("Invalid address\n"); DEBUG("Invalid address\n");
return 0; return 0;
} }
/* check sector */ /* check sector */
if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) { if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) {
DEBUG("Warning: Sector %i not blank\n", sec); DEBUG("Warning: Sector %i not blank\n", sec);
} }
/* prepare sector */ /* prepare sector */
err = prepare_sectors(sec, sec); err = prepare_sectors(sec, sec);
if (err) { if (err) {
DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err); DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err);
/* set interrupts back and return */ /* set interrupts back and return */
// VICIntEnable = buffer_vic; // VICIntEnable = buffer_vic;
return 0; return 0;
} }
/* write flash */ /* write flash */
else { else {
intstate = disableIRQ(); intstate = disableIRQ();
err = copy_ram_to_flash(dst, (uint32_t) src, 256); err = copy_ram_to_flash(dst, (uint32_t) src, 256);
restoreIRQ(intstate); restoreIRQ(intstate);
if(err) { if(err) {
DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err); DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
/* set interrupts back and return */ /* set interrupts back and return */
restoreIRQ(intstate); restoreIRQ(intstate);
// VICIntEnable = buffer_vic; // VICIntEnable = buffer_vic;
return 0; return 0;
} }
/* check result */ /* check result */
else { else {
err = compare(dst, (uint32_t) src, 256); err = compare(dst, (uint32_t) src, 256);
if (err) { if (err) {
DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]); DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
/* set interrupts back and return */ /* set interrupts back and return */
// VICIntEnable = buffer_vic; // VICIntEnable = buffer_vic;
return 0; return 0;
} }
else else
{ {
DEBUG("Data successfully written!\n"); DEBUG("Data successfully written!\n");
/* set interrupts back and return */ /* set interrupts back and return */
// VICIntEnable = buffer_vic; // VICIntEnable = buffer_vic;
return 1; return 1;
} }
} }
} }
} }
uint8_t flashrom_erase(uint32_t addr) { uint8_t flashrom_erase(uint32_t addr) {
uint8_t sec = flashrom_get_sector(addr); uint8_t sec = flashrom_get_sector(addr);
unsigned intstate; unsigned intstate;
if (sec == INVALID_ADDRESS) { if (sec == INVALID_ADDRESS) {
DEBUG("Invalid address\n"); DEBUG("Invalid address\n");
return 0; return 0;
} }
/* check sector */ /* check sector */
if (!blank_check_sector(sec, sec)) { if (!blank_check_sector(sec, sec)) {
DEBUG("Sector already blank!\n"); DEBUG("Sector already blank!\n");
return 1; return 1;
} }
/* prepare sector */ /* prepare sector */
if (prepare_sectors(sec, sec)) { if (prepare_sectors(sec, sec)) {
DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n"); DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n");
return 0; return 0;
} }
intstate = disableIRQ(); intstate = disableIRQ();
/* erase sector */ /* erase sector */
if (erase_sectors(sec, sec)) { if (erase_sectors(sec, sec)) {
DEBUG("-- ERROR: ERASE SECTOR --\n"); DEBUG("-- ERROR: ERASE SECTOR --\n");
restoreIRQ(intstate); restoreIRQ(intstate);
return 0; return 0;
} }
restoreIRQ(intstate); restoreIRQ(intstate);
/* check again */ /* check again */
if (blank_check_sector(sec, sec)) { if (blank_check_sector(sec, sec)) {
DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n"); DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n");
return 0; return 0;
} }
DEBUG("Sector successfully erased.\n"); DEBUG("Sector successfully erased.\n");
return 1; return 1;
} }
/****************************************************************************** /******************************************************************************
* PRIVATE FUNCTIONS * PRIVATE FUNCTIONS
*****************************************************************************/ *****************************************************************************/
static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4) { static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4) {
iap_command[0] = code; // set command code iap_command[0] = code; // set command code
iap_command[1] = p1; // set 1st param iap_command[1] = p1; // set 1st param
iap_command[2] = p2; // set 2nd param iap_command[2] = p2; // set 2nd param
iap_command[3] = p3; // set 3rd param iap_command[3] = p3; // set 3rd param
iap_command[4] = p4; // set 4th param iap_command[4] = p4; // set 4th param
((void (*)())0x7ffffff1)(iap_command, iap_result); // IAP entry point ((void (*)())0x7ffffff1)(iap_command, iap_result); // IAP entry point
return *iap_result; return *iap_result;
} }
/****************************************************************************** /******************************************************************************
* Function: blank_check_sector * Function: blank_check_sector
* *
* Description: This command is used to blank check a sector or multiple sectors * Description: This command is used to blank check a sector or multiple sectors
* of on-chip Flash memory. To blank check a single sector use the * of on-chip Flash memory. To blank check a single sector use the
* same "Start" and "End" sector numbers. * same "Start" and "End" sector numbers.
* Command: 53 * Command: 53
* Param0: Start Sector Number * Param0: Start Sector Number
* Param1: End Sector Number (should be greater than equal to the start * Param1: End Sector Number (should be greater than equal to the start
* sector number) * sector number)
* *
* Parameters: long tmp_sect1: Param0 * Parameters: long tmp_sect1: Param0
* long tmp_sect2: Param1 * long tmp_sect2: Param1
* *
* Return: Code CMD_SUCCESS | * Return: Code CMD_SUCCESS |
* BUSY | * BUSY |
* SECTOR_NOT_BLANK | * SECTOR_NOT_BLANK |
* INVALID_SECTOR * INVALID_SECTOR
* Result0: Offset of the first non blank word location if the status code is SECTOR_NOT_BLANK. * Result0: Offset of the first non blank word location if the status code is SECTOR_NOT_BLANK.
* Result1: Contents of non blank wird location. * Result1: Contents of non blank wird location.
*****************************************************************************/ *****************************************************************************/
uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2) { uint32_t blank_check_sector(uint32_t tmp_sect1, uint32_t tmp_sect2) {
return iap(BLANK_CHECK_SECTOR, tmp_sect1, tmp_sect2, 0 , 0); return iap(BLANK_CHECK_SECTOR, tmp_sect1, tmp_sect2, 0 , 0);
} }
/****************************************************************************** /******************************************************************************
* Function: copy_ram_to_flash * Function: copy_ram_to_flash
* *
* Description: This command is used to programm the flash memory. the affected should be * Description: This command is used to programm the flash memory. the affected should be
* prepared first by calling "Prepare Sector for Write Operation" command. the * prepared first by calling "Prepare Sector for Write Operation" command. the
* affected sectors are automatically protected again once the copy command is * affected sectors are automatically protected again once the copy command is
* successfully executed. the boot sector cannot be written by this command. * successfully executed. the boot sector cannot be written by this command.
* Command: 51 * Command: 51
* Param0: (DST) Destination Flash adress where data bytes are to be written. * Param0: (DST) Destination Flash adress where data bytes are to be written.
* This address should be a 512 byte boundary. * This address should be a 512 byte boundary.
* Param1: (SRC) Source RAM adress from which data byre are to be read. * Param1: (SRC) Source RAM adress from which data byre are to be read.
* Param2: Number of bytes to be written. Should be 512 | 1024 | 4096 | 8192. * Param2: Number of bytes to be written. Should be 512 | 1024 | 4096 | 8192.
* Param3: System Clock Frequency (CCLK) in KHz. * Param3: System Clock Frequency (CCLK) in KHz.
* *
* Parameters: long tmp_adr_dst: Param0 * Parameters: long tmp_adr_dst: Param0
* long tmp_adr_src: Param1 * long tmp_adr_src: Param1
* long tmp_size: Param2 * long tmp_size: Param2
* *
* Return: Code CMD_SUCCESS | * Return: Code CMD_SUCCESS |
* SRC_ADDR_ERROR (Address not on word boundary) | * SRC_ADDR_ERROR (Address not on word boundary) |
* DST_ADDR_ERROR (Address not on correct boundary) | * DST_ADDR_ERROR (Address not on correct boundary) |
* SRC_ADDR_NOT_MAPPED | * SRC_ADDR_NOT_MAPPED |
* DST_ADDR_NOT_MAPPED | * DST_ADDR_NOT_MAPPED |
* COUNT_ERROR (Byte count is not 512 | 1024 | 4096 | 8192) | * COUNT_ERROR (Byte count is not 512 | 1024 | 4096 | 8192) |
* SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | * SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION |
* BUSY * BUSY
*****************************************************************************/ *****************************************************************************/
uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) { uint32_t copy_ram_to_flash(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) {
return iap(COPY_RAM_TO_FLASH, tmp_adr_dst, tmp_adr_src, tmp_size, _XTAL); return iap(COPY_RAM_TO_FLASH, tmp_adr_dst, tmp_adr_src, tmp_size, _XTAL);
} }
/****************************************************************************** /******************************************************************************
* Function: Prepare_Sector * Function: Prepare_Sector
* *
* Description: This command must be executed before executing "Copy RAM to Flash" or "Erase Sector(s)" * Description: This command must be executed before executing "Copy RAM to Flash" or "Erase Sector(s)"
* command. Successful execution of the "Copy RAM to Flash" or "Erase Sector(s)" command causes * command. Successful execution of the "Copy RAM to Flash" or "Erase Sector(s)" command causes
* relevant sectors to be protected again. The boot sector can not be prepared by this command. To * relevant sectors to be protected again. The boot sector can not be prepared by this command. To
* prepare a single sector use the same "Start" and "End" sector numbers.. * prepare a single sector use the same "Start" and "End" sector numbers..
* Command code: 50 * Command code: 50
* Param0: Start Sector Number * Param0: Start Sector Number
* Param1: End Sector Number: Should be greater than or equal to start sector number. * Param1: End Sector Number: Should be greater than or equal to start sector number.
* *
* Parameters: long tmp_sect1: Param0 * Parameters: long tmp_sect1: Param0
* long tmp_sect2: Param1 * long tmp_sect2: Param1
* *
* Return: Code CMD_SUCCESS | * Return: Code CMD_SUCCESS |
* BUSY | * BUSY |
* INVALID_SECTOR * INVALID_SECTOR
*****************************************************************************/ *****************************************************************************/
uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) { uint32_t prepare_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) {
return iap(PREPARE_SECTOR_FOR_WRITE_OPERATION, tmp_sect1, tmp_sect2, 0 , 0); return iap(PREPARE_SECTOR_FOR_WRITE_OPERATION, tmp_sect1, tmp_sect2, 0 , 0);
} }
/****************************************************************************** /******************************************************************************
* Function: erase_sectors * Function: erase_sectors
* *
* Description: This command is used to erase a sector or multiple sectors of on-chip Flash memory. The boot * Description: This command is used to erase a sector or multiple sectors of on-chip Flash memory. The boot
* sector can not be erased by this command. To erase a single sector use the same "Start" and "End" * sector can not be erased by this command. To erase a single sector use the same "Start" and "End"
* sector numbers. * sector numbers.
* Command code: 52 * Command code: 52
* Param0: Start Sector Number * Param0: Start Sector Number
* Param1: End Sector Number: Should be greater than or equal to start sector number. * Param1: End Sector Number: Should be greater than or equal to start sector number.
* Param2: System Clock Frequency (CCLK) in KHz. * Param2: System Clock Frequency (CCLK) in KHz.
* *
* Parameters: long tmp_sect1: Param0 * Parameters: long tmp_sect1: Param0
* long tmp_sect2: Param1 * long tmp_sect2: Param1
* *
* Return: Code CMD_SUCCESS | * Return: Code CMD_SUCCESS |
* BUSY | * BUSY |
* SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | * SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION |
* INVALID_SECTOR * INVALID_SECTOR
*****************************************************************************/ *****************************************************************************/
uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) { uint32_t erase_sectors(uint32_t tmp_sect1, uint32_t tmp_sect2) {
return iap(ERASE_SECTOR, tmp_sect1, tmp_sect2, _XTAL, 0); return iap(ERASE_SECTOR, tmp_sect1, tmp_sect2, _XTAL, 0);
} }
/****************************************************************************** /******************************************************************************
* Function: compare * Function: compare
* *
* Description: This command is used to compare the memory contents at two locations. compare result may not * Description: This command is used to compare the memory contents at two locations. compare result may not
* be correct when source or destination address contains any of the first 64 bytes starting * be correct when source or destination address contains any of the first 64 bytes starting
* from address zero. First 64 bytes can be re-mapped to RAM. * from address zero. First 64 bytes can be re-mapped to RAM.
* Command Code: 56 * Command Code: 56
* Param0(DST): Starting Flash or RAM address from where data bytes are to be * Param0(DST): Starting Flash or RAM address from where data bytes are to be
* address should be a word boundary. * address should be a word boundary.
* Param1(SRC): Starting Flash or RAM address from where data bytes are to be * Param1(SRC): Starting Flash or RAM address from where data bytes are to be
* address should be a word boundary. * address should be a word boundary.
* Param2: Number of bytes to be compared. Count should be in multiple of 4. * Param2: Number of bytes to be compared. Count should be in multiple of 4.
* *
* Parameters: long tmp_adr_dst * Parameters: long tmp_adr_dst
* long tmp_adr_src * long tmp_adr_src
* long tmp_size * long tmp_size
* *
* Return: Code CMD_SUCCESS | * Return: Code CMD_SUCCESS |
* COMPARE_ERROR | * COMPARE_ERROR |
* COUNT_ERROR (Byte count is not multiple of 4) | * COUNT_ERROR (Byte count is not multiple of 4) |
* ADDR_ERROR | * ADDR_ERROR |
* ADDR_NOT_MAPPED * ADDR_NOT_MAPPED
* Result0: Offset of the first mismatch if the Status Code is COMPARE_ERROR. * Result0: Offset of the first mismatch if the Status Code is COMPARE_ERROR.
*****************************************************************************/ *****************************************************************************/
uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) { uint32_t compare(uint32_t tmp_adr_dst, uint32_t tmp_adr_src, uint32_t tmp_size) {
return iap(COMPARE, tmp_adr_dst, tmp_adr_src, tmp_size, 0); return iap(COMPARE, tmp_adr_dst, tmp_adr_src, tmp_size, 0);
} }

View File

@ -1,6 +1,8 @@
#ifndef CC1100_CONFIG_H #ifndef CC1100_CONFIG_H
#define CC1100_CONFIG_H #define CC1100_CONFIG_H
#include <timex.h>
/** CC1100 register configuration */ /** CC1100 register configuration */
typedef struct { typedef struct {
uint8_t IOCFG2; uint8_t IOCFG2;
@ -56,6 +58,7 @@ typedef struct {
typedef struct typedef struct
{ {
uint32_t TOF; ///< Time of flight of the last packet and last ACK uint32_t TOF; ///< Time of flight of the last packet and last ACK
timex_t TOA; ///< Time of packet arriveal
uint32_t TCP; ///< Time to compute packet uint32_t TCP; ///< Time to compute packet
unsigned RPS : 16; ///< Raw packets sent to transmit last packet unsigned RPS : 16; ///< Raw packets sent to transmit last packet
unsigned RTC : 8; ///< Retransmission count of last send packet unsigned RTC : 8; ///< Retransmission count of last send packet
@ -82,10 +85,8 @@ typedef struct cc1100_statistic {
uint32_t packets_in_dups; uint32_t packets_in_dups;
uint32_t packets_in_up; uint32_t packets_in_up;
uint32_t packets_out; uint32_t packets_out;
uint32_t packets_out_acked;
uint32_t packets_out_broadcast; uint32_t packets_out_broadcast;
uint32_t raw_packets_out; uint32_t raw_packets_out;
uint32_t raw_packets_out_acked;
uint32_t acks_send; uint32_t acks_send;
uint32_t rx_buffer_max; uint32_t rx_buffer_max;
uint32_t watch_dog_resets; uint32_t watch_dog_resets;

View File

@ -60,6 +60,7 @@ uint8_t cc1100_send(cc1100_packet_t *packet) {
restoreIRQ(cpsr); restoreIRQ(cpsr);
// Wait for GDO2 to be cleared -> end of packet // Wait for GDO2 to be cleared -> end of packet
while (cc1100_get_gdo2() != 0); while (cc1100_get_gdo2() != 0);
LED_GREEN_TOGGLE;
// Experimental - TOF Measurement // Experimental - TOF Measurement
cc1100_after_send(); cc1100_after_send();

View File

@ -202,14 +202,14 @@ char* cc1100_state_to_text(uint8_t state) {
} }
} }
void cc1100_print_config(void) { void cc1100_print_config(void) {
printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state)); printf("Current radio state: %s\r\n", cc1100_state_to_text(radio_state));
printf("Current MARC state: %s\r\n", cc1100_get_marc_state()); printf("Current MARC state: %s\r\n", cc1100_get_marc_state());
printf("Current channel number: %u\r\n", sysconfig.radio_channel); printf("Current channel number: %u\r\n", sysconfig.radio_channel);
} }
void switch_to_pwd(void) { void cc1100_switch_to_pwd(void) {
DEBUG("[cc110x_ng] switching to powerdown\n");
cc1100_wakeup_from_rx(); cc1100_wakeup_from_rx();
cc1100_spi_strobe(CC1100_SPWD); cc1100_spi_strobe(CC1100_SPWD);
radio_state = RADIO_PWD; radio_state = RADIO_PWD;

View File

@ -1,5 +1,5 @@
SubDir TOP projects laser ; SubDir TOP projects laser ;
Module laser : main.c : sht11 swtimer auto_init ; Module laser : main.c : sht11 ltc4150 swtimer auto_init ;
UseModule laser ; UseModule laser ;

View File

@ -18,7 +18,7 @@
#define SND_BUFFER_SIZE (100) #define SND_BUFFER_SIZE (100)
#define RCV_BUFFER_SIZE (64) #define RCV_BUFFER_SIZE (64)
#define SENDING_DELAY (1000) #define SENDING_DELAY (5 * 1000)
char shell_stack_buffer[SHELL_STACK_SIZE]; char shell_stack_buffer[SHELL_STACK_SIZE];
char radio_stack_buffer[RADIO_STACK_SIZE]; char radio_stack_buffer[RADIO_STACK_SIZE];
@ -31,12 +31,20 @@ static msg mesg;
static transceiver_command_t tcmd; static transceiver_command_t tcmd;
static radio_packet_t p; static radio_packet_t p;
static uint32_t sending_delay = SENDING_DELAY;
void sender(char *count); void sender(char *count);
void print_buffer(char *unused); void print_buffer(char *unused);
void switch2rx(char *unused);
void powerdown(char *unused);
void set_delay(char *delay);
shell_t shell; shell_t shell;
const shell_command_t sc[] = { const shell_command_t sc[] = {
{"on", "", switch2rx},
{"off", "", powerdown},
{"snd", "", sender}, {"snd", "", sender},
{"delay", "", set_delay},
{"buffer", "", print_buffer}, {"buffer", "", print_buffer},
{NULL, NULL, NULL}}; {NULL, NULL, NULL}};
@ -63,7 +71,7 @@ void sender(char *count) {
puts("."); puts(".");
p.data = snd_buffer[i % SND_BUFFER_SIZE]; p.data = snd_buffer[i % SND_BUFFER_SIZE];
msg_send(&mesg, transceiver_pid, 1); msg_send(&mesg, transceiver_pid, 1);
swtimer_usleep(SENDING_DELAY); swtimer_usleep(sending_delay);
} }
} }
@ -79,6 +87,39 @@ void print_buffer(char *unused) {
} }
} }
void switch2rx(char *unused) {
mesg.type = SWITCH_RX;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
puts("Turning transceiver on");
if (msg_send(&mesg, transceiver_pid, 1)) {
puts("\tsuccess");
}
}
void powerdown(char *unused) {
mesg.type = POWERDOWN;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
puts("Turning transceiver off");
if (msg_send(&mesg, transceiver_pid, 1)) {
puts("\tsuccess");
}
}
void set_delay(char *delay) {
uint32_t d;
if (sscanf(delay, "delay %lu", &d) == 1) {
sending_delay = d;
}
else {
puts("Usage:\tdelay <µs>");
}
}
void radio(void) { void radio(void) {
msg m; msg m;
radio_packet_t *p; radio_packet_t *p;

View File

@ -40,6 +40,7 @@ and the mailinglist (subscription via web site)
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <timex.h>
typedef uint8_t protocol_t; ///< Packet protocol type typedef uint8_t protocol_t; ///< Packet protocol type
typedef uint16_t radio_address_t; ///< Radio layer address type typedef uint16_t radio_address_t; ///< Radio layer address type
@ -83,6 +84,7 @@ typedef struct __attribute__ ((packed)) {
uint16_t dst; ///< Radio destination address uint16_t dst; ///< Radio destination address
uint8_t rssi; ///< Radio Signal Strength Indication uint8_t rssi; ///< Radio Signal Strength Indication
uint8_t lqi; ///< Link Quality Indicator uint8_t lqi; ///< Link Quality Indicator
timex_t toa; ///< Time of Arrival
uint8_t length; ///< Length of payload uint8_t length; ///< Length of payload
uint8_t *data; ///< Payload uint8_t *data; ///< Payload
} radio_packet_t; } radio_packet_t;

View File

@ -82,5 +82,3 @@ void _cc1100_ng_monitor_handler(char *mode) {
puts("Usage:\nmonitor <MODE>"); puts("Usage:\nmonitor <MODE>");
} }
} }

View File

@ -19,7 +19,7 @@
#endif #endif
#endif #endif
#define ENABLE_DEBUG (1) //#define ENABLE_DEBUG (1)
#include <debug.h> #include <debug.h>
/*------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------*/
@ -57,6 +57,8 @@ static int16_t set_channel(transceiver_type_t t, void *channel);
static int16_t get_address(transceiver_type_t t); static int16_t get_address(transceiver_type_t t);
static int16_t set_address(transceiver_type_t t, void *address); static int16_t set_address(transceiver_type_t t, void *address);
static void set_monitor(transceiver_type_t t, void *mode); static void set_monitor(transceiver_type_t t, void *mode);
static void powerdown(transceiver_type_t t);
static void switch_to_rx(transceiver_type_t t);
/*------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------*/
/* Transceiver init */ /* Transceiver init */
@ -122,6 +124,7 @@ void run(void) {
msg_receive(&m); msg_receive(&m);
/* only makes sense for messages for upper layers */ /* only makes sense for messages for upper layers */
cmd = (transceiver_command_t*) m.content.ptr; cmd = (transceiver_command_t*) m.content.ptr;
DEBUG("Transceiver: Message received\n"); DEBUG("Transceiver: Message received\n");
switch (m.type) { switch (m.type) {
case RCV_PKT_CC1020: case RCV_PKT_CC1020:
@ -152,6 +155,12 @@ void run(void) {
case SET_MONITOR: case SET_MONITOR:
set_monitor(cmd->transceivers, cmd->data); set_monitor(cmd->transceivers, cmd->data);
break; break;
case POWERDOWN:
powerdown(cmd->transceivers);
break;
case SWITCH_RX:
switch_to_rx(cmd->transceivers);
break;
default: default:
DEBUG("Unknown message received\n"); DEBUG("Unknown message received\n");
break; break;
@ -219,7 +228,7 @@ static void receive_packet(uint16_t type, uint8_t pos) {
if (reg[i].transceivers & t) { if (reg[i].transceivers & t) {
m.content.ptr = (char*) &(transceiver_buffer[transceiver_buffer_pos]); m.content.ptr = (char*) &(transceiver_buffer[transceiver_buffer_pos]);
DEBUG("Notify thread %i\n", reg[i].pid); DEBUG("Notify thread %i\n", reg[i].pid);
if (msg_send(&m, reg[i].pid, false)) { if (msg_send(&m, reg[i].pid, false) && (m.type != ENOBUFFER)) {
transceiver_buffer[transceiver_buffer_pos].processing++; transceiver_buffer[transceiver_buffer_pos].processing++;
} }
} }
@ -364,3 +373,24 @@ static void set_monitor(transceiver_type_t t, void *mode) {
break; break;
} }
} }
/*------------------------------------------------------------------------------------*/
static void powerdown(transceiver_type_t t) {
switch (t) {
case TRANSCEIVER_CC1100:
cc1100_switch_to_pwd();
break;
default:
break;
}
}
/*------------------------------------------------------------------------------------*/
static void switch_to_rx(transceiver_type_t t) {
switch (t) {
case TRANSCEIVER_CC1100:
cc1100_switch_to_rx();
break;
default:
break;
}
}