From aabfeb9b5b2cb5609056f85a31b52d709cfcfda4 Mon Sep 17 00:00:00 2001 From: travisutk Date: Mon, 14 Jun 2010 21:38:39 +0000 Subject: [PATCH 1/1] TelosB platform target. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@623 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- firmware/Makefile | 2 +- firmware/include/platform.h | 25 +++++++++++++++--- firmware/lib/msp430x1612.c | 48 +++++++++++++++++++++++++---------- firmware/tests/blink/Makefile | 2 +- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index c674531..4f3bbb6 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -26,7 +26,7 @@ platform?=goodfet GCCINC=-T ldscripts/$(mcu).x CCEXTRA?= -CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -D$(mcu) -Dplatform=$(platform) -DGCC $(GCCINC) -I include $(CCEXTRA) +CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -D$(mcu) -D$(platform) -Dplatform=$(platform) -DGCC $(GCCINC) -I include $(CCEXTRA) #Define extra modules here. #moreapps?=apps/i2c/i2c.o apps/glitch/glitch.o apps/jtag/sbw.o apps/smartcard/smartcard.o apps/jtag/ejtag.o apps/jtag/jtagxscale.o diff --git a/firmware/include/platform.h b/firmware/include/platform.h index 067d3f6..014ea20 100644 --- a/firmware/include/platform.h +++ b/firmware/include/platform.h @@ -8,17 +8,34 @@ #include "gfports.h" -unsigned char serial_rx(); -void serial_tx(unsigned char); +#ifdef telosb +//TelosB uses second serial port. +#define serial_tx serial1_tx +#define serial_rx serial1_rx +#define setbaud setbaud1 +#define msp430_init_uart msp430_init_uart1 +#else +//Other targets use first. +#define serial_tx serial0_tx +#define serial_rx serial0_rx +#define setbaud setbaud0 +#define msp430_init_uart msp430_init_uart0 +#endif + +unsigned char serial0_rx(); +void serial0_tx(unsigned char); unsigned char serial1_rx(); void serial1_tx(unsigned char); -void setbaud(unsigned char); +void setbaud0(unsigned char); void setbaud1(unsigned char); //! Initialize the UART -void msp430_init_uart(); +void msp430_init_uart0(); +//! Initialize the UART +void msp430_init_uart1(); + //! Initialize the DCO Clock void msp430_init_dco(); //! Called by monitor() when the DCO is correct and communication established. diff --git a/firmware/lib/msp430x1612.c b/firmware/lib/msp430x1612.c index d125b78..7d6b7c1 100644 --- a/firmware/lib/msp430x1612.c +++ b/firmware/lib/msp430x1612.c @@ -7,7 +7,7 @@ #include //! Receive a byte. -unsigned char serial_rx(){ +unsigned char serial0_rx(){ char c; while(!(IFG1&URXIFG0));//wait for a byte @@ -31,7 +31,7 @@ unsigned char serial1_rx(){ } //! Transmit a byte. -void serial_tx(unsigned char x){ +void serial0_tx(unsigned char x){ while ((IFG1 & UTXIFG0) == 0); //loop until buffer is free TXBUF0 = x; } @@ -51,7 +51,7 @@ void serial1_tx(unsigned char x){ */ //! Set the baud rate. -void setbaud(unsigned char rate){ +void setbaud0(unsigned char rate){ //http://mspgcc.sourceforge.net/baudrate.html switch(rate){ @@ -76,31 +76,29 @@ void setbaud(unsigned char rate){ //! Set the baud rate of the second uart. void setbaud1(unsigned char rate){ - //http://mspgcc.sourceforge.net/baudrate.html switch(rate){ case 1://9600 baud - // UBR01=0x7F; UBR11=0x01; UMCTL1=0x5B; /* uart0 3683400Hz 9599bps */ + UBR01=0x7F; UBR11=0x01; UMCTL1=0x5B; /* uart0 3683400Hz 9599bps */ break; case 2://19200 baud - //UBR01=0xBF; UBR11=0x00; UMCTL1=0xF7; /* uart0 3683400Hz 19194bps */ + UBR01=0xBF; UBR11=0x00; UMCTL1=0xF7; /* uart0 3683400Hz 19194bps */ break; case 3://38400 baud - //UBR01=0x5F; UBR11=0x00; UMCTL1=0xBF; /* uart0 3683400Hz 38408bps */ + UBR01=0x5F; UBR11=0x00; UMCTL1=0xBF; /* uart0 3683400Hz 38408bps */ break; case 4://57600 baud - //UBR01=0x40; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 57553bps */ + UBR01=0x40; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 57553bps */ break; default: case 5://115200 baud - //UBR01=0x20; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 115106bps */ + UBR01=0x20; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 115106bps */ break; } } -void msp430_init_uart(){ - +void msp430_init_uart0(){ /* RS232 */ P3SEL |= BIT4|BIT5; // P3.4,5 = USART0 TXD/RXD @@ -109,7 +107,7 @@ void msp430_init_uart(){ UCTL0 = SWRST | CHAR; /* 8-bit character, UART mode */ UTCTL0 = SSEL1; /* UCLK = MCLK */ - setbaud(0); + setbaud0(0); ME1 &= ~USPIE0; /* USART1 SPI module disable */ ME1 |= (UTXE0 | URXE0); /* Enable USART1 TXD/RXD */ @@ -124,6 +122,30 @@ void msp430_init_uart(){ } +void msp430_init_uart1(){ + + /* RS232 */ + P3DIR &= ~0x80; /* Select P37 for input (UART1RX) */ + P3DIR |= 0x40; /* Select P36 for output (UART1TX) */ + P3SEL |= 0xC0; /* Select P36,P37 for UART1{TX,RX} */ + + UCTL1 = SWRST | CHAR; /* 8-bit character, UART mode */ + UTCTL1 = SSEL1; /* UCLK = MCLK */ + + setbaud1(0); + + ME2 &= ~USPIE1; /* USART1 SPI module disable */ + ME2 |= (UTXE1 | URXE1); /* Enable USART1 TXD/RXD */ + + UCTL1 &= ~SWRST; + + /* XXX Clear pending interrupts before enable!!! */ + U1TCTL |= URXSE; + + //IE2 |= URXIE1; /* Enable USART1 RX interrupt */ +} + + /** For EZ430/FETUIF void msp430_init_dco() { WDTCTL = WDTPW + WDTHOLD; //stop WDT @@ -160,7 +182,7 @@ void msp430_init_dco() { //#define MSP430_CPU_SPEED 4915200UL //Max speed. -//#deefine MSP430_CPU_SPEED 4500000UL +//#define MSP430_CPU_SPEED 4500000UL //baud rate speed #define MSP430_CPU_SPEED 3683400UL diff --git a/firmware/tests/blink/Makefile b/firmware/tests/blink/Makefile index 0c6ffc1..71a5c9b 100644 --- a/firmware/tests/blink/Makefile +++ b/firmware/tests/blink/Makefile @@ -6,7 +6,7 @@ BSL=goodfet.bsl #mcu=msp430x1611 #mcu=msp430x2618 -mcu=msp430x2001 +mcu?=msp430x2001 #GCCINC=-T ../../ldscripts/161x.x CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I ../../include -- 2.20.1