Reworking main/msp4th/uart code
authorDan White <dan@whiteaudio.com>
Fri, 7 Sep 2012 17:57:06 +0000 (12:57 -0500)
committerDan White <dan@whiteaudio.com>
Fri, 7 Sep 2012 17:57:06 +0000 (12:57 -0500)
msp4th/main.c [new file with mode: 0644]
msp4th/mkfile
msp4th/msp4th.c
msp4th/ns430-uart.c [new file with mode: 0644]
ns430-uart.h

diff --git a/msp4th/main.c b/msp4th/main.c
new file mode 100644 (file)
index 0000000..55bad0b
--- /dev/null
@@ -0,0 +1,54 @@
+
+
+#include <stdio.h>
+#include <signal.h>
+#include <iomacros.h>
+
+#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;
+}
index 7821bac93bc42454a1f4f35f99f71b8839e24e98..950974a35dc35c1fcfcca19ede94bfc11d7ee4f2 100644 (file)
@@ -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.
index 8d6ea4859e125b17ec8bb96cbc29e4d60c3d0ba8..05f27c22766c8577120bea92ec6accccea73ce1f 100644 (file)
@@ -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
 
 #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 (file)
index 0000000..b1b6cf5
--- /dev/null
@@ -0,0 +1,30 @@
+
+
+#include <iomacros.h>
+
+#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;
+} 
+
index e768edf7537d5300f14186c211bcdade6686fa83..37e57ede0ff6d492b284de7e834f45a78d8d49b6 100644 (file)
@@ -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