From: travisutk Date: Tue, 24 Jul 2012 01:00:45 +0000 (+0000) Subject: Hello world on the Apimote! X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=a1306ffe48d2020061f2f678f5554659673de425;ds=sidebyside Hello world on the Apimote! git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1202 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/firmware/config.mk b/firmware/config.mk index 9a223a6..76c118f 100644 --- a/firmware/config.mk +++ b/firmware/config.mk @@ -5,6 +5,14 @@ #Unset by default, but can be explicitly set later. config=undef +ifneq (,$(findstring $(board),apimote)) +mcu ?= msp430f2618 +platform := apimote +config := monitor spi ccspi +MSP430BSL?=goodfet.bsl --speed=38400 --swap-reset-test +CFLAGS += -Duseuart1 +endif + ifneq (,$(findstring $(board),goodfet20 goodfet10 goodfet11)) mcu ?= msp430f1612 platform := goodfet diff --git a/firmware/lib/msp430f2618.c b/firmware/lib/msp430f2618.c index 8ba3319..f0868f5 100644 --- a/firmware/lib/msp430f2618.c +++ b/firmware/lib/msp430f2618.c @@ -24,8 +24,13 @@ unsigned char serial0_rx(){ //! Receive a byte. unsigned char serial1_rx(){ - //TODO - return 00; + char c; + + while (!(UC1IFG&UCA1RXIFG)); // USCI_A1 TX buffer ready? + c = UCA1RXBUF; + UC1IFG&=~UCA1RXIFG; + + return c; } //! Transmit a byte. @@ -34,6 +39,13 @@ void serial0_tx(unsigned char x){ UCA0TXBUF = x; /* send the character */ while(!(IFG2 & UCA0TXIFG)); } +//! Transmit a byte on the second UART. +void serial1_tx(unsigned char x){ + while ((UC1IFG & UCA1TXIFG) == 0); //loop until buffer is free + UCA1TXBUF = x; /* send the character */ + while(!(UC1IFG & UCA1TXIFG)); +} + //! Transmit a byte. void serial_tx_old(unsigned char x){ while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free @@ -41,10 +53,6 @@ void serial_tx_old(unsigned char x){ while(!(IFG2 & UCA0TXIFG)); } -//! Transmit a byte on the second UART. -void serial1_tx(unsigned char x){ - -} //! Set the baud rate. void setbaud0(unsigned char rate){ @@ -77,7 +85,30 @@ void setbaud0(unsigned char rate){ //! Set the baud rate of the second uart. void setbaud1(unsigned char rate){ - + //Table 15-4, page 481 of 2xx Family Guide + switch(rate){ + case 1://9600 baud + UCA1BR1 = 0x06; + UCA1BR0 = 0x82; + break; + case 2://19200 baud + UCA1BR1 = 0x03; + UCA1BR0 = 0x41; + break; + case 3://38400 baud + UCA1BR1 = 0xa0; + UCA1BR0 = 0x01; + break; + case 4://57600 baud + UCA1BR1 = 0x1d; + UCA1BR0 = 0x01; + break; + default: + case 5://115200 baud + UCA1BR0 = 0x8a; + UCA1BR1 = 0x00; + break; + } } #define BAUD0EN 0x41 @@ -85,7 +116,7 @@ void setbaud1(unsigned char rate){ void msp430_init_uart(){ - // Serial on P3.4, P3.5 + // Serial0 on P3.4, P3.5 P3SEL |= BIT4 + BIT5; P3DIR |= BIT4; @@ -106,7 +137,16 @@ void msp430_init_uart(){ //Leave this commented! //Interrupt is handled by target code, not by bootloader. - //IE2 |= UCA0RXIE; + //IE2 |= UCA0RXIE; //DO NOT UNCOMMENT + + // Serial 1 on P3.6, 3.7 + P3SEL |= 0xC0; + //UCA1CTL0 = 0x00; + UCA1CTL1 |= UCSSEL_2; // SMCLK + setbaud1(5); //115200 + UCA1MCTL = 0; + UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine + } diff --git a/firmware/platforms/apimote.h b/firmware/platforms/apimote.h new file mode 100644 index 0000000..082947a --- /dev/null +++ b/firmware/platforms/apimote.h @@ -0,0 +1,94 @@ +/*! \file apimote.h + \author Ryan Speers + \brief Port descriptions for the GoodFET platform. +*/ + +/* #ifdef __MSPGCC__ */ +/* #include */ +/* #else */ +/* #include */ +/* #include */ +/* #include */ +/* #endif */ + +#ifndef _GNU_ASSEMBLER_ +#include +#endif + +//LED on P5.5 (pin 49) (LED1 red) +#define PLEDOUT P5OUT +#define PLEDDIR P5DIR +#define PLEDPIN BIT5 +//LED on P5.6 (pin 50) (LED2 green) +#define PLED2OUT P5OUT +#define PLED2DIR P5DIR +#define PLED2PIN BIT6 +//LED on P5.7 (pin 51) (LED3 blue) +#define PLED3OUT P5OUT +#define PLED3DIR P5DIR +#define PLED3PIN BIT7 + +//mtx frx p34 +//mrx ftx p35 + +//SPI +//TelosB: 29/3.1=RF_SI, 30/3.2=RF_SO, 31/3.3=RF_SCLK +//ApiMote: 29/3.1=RF_SI, 30/3.2=RF_SO, 31/3.3=RF_SCLK +#define SPIOUT P3OUT +#define SPIDIR P3DIR +#define SPIIN P3IN +#define SPIREN P3REN + +/* For the radio to be used: + 2.7 (!RST) must be low + 2.0 (VREF_EN) must be high (cc2420-41 rf_vreg) + 3.0 (!CS) must be low for the transaction. +*/ + + +/* TODO what to do here?. Hopefully nothing. +#define INITPLATFORM \ + P1DIR = 0xe0;\ + P1OUT = 0x00;\ + P2DIR = 0x7b;\ + P2OUT = 0x10;\ + P3DIR = 0xf1;\ + P3OUT = 0x00;\ + P4DIR = 0xfd;\ + P4OUT = 0xFd;\ + P5DIR = 0xff;\ + P5OUT = 0xff;\ + P6DIR = 0xff;\ + P6OUT = 0x00; +*/ + +//RF Control +//TelosB: Radio CS is 38/P4.2 (to CC2420 pin31) +//ApiMote: Radio CS is 28/P3.0 +#define SETSS P3OUT|=BIT0 +#define CLRSS P3OUT&=~BIT0 +#define DIRSS P3DIR|=BIT0 + +//CC2420 Chip Enable +//TelosB: Radio RESETn is 42/P4.6 (to CC2420 pin21) +//ApiMote: Radio RESETn is 27/P2.7 (to CC2420 pin21) +#define SETCE P2OUT|=BIT7 +#define CLRCE P2OUT&=~BIT7 +#define DIRCE P2DIR|=BIT7 + +//CC2420 signals +#define SFD (P2IN&BIT6) //TelosB 37/P4.1 -> ApiMote 26/P2.6 +#define FIFOP (P2IN&BIT4) //TelosB 12/P1.0 -> ApiMote 24/P2.4 (rf_pkt cc2420-29) +#define FIFO (P2IN&BIT3) //TelosB 15/P1.3 -> ApiMote 23/P2.3 (rf_gio0 cc2420-30) + +// network byte order converters +#define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \ + (((uint16_t)(x) & 0x00FF) << 8)) +#define htonl(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \ + (((uint32_t)(x) & 0x00FF0000) >> 8) | \ + (((uint32_t)(x) & 0x0000FF00) << 8) | \ + (((uint32_t)(x) & 0x000000FF) << 24)) + +#define ntohs htons +#define ntohl htonl +