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++) {
for (i=0; i < ADDR_STACK_SIZE; i++) {
addrStackArray[i] = 0;
}
+
+ msp4th_putchar = &uart_putchar;
+ msp4th_getchar = &uart_getchar;
+ msp4th_puts = &uart_puts;
}
#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 <stdio.h>
+// mixins to test msp4th on PC
#include <stdint.h>
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
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 == '\ 4')) && (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
lineBuffer[lineBufferIdx] = 0;
}
}
- uart_putchar('\n');
+ msp4th_putchar('\n');
lineBufferIdx = 0;
}
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);
}
uint8_t x[7];
if (n < 0) {
- uart_putchar('-');
+ msp4th_putchar('-');
nu = -n;
} else {
nu = n;
do{
i = i - 1;
- uart_putchar(x[i]);
+ msp4th_putchar(x[i]);
} while (i > 0);
- uart_putchar(' ');
+ msp4th_putchar(' ');
}
n += 7;
}
n += '0';
- uart_putchar(n);
+ msp4th_putchar(n);
}
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- )
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 )
#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);
+#include <stdio.h>
+#include <stdint.h>
-#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
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;
for (i=0; i < ADDR_STACK_SIZE; i++) {
addrStackArray[i] = 0;
}
+
+ msp4th_putchar = &my_putchar;
+ msp4th_getchar = &my_getchar;
+ msp4th_puts = &my_puts;
}