cr->lf
This commit is contained in:
parent
ebe39794fd
commit
81174c6389
13 changed files with 1412 additions and 1412 deletions
|
@ -1,86 +1,86 @@
|
||||||
#ifndef CONTIKI_CONF_H
|
#ifndef CONTIKI_CONF_H
|
||||||
#define CONTIKI_CONF_H
|
#define CONTIKI_CONF_H
|
||||||
|
|
||||||
#define HAVE_STDINT_H
|
#define HAVE_STDINT_H
|
||||||
#include "msp430def.h"
|
#include "msp430def.h"
|
||||||
|
|
||||||
#define IRQ_PORT1 0x01
|
#define IRQ_PORT1 0x01
|
||||||
#define IRQ_PORT2 0x02
|
#define IRQ_PORT2 0x02
|
||||||
#define IRQ_ADC 0x03
|
#define IRQ_ADC 0x03
|
||||||
|
|
||||||
// MSB430 SD Card driver
|
// MSB430 SD Card driver
|
||||||
#define SD_CACHE 1
|
#define SD_CACHE 1
|
||||||
#define SD_READ_ANY 1
|
#define SD_READ_ANY 1
|
||||||
#define SD_WRITE 1
|
#define SD_WRITE 1
|
||||||
|
|
||||||
// MSP430 Infomemory
|
// MSP430 Infomemory
|
||||||
#define INFOMEM_START 0x1000
|
#define INFOMEM_START 0x1000
|
||||||
#define INFOMEM_BLOCK_SIZE 128
|
#define INFOMEM_BLOCK_SIZE 128
|
||||||
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
|
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
|
||||||
|
|
||||||
#define CFS_SD_CONF_OFFSET 0x0000
|
#define CFS_SD_CONF_OFFSET 0x0000
|
||||||
|
|
||||||
#define CC_CONF_REGISTER_ARGS 1
|
#define CC_CONF_REGISTER_ARGS 1
|
||||||
#define CC_CONF_FUNCTION_POINTER_ARGS 1
|
#define CC_CONF_FUNCTION_POINTER_ARGS 1
|
||||||
|
|
||||||
#define CC_CONF_INLINE inline
|
#define CC_CONF_INLINE inline
|
||||||
|
|
||||||
#define CC_CONF_VA_ARGS 1
|
#define CC_CONF_VA_ARGS 1
|
||||||
|
|
||||||
#define CCIF
|
#define CCIF
|
||||||
#define CLIF
|
#define CLIF
|
||||||
|
|
||||||
// Clock
|
// Clock
|
||||||
typedef unsigned short clock_time_t;
|
typedef unsigned short clock_time_t;
|
||||||
#define CLOCK_CONF_SECOND 100
|
#define CLOCK_CONF_SECOND 100
|
||||||
#define F_CPU 2457600uL // CPU target speed in Hz
|
#define F_CPU 2457600uL // CPU target speed in Hz
|
||||||
|
|
||||||
#define BAUD2UBR(baud) (F_CPU/(baud))
|
#define BAUD2UBR(baud) (F_CPU/(baud))
|
||||||
|
|
||||||
#include "ctk/ctk-vncarch.h"
|
#include "ctk/ctk-vncarch.h"
|
||||||
|
|
||||||
#define LOG_CONF_ENABLED 0
|
#define LOG_CONF_ENABLED 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The statistics data type.
|
* The statistics data type.
|
||||||
*
|
*
|
||||||
* This datatype determines how high the statistics counters are able
|
* This datatype determines how high the statistics counters are able
|
||||||
* to count.
|
* to count.
|
||||||
*/
|
*/
|
||||||
typedef uint16_t uip_stats_t;
|
typedef uint16_t uip_stats_t;
|
||||||
|
|
||||||
typedef int bool;
|
typedef int bool;
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||||
#define UIP_CONF_BUFFER_SIZE 140
|
#define UIP_CONF_BUFFER_SIZE 140
|
||||||
/*#define UIP_CONF_RECEIVE_WINDOW 140*/
|
/*#define UIP_CONF_RECEIVE_WINDOW 140*/
|
||||||
|
|
||||||
#define UIP_CONF_LLH_LEN 6
|
#define UIP_CONF_LLH_LEN 6
|
||||||
#define UIP_CONF_RESOLV_ENTRIES 1
|
#define UIP_CONF_RESOLV_ENTRIES 1
|
||||||
#define UIP_CONF_PINGADDRCONF 1
|
#define UIP_CONF_PINGADDRCONF 1
|
||||||
#define UIP_CONF_LOGGING 0
|
#define UIP_CONF_LOGGING 0
|
||||||
#define UIP_CONF_UDP_CONNS 6
|
#define UIP_CONF_UDP_CONNS 6
|
||||||
#define UIP_CONF_FWCACHE_SIZE 1
|
#define UIP_CONF_FWCACHE_SIZE 1
|
||||||
#define UIP_CONF_BROADCAST 1
|
#define UIP_CONF_BROADCAST 1
|
||||||
|
|
||||||
#define LOADER_CONF_ARCH "loader/loader-arch.h"
|
#define LOADER_CONF_ARCH "loader/loader-arch.h"
|
||||||
|
|
||||||
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
|
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
|
||||||
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
|
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
|
||||||
|
|
||||||
/* LEDs ports MSB430 */
|
/* LEDs ports MSB430 */
|
||||||
#define LEDS_PxDIR P5DIR
|
#define LEDS_PxDIR P5DIR
|
||||||
#define LEDS_PxOUT P5OUT
|
#define LEDS_PxOUT P5OUT
|
||||||
#define LEDS_CONF_RED 0x80
|
#define LEDS_CONF_RED 0x80
|
||||||
#define LEDS_CONF_GREEN 0x00
|
#define LEDS_CONF_GREEN 0x00
|
||||||
#define LEDS_CONF_YELLOW 0x00
|
#define LEDS_CONF_YELLOW 0x00
|
||||||
|
|
||||||
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
|
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
|
||||||
#define SD_LED_READ_OFF (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_ON SD_LED_READ_ON
|
||||||
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
|
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
|
||||||
|
|
||||||
#endif /* !CONTIKI_CONF_H */
|
#endif /* !CONTIKI_CONF_H */
|
||||||
|
|
|
@ -1,80 +1,80 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
* 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
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef __CONTIKI_MSB430_H__
|
#ifndef __CONTIKI_MSB430_H__
|
||||||
#define __CONTIKI_MSB430_H__
|
#define __CONTIKI_MSB430_H__
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "contiki-net.h"
|
#include "contiki-net.h"
|
||||||
#include "contiki-lib.h"
|
#include "contiki-lib.h"
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
#include "dev/hwconf.h"
|
#include "dev/hwconf.h"
|
||||||
#include "dev/irq.h"
|
#include "dev/irq.h"
|
||||||
#include "dev/lpm.h"
|
#include "dev/lpm.h"
|
||||||
|
|
||||||
#include "codeprop.h"
|
#include "codeprop.h"
|
||||||
|
|
||||||
#include "dev/infomem.h"
|
#include "dev/infomem.h"
|
||||||
#include "dev/msb430-uart1.h"
|
#include "dev/msb430-uart1.h"
|
||||||
#include "dev/rs232.h"
|
#include "dev/rs232.h"
|
||||||
#include "dev/sdspi.h"
|
#include "dev/sdspi.h"
|
||||||
|
|
||||||
#include "dev/serial.h"
|
#include "dev/serial.h"
|
||||||
#include "dev/slip.h"
|
#include "dev/slip.h"
|
||||||
#include "dev/cc1020.h"
|
#include "dev/cc1020.h"
|
||||||
|
|
||||||
#ifdef WITH_SDC
|
#ifdef WITH_SDC
|
||||||
#include "dev/sd/sd.h"
|
#include "dev/sd/sd.h"
|
||||||
#include "cfs/cfs-sd.h"
|
#include "cfs/cfs-sd.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "node-id.h"
|
#include "node-id.h"
|
||||||
|
|
||||||
//#include "dev/vib-sensor.h"
|
//#include "dev/vib-sensor.h"
|
||||||
//#include "dev/pir-sensor.h"
|
//#include "dev/pir-sensor.h"
|
||||||
//#include "dev/button-sensor.h"
|
//#include "dev/button-sensor.h"
|
||||||
//#include "dev/radio-sensor.h"
|
//#include "dev/radio-sensor.h"
|
||||||
//#include "dev/sound-sensor.h"
|
//#include "dev/sound-sensor.h"
|
||||||
//#include "dev/battery-sensor.h"
|
//#include "dev/battery-sensor.h"
|
||||||
//#include "dev/temperature-sensor.h"
|
//#include "dev/temperature-sensor.h"
|
||||||
//#include "dev/ctsrts-sensor.h"
|
//#include "dev/ctsrts-sensor.h"
|
||||||
//#include "dev/beep.h"
|
//#include "dev/beep.h"
|
||||||
//#include "dev/ir.h"
|
//#include "dev/ir.h"
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
|
|
||||||
#include "node-id.h"
|
#include "node-id.h"
|
||||||
|
|
||||||
#include "net/rime.h"
|
#include "net/rime.h"
|
||||||
|
|
||||||
void msp430_cpu_init(void);
|
void msp430_cpu_init(void);
|
||||||
|
|
||||||
#endif /* __CONTIKI_MSB430_H__ */
|
#endif /* __CONTIKI_MSB430_H__ */
|
||||||
|
|
|
@ -1,229 +1,229 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#define CC1020_MAIN 0x00
|
#define CC1020_MAIN 0x00
|
||||||
#define CC1020_INTERFACE 0x01
|
#define CC1020_INTERFACE 0x01
|
||||||
#define CC1020_RESET 0x02
|
#define CC1020_RESET 0x02
|
||||||
#define CC1020_SEQUENCING 0x03
|
#define CC1020_SEQUENCING 0x03
|
||||||
#define CC1020_FREQ_2A 0x04
|
#define CC1020_FREQ_2A 0x04
|
||||||
#define CC1020_FREQ_1A 0x05
|
#define CC1020_FREQ_1A 0x05
|
||||||
#define CC1020_FREQ_0A 0x06
|
#define CC1020_FREQ_0A 0x06
|
||||||
#define CC1020_CLOCK_A 0x07
|
#define CC1020_CLOCK_A 0x07
|
||||||
#define CC1020_FREQ_2B 0x08
|
#define CC1020_FREQ_2B 0x08
|
||||||
#define CC1020_FREQ_1B 0x09
|
#define CC1020_FREQ_1B 0x09
|
||||||
#define CC1020_FREQ_0B 0x0A
|
#define CC1020_FREQ_0B 0x0A
|
||||||
#define CC1020_CLOCK_B 0x0B
|
#define CC1020_CLOCK_B 0x0B
|
||||||
#define CC1020_VCO 0x0C
|
#define CC1020_VCO 0x0C
|
||||||
#define CC1020_MODEM 0x0D
|
#define CC1020_MODEM 0x0D
|
||||||
#define CC1020_DEVIATION 0x0E
|
#define CC1020_DEVIATION 0x0E
|
||||||
#define CC1020_AFC_CONTROL 0x0F
|
#define CC1020_AFC_CONTROL 0x0F
|
||||||
#define CC1020_FILTER 0x10
|
#define CC1020_FILTER 0x10
|
||||||
#define CC1020_VGA1 0x11
|
#define CC1020_VGA1 0x11
|
||||||
#define CC1020_VGA2 0x12
|
#define CC1020_VGA2 0x12
|
||||||
#define CC1020_VGA3 0x13
|
#define CC1020_VGA3 0x13
|
||||||
#define CC1020_VGA4 0x14
|
#define CC1020_VGA4 0x14
|
||||||
#define CC1020_LOCK 0x15
|
#define CC1020_LOCK 0x15
|
||||||
#define CC1020_FRONTEND 0x16
|
#define CC1020_FRONTEND 0x16
|
||||||
#define CC1020_ANALOG 0x17
|
#define CC1020_ANALOG 0x17
|
||||||
#define CC1020_BUFF_SWING 0x18
|
#define CC1020_BUFF_SWING 0x18
|
||||||
#define CC1020_BUFF_CURRENT 0x19
|
#define CC1020_BUFF_CURRENT 0x19
|
||||||
#define CC1020_PLL_BW 0x1A
|
#define CC1020_PLL_BW 0x1A
|
||||||
#define CC1020_CALIBRATE 0x1B
|
#define CC1020_CALIBRATE 0x1B
|
||||||
#define CC1020_PA_POWER 0x1C
|
#define CC1020_PA_POWER 0x1C
|
||||||
#define CC1020_MATCH 0x1D
|
#define CC1020_MATCH 0x1D
|
||||||
#define CC1020_PHASE_COMP 0x1E
|
#define CC1020_PHASE_COMP 0x1E
|
||||||
#define CC1020_GAIN_COMP 0x1F
|
#define CC1020_GAIN_COMP 0x1F
|
||||||
#define CC1020_POWERDOWN 0x20
|
#define CC1020_POWERDOWN 0x20
|
||||||
#define CC1020_TEST1 0x21
|
#define CC1020_TEST1 0x21
|
||||||
#define CC1020_TEST2 0x22
|
#define CC1020_TEST2 0x22
|
||||||
#define CC1020_TEST3 0x23
|
#define CC1020_TEST3 0x23
|
||||||
#define CC1020_TEST4 0x24
|
#define CC1020_TEST4 0x24
|
||||||
#define CC1020_TEST5 0x25
|
#define CC1020_TEST5 0x25
|
||||||
#define CC1020_TEST6 0x26
|
#define CC1020_TEST6 0x26
|
||||||
#define CC1020_TEST7 0x27
|
#define CC1020_TEST7 0x27
|
||||||
#define CC1020_STATUS 0x40
|
#define CC1020_STATUS 0x40
|
||||||
#define CC1020_RESET_DONE 0x41
|
#define CC1020_RESET_DONE 0x41
|
||||||
#define CC1020_RSS 0x42
|
#define CC1020_RSS 0x42
|
||||||
#define CC1020_AFC 0x43
|
#define CC1020_AFC 0x43
|
||||||
#define CC1020_GAUSS_FILTER 0x44
|
#define CC1020_GAUSS_FILTER 0x44
|
||||||
#define CC1020_STATUS1 0x45
|
#define CC1020_STATUS1 0x45
|
||||||
#define CC1020_STATUS2 0x46
|
#define CC1020_STATUS2 0x46
|
||||||
#define CC1020_STATUS3 0x47
|
#define CC1020_STATUS3 0x47
|
||||||
#define CC1020_STATUS4 0x48
|
#define CC1020_STATUS4 0x48
|
||||||
#define CC1020_STATUS5 0x49
|
#define CC1020_STATUS5 0x49
|
||||||
#define CC1020_STATUS6 0x4A
|
#define CC1020_STATUS6 0x4A
|
||||||
#define CC1020_STATUS7 0x4B
|
#define CC1020_STATUS7 0x4B
|
||||||
|
|
||||||
// For CC1020_STATUS
|
// For CC1020_STATUS
|
||||||
#define LOCK_CONTINUOUS 0x10
|
#define LOCK_CONTINUOUS 0x10
|
||||||
#define CAL_COMPLETE 0x80
|
#define CAL_COMPLETE 0x80
|
||||||
#define PA_POWER 0x0F // initial default for output power
|
#define PA_POWER 0x0F // initial default for output power
|
||||||
#define LOCK_NOK 0x00
|
#define LOCK_NOK 0x00
|
||||||
#define LOCK_OK 0x01
|
#define LOCK_OK 0x01
|
||||||
#define LOCK_RECAL_OK 0x02
|
#define LOCK_RECAL_OK 0x02
|
||||||
#define CAL_TIMEOUT 0x7FFE
|
#define CAL_TIMEOUT 0x7FFE
|
||||||
#define LOCK_TIMEOUT 0x7FFE
|
#define LOCK_TIMEOUT 0x7FFE
|
||||||
#define RESET_TIMEOUT 0x7FFE
|
#define RESET_TIMEOUT 0x7FFE
|
||||||
#define TX_CURRENT 0x87
|
#define TX_CURRENT 0x87
|
||||||
#define RX_CURRENT 0x86
|
#define RX_CURRENT 0x86
|
||||||
|
|
||||||
// CC1020 driver configuration
|
// CC1020 driver configuration
|
||||||
#define CC1020_BUFFERSIZE 250
|
#define CC1020_BUFFERSIZE 250
|
||||||
|
|
||||||
// PDI (Data in) is on P21
|
// PDI (Data in) is on P21
|
||||||
#define PDO (P2IN & 0x01)
|
#define PDO (P2IN & 0x01)
|
||||||
|
|
||||||
// PSEL is on P30 and low active
|
// PSEL is on P30 and low active
|
||||||
#define PSEL_ON do { P3OUT &= ~0x01; } while(0)
|
#define PSEL_ON do { P3OUT &= ~0x01; } while(0)
|
||||||
#define PSEL_OFF do { P3OUT |= 0x01; } while(0)
|
#define PSEL_OFF do { P3OUT |= 0x01; } while(0)
|
||||||
#define PCLK_HIGH do { P2OUT |= 0x08; } while(0)
|
#define PCLK_HIGH do { P2OUT |= 0x08; } while(0)
|
||||||
#define PCLK_LOW do { P2OUT &= ~0x08; } while(0)
|
#define PCLK_LOW do { P2OUT &= ~0x08; } while(0)
|
||||||
|
|
||||||
// PDO (Data out) is on P22
|
// PDO (Data out) is on P22
|
||||||
#define PDI_HIGH do { P2OUT |= 0x02; } while(0)
|
#define PDI_HIGH do { P2OUT |= 0x02; } while(0)
|
||||||
|
|
||||||
#define PDI_LOW do { P2OUT &= ~0x02; } while(0)
|
#define PDI_LOW do { P2OUT &= ~0x02; } while(0)
|
||||||
|
|
||||||
// Enable power for LNA (P24, low-active)
|
// Enable power for LNA (P24, low-active)
|
||||||
#define LNA_POWER_ON() do { P2OUT &= ~0x10; } while(0)
|
#define LNA_POWER_ON() do { P2OUT &= ~0x10; } while(0)
|
||||||
|
|
||||||
#define LNA_POWER_OFF() do { P2OUT |= 0x10; } while(0)
|
#define LNA_POWER_OFF() do { P2OUT |= 0x10; } while(0)
|
||||||
|
|
||||||
#define CC_LOCK (P2IN & 0x04)
|
#define CC_LOCK (P2IN & 0x04)
|
||||||
|
|
||||||
#define DISABLE_RX_IRQ() \
|
#define DISABLE_RX_IRQ() \
|
||||||
do { IE1 &= ~(URXIE0); } while(0)
|
do { IE1 &= ~(URXIE0); } while(0)
|
||||||
|
|
||||||
#define ENABLE_RX_IRQ() \
|
#define ENABLE_RX_IRQ() \
|
||||||
do { IFG1 &= ~URXIFG0; IE1 |= URXIE0; } while(0)
|
do { IFG1 &= ~URXIFG0; IE1 |= URXIE0; } while(0)
|
||||||
|
|
||||||
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
|
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
|
||||||
#define ACK_TIMEOUT_19 16
|
#define ACK_TIMEOUT_19 16
|
||||||
|
|
||||||
#define MHZ_869525 1
|
#define MHZ_869525 1
|
||||||
|
|
||||||
const u8_t cc1020_config_19200[41] = {
|
const u8_t cc1020_config_19200[41] = {
|
||||||
0x01, // 0x00, MAIN
|
0x01, // 0x00, MAIN
|
||||||
0x0F, // 0x01, INTERFACE
|
0x0F, // 0x01, INTERFACE
|
||||||
0xFF, // 0x02, RESET
|
0xFF, // 0x02, RESET
|
||||||
0x8F, // 0x03, SEQUENCING
|
0x8F, // 0x03, SEQUENCING
|
||||||
// 869.525 at 50kHz
|
// 869.525 at 50kHz
|
||||||
0x3A, // 0x04, FREQ_2A
|
0x3A, // 0x04, FREQ_2A
|
||||||
0x32, // 0x05, FREQ_1A
|
0x32, // 0x05, FREQ_1A
|
||||||
0x97, // 0x06, FREQ_0A // 19200
|
0x97, // 0x06, FREQ_0A // 19200
|
||||||
0x38, // 0x07, CLOCK_A // 19200
|
0x38, // 0x07, CLOCK_A // 19200
|
||||||
0x3A, // 0x08, FREQ_2B
|
0x3A, // 0x08, FREQ_2B
|
||||||
0x37, // 0x09, FREQ_1B
|
0x37, // 0x09, FREQ_1B
|
||||||
0xEB, // 0x0A, FREQ_0B // 19200
|
0xEB, // 0x0A, FREQ_0B // 19200
|
||||||
0x38, // 0x0B, CLOCK_B // 19200
|
0x38, // 0x0B, CLOCK_B // 19200
|
||||||
0x44, // 0x0C, VCO 44
|
0x44, // 0x0C, VCO 44
|
||||||
0x51, // 0x0D, MODEM Manchester
|
0x51, // 0x0D, MODEM Manchester
|
||||||
0x2B, // 0x0E, DEVIATION // FSK
|
0x2B, // 0x0E, DEVIATION // FSK
|
||||||
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
|
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
|
||||||
0x25, // 0x10, FILTER Bandwith 100 kHz
|
0x25, // 0x10, FILTER Bandwith 100 kHz
|
||||||
0x61, // 0x11, VGA1
|
0x61, // 0x11, VGA1
|
||||||
0x55, // 0x12, VGA2
|
0x55, // 0x12, VGA2
|
||||||
0x2D, // 0x13, VGA3
|
0x2D, // 0x13, VGA3
|
||||||
0x37, // 0x14, VGA4 // 0x29, VGA4 ADJUSTED CS to 23!
|
0x37, // 0x14, VGA4 // 0x29, VGA4 ADJUSTED CS to 23!
|
||||||
0x40, // 0x15, LOCK is Carrier SENSE
|
0x40, // 0x15, LOCK is Carrier SENSE
|
||||||
0x76, // 0x16, FRONTEND
|
0x76, // 0x16, FRONTEND
|
||||||
0x87, // 0x17, ANALOG, RX=86/TX=87
|
0x87, // 0x17, ANALOG, RX=86/TX=87
|
||||||
0x10, // 0x18, BUFF_SWING
|
0x10, // 0x18, BUFF_SWING
|
||||||
0x25, // 0x19, BUFF_CURRENT
|
0x25, // 0x19, BUFF_CURRENT
|
||||||
0xAE, // 0x1A, PLL_BW
|
0xAE, // 0x1A, PLL_BW
|
||||||
0x34, // 0x1B, CALIBRATE
|
0x34, // 0x1B, CALIBRATE
|
||||||
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
|
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
|
||||||
0xF0, // 0x1D, MATCH
|
0xF0, // 0x1D, MATCH
|
||||||
0x00, // 0x1E, PHASE_COMP
|
0x00, // 0x1E, PHASE_COMP
|
||||||
0x00, // 0x1F, GAIN_COMP
|
0x00, // 0x1F, GAIN_COMP
|
||||||
0x00, // 0x20, POWERDOWN
|
0x00, // 0x20, POWERDOWN
|
||||||
0x4d, // 0x4d, // 0x21,
|
0x4d, // 0x4d, // 0x21,
|
||||||
0x10, // 0x10, // 0x22,
|
0x10, // 0x10, // 0x22,
|
||||||
0x06, // 0x06, // 0x23,
|
0x06, // 0x06, // 0x23,
|
||||||
0x00, // 0x00, // 0x24,
|
0x00, // 0x00, // 0x24,
|
||||||
0x40, // 0x40, // 0x25,
|
0x40, // 0x40, // 0x25,
|
||||||
0x00, // 0x00, // 0x26,
|
0x00, // 0x00, // 0x26,
|
||||||
0x00, // 0x00, // 0x27,
|
0x00, // 0x00, // 0x27,
|
||||||
// Not in real config of chipCon from here!!!
|
// Not in real config of chipCon from here!!!
|
||||||
ACK_TIMEOUT_19
|
ACK_TIMEOUT_19
|
||||||
};
|
};
|
||||||
|
|
||||||
const u8_t cc1020_config_115200[41] = {
|
const u8_t cc1020_config_115200[41] = {
|
||||||
0x01, // 0x00, MAIN
|
0x01, // 0x00, MAIN
|
||||||
0x0F, // 0x01, INTERFACE
|
0x0F, // 0x01, INTERFACE
|
||||||
0xFF, // 0x02, RESET
|
0xFF, // 0x02, RESET
|
||||||
0x8F, // 0x03, SEQUENCING
|
0x8F, // 0x03, SEQUENCING
|
||||||
// 869.525 at 200kHz
|
// 869.525 at 200kHz
|
||||||
0x3A, // 0x04, FREQ_2A
|
0x3A, // 0x04, FREQ_2A
|
||||||
0x32, // 0x05, FREQ_1A
|
0x32, // 0x05, FREQ_1A
|
||||||
0x97, // 0x06, FREQ_0A // 19200
|
0x97, // 0x06, FREQ_0A // 19200
|
||||||
0x29, // 0x07, CLOCK_A // 19200
|
0x29, // 0x07, CLOCK_A // 19200
|
||||||
0x3A, // 0x08, FREQ_2B
|
0x3A, // 0x08, FREQ_2B
|
||||||
0x37, // 0x09, FREQ_1B
|
0x37, // 0x09, FREQ_1B
|
||||||
0xEB, // 0x0A, FREQ_0B // 19200
|
0xEB, // 0x0A, FREQ_0B // 19200
|
||||||
0x29, // 0x0B, CLOCK_B // 19200
|
0x29, // 0x0B, CLOCK_B // 19200
|
||||||
0x44, // 0x0C, VCO 44
|
0x44, // 0x0C, VCO 44
|
||||||
0x51, // 0x0D, MODEM Manchester
|
0x51, // 0x0D, MODEM Manchester
|
||||||
0x58, // 0x0E, DEVIATION // FSK
|
0x58, // 0x0E, DEVIATION // FSK
|
||||||
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
|
0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
|
||||||
0x80, // 0x10, FILTER Bandwith 500 kHz
|
0x80, // 0x10, FILTER Bandwith 500 kHz
|
||||||
0x61, // 0x11, VGA1
|
0x61, // 0x11, VGA1
|
||||||
0x55, // 0x12, VGA2
|
0x55, // 0x12, VGA2
|
||||||
0x30, // 0x13, VGA3
|
0x30, // 0x13, VGA3
|
||||||
0x35, // 0x14, VGA4
|
0x35, // 0x14, VGA4
|
||||||
0x20, // 0x15, LOCK is Carrier SENSE
|
0x20, // 0x15, LOCK is Carrier SENSE
|
||||||
0x76, // 0x16, FRONTEND
|
0x76, // 0x16, FRONTEND
|
||||||
0x87, // 0x17, ANALOG, RX=86/TX=87
|
0x87, // 0x17, ANALOG, RX=86/TX=87
|
||||||
0x10, // 0x18, BUFF_SWING
|
0x10, // 0x18, BUFF_SWING
|
||||||
0x25, // 0x19, BUFF_CURRENT
|
0x25, // 0x19, BUFF_CURRENT
|
||||||
0xAE, // 0x1A, PLL_BW
|
0xAE, // 0x1A, PLL_BW
|
||||||
0x34, // 0x1B, CALIBRATE
|
0x34, // 0x1B, CALIBRATE
|
||||||
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
|
PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
|
||||||
0xF0, // 0x1D, MATCH
|
0xF0, // 0x1D, MATCH
|
||||||
0x00, // 0x1E, PHASE_COMP
|
0x00, // 0x1E, PHASE_COMP
|
||||||
0x00, // 0x1F, GAIN_COMP
|
0x00, // 0x1F, GAIN_COMP
|
||||||
0x00, // 0x20, POWERDOWN
|
0x00, // 0x20, POWERDOWN
|
||||||
0x4d, // 0x21,
|
0x4d, // 0x21,
|
||||||
0x10, // 0x22,
|
0x10, // 0x22,
|
||||||
0x06, // 0x23,
|
0x06, // 0x23,
|
||||||
0x00, // 0x24,
|
0x00, // 0x24,
|
||||||
0x40, // 0x25,
|
0x40, // 0x25,
|
||||||
0x00, // 0x26,
|
0x00, // 0x26,
|
||||||
0x00, // 0x27,
|
0x00, // 0x27,
|
||||||
// Not in real config of chipCon from here!!!
|
// Not in real config of chipCon from here!!!
|
||||||
ACK_TIMEOUT_115
|
ACK_TIMEOUT_115
|
||||||
};
|
};
|
||||||
|
|
||||||
/// cc1020 state
|
/// cc1020 state
|
||||||
enum cc1020_state {
|
enum cc1020_state {
|
||||||
CC1020_OFF,
|
CC1020_OFF,
|
||||||
CC1020_RX,
|
CC1020_RX,
|
||||||
CC1020_TX
|
CC1020_TX
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* @name Packet specification
|
* @name Packet specification
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const u8_t syncword[2] = {0xD3,0x91};
|
const u8_t syncword[2] = {0xD3,0x91};
|
||||||
__attribute__((packed))
|
__attribute__((packed))
|
||||||
struct cc1020_header {
|
struct cc1020_header {
|
||||||
u8_t length; // header: number of bytes in packet including header
|
u8_t length; // header: number of bytes in packet including header
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PREAMBLESIZE 6
|
#define PREAMBLESIZE 6
|
||||||
#define PREAMBLE 0xAA
|
#define PREAMBLE 0xAA
|
||||||
#define TAILSIZE 2
|
#define TAILSIZE 2
|
||||||
#define TAIL 0xFA
|
#define TAIL 0xFA
|
||||||
|
|
||||||
#define SYNCWDSIZE (sizeof (syncword))
|
#define SYNCWDSIZE (sizeof (syncword))
|
||||||
#define HDRSIZE (sizeof (struct cc1020_header))
|
#define HDRSIZE (sizeof (struct cc1020_header))
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/// cc1020 receiver state
|
/// cc1020 receiver state
|
||||||
enum cc1020_rxstate {
|
enum cc1020_rxstate {
|
||||||
CC1020_RX_SEARCHING, // searching for preamble + sync word
|
CC1020_RX_SEARCHING, // searching for preamble + sync word
|
||||||
CC1020_RX_RECEIVE, // receiving bytes
|
CC1020_RX_RECEIVE, // receiving bytes
|
||||||
CC1020_RX_PROCESSING // processing data in buffer
|
CC1020_RX_PROCESSING // processing data in buffer
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,97 +1,97 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
|
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
|
||||||
|
|
||||||
These sources were developed at the Freie Universität Berlin, Computer
|
These sources were developed at the Freie Universität Berlin, Computer
|
||||||
Systems and Telematics group.
|
Systems and Telematics group.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
met:
|
met:
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
- Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
- Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
This software is provided by FUB and the contributors on an "as is"
|
This software is provided by FUB and the contributors on an "as is"
|
||||||
basis, without any representations or warranties of any kind, express
|
basis, without any representations or warranties of any kind, express
|
||||||
or implied including, but not limited to, representations or
|
or implied including, but not limited to, representations or
|
||||||
warranties of non-infringement, merchantability or fitness for a
|
warranties of non-infringement, merchantability or fitness for a
|
||||||
particular purpose. In no event shall FUB or contributors be liable
|
particular purpose. In no event shall FUB or contributors be liable
|
||||||
for any direct, indirect, incidental, special, exemplary, or
|
for any direct, indirect, incidental, special, exemplary, or
|
||||||
consequential damages (including, but not limited to, procurement of
|
consequential damages (including, but not limited to, procurement of
|
||||||
substitute goods or services; loss of use, data, or profits; or
|
substitute goods or services; loss of use, data, or profits; or
|
||||||
business interruption) however caused and on any theory of liability,
|
business interruption) however caused and on any theory of liability,
|
||||||
whether in contract, strict liability, or tort (including negligence
|
whether in contract, strict liability, or tort (including negligence
|
||||||
or otherwise) arising in any way out of the use of this software, even
|
or otherwise) arising in any way out of the use of this software, even
|
||||||
if advised of the possibility of such damage.
|
if advised of the possibility of such damage.
|
||||||
|
|
||||||
This implementation was developed by the CST group at the FUB.
|
This implementation was developed by the CST group at the FUB.
|
||||||
|
|
||||||
For documentation and questions please use the web site
|
For documentation and questions please use the web site
|
||||||
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
||||||
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
||||||
Berlin, 2006
|
Berlin, 2006
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file cc1020.h
|
* @file cc1020.h
|
||||||
* @author FUB ScatterWeb Developers, Michael Baar, Nicolas Tsiftes
|
* @author FUB ScatterWeb Developers, Michael Baar, Nicolas Tsiftes
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#ifndef CC1020_H
|
#ifndef CC1020_H
|
||||||
#define CC1020_H
|
#define CC1020_H
|
||||||
|
|
||||||
#include "dev/radio.h"
|
#include "dev/radio.h"
|
||||||
|
|
||||||
enum cc1020_power_mode {
|
enum cc1020_power_mode {
|
||||||
CC1020_ALWAYS_ON
|
CC1020_ALWAYS_ON
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const u8_t cc1020_config_19200[];
|
extern const u8_t cc1020_config_19200[];
|
||||||
extern const u8_t cc1020_config_115200[];
|
extern const u8_t cc1020_config_115200[];
|
||||||
|
|
||||||
void cc1020_init(const u8_t* config);
|
void cc1020_init(const u8_t* config);
|
||||||
|
|
||||||
int cc1020_on(void);
|
int cc1020_on(void);
|
||||||
|
|
||||||
void cc1020_set_rx(void);
|
void cc1020_set_rx(void);
|
||||||
|
|
||||||
void cc1020_set_tx(void);
|
void cc1020_set_tx(void);
|
||||||
|
|
||||||
void cc1020_off(void);
|
void cc1020_off(void);
|
||||||
|
|
||||||
void cc1020_set_receiver(void (*recv)(void));
|
void cc1020_set_receiver(void (*recv)(void));
|
||||||
|
|
||||||
void cc1020_set_power_mode(enum cc1020_power_mode mode);
|
void cc1020_set_power_mode(enum cc1020_power_mode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set output power amplifier power-
|
* @brief Set output power amplifier power-
|
||||||
*
|
*
|
||||||
* For good values see CC1020 documentation.
|
* For good values see CC1020 documentation.
|
||||||
*/
|
*/
|
||||||
void cc1020_set_power(u8_t pa_power);
|
void cc1020_set_power(u8_t pa_power);
|
||||||
|
|
||||||
unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
|
unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get RSSI of last received packet
|
* @brief Get RSSI of last received packet
|
||||||
*
|
*
|
||||||
* Best to call in packet handler
|
* Best to call in packet handler
|
||||||
*/
|
*/
|
||||||
u8_t cc1020_get_rssi(void);
|
u8_t cc1020_get_rssi(void);
|
||||||
|
|
||||||
unsigned int cc1020_send(u8_t *buf, unsigned int bufsize);
|
unsigned int cc1020_send(u8_t *buf, unsigned int bufsize);
|
||||||
|
|
||||||
extern const struct radio_driver cc1020_driver;
|
extern const struct radio_driver cc1020_driver;
|
||||||
|
|
||||||
PROCESS_NAME(cc1020_sender_process);
|
PROCESS_NAME(cc1020_sender_process);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,121 +1,121 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
||||||
|
|
||||||
These sources were developed at the Freie Universität Berlin, Computer
|
These sources were developed at the Freie Universität Berlin, Computer
|
||||||
Systems and Telematics group.
|
Systems and Telematics group.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
met:
|
met:
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
- Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
- Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
This software is provided by FUB and the contributors on an "as is"
|
This software is provided by FUB and the contributors on an "as is"
|
||||||
basis, without any representations or warranties of any kind, express
|
basis, without any representations or warranties of any kind, express
|
||||||
or implied including, but not limited to, representations or
|
or implied including, but not limited to, representations or
|
||||||
warranties of non-infringement, merchantability or fitness for a
|
warranties of non-infringement, merchantability or fitness for a
|
||||||
particular purpose. In no event shall FUB or contributors be liable
|
particular purpose. In no event shall FUB or contributors be liable
|
||||||
for any direct, indirect, incidental, special, exemplary, or
|
for any direct, indirect, incidental, special, exemplary, or
|
||||||
consequential damages (including, but not limited to, procurement of
|
consequential damages (including, but not limited to, procurement of
|
||||||
substitute goods or services; loss of use, data, or profits; or
|
substitute goods or services; loss of use, data, or profits; or
|
||||||
business interruption) however caused and on any theory of liability,
|
business interruption) however caused and on any theory of liability,
|
||||||
whether in contract, strict liability, or tort (including negligence
|
whether in contract, strict liability, or tort (including negligence
|
||||||
or otherwise) arising in any way out of the use of this software, even
|
or otherwise) arising in any way out of the use of this software, even
|
||||||
if advised of the possibility of such damage.
|
if advised of the possibility of such damage.
|
||||||
|
|
||||||
This implementation was developed by the CST group at the FUB.
|
This implementation was developed by the CST group at the FUB.
|
||||||
|
|
||||||
For documentation and questions please use the web site
|
For documentation and questions please use the web site
|
||||||
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
||||||
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
||||||
Berlin, 2007
|
Berlin, 2007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file infomem.c
|
* @file infomem.c
|
||||||
* @addtogroup storage
|
* @addtogroup storage
|
||||||
* @brief MSP430 Infomemory Storage
|
* @brief MSP430 Infomemory Storage
|
||||||
* @author Michael Baar <baar@inf.fu-berlin.de>
|
* @author Michael Baar <baar@inf.fu-berlin.de>
|
||||||
*
|
*
|
||||||
* Functions to store and read data from the two infomemories (2 x 128 Bytes).
|
* 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
|
* Offset addresses start at zero, size has a maximum of 128, write operations
|
||||||
* across both blocks are not allowed.
|
* across both blocks are not allowed.
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
#include <msp430/flash.h>
|
#include <msp430/flash.h>
|
||||||
#include "infomem.h"
|
#include "infomem.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
infomem_read(void *buffer, unsigned int offset, unsigned char size)
|
infomem_read(void *buffer, unsigned int offset, unsigned char size)
|
||||||
{
|
{
|
||||||
uint8_t *address = (uint8_t *) INFOMEM_START + offset;
|
uint8_t *address = (uint8_t *) INFOMEM_START + offset;
|
||||||
memcpy(buffer, address, size);
|
memcpy(buffer, address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
infomem_write(unsigned int offset, unsigned char count, ...)
|
infomem_write(unsigned int offset, unsigned char count, ...)
|
||||||
{
|
{
|
||||||
char backup[INFOMEM_BLOCK_SIZE];
|
char backup[INFOMEM_BLOCK_SIZE];
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint8_t *flash;
|
uint8_t *flash;
|
||||||
va_list argp;
|
va_list argp;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
|
|
||||||
if (offset > (2 * INFOMEM_BLOCK_SIZE))
|
if (offset > (2 * INFOMEM_BLOCK_SIZE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
flash = (uint8_t *) INFOMEM_START + offset;
|
flash = (uint8_t *) INFOMEM_START + offset;
|
||||||
|
|
||||||
_DINT();
|
_DINT();
|
||||||
|
|
||||||
// backup into RAM
|
// backup into RAM
|
||||||
memcpy(backup, flash, INFOMEM_BLOCK_SIZE);
|
memcpy(backup, flash, INFOMEM_BLOCK_SIZE);
|
||||||
|
|
||||||
// merge backup with new data
|
// merge backup with new data
|
||||||
va_start(argp, count);
|
va_start(argp, count);
|
||||||
|
|
||||||
buffer = (uint8_t *) backup;
|
buffer = (uint8_t *) backup;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
data = va_arg(argp, uint8_t*);
|
data = va_arg(argp, uint8_t*);
|
||||||
size = va_arg(argp, uint16_t);
|
size = va_arg(argp, uint16_t);
|
||||||
memcpy(buffer, data, size);
|
memcpy(buffer, data, size);
|
||||||
buffer += size;
|
buffer += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
// init flash access
|
// init flash access
|
||||||
FCTL2 = FWKEY + FSSEL1 + FN2;
|
FCTL2 = FWKEY + FSSEL1 + FN2;
|
||||||
FCTL3 = FWKEY;
|
FCTL3 = FWKEY;
|
||||||
|
|
||||||
// erase flash
|
// erase flash
|
||||||
FCTL1 = FWKEY + ERASE;
|
FCTL1 = FWKEY + ERASE;
|
||||||
*flash = 0;
|
*flash = 0;
|
||||||
|
|
||||||
// write flash
|
// write flash
|
||||||
FCTL1 = FWKEY + WRT;
|
FCTL1 = FWKEY + WRT;
|
||||||
buffer = (uint8_t *) backup;
|
buffer = (uint8_t *) backup;
|
||||||
for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) {
|
for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) {
|
||||||
*flash++ = *buffer++;
|
*flash++ = *buffer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
FCTL1 = FWKEY;
|
FCTL1 = FWKEY;
|
||||||
FCTL3 = FWKEY + LOCK;
|
FCTL3 = FWKEY + LOCK;
|
||||||
|
|
||||||
_EINT();
|
_EINT();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,82 +1,82 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
|
Copyright 2006, Freie Universitaet Berlin. All rights reserved.
|
||||||
|
|
||||||
These sources were developed at the Freie Universität Berlin, Computer
|
These sources were developed at the Freie Universität Berlin, Computer
|
||||||
Systems and Telematics group.
|
Systems and Telematics group.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
met:
|
met:
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
- Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
- Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
This software is provided by FUB and the contributors on an "as is"
|
This software is provided by FUB and the contributors on an "as is"
|
||||||
basis, without any representations or warranties of any kind, express
|
basis, without any representations or warranties of any kind, express
|
||||||
or implied including, but not limited to, representations or
|
or implied including, but not limited to, representations or
|
||||||
warranties of non-infringement, merchantability or fitness for a
|
warranties of non-infringement, merchantability or fitness for a
|
||||||
particular purpose. In no event shall FUB or contributors be liable
|
particular purpose. In no event shall FUB or contributors be liable
|
||||||
for any direct, indirect, incidental, special, exemplary, or
|
for any direct, indirect, incidental, special, exemplary, or
|
||||||
consequential damages (including, but not limited to, procurement of
|
consequential damages (including, but not limited to, procurement of
|
||||||
substitute goods or services; loss of use, data, or profits; or
|
substitute goods or services; loss of use, data, or profits; or
|
||||||
business interruption) however caused and on any theory of liability,
|
business interruption) however caused and on any theory of liability,
|
||||||
whether in contract, strict liability, or tort (including negligence
|
whether in contract, strict liability, or tort (including negligence
|
||||||
or otherwise) arising in any way out of the use of this software, even
|
or otherwise) arising in any way out of the use of this software, even
|
||||||
if advised of the possibility of such damage.
|
if advised of the possibility of such damage.
|
||||||
|
|
||||||
This implementation was developed by the CST group at the FUB.
|
This implementation was developed by the CST group at the FUB.
|
||||||
|
|
||||||
For documentation and questions please use the web site
|
For documentation and questions please use the web site
|
||||||
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
||||||
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
||||||
Berlin, 2006
|
Berlin, 2006
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file infomem.h
|
* @file infomem.h
|
||||||
* @addtogroup storage
|
* @addtogroup storage
|
||||||
* @brief MSP430 Infomemory Storage
|
* @brief MSP430 Infomemory Storage
|
||||||
*
|
*
|
||||||
* @author Michael Baar <baar@inf.fu-berlin.de>
|
* @author Michael Baar <baar@inf.fu-berlin.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INFOMEM_H
|
#ifndef INFOMEM_H
|
||||||
#define INFOMEM_H
|
#define INFOMEM_H
|
||||||
|
|
||||||
#if !defined(INFOMEM_START) || !defined(INFOMEM_BLOCK_SIZE)
|
#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"
|
#error "infomem position (INFOMEM_START) and block size (INFOMEM_BLOCK_SIZE) need to be defined for the platform"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read bytes from infomemory
|
* @brief Read bytes from infomemory
|
||||||
* @param[out] buffer Pointer to buffer for read data
|
* @param[out] buffer Pointer to buffer for read data
|
||||||
* @param[in] offset Offset in infomemory (0-254)
|
* @param[in] offset Offset in infomemory (0-254)
|
||||||
* @param[in] size Number of bytes to read
|
* @param[in] size Number of bytes to read
|
||||||
*/
|
*/
|
||||||
void infomem_read(void *buffer, unsigned int offset, unsigned char size);
|
void infomem_read(void *buffer, unsigned int offset, unsigned char size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Write bytes to infomemory
|
* @brief Write bytes to infomemory
|
||||||
* @param[in] offset Offset in infomemory (0-254)
|
* @param[in] offset Offset in infomemory (0-254)
|
||||||
* @param[in] count Number of items following
|
* @param[in] count Number of items following
|
||||||
* each item is a pair pointer, length
|
* each item is a pair pointer, length
|
||||||
*
|
*
|
||||||
* Example: Infomem_write( 0, 2, &a,3, &b,1 );
|
* Example: Infomem_write( 0, 2, &a,3, &b,1 );
|
||||||
*
|
*
|
||||||
* \note: The MSP430 has two consecutive blocks of infomemory.
|
* \note: The MSP430 has two consecutive blocks of infomemory.
|
||||||
* Each is 128 bytes large. The offset is the relative address
|
* Each is 128 bytes large. The offset is the relative address
|
||||||
* starting at the beginning of the first block. You can write an
|
* starting at the beginning of the first block. You can write an
|
||||||
* arbitrary number of bytes at any offset, but this function
|
* arbitrary number of bytes at any offset, but this function
|
||||||
* cannot write across the two blocks of infomemory.
|
* cannot write across the two blocks of infomemory.
|
||||||
*/
|
*/
|
||||||
bool infomem_write(unsigned int offset, unsigned char count, ...);
|
bool infomem_write(unsigned int offset, unsigned char count, ...);
|
||||||
|
|
||||||
#endif // !INFOMEM_H
|
#endif // !INFOMEM_H
|
||||||
|
|
|
@ -1,203 +1,203 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
||||||
|
|
||||||
These sources were developed at the Freie Universität Berlin, Computer
|
These sources were developed at the Freie Universität Berlin, Computer
|
||||||
Systems and Telematics group.
|
Systems and Telematics group.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
met:
|
met:
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
- Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
- Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
This software is provided by FUB and the contributors on an "as is"
|
This software is provided by FUB and the contributors on an "as is"
|
||||||
basis, without any representations or warranties of any kind, express
|
basis, without any representations or warranties of any kind, express
|
||||||
or implied including, but not limited to, representations or
|
or implied including, but not limited to, representations or
|
||||||
warranties of non-infringement, merchantability or fitness for a
|
warranties of non-infringement, merchantability or fitness for a
|
||||||
particular purpose. In no event shall FUB or contributors be liable
|
particular purpose. In no event shall FUB or contributors be liable
|
||||||
for any direct, indirect, incidental, special, exemplary, or
|
for any direct, indirect, incidental, special, exemplary, or
|
||||||
consequential damages (including, but not limited to, procurement of
|
consequential damages (including, but not limited to, procurement of
|
||||||
substitute goods or services; loss of use, data, or profits; or
|
substitute goods or services; loss of use, data, or profits; or
|
||||||
business interruption) however caused and on any theory of liability,
|
business interruption) however caused and on any theory of liability,
|
||||||
whether in contract, strict liability, or tort (including negligence
|
whether in contract, strict liability, or tort (including negligence
|
||||||
or otherwise) arising in any way out of the use of this software, even
|
or otherwise) arising in any way out of the use of this software, even
|
||||||
if advised of the possibility of such damage.
|
if advised of the possibility of such damage.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file UART interface
|
* \file UART interface
|
||||||
* \author Michael Baar <baar@inf.fu-berlin.de>
|
* \author Michael Baar <baar@inf.fu-berlin.de>
|
||||||
*
|
*
|
||||||
* UART switch for RS232 and SPI protocols on UART1 written for
|
* UART switch for RS232 and SPI protocols on UART1 written for
|
||||||
* ScatterWeb MSB boards. Compatible to ScatterWeb EOS,
|
* ScatterWeb MSB boards. Compatible to ScatterWeb EOS,
|
||||||
* ScatterWeb Bootload and Contiki.
|
* ScatterWeb Bootload and Contiki.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "dev/msb430-uart1.h"
|
#include "dev/msb430-uart1.h"
|
||||||
#include "msp430.h"
|
#include "msp430.h"
|
||||||
#include "dev/lpm.h"
|
#include "dev/lpm.h"
|
||||||
|
|
||||||
#ifndef U1ME
|
#ifndef U1ME
|
||||||
#define U1ME ME2
|
#define U1ME ME2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void uart_configure(unsigned char mode);
|
static void uart_configure(unsigned char mode);
|
||||||
static void uart_set_mode(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_mode = UART_MODE_RESET;
|
||||||
static volatile unsigned char uart_lockcnt;
|
static volatile unsigned char uart_lockcnt;
|
||||||
|
|
||||||
static unsigned char uart_speed_br0[UART_NUM_MODES];
|
static unsigned char uart_speed_br0[UART_NUM_MODES];
|
||||||
static unsigned char uart_speed_br1[UART_NUM_MODES];
|
static unsigned char uart_speed_br1[UART_NUM_MODES];
|
||||||
static unsigned char uart_speed_bmn[UART_NUM_MODES];
|
static unsigned char uart_speed_bmn[UART_NUM_MODES];
|
||||||
static fp_uart_handler uart_handler[UART_NUM_MODES];
|
static fp_uart_handler uart_handler[UART_NUM_MODES];
|
||||||
|
|
||||||
void
|
void
|
||||||
uart_set_speed(unsigned char mode, unsigned char ubr0,
|
uart_set_speed(unsigned char mode, unsigned char ubr0,
|
||||||
unsigned char ubr1, unsigned char umctl)
|
unsigned char ubr1, unsigned char umctl)
|
||||||
{
|
{
|
||||||
// store setting
|
// store setting
|
||||||
uart_speed_br0[mode] = ubr0; // baudrate
|
uart_speed_br0[mode] = ubr0; // baudrate
|
||||||
uart_speed_br1[mode] = ubr1; // baudrate
|
uart_speed_br1[mode] = ubr1; // baudrate
|
||||||
uart_speed_bmn[mode] = umctl; // modulation
|
uart_speed_bmn[mode] = umctl; // modulation
|
||||||
|
|
||||||
// reconfigure, if mode active
|
// reconfigure, if mode active
|
||||||
if (uart_mode == mode)
|
if (uart_mode == mode)
|
||||||
uart_configure(mode);
|
uart_configure(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
|
uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
|
||||||
{
|
{
|
||||||
// store setting
|
// store setting
|
||||||
uart_handler[mode] = fpHandler;
|
uart_handler[mode] = fpHandler;
|
||||||
if (mode == uart_mode) {
|
if (mode == uart_mode) {
|
||||||
if (fpHandler == NULL)
|
if (fpHandler == NULL)
|
||||||
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
|
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
|
||||||
else
|
else
|
||||||
IE2 |= URXIE1; // Enable USART1 RX interrupt
|
IE2 |= URXIE1; // Enable USART1 RX interrupt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uart_lock(unsigned char mode)
|
uart_lock(unsigned char mode)
|
||||||
{
|
{
|
||||||
// already locked?
|
// already locked?
|
||||||
if ((mode != uart_mode) && (uart_lockcnt)) {
|
if ((mode != uart_mode) && (uart_lockcnt)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// increase lock count
|
// increase lock count
|
||||||
uart_lockcnt++;
|
uart_lockcnt++;
|
||||||
// switch mode (if neccessary)
|
// switch mode (if neccessary)
|
||||||
uart_set_mode(mode);
|
uart_set_mode(mode);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uart_unlock(unsigned char mode)
|
uart_unlock(unsigned char mode)
|
||||||
{
|
{
|
||||||
/* Strict checking. */
|
/* Strict checking. */
|
||||||
if (mode != uart_mode)
|
if (mode != uart_mode)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// decrement lock
|
// decrement lock
|
||||||
if (uart_lockcnt > 0) {
|
if (uart_lockcnt > 0) {
|
||||||
uart_lockcnt--;
|
uart_lockcnt--;
|
||||||
|
|
||||||
// if no more locks, switch back to default mode
|
// if no more locks, switch back to default mode
|
||||||
if (uart_lockcnt == 0) {
|
if (uart_lockcnt == 0) {
|
||||||
uart_set_mode(UART_MODE_DEFAULT);
|
uart_set_mode(UART_MODE_DEFAULT);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
uart_configure(unsigned char mode)
|
uart_configure(unsigned char mode)
|
||||||
{
|
{
|
||||||
_DINT();
|
_DINT();
|
||||||
|
|
||||||
UART_WAIT_TXDONE();
|
UART_WAIT_TXDONE();
|
||||||
|
|
||||||
// configure
|
// configure
|
||||||
if (mode == UART_MODE_RS232) {
|
if (mode == UART_MODE_RS232) {
|
||||||
P5OUT |= 0x01;
|
P5OUT |= 0x01;
|
||||||
// unselect SPI
|
// unselect SPI
|
||||||
P3SEL |= 0xC0;
|
P3SEL |= 0xC0;
|
||||||
// select rs232 to RS232 mode
|
// select rs232 to RS232 mode
|
||||||
UCTL1 = SWRST | CHAR; // 8-bit character
|
UCTL1 = SWRST | CHAR; // 8-bit character
|
||||||
UTCTL1 |= SSEL1; // UCLK = MCLK
|
UTCTL1 |= SSEL1; // UCLK = MCLK
|
||||||
// activate
|
// activate
|
||||||
U1ME |= UTXE1 | URXE1; // Enable USART1 TXD/RXD
|
U1ME |= UTXE1 | URXE1; // Enable USART1 TXD/RXD
|
||||||
} else if( mode == UART_MODE_SPI ) {
|
} else if( mode == UART_MODE_SPI ) {
|
||||||
P3SEL &= ~0xC0; // unselect RS232
|
P3SEL &= ~0xC0; // unselect RS232
|
||||||
// to SPI mode
|
// to SPI mode
|
||||||
UCTL1 = SWRST | CHAR | SYNC | MM; // 8-bit SPI Master
|
UCTL1 = SWRST | CHAR | SYNC | MM; // 8-bit SPI Master
|
||||||
/*
|
/*
|
||||||
* SMCLK, 3-pin mode, clock idle low, data valid on
|
* SMCLK, 3-pin mode, clock idle low, data valid on
|
||||||
* rising edge, UCLK delayed
|
* rising edge, UCLK delayed
|
||||||
*/
|
*/
|
||||||
UTCTL1 |= CKPH | SSEL1 | SSEL0 | STC; // activate
|
UTCTL1 |= CKPH | SSEL1 | SSEL0 | STC; // activate
|
||||||
U1ME |= USPIE1; // Enable USART1 SPI
|
U1ME |= USPIE1; // Enable USART1 SPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore speed settings
|
// restore speed settings
|
||||||
UBR01 = uart_speed_br0[mode]; // set baudrate
|
UBR01 = uart_speed_br0[mode]; // set baudrate
|
||||||
UBR11 = uart_speed_br1[mode];
|
UBR11 = uart_speed_br1[mode];
|
||||||
UMCTL1 = uart_speed_bmn[mode]; // set modulation
|
UMCTL1 = uart_speed_bmn[mode]; // set modulation
|
||||||
|
|
||||||
UCTL1 &= ~SWRST; // clear reset flag
|
UCTL1 &= ~SWRST; // clear reset flag
|
||||||
_EINT(); // enable interrupts
|
_EINT(); // enable interrupts
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
uart_set_mode(unsigned char mode)
|
uart_set_mode(unsigned char mode)
|
||||||
{
|
{
|
||||||
// do nothing if mode already set
|
// do nothing if mode already set
|
||||||
if (mode == uart_mode )
|
if (mode == uart_mode )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IE2 &= ~(URXIE1 | UTXIE1); // disable irq
|
IE2 &= ~(URXIE1 | UTXIE1); // disable irq
|
||||||
uart_configure(mode); // configure uart parameters
|
uart_configure(mode); // configure uart parameters
|
||||||
uart_mode = mode;
|
uart_mode = mode;
|
||||||
|
|
||||||
if (uart_handler[mode] != NULL)
|
if (uart_handler[mode] != NULL)
|
||||||
IE2 |= URXIE1; // Enable USART1 RX interrupt
|
IE2 |= URXIE1; // Enable USART1 RX interrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
interrupt(UART1RX_VECTOR) uart_rx(void)
|
interrupt(UART1RX_VECTOR) uart_rx(void)
|
||||||
{
|
{
|
||||||
fp_uart_handler handler = uart_handler[uart_mode];
|
fp_uart_handler handler = uart_handler[uart_mode];
|
||||||
|
|
||||||
/* Check status register for receive errors. - before reading RXBUF since
|
/* Check status register for receive errors. - before reading RXBUF since
|
||||||
it clears the error and interrupt flags */
|
it clears the error and interrupt flags */
|
||||||
if (!(URCTL1 & RXERR) && handler != NULL) {
|
if (!(URCTL1 & RXERR) && handler != NULL) {
|
||||||
if(handler(UART_RX)) {
|
if(handler(UART_RX)) {
|
||||||
LPM_AWAKE();
|
LPM_AWAKE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// read out the char to clear the I-flags, etc.
|
// read out the char to clear the I-flags, etc.
|
||||||
UART_RX;
|
UART_RX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uart_get_mode(void)
|
uart_get_mode(void)
|
||||||
{
|
{
|
||||||
return uart_mode;
|
return uart_mode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,122 +1,122 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
|
||||||
|
|
||||||
These sources were developed at the Freie Universität Berlin, Computer
|
These sources were developed at the Freie Universität Berlin, Computer
|
||||||
Systems and Telematics group.
|
Systems and Telematics group.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
met:
|
met:
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
- Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
- Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
This software is provided by FUB and the contributors on an "as is"
|
This software is provided by FUB and the contributors on an "as is"
|
||||||
basis, without any representations or warranties of any kind, express
|
basis, without any representations or warranties of any kind, express
|
||||||
or implied including, but not limited to, representations or
|
or implied including, but not limited to, representations or
|
||||||
warranties of non-infringement, merchantability or fitness for a
|
warranties of non-infringement, merchantability or fitness for a
|
||||||
particular purpose. In no event shall FUB or contributors be liable
|
particular purpose. In no event shall FUB or contributors be liable
|
||||||
for any direct, indirect, incidental, special, exemplary, or
|
for any direct, indirect, incidental, special, exemplary, or
|
||||||
consequential damages (including, but not limited to, procurement of
|
consequential damages (including, but not limited to, procurement of
|
||||||
substitute goods or services; loss of use, data, or profits; or
|
substitute goods or services; loss of use, data, or profits; or
|
||||||
business interruption) however caused and on any theory of liability,
|
business interruption) however caused and on any theory of liability,
|
||||||
whether in contract, strict liability, or tort (including negligence
|
whether in contract, strict liability, or tort (including negligence
|
||||||
or otherwise) arising in any way out of the use of this software, even
|
or otherwise) arising in any way out of the use of this software, even
|
||||||
if advised of the possibility of such damage.
|
if advised of the possibility of such damage.
|
||||||
|
|
||||||
This implementation was developed by the CST group at the FUB.
|
This implementation was developed by the CST group at the FUB.
|
||||||
|
|
||||||
For documentation and questions please use the web site
|
For documentation and questions please use the web site
|
||||||
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
http://scatterweb.mi.fu-berlin.de and the mailinglist
|
||||||
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
|
||||||
Berlin, 2007
|
Berlin, 2007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup interfaces
|
* @addtogroup interfaces
|
||||||
* @{ */
|
* @{ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup uart1 UART1
|
* @defgroup uart1 UART1
|
||||||
* The UART module multiplexes differenct protocol on the MSB's UART1
|
* The UART module multiplexes differenct protocol on the MSB's UART1
|
||||||
* interface. Currently RS232 and SPI are supported.
|
* interface. Currently RS232 and SPI are supported.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file ScatterWeb.Uart.h
|
* @file ScatterWeb.Uart.h
|
||||||
* @author Michael Baar <baar@inf.fu-berlin.de>
|
* @author Michael Baar <baar@inf.fu-berlin.de>
|
||||||
*
|
*
|
||||||
* Header file for MSP430 UART driver.
|
* Header file for MSP430 UART driver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UART_H__
|
#ifndef __UART_H__
|
||||||
#define __UART_H__
|
#define __UART_H__
|
||||||
|
|
||||||
#define UART_RX RXBUF1
|
#define UART_RX RXBUF1
|
||||||
#define UART_TX TXBUF1
|
#define UART_TX TXBUF1
|
||||||
#define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
|
#define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
|
||||||
#define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
|
#define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
|
||||||
#define UART_WAIT_RX() while( (U1IFG & URXIFG1) == 0 ) { _NOP(); }
|
#define UART_WAIT_RX() while( (U1IFG & URXIFG1) == 0 ) { _NOP(); }
|
||||||
#define UART_WAIT_TX() while( (U1IFG & UTXIFG1) == 0 ) { _NOP(); }
|
#define UART_WAIT_TX() while( (U1IFG & UTXIFG1) == 0 ) { _NOP(); }
|
||||||
#define UART_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
|
#define UART_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Operating state
|
* @brief Operating state
|
||||||
*/
|
*/
|
||||||
extern volatile unsigned char uart_mode;
|
extern volatile unsigned char uart_mode;
|
||||||
extern volatile unsigned char uart_lockcnt;
|
extern volatile unsigned char uart_lockcnt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name UART mode flags
|
* @name UART mode flags
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define UART_MODE_RS232 (0x00u) ///< RS232 mode
|
#define UART_MODE_RS232 (0x00u) ///< RS232 mode
|
||||||
#define UART_MODE_SPI (0x01u) ///< SPI mode
|
#define UART_MODE_SPI (0x01u) ///< SPI mode
|
||||||
#define UART_MODE_DEFAULT UART_MODE_RS232
|
#define UART_MODE_DEFAULT UART_MODE_RS232
|
||||||
#define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number
|
#define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number
|
||||||
#define UART_MODE_RESET (0xFFu) ///< reset with current settings
|
#define UART_MODE_RESET (0xFFu) ///< reset with current settings
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#define UART_WAIT_LOCK(x) ( (uart_mode != x ) && (uart_lockcnt) )
|
#define UART_WAIT_LOCK(x) ( (uart_mode != x ) && (uart_lockcnt) )
|
||||||
#define UART_MODE_IS(x) ( uart_mode == x )
|
#define UART_MODE_IS(x) ( uart_mode == x )
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#ifdef __SCATTERWEB__
|
#ifdef __SCATTERWEB__
|
||||||
typedef void(*fp_uart_handler)(void);
|
typedef void(*fp_uart_handler)(void);
|
||||||
#else
|
#else
|
||||||
typedef unsigned int(*fp_uart_handler)(unsigned char);
|
typedef unsigned int(*fp_uart_handler)(unsigned char);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
typedef unsigned int(*fp_uart_handler)(unsigned char);
|
typedef unsigned int(*fp_uart_handler)(unsigned char);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize the UART module
|
* \brief Initialize the UART module
|
||||||
*
|
*
|
||||||
* This function is called from the boot up code to
|
* This function is called from the boot up code to
|
||||||
* initalize the UART module.
|
* initalize the UART module.
|
||||||
*/
|
*/
|
||||||
void uart_init(void);
|
void uart_init(void);
|
||||||
|
|
||||||
void uart_set_speed(unsigned char mode, unsigned char ubr0, unsigned char ubr1, unsigned char umctl);
|
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);
|
void uart_set_handler(unsigned char mode, fp_uart_handler fpHandler);
|
||||||
|
|
||||||
int uart_lock(unsigned char mode);
|
int uart_lock(unsigned char mode);
|
||||||
|
|
||||||
int uart_unlock(unsigned char mode);
|
int uart_unlock(unsigned char mode);
|
||||||
|
|
||||||
int uart_get_mode(void);
|
int uart_get_mode(void);
|
||||||
|
|
||||||
#endif /* __UART_H__ */
|
#endif /* __UART_H__ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -1,117 +1,117 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
* 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
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rs232.c,v 1.2 2007/08/16 20:29:56 nvt-se Exp $
|
* @(#)$Id: rs232.c,v 1.3 2007/08/20 11:01:14 nvt-se Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \addtogroup esbrs232
|
/** \addtogroup esbrs232
|
||||||
* @{ */
|
* @{ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* RS232 communication device driver for the MSP430.
|
* RS232 communication device driver for the MSP430.
|
||||||
* \author Adam Dunkels <adam@sics.se>
|
* \author Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
* This file contains an RS232 device driver for the MSP430 microcontroller.
|
* This file contains an RS232 device driver for the MSP430 microcontroller.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "dev/msb430-uart1.h"
|
#include "dev/msb430-uart1.h"
|
||||||
#include "rs232.h"
|
#include "rs232.h"
|
||||||
|
|
||||||
#ifndef U1IFG
|
#ifndef U1IFG
|
||||||
#define U1IFG IFG2
|
#define U1IFG IFG2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* Initalize the RS232 port.
|
* Initalize the RS232 port.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
rs232_init(void)
|
rs232_init(void)
|
||||||
{
|
{
|
||||||
// rs232_set_speed(RS232_57600);
|
// rs232_set_speed(RS232_57600);
|
||||||
rs232_set_speed(RS232_115200);
|
rs232_set_speed(RS232_115200);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rs232_send(char c)
|
rs232_send(char c)
|
||||||
{
|
{
|
||||||
/* Check if the UART is in RS232 mode before sending.
|
/* Check if the UART is in RS232 mode before sending.
|
||||||
This check can be ommitted if every access to rs232 locks the uart
|
This check can be ommitted if every access to rs232 locks the uart
|
||||||
before using it.
|
before using it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (uart_get_mode() == UART_MODE_RS232) {
|
if (uart_get_mode() == UART_MODE_RS232) {
|
||||||
/* Loop until the transmission buffer is available. */
|
/* Loop until the transmission buffer is available. */
|
||||||
UART_WAIT_TX();
|
UART_WAIT_TX();
|
||||||
/* Transmit the data. */
|
/* Transmit the data. */
|
||||||
UART_TX = c;
|
UART_TX = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rs232_set_speed(enum rs232_speed speed)
|
rs232_set_speed(enum rs232_speed speed)
|
||||||
{
|
{
|
||||||
// baud
|
// baud
|
||||||
const unsigned char br_table[4][3] = {
|
const unsigned char br_table[4][3] = {
|
||||||
{0x80, 0x00, 0x00}, // 19200
|
{0x80, 0x00, 0x00}, // 19200
|
||||||
{0x40, 0x00, 0x00}, // 38400
|
{0x40, 0x00, 0x00}, // 38400
|
||||||
{0x2a, 0x00, 0x5b}, // 57600
|
{0x2a, 0x00, 0x5b}, // 57600
|
||||||
{0x15, 0x00, 0x4a} // 115200
|
{0x15, 0x00, 0x4a} // 115200
|
||||||
};
|
};
|
||||||
|
|
||||||
uart_set_speed(UART_MODE_RS232, br_table[speed][0],
|
uart_set_speed(UART_MODE_RS232, br_table[speed][0],
|
||||||
br_table[speed][1], br_table[speed][2]);
|
br_table[speed][1], br_table[speed][2]);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rs232_print(char *cptr)
|
rs232_print(char *cptr)
|
||||||
{
|
{
|
||||||
// lock UART for print operation
|
// lock UART for print operation
|
||||||
if (uart_lock(UART_MODE_RS232)) {
|
if (uart_lock(UART_MODE_RS232)) {
|
||||||
while(*cptr != 0) {
|
while(*cptr != 0) {
|
||||||
rs232_send(*cptr);
|
rs232_send(*cptr);
|
||||||
++cptr;
|
++cptr;
|
||||||
}
|
}
|
||||||
uart_unlock(UART_MODE_RS232);
|
uart_unlock(UART_MODE_RS232);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rs232_set_input(fp_uart_handler f)
|
rs232_set_input(fp_uart_handler f)
|
||||||
{
|
{
|
||||||
uart_set_handler(UART_MODE_RS232, f);
|
uart_set_handler(UART_MODE_RS232, f);
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -1,120 +1,120 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
* 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
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rs232.h,v 1.1 2007/06/28 12:52:42 nvt-se Exp $
|
* @(#)$Id: rs232.h,v 1.2 2007/08/20 11:01:14 nvt-se Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \addtogroup esb
|
/** \addtogroup esb
|
||||||
* @{ */
|
* @{ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \defgroup esbrs232 ESB RS232
|
* \defgroup esbrs232 ESB RS232
|
||||||
*
|
*
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Header file for MSP430 RS232 driver.
|
* Header file for MSP430 RS232 driver.
|
||||||
* \author Adam Dunkels <adam@sics.se>
|
* \author Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef __RS232_H__
|
#ifndef __RS232_H__
|
||||||
#define __RS232_H__
|
#define __RS232_H__
|
||||||
|
|
||||||
enum rs232_speed {
|
enum rs232_speed {
|
||||||
RS232_19200 = 0,
|
RS232_19200 = 0,
|
||||||
RS232_38400 = 1,
|
RS232_38400 = 1,
|
||||||
RS232_57600 = 2,
|
RS232_57600 = 2,
|
||||||
RS232_115200 = 3
|
RS232_115200 = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize the RS232 module
|
* \brief Initialize the RS232 module
|
||||||
*
|
*
|
||||||
* This function is called from the boot up code to
|
* This function is called from the boot up code to
|
||||||
* initalize the RS232 module.
|
* initalize the RS232 module.
|
||||||
*/
|
*/
|
||||||
void rs232_init(void);
|
void rs232_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Set an input handler for incoming RS232 data
|
* \brief Set an input handler for incoming RS232 data
|
||||||
* \param f A pointer to a byte input handler
|
* \param f A pointer to a byte input handler
|
||||||
*
|
*
|
||||||
* This function sets the input handler for incoming RS232
|
* This function sets the input handler for incoming RS232
|
||||||
* data. The input handler function is called for every
|
* data. The input handler function is called for every
|
||||||
* incoming data byte. The function is called from the
|
* incoming data byte. The function is called from the
|
||||||
* RS232 interrupt handler, so care must be taken when
|
* RS232 interrupt handler, so care must be taken when
|
||||||
* implementing the input handler to avoid race
|
* implementing the input handler to avoid race
|
||||||
* conditions.
|
* conditions.
|
||||||
*
|
*
|
||||||
* The return value of the input handler affects the sleep
|
* The return value of the input handler affects the sleep
|
||||||
* mode of the CPU: if the input handler returns non-zero
|
* mode of the CPU: if the input handler returns non-zero
|
||||||
* (true), the CPU is awakened to let other processing
|
* (true), the CPU is awakened to let other processing
|
||||||
* take place. If the input handler returns zero, the CPU
|
* take place. If the input handler returns zero, the CPU
|
||||||
* is kept sleeping.
|
* is kept sleeping.
|
||||||
*/
|
*/
|
||||||
void rs232_set_input(fp_uart_handler f);
|
void rs232_set_input(fp_uart_handler f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Configure the speed of the RS232 hardware
|
* \brief Configure the speed of the RS232 hardware
|
||||||
* \param speed The speed
|
* \param speed The speed
|
||||||
*
|
*
|
||||||
* This function configures the speed of the RS232
|
* This function configures the speed of the RS232
|
||||||
* hardware. The allowed parameters are RS232_19200,
|
* hardware. The allowed parameters are RS232_19200,
|
||||||
* RS232_38400, RS232_57600, and RS232_115200.
|
* RS232_38400, RS232_57600, and RS232_115200.
|
||||||
*/
|
*/
|
||||||
void rs232_set_speed(enum rs232_speed speed);
|
void rs232_set_speed(enum rs232_speed speed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Print a text string on RS232
|
* \brief Print a text string on RS232
|
||||||
* \param str A pointer to the string that is to be printed
|
* \param str A pointer to the string that is to be printed
|
||||||
*
|
*
|
||||||
* This function prints a string to RS232. The string must
|
* This function prints a string to RS232. The string must
|
||||||
* be terminated by a null byte. The RS232 module must be
|
* be terminated by a null byte. The RS232 module must be
|
||||||
* correctly initalized and configured for this function
|
* correctly initalized and configured for this function
|
||||||
* to work.
|
* to work.
|
||||||
*/
|
*/
|
||||||
void rs232_print(char *text);
|
void rs232_print(char *text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Print a character on RS232
|
* \brief Print a character on RS232
|
||||||
* \param c The character to be printed
|
* \param c The character to be printed
|
||||||
*
|
*
|
||||||
* This function prints a character to RS232. The RS232
|
* This function prints a character to RS232. The RS232
|
||||||
* module must be correctly initalized and configured for
|
* module must be correctly initalized and configured for
|
||||||
* this function to work.
|
* this function to work.
|
||||||
*/
|
*/
|
||||||
void rs232_send(char c);
|
void rs232_send(char c);
|
||||||
|
|
||||||
#endif /* __RS232_H__ */
|
#endif /* __RS232_H__ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -1,56 +1,56 @@
|
||||||
#include "dev/msb430-uart1.h"
|
#include "dev/msb430-uart1.h"
|
||||||
#include "dev/rs232.h"
|
#include "dev/rs232.h"
|
||||||
#include "sys/clock.h"
|
#include "sys/clock.h"
|
||||||
#include "dev/slip.h"
|
#include "dev/slip.h"
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
slip_arch_writeb(unsigned char c)
|
slip_arch_writeb(unsigned char c)
|
||||||
{
|
{
|
||||||
rs232_send(c);
|
rs232_send(c);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The serial line is used to transfer IP packets using slip. To make
|
* 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
|
* it possible to send debug output over the same line we send debug
|
||||||
* output as slip frames (i.e delimeted by SLIP_END).
|
* output as slip frames (i.e delimeted by SLIP_END).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
putchar(int c)
|
putchar(int c)
|
||||||
{
|
{
|
||||||
#define SLIP_END 0300
|
#define SLIP_END 0300
|
||||||
static char debug_frame = 0;
|
static char debug_frame = 0;
|
||||||
|
|
||||||
if (!debug_frame) { /* Start of debug output */
|
if (!debug_frame) { /* Start of debug output */
|
||||||
slip_arch_writeb(SLIP_END);
|
slip_arch_writeb(SLIP_END);
|
||||||
slip_arch_writeb('\r'); /* Type debug line == '\r' */
|
slip_arch_writeb('\r'); /* Type debug line == '\r' */
|
||||||
debug_frame = 1;
|
debug_frame = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
slip_arch_writeb((char)c);
|
slip_arch_writeb((char)c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Line buffered output, a newline marks the end of debug output and
|
* Line buffered output, a newline marks the end of debug output and
|
||||||
* implicitly flushes debug output.
|
* implicitly flushes debug output.
|
||||||
*/
|
*/
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
slip_arch_writeb(SLIP_END);
|
slip_arch_writeb(SLIP_END);
|
||||||
debug_frame = 0;
|
debug_frame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_delay(100);
|
clock_delay(100);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initalize the RS232 port and the SLIP driver.
|
* Initalize the RS232 port and the SLIP driver.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
slip_arch_init(unsigned long ubr)
|
slip_arch_init(unsigned long ubr)
|
||||||
{
|
{
|
||||||
rs232_set_input(slip_input_byte);
|
rs232_set_input(slip_input_byte);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,55 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
* 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
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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 $
|
* $Id: node-id.c,v 1.2 2007/08/20 11:01:13 nvt-se Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "node-id.h"
|
#include "node-id.h"
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
#include "dev/infomem.h"
|
#include "dev/infomem.h"
|
||||||
|
|
||||||
unsigned short node_id = 0;
|
unsigned short node_id = 0;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
node_id_restore(void)
|
node_id_restore(void)
|
||||||
{
|
{
|
||||||
unsigned short newid[2];
|
unsigned short newid[2];
|
||||||
|
|
||||||
infomem_read(newid, INFOMEM_NODE_ID, 2 * sizeof(node_id));
|
infomem_read(newid, INFOMEM_NODE_ID, 2 * sizeof(node_id));
|
||||||
node_id = ( newid[0] == 0xdead ) ? newid[1] : newid[0];
|
node_id = ( newid[0] == 0xdead ) ? newid[1] : newid[0];
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
node_id_burn(unsigned short id)
|
node_id_burn(unsigned short id)
|
||||||
{
|
{
|
||||||
unsigned short buffer[2] = { 0xdead, id };
|
unsigned short buffer[2] = { 0xdead, id };
|
||||||
infomem_write(INFOMEM_NODE_ID, 1, buffer, 2 * sizeof(node_id));
|
infomem_write(INFOMEM_NODE_ID, 1, buffer, 2 * sizeof(node_id));
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Swedish Institute of Computer Science.
|
* Copyright (c) 2005, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
* 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
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
* $Id: node-id.h,v 1.1 2007/06/28 12:49:57 nvt-se Exp $
|
* $Id: node-id.h,v 1.2 2007/08/20 11:01:13 nvt-se Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __NODE_ID_H__
|
#ifndef __NODE_ID_H__
|
||||||
#define __NODE_ID_H__
|
#define __NODE_ID_H__
|
||||||
|
|
||||||
void node_id_restore(void);
|
void node_id_restore(void);
|
||||||
void node_id_burn(unsigned short node_id);
|
void node_id_burn(unsigned short node_id);
|
||||||
|
|
||||||
extern unsigned short node_id;
|
extern unsigned short node_id;
|
||||||
|
|
||||||
#endif /* __NODE_ID_H__ */
|
#endif /* __NODE_ID_H__ */
|
||||||
|
|
Loading…
Reference in a new issue