This commit is contained in:
nvt-se 2007-08-20 11:01:13 +00:00
parent ebe39794fd
commit 81174c6389
13 changed files with 1412 additions and 1412 deletions

View file

@ -1,86 +1,86 @@
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
#define HAVE_STDINT_H
#include "msp430def.h"
#define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02
#define IRQ_ADC 0x03
// MSB430 SD Card driver
#define SD_CACHE 1
#define SD_READ_ANY 1
#define SD_WRITE 1
// MSP430 Infomemory
#define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
#define CFS_SD_CONF_OFFSET 0x0000
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_INLINE inline
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
// Clock
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 100
#define F_CPU 2457600uL // CPU target speed in Hz
#define BAUD2UBR(baud) (F_CPU/(baud))
#include "ctk/ctk-vncarch.h"
#define LOG_CONF_ENABLED 0
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef uint16_t uip_stats_t;
typedef int bool;
#define TRUE 1
#define FALSE 0
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_BUFFER_SIZE 140
/*#define UIP_CONF_RECEIVE_WINDOW 140*/
#define UIP_CONF_LLH_LEN 6
#define UIP_CONF_RESOLV_ENTRIES 1
#define UIP_CONF_PINGADDRCONF 1
#define UIP_CONF_LOGGING 0
#define UIP_CONF_UDP_CONNS 6
#define UIP_CONF_FWCACHE_SIZE 1
#define UIP_CONF_BROADCAST 1
#define LOADER_CONF_ARCH "loader/loader-arch.h"
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
/* LEDs ports MSB430 */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x80
#define LEDS_CONF_GREEN 0x00
#define LEDS_CONF_YELLOW 0x00
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
#define SD_LED_READ_OFF (LEDS_PxOUT |= LEDS_CONF_RED)
#define SD_LED_WRITE_ON SD_LED_READ_ON
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
#endif /* !CONTIKI_CONF_H */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
#define HAVE_STDINT_H
#include "msp430def.h"
#define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02
#define IRQ_ADC 0x03
// MSB430 SD Card driver
#define SD_CACHE 1
#define SD_READ_ANY 1
#define SD_WRITE 1
// MSP430 Infomemory
#define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
#define CFS_SD_CONF_OFFSET 0x0000
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_INLINE inline
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
// Clock
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 100
#define F_CPU 2457600uL // CPU target speed in Hz
#define BAUD2UBR(baud) (F_CPU/(baud))
#include "ctk/ctk-vncarch.h"
#define LOG_CONF_ENABLED 0
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef uint16_t uip_stats_t;
typedef int bool;
#define TRUE 1
#define FALSE 0
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_BUFFER_SIZE 140
/*#define UIP_CONF_RECEIVE_WINDOW 140*/
#define UIP_CONF_LLH_LEN 6
#define UIP_CONF_RESOLV_ENTRIES 1
#define UIP_CONF_PINGADDRCONF 1
#define UIP_CONF_LOGGING 0
#define UIP_CONF_UDP_CONNS 6
#define UIP_CONF_FWCACHE_SIZE 1
#define UIP_CONF_BROADCAST 1
#define LOADER_CONF_ARCH "loader/loader-arch.h"
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
/* LEDs ports MSB430 */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x80
#define LEDS_CONF_GREEN 0x00
#define LEDS_CONF_YELLOW 0x00
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
#define SD_LED_READ_OFF (LEDS_PxOUT |= LEDS_CONF_RED)
#define SD_LED_WRITE_ON SD_LED_READ_ON
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
#endif /* !CONTIKI_CONF_H */

View file

@ -1,80 +1,80 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __CONTIKI_MSB430_H__
#define __CONTIKI_MSB430_H__
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/irq.h"
#include "dev/lpm.h"
#include "codeprop.h"
#include "dev/infomem.h"
#include "dev/msb430-uart1.h"
#include "dev/rs232.h"
#include "dev/sdspi.h"
#include "dev/serial.h"
#include "dev/slip.h"
#include "dev/cc1020.h"
#ifdef WITH_SDC
#include "dev/sd/sd.h"
#include "cfs/cfs-sd.h"
#endif
#include "node-id.h"
//#include "dev/vib-sensor.h"
//#include "dev/pir-sensor.h"
//#include "dev/button-sensor.h"
//#include "dev/radio-sensor.h"
//#include "dev/sound-sensor.h"
//#include "dev/battery-sensor.h"
//#include "dev/temperature-sensor.h"
//#include "dev/ctsrts-sensor.h"
//#include "dev/beep.h"
//#include "dev/ir.h"
#include "dev/leds.h"
#include "node-id.h"
#include "net/rime.h"
void msp430_cpu_init(void);
#endif /* __CONTIKI_MSB430_H__ */
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __CONTIKI_MSB430_H__
#define __CONTIKI_MSB430_H__
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/irq.h"
#include "dev/lpm.h"
#include "codeprop.h"
#include "dev/infomem.h"
#include "dev/msb430-uart1.h"
#include "dev/rs232.h"
#include "dev/sdspi.h"
#include "dev/serial.h"
#include "dev/slip.h"
#include "dev/cc1020.h"
#ifdef WITH_SDC
#include "dev/sd/sd.h"
#include "cfs/cfs-sd.h"
#endif
#include "node-id.h"
//#include "dev/vib-sensor.h"
//#include "dev/pir-sensor.h"
//#include "dev/button-sensor.h"
//#include "dev/radio-sensor.h"
//#include "dev/sound-sensor.h"
//#include "dev/battery-sensor.h"
//#include "dev/temperature-sensor.h"
//#include "dev/ctsrts-sensor.h"
//#include "dev/beep.h"
//#include "dev/ir.h"
#include "dev/leds.h"
#include "node-id.h"
#include "net/rime.h"
void msp430_cpu_init(void);
#endif /* __CONTIKI_MSB430_H__ */

View file

@ -1,229 +1,229 @@
#include <signal.h>
#define CC1020_MAIN 0x00
#define CC1020_INTERFACE 0x01
#define CC1020_RESET 0x02
#define CC1020_SEQUENCING 0x03
#define CC1020_FREQ_2A 0x04
#define CC1020_FREQ_1A 0x05
#define CC1020_FREQ_0A 0x06
#define CC1020_CLOCK_A 0x07
#define CC1020_FREQ_2B 0x08
#define CC1020_FREQ_1B 0x09
#define CC1020_FREQ_0B 0x0A
#define CC1020_CLOCK_B 0x0B
#define CC1020_VCO 0x0C
#define CC1020_MODEM 0x0D
#define CC1020_DEVIATION 0x0E
#define CC1020_AFC_CONTROL 0x0F
#define CC1020_FILTER 0x10
#define CC1020_VGA1 0x11
#define CC1020_VGA2 0x12
#define CC1020_VGA3 0x13
#define CC1020_VGA4 0x14
#define CC1020_LOCK 0x15
#define CC1020_FRONTEND 0x16
#define CC1020_ANALOG 0x17
#define CC1020_BUFF_SWING 0x18
#define CC1020_BUFF_CURRENT 0x19
#define CC1020_PLL_BW 0x1A
#define CC1020_CALIBRATE 0x1B
#define CC1020_PA_POWER 0x1C
#define CC1020_MATCH 0x1D
#define CC1020_PHASE_COMP 0x1E
#define CC1020_GAIN_COMP 0x1F
#define CC1020_POWERDOWN 0x20
#define CC1020_TEST1 0x21
#define CC1020_TEST2 0x22
#define CC1020_TEST3 0x23
#define CC1020_TEST4 0x24
#define CC1020_TEST5 0x25
#define CC1020_TEST6 0x26
#define CC1020_TEST7 0x27
#define CC1020_STATUS 0x40
#define CC1020_RESET_DONE 0x41
#define CC1020_RSS 0x42
#define CC1020_AFC 0x43
#define CC1020_GAUSS_FILTER 0x44
#define CC1020_STATUS1 0x45
#define CC1020_STATUS2 0x46
#define CC1020_STATUS3 0x47
#define CC1020_STATUS4 0x48
#define CC1020_STATUS5 0x49
#define CC1020_STATUS6 0x4A
#define CC1020_STATUS7 0x4B
// For CC1020_STATUS
#define LOCK_CONTINUOUS 0x10
#define CAL_COMPLETE 0x80
#define PA_POWER 0x0F // initial default for output power
#define LOCK_NOK 0x00
#define LOCK_OK 0x01
#define LOCK_RECAL_OK 0x02
#define CAL_TIMEOUT 0x7FFE
#define LOCK_TIMEOUT 0x7FFE
#define RESET_TIMEOUT 0x7FFE
#define TX_CURRENT 0x87
#define RX_CURRENT 0x86
// CC1020 driver configuration
#define CC1020_BUFFERSIZE 250
// PDI (Data in) is on P21
#define PDO (P2IN & 0x01)
// PSEL is on P30 and low active
#define PSEL_ON do { P3OUT &= ~0x01; } while(0)
#define PSEL_OFF do { P3OUT |= 0x01; } while(0)
#define PCLK_HIGH do { P2OUT |= 0x08; } while(0)
#define PCLK_LOW do { P2OUT &= ~0x08; } while(0)
// PDO (Data out) is on P22
#define PDI_HIGH do { P2OUT |= 0x02; } while(0)
#define PDI_LOW do { P2OUT &= ~0x02; } while(0)
// Enable power for LNA (P24, low-active)
#define LNA_POWER_ON() do { P2OUT &= ~0x10; } while(0)
#define LNA_POWER_OFF() do { P2OUT |= 0x10; } while(0)
#define CC_LOCK (P2IN & 0x04)
#define DISABLE_RX_IRQ() \
do { IE1 &= ~(URXIE0); } while(0)
#define ENABLE_RX_IRQ() \
do { IFG1 &= ~URXIFG0; IE1 |= URXIE0; } while(0)
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
#define ACK_TIMEOUT_19 16
#define MHZ_869525 1
const u8_t cc1020_config_19200[41] = {
0x01, // 0x00, MAIN
0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING
// 869.525 at 50kHz
0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200
0x38, // 0x07, CLOCK_A // 19200
0x3A, // 0x08, FREQ_2B
0x37, // 0x09, FREQ_1B
0xEB, // 0x0A, FREQ_0B // 19200
0x38, // 0x0B, CLOCK_B // 19200
0x44, // 0x0C, VCO 44
0x51, // 0x0D, MODEM Manchester
0x2B, // 0x0E, DEVIATION // FSK
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
0x25, // 0x10, FILTER Bandwith 100 kHz
0x61, // 0x11, VGA1
0x55, // 0x12, VGA2
0x2D, // 0x13, VGA3
0x37, // 0x14, VGA4 // 0x29, VGA4 ADJUSTED CS to 23!
0x40, // 0x15, LOCK is Carrier SENSE
0x76, // 0x16, FRONTEND
0x87, // 0x17, ANALOG, RX=86/TX=87
0x10, // 0x18, BUFF_SWING
0x25, // 0x19, BUFF_CURRENT
0xAE, // 0x1A, PLL_BW
0x34, // 0x1B, CALIBRATE
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
0xF0, // 0x1D, MATCH
0x00, // 0x1E, PHASE_COMP
0x00, // 0x1F, GAIN_COMP
0x00, // 0x20, POWERDOWN
0x4d, // 0x4d, // 0x21,
0x10, // 0x10, // 0x22,
0x06, // 0x06, // 0x23,
0x00, // 0x00, // 0x24,
0x40, // 0x40, // 0x25,
0x00, // 0x00, // 0x26,
0x00, // 0x00, // 0x27,
// Not in real config of chipCon from here!!!
ACK_TIMEOUT_19
};
const u8_t cc1020_config_115200[41] = {
0x01, // 0x00, MAIN
0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING
// 869.525 at 200kHz
0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200
0x29, // 0x07, CLOCK_A // 19200
0x3A, // 0x08, FREQ_2B
0x37, // 0x09, FREQ_1B
0xEB, // 0x0A, FREQ_0B // 19200
0x29, // 0x0B, CLOCK_B // 19200
0x44, // 0x0C, VCO 44
0x51, // 0x0D, MODEM Manchester
0x58, // 0x0E, DEVIATION // FSK
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
0x80, // 0x10, FILTER Bandwith 500 kHz
0x61, // 0x11, VGA1
0x55, // 0x12, VGA2
0x30, // 0x13, VGA3
0x35, // 0x14, VGA4
0x20, // 0x15, LOCK is Carrier SENSE
0x76, // 0x16, FRONTEND
0x87, // 0x17, ANALOG, RX=86/TX=87
0x10, // 0x18, BUFF_SWING
0x25, // 0x19, BUFF_CURRENT
0xAE, // 0x1A, PLL_BW
0x34, // 0x1B, CALIBRATE
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
0xF0, // 0x1D, MATCH
0x00, // 0x1E, PHASE_COMP
0x00, // 0x1F, GAIN_COMP
0x00, // 0x20, POWERDOWN
0x4d, // 0x21,
0x10, // 0x22,
0x06, // 0x23,
0x00, // 0x24,
0x40, // 0x25,
0x00, // 0x26,
0x00, // 0x27,
// Not in real config of chipCon from here!!!
ACK_TIMEOUT_115
};
/// cc1020 state
enum cc1020_state {
CC1020_OFF,
CC1020_RX,
CC1020_TX
};
/******************************************************************************
* @name Packet specification
* @{
*/
const u8_t syncword[2] = {0xD3,0x91};
__attribute__((packed))
struct cc1020_header {
u8_t length; // header: number of bytes in packet including header
};
#define PREAMBLESIZE 6
#define PREAMBLE 0xAA
#define TAILSIZE 2
#define TAIL 0xFA
#define SYNCWDSIZE (sizeof (syncword))
#define HDRSIZE (sizeof (struct cc1020_header))
///@}
/// cc1020 receiver state
enum cc1020_rxstate {
CC1020_RX_SEARCHING, // searching for preamble + sync word
CC1020_RX_RECEIVE, // receiving bytes
CC1020_RX_PROCESSING // processing data in buffer
};
#include <signal.h>
#define CC1020_MAIN 0x00
#define CC1020_INTERFACE 0x01
#define CC1020_RESET 0x02
#define CC1020_SEQUENCING 0x03
#define CC1020_FREQ_2A 0x04
#define CC1020_FREQ_1A 0x05
#define CC1020_FREQ_0A 0x06
#define CC1020_CLOCK_A 0x07
#define CC1020_FREQ_2B 0x08
#define CC1020_FREQ_1B 0x09
#define CC1020_FREQ_0B 0x0A
#define CC1020_CLOCK_B 0x0B
#define CC1020_VCO 0x0C
#define CC1020_MODEM 0x0D
#define CC1020_DEVIATION 0x0E
#define CC1020_AFC_CONTROL 0x0F
#define CC1020_FILTER 0x10
#define CC1020_VGA1 0x11
#define CC1020_VGA2 0x12
#define CC1020_VGA3 0x13
#define CC1020_VGA4 0x14
#define CC1020_LOCK 0x15
#define CC1020_FRONTEND 0x16
#define CC1020_ANALOG 0x17
#define CC1020_BUFF_SWING 0x18
#define CC1020_BUFF_CURRENT 0x19
#define CC1020_PLL_BW 0x1A
#define CC1020_CALIBRATE 0x1B
#define CC1020_PA_POWER 0x1C
#define CC1020_MATCH 0x1D
#define CC1020_PHASE_COMP 0x1E
#define CC1020_GAIN_COMP 0x1F
#define CC1020_POWERDOWN 0x20
#define CC1020_TEST1 0x21
#define CC1020_TEST2 0x22
#define CC1020_TEST3 0x23
#define CC1020_TEST4 0x24
#define CC1020_TEST5 0x25
#define CC1020_TEST6 0x26
#define CC1020_TEST7 0x27
#define CC1020_STATUS 0x40
#define CC1020_RESET_DONE 0x41
#define CC1020_RSS 0x42
#define CC1020_AFC 0x43
#define CC1020_GAUSS_FILTER 0x44
#define CC1020_STATUS1 0x45
#define CC1020_STATUS2 0x46
#define CC1020_STATUS3 0x47
#define CC1020_STATUS4 0x48
#define CC1020_STATUS5 0x49
#define CC1020_STATUS6 0x4A
#define CC1020_STATUS7 0x4B
// For CC1020_STATUS
#define LOCK_CONTINUOUS 0x10
#define CAL_COMPLETE 0x80
#define PA_POWER 0x0F // initial default for output power
#define LOCK_NOK 0x00
#define LOCK_OK 0x01
#define LOCK_RECAL_OK 0x02
#define CAL_TIMEOUT 0x7FFE
#define LOCK_TIMEOUT 0x7FFE
#define RESET_TIMEOUT 0x7FFE
#define TX_CURRENT 0x87
#define RX_CURRENT 0x86
// CC1020 driver configuration
#define CC1020_BUFFERSIZE 250
// PDI (Data in) is on P21
#define PDO (P2IN & 0x01)
// PSEL is on P30 and low active
#define PSEL_ON do { P3OUT &= ~0x01; } while(0)
#define PSEL_OFF do { P3OUT |= 0x01; } while(0)
#define PCLK_HIGH do { P2OUT |= 0x08; } while(0)
#define PCLK_LOW do { P2OUT &= ~0x08; } while(0)
// PDO (Data out) is on P22
#define PDI_HIGH do { P2OUT |= 0x02; } while(0)
#define PDI_LOW do { P2OUT &= ~0x02; } while(0)
// Enable power for LNA (P24, low-active)
#define LNA_POWER_ON() do { P2OUT &= ~0x10; } while(0)
#define LNA_POWER_OFF() do { P2OUT |= 0x10; } while(0)
#define CC_LOCK (P2IN & 0x04)
#define DISABLE_RX_IRQ() \
do { IE1 &= ~(URXIE0); } while(0)
#define ENABLE_RX_IRQ() \
do { IFG1 &= ~URXIFG0; IE1 |= URXIE0; } while(0)
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
#define ACK_TIMEOUT_19 16
#define MHZ_869525 1
const u8_t cc1020_config_19200[41] = {
0x01, // 0x00, MAIN
0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING
// 869.525 at 50kHz
0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200
0x38, // 0x07, CLOCK_A // 19200
0x3A, // 0x08, FREQ_2B
0x37, // 0x09, FREQ_1B
0xEB, // 0x0A, FREQ_0B // 19200
0x38, // 0x0B, CLOCK_B // 19200
0x44, // 0x0C, VCO 44
0x51, // 0x0D, MODEM Manchester
0x2B, // 0x0E, DEVIATION // FSK
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
0x25, // 0x10, FILTER Bandwith 100 kHz
0x61, // 0x11, VGA1
0x55, // 0x12, VGA2
0x2D, // 0x13, VGA3
0x37, // 0x14, VGA4 // 0x29, VGA4 ADJUSTED CS to 23!
0x40, // 0x15, LOCK is Carrier SENSE
0x76, // 0x16, FRONTEND
0x87, // 0x17, ANALOG, RX=86/TX=87
0x10, // 0x18, BUFF_SWING
0x25, // 0x19, BUFF_CURRENT
0xAE, // 0x1A, PLL_BW
0x34, // 0x1B, CALIBRATE
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
0xF0, // 0x1D, MATCH
0x00, // 0x1E, PHASE_COMP
0x00, // 0x1F, GAIN_COMP
0x00, // 0x20, POWERDOWN
0x4d, // 0x4d, // 0x21,
0x10, // 0x10, // 0x22,
0x06, // 0x06, // 0x23,
0x00, // 0x00, // 0x24,
0x40, // 0x40, // 0x25,
0x00, // 0x00, // 0x26,
0x00, // 0x00, // 0x27,
// Not in real config of chipCon from here!!!
ACK_TIMEOUT_19
};
const u8_t cc1020_config_115200[41] = {
0x01, // 0x00, MAIN
0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING
// 869.525 at 200kHz
0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200
0x29, // 0x07, CLOCK_A // 19200
0x3A, // 0x08, FREQ_2B
0x37, // 0x09, FREQ_1B
0xEB, // 0x0A, FREQ_0B // 19200
0x29, // 0x0B, CLOCK_B // 19200
0x44, // 0x0C, VCO 44
0x51, // 0x0D, MODEM Manchester
0x58, // 0x0E, DEVIATION // FSK
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
0x80, // 0x10, FILTER Bandwith 500 kHz
0x61, // 0x11, VGA1
0x55, // 0x12, VGA2
0x30, // 0x13, VGA3
0x35, // 0x14, VGA4
0x20, // 0x15, LOCK is Carrier SENSE
0x76, // 0x16, FRONTEND
0x87, // 0x17, ANALOG, RX=86/TX=87
0x10, // 0x18, BUFF_SWING
0x25, // 0x19, BUFF_CURRENT
0xAE, // 0x1A, PLL_BW
0x34, // 0x1B, CALIBRATE
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
0xF0, // 0x1D, MATCH
0x00, // 0x1E, PHASE_COMP
0x00, // 0x1F, GAIN_COMP
0x00, // 0x20, POWERDOWN
0x4d, // 0x21,
0x10, // 0x22,
0x06, // 0x23,
0x00, // 0x24,
0x40, // 0x25,
0x00, // 0x26,
0x00, // 0x27,
// Not in real config of chipCon from here!!!
ACK_TIMEOUT_115
};
/// cc1020 state
enum cc1020_state {
CC1020_OFF,
CC1020_RX,
CC1020_TX
};
/******************************************************************************
* @name Packet specification
* @{
*/
const u8_t syncword[2] = {0xD3,0x91};
__attribute__((packed))
struct cc1020_header {
u8_t length; // header: number of bytes in packet including header
};
#define PREAMBLESIZE 6
#define PREAMBLE 0xAA
#define TAILSIZE 2
#define TAIL 0xFA
#define SYNCWDSIZE (sizeof (syncword))
#define HDRSIZE (sizeof (struct cc1020_header))
///@}
/// cc1020 receiver state
enum cc1020_rxstate {
CC1020_RX_SEARCHING, // searching for preamble + sync word
CC1020_RX_RECEIVE, // receiving bytes
CC1020_RX_PROCESSING // processing data in buffer
};

View file

@ -1,97 +1,97 @@
/*
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2006
*/
/**
* @file cc1020.h
* @author FUB ScatterWeb Developers, Michael Baar, Nicolas Tsiftes
*
**/
#ifndef CC1020_H
#define CC1020_H
#include "dev/radio.h"
enum cc1020_power_mode {
CC1020_ALWAYS_ON
};
extern const u8_t cc1020_config_19200[];
extern const u8_t cc1020_config_115200[];
void cc1020_init(const u8_t* config);
int cc1020_on(void);
void cc1020_set_rx(void);
void cc1020_set_tx(void);
void cc1020_off(void);
void cc1020_set_receiver(void (*recv)(void));
void cc1020_set_power_mode(enum cc1020_power_mode mode);
/**
* @brief Set output power amplifier power-
*
* For good values see CC1020 documentation.
*/
void cc1020_set_power(u8_t pa_power);
unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
/**
* @brief Get RSSI of last received packet
*
* Best to call in packet handler
*/
u8_t cc1020_get_rssi(void);
unsigned int cc1020_send(u8_t *buf, unsigned int bufsize);
extern const struct radio_driver cc1020_driver;
PROCESS_NAME(cc1020_sender_process);
#endif
/*
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2006
*/
/**
* @file cc1020.h
* @author FUB ScatterWeb Developers, Michael Baar, Nicolas Tsiftes
*
**/
#ifndef CC1020_H
#define CC1020_H
#include "dev/radio.h"
enum cc1020_power_mode {
CC1020_ALWAYS_ON
};
extern const u8_t cc1020_config_19200[];
extern const u8_t cc1020_config_115200[];
void cc1020_init(const u8_t* config);
int cc1020_on(void);
void cc1020_set_rx(void);
void cc1020_set_tx(void);
void cc1020_off(void);
void cc1020_set_receiver(void (*recv)(void));
void cc1020_set_power_mode(enum cc1020_power_mode mode);
/**
* @brief Set output power amplifier power-
*
* For good values see CC1020 documentation.
*/
void cc1020_set_power(u8_t pa_power);
unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
/**
* @brief Get RSSI of last received packet
*
* Best to call in packet handler
*/
u8_t cc1020_get_rssi(void);
unsigned int cc1020_send(u8_t *buf, unsigned int bufsize);
extern const struct radio_driver cc1020_driver;
PROCESS_NAME(cc1020_sender_process);
#endif

View file

@ -1,121 +1,121 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/
/**
* @file infomem.c
* @addtogroup storage
* @brief MSP430 Infomemory Storage
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* Functions to store and read data from the two infomemories (2 x 128 Bytes).
* Offset addresses start at zero, size has a maximum of 128, write operations
* across both blocks are not allowed.
*/
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include "contiki-conf.h"
#include <msp430/flash.h>
#include "infomem.h"
void
infomem_read(void *buffer, unsigned int offset, unsigned char size)
{
uint8_t *address = (uint8_t *) INFOMEM_START + offset;
memcpy(buffer, address, size);
}
bool
infomem_write(unsigned int offset, unsigned char count, ...)
{
char backup[INFOMEM_BLOCK_SIZE];
uint8_t *buffer;
uint16_t i;
uint8_t *flash;
va_list argp;
uint16_t size;
uint8_t *data;
if (offset > (2 * INFOMEM_BLOCK_SIZE))
return FALSE;
flash = (uint8_t *) INFOMEM_START + offset;
_DINT();
// backup into RAM
memcpy(backup, flash, INFOMEM_BLOCK_SIZE);
// merge backup with new data
va_start(argp, count);
buffer = (uint8_t *) backup;
for (i = 0; i < count; i++) {
data = va_arg(argp, uint8_t*);
size = va_arg(argp, uint16_t);
memcpy(buffer, data, size);
buffer += size;
}
va_end(argp);
// init flash access
FCTL2 = FWKEY + FSSEL1 + FN2;
FCTL3 = FWKEY;
// erase flash
FCTL1 = FWKEY + ERASE;
*flash = 0;
// write flash
FCTL1 = FWKEY + WRT;
buffer = (uint8_t *) backup;
for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) {
*flash++ = *buffer++;
}
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
_EINT();
return TRUE;
}
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/
/**
* @file infomem.c
* @addtogroup storage
* @brief MSP430 Infomemory Storage
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* Functions to store and read data from the two infomemories (2 x 128 Bytes).
* Offset addresses start at zero, size has a maximum of 128, write operations
* across both blocks are not allowed.
*/
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include "contiki-conf.h"
#include <msp430/flash.h>
#include "infomem.h"
void
infomem_read(void *buffer, unsigned int offset, unsigned char size)
{
uint8_t *address = (uint8_t *) INFOMEM_START + offset;
memcpy(buffer, address, size);
}
bool
infomem_write(unsigned int offset, unsigned char count, ...)
{
char backup[INFOMEM_BLOCK_SIZE];
uint8_t *buffer;
uint16_t i;
uint8_t *flash;
va_list argp;
uint16_t size;
uint8_t *data;
if (offset > (2 * INFOMEM_BLOCK_SIZE))
return FALSE;
flash = (uint8_t *) INFOMEM_START + offset;
_DINT();
// backup into RAM
memcpy(backup, flash, INFOMEM_BLOCK_SIZE);
// merge backup with new data
va_start(argp, count);
buffer = (uint8_t *) backup;
for (i = 0; i < count; i++) {
data = va_arg(argp, uint8_t*);
size = va_arg(argp, uint16_t);
memcpy(buffer, data, size);
buffer += size;
}
va_end(argp);
// init flash access
FCTL2 = FWKEY + FSSEL1 + FN2;
FCTL3 = FWKEY;
// erase flash
FCTL1 = FWKEY + ERASE;
*flash = 0;
// write flash
FCTL1 = FWKEY + WRT;
buffer = (uint8_t *) backup;
for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) {
*flash++ = *buffer++;
}
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
_EINT();
return TRUE;
}

View file

@ -1,82 +1,82 @@
/*
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2006
*/
/**
* @file infomem.h
* @addtogroup storage
* @brief MSP430 Infomemory Storage
*
* @author Michael Baar <baar@inf.fu-berlin.de>
*/
#ifndef INFOMEM_H
#define INFOMEM_H
#if !defined(INFOMEM_START) || !defined(INFOMEM_BLOCK_SIZE)
#error "infomem position (INFOMEM_START) and block size (INFOMEM_BLOCK_SIZE) need to be defined for the platform"
#endif
/**
* @brief Read bytes from infomemory
* @param[out] buffer Pointer to buffer for read data
* @param[in] offset Offset in infomemory (0-254)
* @param[in] size Number of bytes to read
*/
void infomem_read(void *buffer, unsigned int offset, unsigned char size);
/**
* @brief Write bytes to infomemory
* @param[in] offset Offset in infomemory (0-254)
* @param[in] count Number of items following
* each item is a pair pointer, length
*
* Example: Infomem_write( 0, 2, &a,3, &b,1 );
*
* \note: The MSP430 has two consecutive blocks of infomemory.
* Each is 128 bytes large. The offset is the relative address
* starting at the beginning of the first block. You can write an
* arbitrary number of bytes at any offset, but this function
* cannot write across the two blocks of infomemory.
*/
bool infomem_write(unsigned int offset, unsigned char count, ...);
#endif // !INFOMEM_H
/*
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2006
*/
/**
* @file infomem.h
* @addtogroup storage
* @brief MSP430 Infomemory Storage
*
* @author Michael Baar <baar@inf.fu-berlin.de>
*/
#ifndef INFOMEM_H
#define INFOMEM_H
#if !defined(INFOMEM_START) || !defined(INFOMEM_BLOCK_SIZE)
#error "infomem position (INFOMEM_START) and block size (INFOMEM_BLOCK_SIZE) need to be defined for the platform"
#endif
/**
* @brief Read bytes from infomemory
* @param[out] buffer Pointer to buffer for read data
* @param[in] offset Offset in infomemory (0-254)
* @param[in] size Number of bytes to read
*/
void infomem_read(void *buffer, unsigned int offset, unsigned char size);
/**
* @brief Write bytes to infomemory
* @param[in] offset Offset in infomemory (0-254)
* @param[in] count Number of items following
* each item is a pair pointer, length
*
* Example: Infomem_write( 0, 2, &a,3, &b,1 );
*
* \note: The MSP430 has two consecutive blocks of infomemory.
* Each is 128 bytes large. The offset is the relative address
* starting at the beginning of the first block. You can write an
* arbitrary number of bytes at any offset, but this function
* cannot write across the two blocks of infomemory.
*/
bool infomem_write(unsigned int offset, unsigned char count, ...);
#endif // !INFOMEM_H

View file

@ -1,203 +1,203 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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 UART interface
* \author Michael Baar <baar@inf.fu-berlin.de>
*
* UART switch for RS232 and SPI protocols on UART1 written for
* ScatterWeb MSB boards. Compatible to ScatterWeb EOS,
* ScatterWeb Bootload and Contiki.
*/
#include <io.h>
#include <signal.h>
#include <string.h>
#include "dev/msb430-uart1.h"
#include "msp430.h"
#include "dev/lpm.h"
#ifndef U1ME
#define U1ME ME2
#endif
static void uart_configure(unsigned char mode);
static void uart_set_mode(unsigned char mode);
static volatile unsigned char uart_mode = UART_MODE_RESET;
static volatile unsigned char uart_lockcnt;
static unsigned char uart_speed_br0[UART_NUM_MODES];
static unsigned char uart_speed_br1[UART_NUM_MODES];
static unsigned char uart_speed_bmn[UART_NUM_MODES];
static fp_uart_handler uart_handler[UART_NUM_MODES];
void
uart_set_speed(unsigned char mode, unsigned char ubr0,
unsigned char ubr1, unsigned char umctl)
{
// store setting
uart_speed_br0[mode] = ubr0; // baudrate
uart_speed_br1[mode] = ubr1; // baudrate
uart_speed_bmn[mode] = umctl; // modulation
// reconfigure, if mode active
if (uart_mode == mode)
uart_configure(mode);
}
void
uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
{
// store setting
uart_handler[mode] = fpHandler;
if (mode == uart_mode) {
if (fpHandler == NULL)
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
else
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
}
int
uart_lock(unsigned char mode)
{
// already locked?
if ((mode != uart_mode) && (uart_lockcnt)) {
return FALSE;
}
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode);
return TRUE;
}
int
uart_unlock(unsigned char mode)
{
/* Strict checking. */
if (mode != uart_mode)
return FALSE;
// decrement lock
if (uart_lockcnt > 0) {
uart_lockcnt--;
// if no more locks, switch back to default mode
if (uart_lockcnt == 0) {
uart_set_mode(UART_MODE_DEFAULT);
}
return TRUE;
}
return FALSE;
}
static void
uart_configure(unsigned char mode)
{
_DINT();
UART_WAIT_TXDONE();
// configure
if (mode == UART_MODE_RS232) {
P5OUT |= 0x01;
// unselect SPI
P3SEL |= 0xC0;
// select rs232 to RS232 mode
UCTL1 = SWRST | CHAR; // 8-bit character
UTCTL1 |= SSEL1; // UCLK = MCLK
// activate
U1ME |= UTXE1 | URXE1; // Enable USART1 TXD/RXD
} else if( mode == UART_MODE_SPI ) {
P3SEL &= ~0xC0; // unselect RS232
// to SPI mode
UCTL1 = SWRST | CHAR | SYNC | MM; // 8-bit SPI Master
/*
* SMCLK, 3-pin mode, clock idle low, data valid on
* rising edge, UCLK delayed
*/
UTCTL1 |= CKPH | SSEL1 | SSEL0 | STC; // activate
U1ME |= USPIE1; // Enable USART1 SPI
}
// restore speed settings
UBR01 = uart_speed_br0[mode]; // set baudrate
UBR11 = uart_speed_br1[mode];
UMCTL1 = uart_speed_bmn[mode]; // set modulation
UCTL1 &= ~SWRST; // clear reset flag
_EINT(); // enable interrupts
}
static void
uart_set_mode(unsigned char mode)
{
// do nothing if mode already set
if (mode == uart_mode )
return;
IE2 &= ~(URXIE1 | UTXIE1); // disable irq
uart_configure(mode); // configure uart parameters
uart_mode = mode;
if (uart_handler[mode] != NULL)
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
interrupt(UART1RX_VECTOR) uart_rx(void)
{
fp_uart_handler handler = uart_handler[uart_mode];
/* Check status register for receive errors. - before reading RXBUF since
it clears the error and interrupt flags */
if (!(URCTL1 & RXERR) && handler != NULL) {
if(handler(UART_RX)) {
LPM_AWAKE();
}
} else {
// read out the char to clear the I-flags, etc.
UART_RX;
}
}
int
uart_get_mode(void)
{
return uart_mode;
}
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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 UART interface
* \author Michael Baar <baar@inf.fu-berlin.de>
*
* UART switch for RS232 and SPI protocols on UART1 written for
* ScatterWeb MSB boards. Compatible to ScatterWeb EOS,
* ScatterWeb Bootload and Contiki.
*/
#include <io.h>
#include <signal.h>
#include <string.h>
#include "dev/msb430-uart1.h"
#include "msp430.h"
#include "dev/lpm.h"
#ifndef U1ME
#define U1ME ME2
#endif
static void uart_configure(unsigned char mode);
static void uart_set_mode(unsigned char mode);
static volatile unsigned char uart_mode = UART_MODE_RESET;
static volatile unsigned char uart_lockcnt;
static unsigned char uart_speed_br0[UART_NUM_MODES];
static unsigned char uart_speed_br1[UART_NUM_MODES];
static unsigned char uart_speed_bmn[UART_NUM_MODES];
static fp_uart_handler uart_handler[UART_NUM_MODES];
void
uart_set_speed(unsigned char mode, unsigned char ubr0,
unsigned char ubr1, unsigned char umctl)
{
// store setting
uart_speed_br0[mode] = ubr0; // baudrate
uart_speed_br1[mode] = ubr1; // baudrate
uart_speed_bmn[mode] = umctl; // modulation
// reconfigure, if mode active
if (uart_mode == mode)
uart_configure(mode);
}
void
uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
{
// store setting
uart_handler[mode] = fpHandler;
if (mode == uart_mode) {
if (fpHandler == NULL)
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
else
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
}
int
uart_lock(unsigned char mode)
{
// already locked?
if ((mode != uart_mode) && (uart_lockcnt)) {
return FALSE;
}
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode);
return TRUE;
}
int
uart_unlock(unsigned char mode)
{
/* Strict checking. */
if (mode != uart_mode)
return FALSE;
// decrement lock
if (uart_lockcnt > 0) {
uart_lockcnt--;
// if no more locks, switch back to default mode
if (uart_lockcnt == 0) {
uart_set_mode(UART_MODE_DEFAULT);
}
return TRUE;
}
return FALSE;
}
static void
uart_configure(unsigned char mode)
{
_DINT();
UART_WAIT_TXDONE();
// configure
if (mode == UART_MODE_RS232) {
P5OUT |= 0x01;
// unselect SPI
P3SEL |= 0xC0;
// select rs232 to RS232 mode
UCTL1 = SWRST | CHAR; // 8-bit character
UTCTL1 |= SSEL1; // UCLK = MCLK
// activate
U1ME |= UTXE1 | URXE1; // Enable USART1 TXD/RXD
} else if( mode == UART_MODE_SPI ) {
P3SEL &= ~0xC0; // unselect RS232
// to SPI mode
UCTL1 = SWRST | CHAR | SYNC | MM; // 8-bit SPI Master
/*
* SMCLK, 3-pin mode, clock idle low, data valid on
* rising edge, UCLK delayed
*/
UTCTL1 |= CKPH | SSEL1 | SSEL0 | STC; // activate
U1ME |= USPIE1; // Enable USART1 SPI
}
// restore speed settings
UBR01 = uart_speed_br0[mode]; // set baudrate
UBR11 = uart_speed_br1[mode];
UMCTL1 = uart_speed_bmn[mode]; // set modulation
UCTL1 &= ~SWRST; // clear reset flag
_EINT(); // enable interrupts
}
static void
uart_set_mode(unsigned char mode)
{
// do nothing if mode already set
if (mode == uart_mode )
return;
IE2 &= ~(URXIE1 | UTXIE1); // disable irq
uart_configure(mode); // configure uart parameters
uart_mode = mode;
if (uart_handler[mode] != NULL)
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
interrupt(UART1RX_VECTOR) uart_rx(void)
{
fp_uart_handler handler = uart_handler[uart_mode];
/* Check status register for receive errors. - before reading RXBUF since
it clears the error and interrupt flags */
if (!(URCTL1 & RXERR) && handler != NULL) {
if(handler(UART_RX)) {
LPM_AWAKE();
}
} else {
// read out the char to clear the I-flags, etc.
UART_RX;
}
}
int
uart_get_mode(void)
{
return uart_mode;
}

View file

@ -1,122 +1,122 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/
/**
* @addtogroup interfaces
* @{ */
/**
* @defgroup uart1 UART1
* The UART module multiplexes differenct protocol on the MSB's UART1
* interface. Currently RS232 and SPI are supported.
* @{
*/
/**
* @file ScatterWeb.Uart.h
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* Header file for MSP430 UART driver.
*/
#ifndef __UART_H__
#define __UART_H__
#define UART_RX RXBUF1
#define UART_TX TXBUF1
#define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
#define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
#define UART_WAIT_RX() while( (U1IFG & URXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TX() while( (U1IFG & UTXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
/**
* @brief Operating state
*/
extern volatile unsigned char uart_mode;
extern volatile unsigned char uart_lockcnt;
/**
* @name UART mode flags
* @{
*/
#define UART_MODE_RS232 (0x00u) ///< RS232 mode
#define UART_MODE_SPI (0x01u) ///< SPI mode
#define UART_MODE_DEFAULT UART_MODE_RS232
#define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number
#define UART_MODE_RESET (0xFFu) ///< reset with current settings
/** @} */
#define UART_WAIT_LOCK(x) ( (uart_mode != x ) && (uart_lockcnt) )
#define UART_MODE_IS(x) ( uart_mode == x )
#if 0
#ifdef __SCATTERWEB__
typedef void(*fp_uart_handler)(void);
#else
typedef unsigned int(*fp_uart_handler)(unsigned char);
#endif
#endif
typedef unsigned int(*fp_uart_handler)(unsigned char);
/**
* \brief Initialize the UART module
*
* This function is called from the boot up code to
* initalize the UART module.
*/
void uart_init(void);
void uart_set_speed(unsigned char mode, unsigned char ubr0, unsigned char ubr1, unsigned char umctl);
void uart_set_handler(unsigned char mode, fp_uart_handler fpHandler);
int uart_lock(unsigned char mode);
int uart_unlock(unsigned char mode);
int uart_get_mode(void);
#endif /* __UART_H__ */
/** @} */
/** @} */
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors 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.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/
/**
* @addtogroup interfaces
* @{ */
/**
* @defgroup uart1 UART1
* The UART module multiplexes differenct protocol on the MSB's UART1
* interface. Currently RS232 and SPI are supported.
* @{
*/
/**
* @file ScatterWeb.Uart.h
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* Header file for MSP430 UART driver.
*/
#ifndef __UART_H__
#define __UART_H__
#define UART_RX RXBUF1
#define UART_TX TXBUF1
#define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
#define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
#define UART_WAIT_RX() while( (U1IFG & URXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TX() while( (U1IFG & UTXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
/**
* @brief Operating state
*/
extern volatile unsigned char uart_mode;
extern volatile unsigned char uart_lockcnt;
/**
* @name UART mode flags
* @{
*/
#define UART_MODE_RS232 (0x00u) ///< RS232 mode
#define UART_MODE_SPI (0x01u) ///< SPI mode
#define UART_MODE_DEFAULT UART_MODE_RS232
#define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number
#define UART_MODE_RESET (0xFFu) ///< reset with current settings
/** @} */
#define UART_WAIT_LOCK(x) ( (uart_mode != x ) && (uart_lockcnt) )
#define UART_MODE_IS(x) ( uart_mode == x )
#if 0
#ifdef __SCATTERWEB__
typedef void(*fp_uart_handler)(void);
#else
typedef unsigned int(*fp_uart_handler)(unsigned char);
#endif
#endif
typedef unsigned int(*fp_uart_handler)(unsigned char);
/**
* \brief Initialize the UART module
*
* This function is called from the boot up code to
* initalize the UART module.
*/
void uart_init(void);
void uart_set_speed(unsigned char mode, unsigned char ubr0, unsigned char ubr1, unsigned char umctl);
void uart_set_handler(unsigned char mode, fp_uart_handler fpHandler);
int uart_lock(unsigned char mode);
int uart_unlock(unsigned char mode);
int uart_get_mode(void);
#endif /* __UART_H__ */
/** @} */
/** @} */

View file

@ -1,117 +1,117 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.c,v 1.2 2007/08/16 20:29:56 nvt-se Exp $
*/
/** \addtogroup esbrs232
* @{ */
/**
* \file
* RS232 communication device driver for the MSP430.
* \author Adam Dunkels <adam@sics.se>
*
* This file contains an RS232 device driver for the MSP430 microcontroller.
*
*/
#include <io.h>
#include <signal.h>
#include <string.h>
#include "dev/msb430-uart1.h"
#include "rs232.h"
#ifndef U1IFG
#define U1IFG IFG2
#endif
/*---------------------------------------------------------------------------*/
/**
* Initalize the RS232 port.
*
*/
void
rs232_init(void)
{
// rs232_set_speed(RS232_57600);
rs232_set_speed(RS232_115200);
}
/*---------------------------------------------------------------------------*/
void
rs232_send(char c)
{
/* Check if the UART is in RS232 mode before sending.
This check can be ommitted if every access to rs232 locks the uart
before using it.
*/
if (uart_get_mode() == UART_MODE_RS232) {
/* Loop until the transmission buffer is available. */
UART_WAIT_TX();
/* Transmit the data. */
UART_TX = c;
}
}
/*---------------------------------------------------------------------------*/
void
rs232_set_speed(enum rs232_speed speed)
{
// baud
const unsigned char br_table[4][3] = {
{0x80, 0x00, 0x00}, // 19200
{0x40, 0x00, 0x00}, // 38400
{0x2a, 0x00, 0x5b}, // 57600
{0x15, 0x00, 0x4a} // 115200
};
uart_set_speed(UART_MODE_RS232, br_table[speed][0],
br_table[speed][1], br_table[speed][2]);
}
/*---------------------------------------------------------------------------*/
void
rs232_print(char *cptr)
{
// lock UART for print operation
if (uart_lock(UART_MODE_RS232)) {
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
}
uart_unlock(UART_MODE_RS232);
}
}
/*---------------------------------------------------------------------------*/
void
rs232_set_input(fp_uart_handler f)
{
uart_set_handler(UART_MODE_RS232, f);
}
/** @} */
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.c,v 1.3 2007/08/20 11:01:14 nvt-se Exp $
*/
/** \addtogroup esbrs232
* @{ */
/**
* \file
* RS232 communication device driver for the MSP430.
* \author Adam Dunkels <adam@sics.se>
*
* This file contains an RS232 device driver for the MSP430 microcontroller.
*
*/
#include <io.h>
#include <signal.h>
#include <string.h>
#include "dev/msb430-uart1.h"
#include "rs232.h"
#ifndef U1IFG
#define U1IFG IFG2
#endif
/*---------------------------------------------------------------------------*/
/**
* Initalize the RS232 port.
*
*/
void
rs232_init(void)
{
// rs232_set_speed(RS232_57600);
rs232_set_speed(RS232_115200);
}
/*---------------------------------------------------------------------------*/
void
rs232_send(char c)
{
/* Check if the UART is in RS232 mode before sending.
This check can be ommitted if every access to rs232 locks the uart
before using it.
*/
if (uart_get_mode() == UART_MODE_RS232) {
/* Loop until the transmission buffer is available. */
UART_WAIT_TX();
/* Transmit the data. */
UART_TX = c;
}
}
/*---------------------------------------------------------------------------*/
void
rs232_set_speed(enum rs232_speed speed)
{
// baud
const unsigned char br_table[4][3] = {
{0x80, 0x00, 0x00}, // 19200
{0x40, 0x00, 0x00}, // 38400
{0x2a, 0x00, 0x5b}, // 57600
{0x15, 0x00, 0x4a} // 115200
};
uart_set_speed(UART_MODE_RS232, br_table[speed][0],
br_table[speed][1], br_table[speed][2]);
}
/*---------------------------------------------------------------------------*/
void
rs232_print(char *cptr)
{
// lock UART for print operation
if (uart_lock(UART_MODE_RS232)) {
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
}
uart_unlock(UART_MODE_RS232);
}
}
/*---------------------------------------------------------------------------*/
void
rs232_set_input(fp_uart_handler f)
{
uart_set_handler(UART_MODE_RS232, f);
}
/** @} */

View file

@ -1,120 +1,120 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.h,v 1.1 2007/06/28 12:52:42 nvt-se Exp $
*/
/** \addtogroup esb
* @{ */
/**
* \defgroup esbrs232 ESB RS232
*
* @{
*/
/**
* \file
* Header file for MSP430 RS232 driver.
* \author Adam Dunkels <adam@sics.se>
*
*/
#ifndef __RS232_H__
#define __RS232_H__
enum rs232_speed {
RS232_19200 = 0,
RS232_38400 = 1,
RS232_57600 = 2,
RS232_115200 = 3
};
/**
* \brief Initialize the RS232 module
*
* This function is called from the boot up code to
* initalize the RS232 module.
*/
void rs232_init(void);
/**
* \brief Set an input handler for incoming RS232 data
* \param f A pointer to a byte input handler
*
* This function sets the input handler for incoming RS232
* data. The input handler function is called for every
* incoming data byte. The function is called from the
* RS232 interrupt handler, so care must be taken when
* implementing the input handler to avoid race
* conditions.
*
* The return value of the input handler affects the sleep
* mode of the CPU: if the input handler returns non-zero
* (true), the CPU is awakened to let other processing
* take place. If the input handler returns zero, the CPU
* is kept sleeping.
*/
void rs232_set_input(fp_uart_handler f);
/**
* \brief Configure the speed of the RS232 hardware
* \param speed The speed
*
* This function configures the speed of the RS232
* hardware. The allowed parameters are RS232_19200,
* RS232_38400, RS232_57600, and RS232_115200.
*/
void rs232_set_speed(enum rs232_speed speed);
/**
* \brief Print a text string on RS232
* \param str A pointer to the string that is to be printed
*
* This function prints a string to RS232. The string must
* be terminated by a null byte. The RS232 module must be
* correctly initalized and configured for this function
* to work.
*/
void rs232_print(char *text);
/**
* \brief Print a character on RS232
* \param c The character to be printed
*
* This function prints a character to RS232. The RS232
* module must be correctly initalized and configured for
* this function to work.
*/
void rs232_send(char c);
#endif /* __RS232_H__ */
/** @} */
/** @} */
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.h,v 1.2 2007/08/20 11:01:14 nvt-se Exp $
*/
/** \addtogroup esb
* @{ */
/**
* \defgroup esbrs232 ESB RS232
*
* @{
*/
/**
* \file
* Header file for MSP430 RS232 driver.
* \author Adam Dunkels <adam@sics.se>
*
*/
#ifndef __RS232_H__
#define __RS232_H__
enum rs232_speed {
RS232_19200 = 0,
RS232_38400 = 1,
RS232_57600 = 2,
RS232_115200 = 3
};
/**
* \brief Initialize the RS232 module
*
* This function is called from the boot up code to
* initalize the RS232 module.
*/
void rs232_init(void);
/**
* \brief Set an input handler for incoming RS232 data
* \param f A pointer to a byte input handler
*
* This function sets the input handler for incoming RS232
* data. The input handler function is called for every
* incoming data byte. The function is called from the
* RS232 interrupt handler, so care must be taken when
* implementing the input handler to avoid race
* conditions.
*
* The return value of the input handler affects the sleep
* mode of the CPU: if the input handler returns non-zero
* (true), the CPU is awakened to let other processing
* take place. If the input handler returns zero, the CPU
* is kept sleeping.
*/
void rs232_set_input(fp_uart_handler f);
/**
* \brief Configure the speed of the RS232 hardware
* \param speed The speed
*
* This function configures the speed of the RS232
* hardware. The allowed parameters are RS232_19200,
* RS232_38400, RS232_57600, and RS232_115200.
*/
void rs232_set_speed(enum rs232_speed speed);
/**
* \brief Print a text string on RS232
* \param str A pointer to the string that is to be printed
*
* This function prints a string to RS232. The string must
* be terminated by a null byte. The RS232 module must be
* correctly initalized and configured for this function
* to work.
*/
void rs232_print(char *text);
/**
* \brief Print a character on RS232
* \param c The character to be printed
*
* This function prints a character to RS232. The RS232
* module must be correctly initalized and configured for
* this function to work.
*/
void rs232_send(char c);
#endif /* __RS232_H__ */
/** @} */
/** @} */

View file

@ -1,56 +1,56 @@
#include "dev/msb430-uart1.h"
#include "dev/rs232.h"
#include "sys/clock.h"
#include "dev/slip.h"
void
slip_arch_writeb(unsigned char c)
{
rs232_send(c);
}
/*---------------------------------------------------------------------------*/
/*
* The serial line is used to transfer IP packets using slip. To make
* it possible to send debug output over the same line we send debug
* output as slip frames (i.e delimeted by SLIP_END).
*
*/
int
putchar(int c)
{
#define SLIP_END 0300
static char debug_frame = 0;
if (!debug_frame) { /* Start of debug output */
slip_arch_writeb(SLIP_END);
slip_arch_writeb('\r'); /* Type debug line == '\r' */
debug_frame = 1;
}
slip_arch_writeb((char)c);
/*
* Line buffered output, a newline marks the end of debug output and
* implicitly flushes debug output.
*/
if (c == '\n') {
slip_arch_writeb(SLIP_END);
debug_frame = 0;
}
clock_delay(100);
return c;
}
/**
* Initalize the RS232 port and the SLIP driver.
*
*/
void
slip_arch_init(unsigned long ubr)
{
rs232_set_input(slip_input_byte);
}
#include "dev/msb430-uart1.h"
#include "dev/rs232.h"
#include "sys/clock.h"
#include "dev/slip.h"
void
slip_arch_writeb(unsigned char c)
{
rs232_send(c);
}
/*---------------------------------------------------------------------------*/
/*
* The serial line is used to transfer IP packets using slip. To make
* it possible to send debug output over the same line we send debug
* output as slip frames (i.e delimeted by SLIP_END).
*
*/
int
putchar(int c)
{
#define SLIP_END 0300
static char debug_frame = 0;
if (!debug_frame) { /* Start of debug output */
slip_arch_writeb(SLIP_END);
slip_arch_writeb('\r'); /* Type debug line == '\r' */
debug_frame = 1;
}
slip_arch_writeb((char)c);
/*
* Line buffered output, a newline marks the end of debug output and
* implicitly flushes debug output.
*/
if (c == '\n') {
slip_arch_writeb(SLIP_END);
debug_frame = 0;
}
clock_delay(100);
return c;
}
/**
* Initalize the RS232 port and the SLIP driver.
*
*/
void
slip_arch_init(unsigned long ubr)
{
rs232_set_input(slip_input_byte);
}

View file

@ -1,55 +1,55 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* $Id: node-id.c,v 1.1 2007/06/28 12:49:57 nvt-se Exp $
*/
#include "node-id.h"
#include "contiki-conf.h"
#include "dev/infomem.h"
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
unsigned short newid[2];
infomem_read(newid, INFOMEM_NODE_ID, 2 * sizeof(node_id));
node_id = ( newid[0] == 0xdead ) ? newid[1] : newid[0];
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
unsigned short buffer[2] = { 0xdead, id };
infomem_write(INFOMEM_NODE_ID, 1, buffer, 2 * sizeof(node_id));
}
/*---------------------------------------------------------------------------*/
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* $Id: node-id.c,v 1.2 2007/08/20 11:01:13 nvt-se Exp $
*/
#include "node-id.h"
#include "contiki-conf.h"
#include "dev/infomem.h"
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
unsigned short newid[2];
infomem_read(newid, INFOMEM_NODE_ID, 2 * sizeof(node_id));
node_id = ( newid[0] == 0xdead ) ? newid[1] : newid[0];
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
unsigned short buffer[2] = { 0xdead, id };
infomem_write(INFOMEM_NODE_ID, 1, buffer, 2 * sizeof(node_id));
}
/*---------------------------------------------------------------------------*/

View file

@ -1,44 +1,44 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science.
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node-id.h,v 1.1 2007/06/28 12:49:57 nvt-se Exp $
*/
#ifndef __NODE_ID_H__
#define __NODE_ID_H__
void node_id_restore(void);
void node_id_burn(unsigned short node_id);
extern unsigned short node_id;
#endif /* __NODE_ID_H__ */
/*
* Copyright (c) 2005, Swedish Institute of Computer Science.
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node-id.h,v 1.2 2007/08/20 11:01:13 nvt-se Exp $
*/
#ifndef __NODE_ID_H__
#define __NODE_ID_H__
void node_id_restore(void);
void node_id_burn(unsigned short node_id);
extern unsigned short node_id;
#endif /* __NODE_ID_H__ */