From: Dan White Date: Fri, 7 Sep 2012 17:57:06 +0000 (-0500) Subject: Reworking main/msp4th/uart code X-Git-Tag: bootrom-initial-submission~88 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=bb475a54e441912d0495df217140f841e93eea90;p=430.git Reworking main/msp4th/uart code --- diff --git a/msp4th/main.c b/msp4th/main.c new file mode 100644 index 0000000..55bad0b --- /dev/null +++ b/msp4th/main.c @@ -0,0 +1,54 @@ + + +#include +#include +#include + +#include "ns430-atoi.h" +#include "ns430-uart.h" + +#include "msp4th.h" + + +int main(void){ + + PAPER = 0x0030; + PAOUT = 0x0000; + PAOEN = 0x0010; // set data direction registers + + init_msp4th(); + + /*TMR0_CNT = 0x0000;*/ + /*TMR0_SR = 0;*/ + /*TMR0_RC = 1059;*/ + /*TMR0_CR = 0x003C;*/ + + /* 8e6 / (16*19200) - 1 = 25.0416 */ + /* 8e6 / (16*2400) - 1 = 207.33 */ + /* 25e6 / (16*2400) - 1 = 207.33 */ + UART0_BCR = BCR(25000000L, 2400L); + UART0_CR = UARTEn; + + dint(); + putchar('!'); + + while (1) { + uint8_t c; + c = getchar(); + if (c == '`') break; + putchar(c); + } + + putchar('t'); + putchar('e'); + putchar('s'); + putchar('t'); + putchar('i'); + putchar('n'); + putchar('g'); + puts("This is a test of the UART serial printing\r\nit really does work ...\r\n"); + + processLoop(); + + return 0; +} diff --git a/msp4th/mkfile b/msp4th/mkfile index 7821bac..950974a 100644 --- a/msp4th/mkfile +++ b/msp4th/mkfile @@ -8,12 +8,12 @@ # $(TARGET).elf $(TARGET).hex and $(TARGET).txt nad $(TARGET).map are all generated. # The TXT file is used for BSL loading, the ELF can be used for JTAG use # -TARGET = msp4th +TARGET = main #MCU = msp430f5529 MCU = msp2 # List all the source files here # eg if you have a source file foo.c then list it here -SOURCES = x.c +SOURCES = main.c ns430-uart.c # Include are located in the Include directory #INCLUDES = -IInclude INCLUDES = -I. diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 8d6ea48..05f27c2 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -3,6 +3,10 @@ #include "ns430-uart.h" #include "msp4th.h" + +/* + * Configuration constants + */ #define CMD_LIST_SIZE 128 #define MATH_STACK_SIZE 16 #define ADDR_STACK_SIZE 32 @@ -11,7 +15,34 @@ #define BI_PROG_SHIFT 10000 - +/* + * Local function prototypes + */ +uint8_t getKeyB(void); +void getLine(void); +void getWord(void); +void listFunction(void); +int16_t popMathStack(void); +void pushMathStack(int16_t n); +int16_t popAddrStack(void); +void pushAddrStack(int16_t n); +int16_t lookupToken(uint8_t *x,uint8_t *l); +void luFunc(void); +void numFunc(void); +void ifFunc(uint8_t x); +void pushnFunc(void); +void overFunc(void); +void dfnFunc(void); +void printNumber(int16_t n); +void printHexChar(int16_t n); +void printHexByte(int16_t n); +void printHexWord(int16_t n); +void execN(int16_t n); +void execFunc(void); + +/* + * Module-level global vars + */ // must end in a space !!!! // The order is important .... don't insert anything! // the order matches the execN function @@ -58,10 +89,8 @@ int16_t subSecondClock; int16_t fastTimer; int16_t slowTimer; - int16_t *dirMemory; - uint16_t buckets[260]; // use buckets[256] for total @@ -272,31 +301,6 @@ uint16_t lineBufferPtr; /* input line buffer pointer */ uint8_t wordBuffer[32]; // just get a word -void init_msp4th(void) { -// xit = 0; - addrStackPtr = ADDR_STACK_SIZE; // this is one past the end !!!! as it should be - progCounter = 10000; - progPtr = 1; // this will be the first opcode - i=0; - cmdListPtr = 0; - cmdList[0] = 0; - progOpsPtr = 1; // just skip location zero .... it makes it easy for us - - dirMemory = (void *) 0; // its an array starting at zero - - lineBufferPtr = 0; - for (i=0; i < 128; i++) { - lineBuffer[i] = 0; - } - - for (i=0; i < 32; i++) { - wordBuffer[i] = 0; - } - - getLine(); -} - - uint8_t getKeyB(){ uint8_t i; i = lineBuffer[lineBufferPtr]; @@ -632,8 +636,6 @@ void printHexWord(int16_t n){ printHexByte(n); } -void execN(int16_t n); // proto ... this could get recursive - void execFunc(){ int16_t opcode; opcode = popMathStack(); @@ -1035,12 +1037,36 @@ void execN(int16_t n){ } } + +void init_msp4th(void) { +// xit = 0; + addrStackPtr = ADDR_STACK_SIZE; // this is one past the end !!!! as it should be + progCounter = 10000; + progPtr = 1; // this will be the first opcode + i=0; + cmdListPtr = 0; + cmdList[0] = 0; + progOpsPtr = 1; // just skip location zero .... it makes it easy for us + + dirMemory = (void *) 0; // its an array starting at zero + + lineBufferPtr = 0; + for (i=0; i < 128; i++) { + lineBuffer[i] = 0; + } + + for (i=0; i < 32; i++) { + wordBuffer[i] = 0; + } + + getLine(); +} + + void processLoop(){ // this processes the forth opcodes. int16_t opcode; - while(1){ - printString((const uint8_t *)"processLoop()\r\n"); if(progCounter > 9999){ opcode = progBi[progCounter - 10000]; diff --git a/msp4th/ns430-uart.c b/msp4th/ns430-uart.c new file mode 100644 index 0000000..b1b6cf5 --- /dev/null +++ b/msp4th/ns430-uart.c @@ -0,0 +1,30 @@ + + +#include + +#include "ns430-atoi.h" +#include "ns430-uart.h" + + +int putchar(int c) +{ + int16_t i; + /*while ((UART0_SR & TDRE) == 0) {*/ + while ((UART0_SR & (TDRE | TXEMPTY)) == 0) { + // wait for register to clear + i++; + } + UART0_TDR = c; + return 0; +} + +int getchar(void){ + uint8_t c; + + while ((UART0_SR & RDRF) == 0) { + // wait for char + } + c = UART0_RDR & 0x00ff; + return c; +} + diff --git a/ns430-uart.h b/ns430-uart.h index e768edf..37e57ed 100644 --- a/ns430-uart.h +++ b/ns430-uart.h @@ -1,4 +1,5 @@ - +#ifndef NS430_UART +#define NS430_UART /* UARTx_CR bits */ #define TDRE_IE (1 << 0) @@ -29,3 +30,7 @@ #define PE (1 << 4) #define FE (1 << 5) +int putchar(int c); +int getchar(void); + +#endif