From 246da552f5b2d9277ab0174ba426eb56b7c3e342 Mon Sep 17 00:00:00 2001 From: joxe Date: Thu, 25 Oct 2007 10:58:19 +0000 Subject: [PATCH] added testcases git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@7 23d1a52b-0c3c-0410-b72d-8f29ab48fe35 --- Makefile | 20 ++- tests/Makefile | 50 ++++++ tests/cputest.c | 270 +++++++++++++++++++++++++++++++ tests/msp430setup.c | 380 ++++++++++++++++++++++++++++++++++++++++++++ tests/msp430setup.h | 99 ++++++++++++ 5 files changed, 808 insertions(+), 11 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/cputest.c create mode 100644 tests/msp430setup.c create mode 100644 tests/msp430setup.h diff --git a/Makefile b/Makefile index 610209d..e9d521e 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ ############################################################### -# $Revision: 1.11 $ $Date: 2007/10/21 19:47:53 $ +# Makefile for mspsim # # Needed stuff in the PATH: -# java, javac (JDK 1.2 or newer) +# java, javac (JDK 1.5 or newer) # -# Under MS-DOS/Windows 95/NT -# A GNU compatible Make (for example Cygnus GNU-Win 32, -# http://www.cygnus.com/misc/gnu-win32/) -# Note: might need to be called with "make --win32" under Windows!!! +# Under MS-DOS/Windows +# A GNU compatible Make (for example Cygwin's) ############################################################### ############################################################### @@ -37,7 +35,7 @@ ifndef WINDIR # Add "'" around filenames when removing them because UNIX expands "$" APO='#' (last apostrophe to avoid incorrect font-lock) else - # These setting are for MS-DOS/Windows 95/Windows NT + # These setting are for Windows SEPARATOR=; APO= endif @@ -54,7 +52,7 @@ CCARGS=-deprecation -classpath . # SERVER OBJECTS ############################################################### -IHEXFILE = blinker2.ihex +FIRMWAREFILE = blinker2.ihex CPUTEST := tests/cputest.ihex CPUTESTMAP := $(CPUTEST:.ihex=.map) @@ -81,13 +79,13 @@ help: .PHONY: run run: compile - java se.sics.util.IHexReader $(IHEXFILE) $(MAPFILE) + java se.sics.util.IHexReader $(FIRMWAREFILE) $(MAPFILE) runesb: compile - java se.sics.mspsim.platform.esb.ESBNode $(IHEXFILE) $(MAPFILE) + java se.sics.mspsim.platform.esb.ESBNode $(FIRMWAREFILE) $(MAPFILE) runsky: compile - java se.sics.mspsim.platform.sky.SkyNode $(IHEXFILE) $(MAPFILE) + java se.sics.mspsim.platform.sky.SkyNode $(FIRMWAREFILE) $(MAPFILE) .PHONY: cputest test test: cputest diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..5f206fd --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,50 @@ +### Check if we are running under Windows + +ifndef WINDIR + ifdef OS + ifneq (,$(findstring Windows,$(OS))) + WINDIR := Windows + endif + endif +endif + +.SUFFIXES: + +MCU=msp430x149 + +### Compiler definitions +CC = msp430-gcc +LD = msp430-ld +AS = msp430-as +AR = msp430-ar +OBJCOPY = msp430-objcopy +STRIP = msp430-strip +BSL = msp430-bsl +CFLAGSNO = -I. -DWITH_ASCII \ + -Wall -mmcu=$(MCU) -g +CFLAGS += $(CFLAGSNO) -Os + +SOURCES := msp430setup.c + +OBJECTS := $(SOURCES:.c=.o) + +#all: cputest.ihex +all: cputest.firmware + +%.firmware: %.co $(OBJECTS) + $(CC) -mmcu=$(MCU) -Wl,-Map=$(@:.firmware=.map) $(CFLAGS) -o $@ $^ + +%.ihex: %.firmware + $(OBJCOPY) $^ -O ihex $@ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.co: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@ + +%.u: %.ihex + msp430-jtag -eI $^ + +clean: + rm -f *~ *.lst *.map *.co *.o *.ihex *.firmware diff --git a/tests/cputest.c b/tests/cputest.c new file mode 100644 index 0000000..3ed9578 --- /dev/null +++ b/tests/cputest.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * $Id: cputest.c,v 1.19 2007/10/24 22:17:46 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2006-03-07 + * Updated : $Date: 2007/10/24 22:17:46 $ + * $Revision: 1.19 $ + */ + +#include "msp430setup.h" +#include +#include + +/* From Adams test-suite */ +#define TEST(...) if(__VA_ARGS__) { \ + printf("OK: " #__VA_ARGS__ " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #__VA_ARGS__ " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define TEST2(text,...) if(__VA_ARGS__) { \ + printf("OK: " #text " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #text " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define assertTrue(...) TEST(__VA_ARGS__) +#define assertFalse(...) TEST(!(__VA_ARGS__)) + +#define assertTrue2(text,...) TEST2(text,__VA_ARGS__) +#define assertFalse2(text,...) TEST2(text,!(__VA_ARGS__)) + +static int testzero(int hm) +{ + return hm > 0; +} + +static int caseID = 0; + +static void initTest() { + caseID = 0; +} + +static void testCase(char *description) { + caseID++; + printf("-------------\n"); + printf("TEST %d: %s\n", caseID, description); +} + +static void testSimple() { + int a,b,c; + a = 1; b = 2; c = 4; + testCase("Arithmetic Operations"); + + assertTrue((a << b) == 4); + assertTrue((c >> a) == 2); + + assertFalse(0 > 0); + assertFalse(a > b); + + assertFalse(testzero(0)); +} + +static void testIntegers() { + int a,b,c; + int t[3]; + testCase("Integer Operations"); + a = 1; b = 2; c = -42; + t[0] = 1; + t[1] = 2; + t[2] = 3; + assertTrue(a == 1); + assertTrue((b + c) == -40); + assertTrue(t[0] == 1); + assertTrue(t[1] == 2); + assertTrue(t[t[0]] == 2); + assertTrue((a+b) == 3); + assertTrue((b-a) == 1); + assertTrue((a-b) == -1); + assertTrue((a*b) == 2); + assertTrue(a > 0); + assertTrue(b > a); + assertTrue(b != a); + assertTrue((a ^ b) == 3); + assertTrue((a ^ 4) == 5); + assertTrue((a ^ a) == 0); + assertFalse(a > b); + + a = 15; + b = 17; + assertTrue((a & ~b) == 14); +} + +static void testFloats() { + int i; + float f; + i = 2; + f = 0.5; + testCase("Float Operations"); + assertTrue((i * f) == 1); + i++; + assertTrue((i * f) == 1.5); +} + +static void testStrings() { + char buf[10]; + + testCase("String Operations"); + sprintf(buf, "test"); + assertTrue2("test => test", strcmp(buf, "test") == 0); + sprintf(buf, "%c", 'a'); + assertTrue2("buf == 'a'", strcmp(buf, "a") == 0); +} + +/*--------------------------------------------------------------------------*/ + +static int id(int first, ...) +{ + va_list marker; + va_start( marker, first ); + first = va_arg( marker, int); + va_end( marker ); + return first; +} + +static void testFunctions() { + volatile int i; + + testCase("Functions"); + i = 47; + +/* printf("i=%d i+1=%d id(i)=%d\n", i, i + 1, id(0, i)); */ + + assertTrue(i == 47); + assertTrue(id(0,47) == 47); + assertTrue(id(0,i) == 47); +} + +/*--------------------------------------------------------------------------*/ + +static void testModulo() { + int c,i; + c = 1; + testCase("Modulo"); + do { + i = 13; + + i = i % 14; +/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ +/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ + if (i < 0) printf("%d\n",i); + + + c = c + 1; + } while (c < 3); + +/* if((i % 5) == 0) { */ +/* assertTrue(i != 1); */ +/* } */ +} + +/*--------------------------------------------------------------------------*/ + +/* Bit field tests */ + +static struct { + char green:4, yellow:4, red:4; +} leds; + +static struct { + char green:2, yellow:2, red:2; /* These bit fields should really be + only one bit wide, but that + crashed gcc... */ +} invert; + +#include +#ifndef BV +#define BV(n) (1 << (n)) +#endif + +void testBis() { + P4DIR |= BV(2) | BV(5) | BV(6); + assertTrue(P4DIR == 100); +} + +static void testBitFields() { + static int pelle = 0; + + testCase("Bit field Operations"); + + P4DIR = 0; + testBis(); + + leds.green = 1; + leds.yellow = 1; + leds.red = 1; + + assertTrue(leds.green > 0); + assertTrue(leds.yellow > 0); + assertTrue(leds.red > 0); + + leds.green -= 1; + assertTrue(leds.green == 0); + + pelle = 0x4711; + + invert.green = 1; + invert.yellow = 1; + invert.red = 1; + + assertTrue(invert.green > 0); + assertTrue(invert.yellow > 0); + assertTrue(invert.red > 0); + + invert.green ^= 1; + assertTrue(invert.green == 0); + +} + + +/*--------------------------------------------------------------------------*/ + +int +main(void) +{ + msp430_setup(); + + initTest(); + +/* testSimple(); */ +/* testIntegers(); */ +/* testFloats(); */ +/* testStrings(); */ +/* testBitFields(); */ +/* testFunctions(); */ + testModulo(); + + printf("EXIT\n"); + return 0; +} diff --git a/tests/msp430setup.c b/tests/msp430setup.c new file mode 100644 index 0000000..2220036 --- /dev/null +++ b/tests/msp430setup.c @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: msp430setup.c,v 1.2 2007/01/22 15:45:04 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2007-01-22 + * Updated : $Date: 2007/01/22 15:45:04 $ + * $Revision: 1.2 $ + */ + +#include "msp430setup.h" +#include +#include +#include +#include + + +/*--------------------------------------------------------------------------*/ +/* RS232 Interface */ +/*--------------------------------------------------------------------------*/ + +static int (* input_handler)(unsigned char) = NULL; + +/*---------------------------------------------------------------------------*/ +interrupt(UART1RX_VECTOR) + rs232_rx_usart1(void) +{ + /* Check status register for receive errors. - before reading RXBUF since + it clears the error and interrupt flags */ + if(!(URCTL1 & RXERR) && input_handler != NULL) { + input_handler(RXBUF1); + + } else { + /* Else read out the char to clear the I-flags, etc. */ + RXBUF1; + } +} +/*--------------------------------------------------------------------------*/ +void +rs232_init(void) +{ + + /* RS232 */ + UCTL1 = CHAR; /* 8-bit character */ + UTCTL1 = SSEL1; /* UCLK = MCLK */ + + rs232_set_speed(RS232_57600); + + input_handler = NULL; + + ME2 |= (UTXE1 | URXE1); /* Enable USART1 TXD/RXD */ + IE2 |= URXIE1; /* Enable USART1 RX interrupt */ +} +/*---------------------------------------------------------------------------*/ +void +rs232_send(char c) +{ + /* Loop until the transmission buffer is available. */ + while ((IFG2 & UTXIFG1) == 0); + + /* Transmit the data. */ + TXBUF1 = c; +} +/*---------------------------------------------------------------------------*/ +void +rs232_set_speed(unsigned char speed) +{ + if(speed == RS232_19200) { + /* Set RS232 to 19200 */ + UBR01 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x00; /* no modulation */ + } else if(speed == RS232_38400) { + /* Set RS232 to 38400 */ + UBR01 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x00; /* no modulation */ + } else if(speed == RS232_57600) { + UBR01 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x5b; /* */ + } else if(speed == RS232_115200) { + UBR01 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x4a; /* */ + } else { + rs232_set_speed(RS232_57600); + } +} +/*---------------------------------------------------------------------------*/ +void +rs232_set_input(int (*f)(unsigned char)) +{ + input_handler = f; +} +/*--------------------------------------------------------------------------*/ +int +putchar(int c) +{ + rs232_send(c); + return c; +} +/*--------------------------------------------------------------------------*/ + + + + +/*---------------------------------------------------------------------------*/ +void +esb_sensors_init(void) +{ + P5SEL &= ~(1 << 5); + P5DIR |= (1 << 5); +} +/*---------------------------------------------------------------------------*/ +void +esb_sensors_on(void) +{ + P5OUT &= ~(1 << 5); +} +/*---------------------------------------------------------------------------*/ +void +esb_sensors_off(void) +{ + P5OUT |= (1 << 5); +} +/*---------------------------------------------------------------------------*/ + + + + +/*---------------------------------------------------------------------------*/ +/* CPU INIT */ +/*--------------------------------------------------------------------------*/ + +static void +msp430_init_dco(void) +{ + /* This code taken from the FU Berlin sources and reformatted. */ +#define DELTA 600 + + unsigned int compare, oldcapture = 0; + unsigned int i; + + + BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK + and SSMCLK. XT2 is off. */ + + BCSCTL2 = 0x00; /* Init FLL to desired frequency using the 32762Hz + crystal DCO frquenzy = 2,4576 MHz */ + + WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */ + BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */ + for(i = 0xffff; i > 0; i--); /* Delay for XTAL to settle */ + + CCTL2 = CCIS0 + CM0 + CAP; // Define CCR2, CAP, ACLK + TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode + + + while(1) { + + while((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */ + CCTL2 &= ~CCIFG; /* Capture occured, clear flag */ + compare = CCR2; /* Get current captured SMCLK */ + compare = compare - oldcapture; /* SMCLK difference */ + oldcapture = CCR2; /* Save current captured SMCLK */ + + if(DELTA == compare) { + break; /* if equal, leave "while(1)" */ + } else if(DELTA < compare) { /* DCO is too fast, slow it down */ + DCOCTL--; + if(DCOCTL == 0xFF) { /* Did DCO role under? */ + BCSCTL1--; + } + } else { /* -> Select next lower RSEL */ + DCOCTL++; + if(DCOCTL == 0x00) { /* Did DCO role over? */ + BCSCTL1++; + } + /* -> Select next higher RSEL */ + } + } + + CCTL2 = 0; /* Stop CCR2 function */ + TACTL = 0; /* Stop Timer_A */ + + BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ +} +/*---------------------------------------------------------------------------*/ +static void +init_ports(void) +{ + /* Turn everything off, device drivers are supposed to enable what is + * really needed! + */ + + /* All configured for digital I/O */ +#ifdef P1SEL + P1SEL = 0; +#endif +#ifdef P2SEL + P2SEL = 0; +#endif +#ifdef P3SEL + P3SEL = 0; +#endif +#ifdef P4SEL + P4SEL = 0; +#endif +#ifdef P5SEL + P5SEL = 0; +#endif +#ifdef P6SEL + P6SEL = 0; +#endif + + /* All available inputs */ +#ifdef P1DIR + P1DIR = 0; + P1OUT = 0; +#endif +#ifdef P2DIR + P2DIR = 0; + P2OUT = 0; +#endif +#ifdef P3DIR + P3DIR = 0; + P3OUT = 0; +#endif +#ifdef P4DIR + P4DIR = 0; + P4OUT = 0; +#endif + +#ifdef P5DIR + P5DIR = 0; + P5OUT = 0; +#endif + +#ifdef P6DIR + P6DIR = 0; + P6OUT = 0; +#endif + + P1IE = 0; + P2IE = 0; +} +/*---------------------------------------------------------------------------*/ +static void init_ports_toberemoved() { + ////////// Port 1 //// + P1SEL = 0x00; + P1DIR = 0x81; // Outputs: P10=IRSend, P17=RS232RTS + // Inputs: P11=Light, P12=IRRec, P13=PIR, P14=Vibration, + // P15=Clockalarm, P16=RS232CTS + P1OUT = 0x00; + + ////////// Port 2 //// + P2SEL = 0x00; // No Sels + P2DIR = 0x7F; // Outpus: P20..P23=Leds+Beeper, P24..P26=Poti + // Inputs: P27=Taster + P2OUT = 0x77; + + ////////// Port 3 //// + P3SEL = 0xE0; // Sels for P34..P37 to activate UART, + P3DIR = 0x5F; // Inputs: P30..P33=CON4, P35/P37=RXD Transceiver/RS232 + // OutPuts: P36/P38=TXD Transceiver/RS232 + P3OUT = 0xE0; // Output a Zero on P34(TXD Transceiver) and turn SELECT off when receiving!!! + + ////////// Port 4 //// + P4SEL = 0x00; // CON5 Stecker + P4DIR = 0xFF; + P4OUT = 0x00; + + ////////// Port 5 //// + P5SEL = 0x00; // P50/P51= Clock SDA/SCL, P52/P53/P54=EEPROM SDA/SCL/WP + P5DIR = 0xDA; // P56/P57=Transceiver CNTRL0/1 + P5OUT = 0x0F; + + ////////// Port 6 //// + P6SEL = 0x00; // P60=Microphone, P61=PIR digital (same as P13), P62=PIR analog + P6DIR = 0x00; // P63=extern voltage, P64=battery voltage, P65=Receive power + P6OUT = 0x00; +} +/*--------------------------------------------------------------------------*/ +void +msp430_setup(void) +{ + dint(); + init_ports(); + msp430_init_dco(); + eint(); + + init_ports_toberemoved(); + + esb_sensors_init(); + esb_sensors_on(); + + rs232_init(); +} + +#define asmv(arg) __asm__ __volatile__(arg) + +#define STACK_EXTRA 32 +static char *cur_break = (char *)(&__bss_end + 1); + +/* + * Allocate memory from the heap. Check that we don't collide with the + * stack right now (some other routine might later). A watchdog might + * be used to check if cur_break and the stack pointer meet during + * runtime. + */ +void * +sbrk(int incr) +{ + char *stack_pointer; + + asmv("mov r1, %0" : "=r" (stack_pointer)); + stack_pointer -= STACK_EXTRA; + if(incr > (stack_pointer - cur_break)) + return (void *)-1; /* ENOMEM */ + + void *old_break = cur_break; + cur_break += incr; + /* + * If the stack was never here then [old_break .. cur_break] should + * be filled with zeros. + */ + return old_break; +} + +/* + * Mask all interrupts that can be masked. + */ +int +splhigh_(void) +{ + /* Clear the GIE (General Interrupt Enable) flag. */ + int sr; + asmv("mov r2, %0" : "=r" (sr)); + asmv("bic %0, r2" : : "i" (GIE)); + return sr & GIE; /* Ignore other sr bits. */ +} + +/* + * Restore previous interrupt mask. + */ +void +splx_(int sr) +{ + /* If GIE was set, restore it. */ + asmv("bis %0, r2" : : "r" (sr)); +} diff --git a/tests/msp430setup.h b/tests/msp430setup.h new file mode 100644 index 0000000..939507b --- /dev/null +++ b/tests/msp430setup.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: msp430setup.h,v 1.1 2007/01/22 15:12:27 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2007-01-22 + * Updated : $Date: 2007/01/22 15:12:27 $ + * $Revision: 1.1 $ + */ + +#ifndef __MSP430SETUP_H__ +#define __MSP430SETUP_H__ + +void msp430_setup(void); + +#define RS232_19200 1 +#define RS232_38400 2 +#define RS232_57600 3 +#define RS232_115200 4 + +/** + * \brief Set an input handler for incoming RS232 data + * \param f A pointer to a byte input handler + * + * This function sets the input handler for incoming RS232 + * data. The input handler function is called for every + * incoming data byte. The function is called from the + * RS232 interrupt handler, so care must be taken when + * implementing the input handler to avoid race + * conditions. + * + * The return value of the input handler affects the sleep + * mode of the CPU: if the input handler returns non-zero + * (true), the CPU is awakened to let other processing + * take place. If the input handler returns zero, the CPU + * is kept sleeping. + */ +void rs232_set_input(int (* f)(unsigned char)); + +/** + * \brief Configure the speed of the RS232 hardware + * \param speed The speed + * + * This function configures the speed of the RS232 + * hardware. The allowed parameters are RS232_19200, + * RS232_38400, RS232_57600, and RS232_115200. + */ +void rs232_set_speed(unsigned char speed); + +/** + * \brief Print a text string on RS232 + * \param str A pointer to the string that is to be printed + * + * This function prints a string to RS232. The string must + * be terminated by a null byte. The RS232 module must be + * correctly initalized and configured for this function + * to work. + */ +void rs232_print(char *text); + +/** + * \brief Print a character on RS232 + * \param c The character to be printed + * + * This function prints a character to RS232. The RS232 + * module must be correctly initalized and configured for + * this function to work. + */ +void rs232_send(char c); + +#endif /* __MSP430SETUP_H__ */