From: Dan White Date: Tue, 7 May 2013 16:45:09 +0000 (-0500) Subject: msp4th: also make I/O functions configurable X-Git-Tag: bootrom-initial-submission~2 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=8efd0cc2eb55c9e40d7a67bb179bde1a5bbb7af3;p=430.git msp4th: also make I/O functions configurable This allows grafting in an interrupt-based uart in addition to giving different-sized program and stack spaces. --- diff --git a/msp4th/main.c b/msp4th/main.c index 4177b30..24b7e5b 100644 --- a/msp4th/main.c +++ b/msp4th/main.c @@ -98,16 +98,19 @@ int16_t __attribute__ ((section(".noinit"))) progArray[USER_PROG_SIZE]; int16_t __attribute__ ((section(".noinit"))) progOpcodesArray[USER_OPCODE_MAPPING_SIZE]; uint8_t __attribute__ ((section(".noinit"))) cmdListArray[USER_CMD_LIST_SIZE]; +void (*msp4th_putchar)(uint8_t); +uint8_t (*msp4th_getchar)(void); +void (*msp4th_puts)(uint8_t *); void config_default_msp4th(void) { int16_t i; - mathStackStartAddress = (uint16_t)&mathStackArray[MATH_STACK_SIZE - 1]; - addrStackStartAddress = (uint16_t)&addrStackArray[ADDR_STACK_SIZE - 1]; - progStartAddress = (uint16_t)&progArray[0]; - progOpcodesStartAddress = (uint16_t)&progOpcodesArray[0]; - cmdListStartAddress = (uint16_t)&cmdListArray[0]; + mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1]; + addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1]; + progStartAddress = &progArray[0]; + progOpcodesStartAddress = &progOpcodesArray[0]; + cmdListStartAddress = &cmdListArray[0]; for (i=0; i < MATH_STACK_SIZE; i++) { @@ -117,6 +120,10 @@ void config_default_msp4th(void) for (i=0; i < ADDR_STACK_SIZE; i++) { addrStackArray[i] = 0; } + + msp4th_putchar = &uart_putchar; + msp4th_getchar = &uart_getchar; + msp4th_puts = &uart_puts; } diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 596d3e1..cd0e702 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -16,18 +16,13 @@ #if defined(MSP430) -/* use devboard uart */ +#include "ns430.h" #include "ns430-atoi.h" -#include "ns430-uart.h" #else -/* mixins to test msp4th on PC */ -#include +// mixins to test msp4th on PC #include typedef uint8_t str_t; -void uart_putchar(uint8_t c) { putchar(c); } -uint8_t uart_getchar(void) { return (uint8_t)getchar(); } -void uart_puts(uint8_t *s) { puts((char *)s); } #endif @@ -389,24 +384,24 @@ void getLine() lineBufferIdx = 0; - uart_putchar('\r'); - uart_putchar('\n'); - uart_putchar('>'); // this is our prompt + msp4th_putchar('\r'); + msp4th_putchar('\n'); + msp4th_putchar('>'); // this is our prompt waiting = 1; while (waiting) { // just hang in loop until we get CR - c = uart_getchar(); + c = msp4th_getchar(); if ((c == '\b') && (lineBufferIdx > 0)) { - uart_putchar('\b'); - uart_putchar(' '); - uart_putchar('\b'); + msp4th_putchar('\b'); + msp4th_putchar(' '); + msp4th_putchar('\b'); lineBufferIdx--; } else if ( ((c == 255) || (c == '')) && (lineBufferIdx == 0)) { xit = 1; waiting = 0; } else { - uart_putchar(c); + msp4th_putchar(c); if ( (c == '\r') || (c == '\n') || (lineBufferIdx >= (LINE_SIZE - 1))) { // prevent overflow of line buffer @@ -416,7 +411,7 @@ void getLine() lineBuffer[lineBufferIdx] = 0; } } - uart_putchar('\n'); + msp4th_putchar('\n'); lineBufferIdx = 0; } @@ -493,9 +488,9 @@ void getWord(void) void listFunction() { - uart_puts((str_t *)cmdListBi); - uart_puts((str_t *)cmdListBi2); - uart_puts((str_t *)cmdList); + msp4th_puts((str_t *)cmdListBi); + msp4th_puts((str_t *)cmdListBi2); + msp4th_puts((str_t *)cmdList); } @@ -755,7 +750,7 @@ void printNumber(register int16_t n) uint8_t x[7]; if (n < 0) { - uart_putchar('-'); + msp4th_putchar('-'); nu = -n; } else { nu = n; @@ -771,10 +766,10 @@ void printNumber(register int16_t n) do{ i = i - 1; - uart_putchar(x[i]); + msp4th_putchar(x[i]); } while (i > 0); - uart_putchar(' '); + msp4th_putchar(' '); } @@ -784,7 +779,7 @@ void printHexChar(int16_t n){ n += 7; } n += '0'; - uart_putchar(n); + msp4th_putchar(n); } @@ -1025,11 +1020,11 @@ void execN(int16_t opcode){ break; case 38: // pwrd ( -- ) \ print word buffer - uart_puts((str_t *)wordBuffer); + msp4th_puts((str_t *)wordBuffer); break; case 39: // emit ( c -- ) - uart_putchar(popMathStack()); + msp4th_putchar(popMathStack()); break; case 40: // ; ( pcnt -a- ) @@ -1126,12 +1121,12 @@ void execN(int16_t opcode){ break; case 52: // key ( -- c ) \ get a key from input .... (wait for it) - pushMathStack(uart_getchar()); + pushMathStack(msp4th_getchar()); break; case 53: // cr ( -- ) - uart_putchar(0x0D); - uart_putchar(0x0A); + msp4th_putchar(0x0D); + msp4th_putchar(0x0A); break; case 54: // *2 ( a -- a<<1 ) diff --git a/msp4th/msp4th.h b/msp4th/msp4th.h index 9250567..2f4f163 100644 --- a/msp4th/msp4th.h +++ b/msp4th/msp4th.h @@ -2,19 +2,27 @@ #define __MSP4TH #if defined(MSP430) -extern volatile uint16_t mathStackStartAddress asm("__mathStackStartAddress"); -extern volatile uint16_t addrStackStartAddress asm("__addrStackStartAddress"); -extern volatile uint16_t progStartAddress asm("__progStartAddress"); -extern volatile uint16_t progOpcodesStartAddress asm("__progOpcodesStartAddress"); -extern volatile uint16_t cmdListStartAddress asm("__cmdListStartAddress"); +extern volatile int16_t *mathStackStartAddress asm("__mathStackStartAddress"); +extern volatile int16_t *addrStackStartAddress asm("__addrStackStartAddress"); +extern volatile int16_t *progStartAddress asm("__progStartAddress"); +extern volatile int16_t *progOpcodesStartAddress asm("__progOpcodesStartAddress"); +extern volatile uint8_t *cmdListStartAddress asm("__cmdListStartAddress"); #else -extern volatile uint16_t mathStackStartAddress; -extern volatile uint16_t addrStackStartAddress; -extern volatile uint16_t progStartAddress; -extern volatile uint16_t progOpcodesStartAddress; -extern volatile uint16_t cmdListStartAddress; +extern volatile int16_t *mathStackStartAddress; +extern volatile int16_t *addrStackStartAddress; +extern volatile int16_t *progStartAddress; +extern volatile int16_t *progOpcodesStartAddress; +extern volatile uint8_t *cmdListStartAddress; #endif +/* + * Provide definitions for these functions in user code and assign the function + * pointer before calling init_msp4th() + */ +extern void (*msp4th_putchar)(uint8_t c); +extern uint8_t (*msp4th_getchar)(void); +extern void (*msp4th_puts)(uint8_t *s); + void init_msp4th(void); void processLoop(void); diff --git a/msp4th/test4th.c b/msp4th/test4th.c index 0432846..8520e50 100644 --- a/msp4th/test4th.c +++ b/msp4th/test4th.c @@ -1,8 +1,13 @@ +#include +#include -#include "ns430.h" #include "msp4th.h" +void (*msp4th_putchar)(uint8_t); +uint8_t (*msp4th_getchar)(void); +void (*msp4th_puts)(uint8_t *); + #define MATH_STACK_SIZE 32 #define ADDR_STACK_SIZE 64 @@ -16,22 +21,42 @@ int16_t progArray[USR_OPCODE_SIZE]; int16_t progOpcodesArray[USR_OPCODE_SIZE]; uint8_t cmdListArray[CMD_LIST_SIZE]; -volatile uint16_t mathStackStartAddress; -volatile uint16_t addrStackStartAddress; -volatile uint16_t progStartAddress; -volatile uint16_t progOpcodesStartAddress; -volatile uint16_t cmdListStartAddress; +volatile int16_t *mathStackStartAddress; +volatile int16_t *addrStackStartAddress; +volatile int16_t *progStartAddress; +volatile int16_t *progOpcodesStartAddress; +volatile uint8_t *cmdListStartAddress; + + + +void my_putchar(uint8_t c) +{ + putchar((char)c); +} + + +uint8_t my_getchar(void) +{ + return (uint8_t)getchar(); +} + + +void my_puts(uint8_t *s) +{ + puts((char *)s); +} + void config_msp4th(void) { int16_t i; - mathStackStartAddress = (uint16_t)&mathStackArray[MATH_STACK_SIZE - 1]; - addrStackStartAddress = (uint16_t)&addrStackArray[ADDR_STACK_SIZE - 1]; - progStartAddress = (uint16_t)&progArray[0]; - progOpcodesStartAddress = (uint16_t)&progOpcodesArray[0]; - cmdListStartAddress = (uint16_t)&cmdListArray[0]; + mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1]; + addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1]; + progStartAddress = &progArray[0]; + progOpcodesStartAddress = &progOpcodesArray[0]; + cmdListStartAddress = &cmdListArray[0]; for (i=0; i < MATH_STACK_SIZE; i++) { mathStackArray[i] = 0; @@ -40,6 +65,10 @@ void config_msp4th(void) for (i=0; i < ADDR_STACK_SIZE; i++) { addrStackArray[i] = 0; } + + msp4th_putchar = &my_putchar; + msp4th_getchar = &my_getchar; + msp4th_puts = &my_puts; }