From 79e87fd66cca0efddecda13da9b7e436d7dabaf7 Mon Sep 17 00:00:00 2001 From: Dan White Date: Sat, 11 May 2013 00:49:30 -0500 Subject: [PATCH] msp4th: cleanup, documentation, fix live re-init --- msp4th/bootrom.rcf | 792 ++++++++++++++++++++++----------------------- msp4th/main.c | 1 + msp4th/msp4th.c | 380 ++++++++++++---------- msp4th/msp4th.h | 1 + msp4th/test4th.c | 6 + 5 files changed, 613 insertions(+), 567 deletions(-) diff --git a/msp4th/bootrom.rcf b/msp4th/bootrom.rcf index b6e66a9..42b2026 100644 --- a/msp4th/bootrom.rcf +++ b/msp4th/bootrom.rcf @@ -113,53 +113,56 @@ 0100001000011111 0010001000000100 0100000010110010 -0100000001100000 -0100010001000010 -0100000010110010 -0100000011100000 +0100000001100010 0100010001000100 0100000010110010 0100000011100010 0100010001000110 0100000010110010 -0100001011100010 +0100000011100100 0100010001001000 0100000010110010 -0100001100100010 +0100001011100100 0100010001001010 0100000010110010 -0100001110100010 +0100001100100100 0100010001001100 0100000010110010 -0000000010000000 +0100001110100100 0100010001001110 0100000010110010 -0100010000100010 +0000000010000000 0100010001010000 0100000010110010 -0000000000100000 +0100010000100100 0100010001010010 0100000010110010 -0011000101001100 +0000000000100000 0100010001010100 0100000010110010 -0011000101011100 +0011000101010010 0100010001010110 +0100000010110010 +0011000101100010 +0100010001011000 +0100000010110010 +0011000101101110 +0100010001011010 0100001111000010 -0100001110100010 +0100001110100100 0100001111000010 -0100010000100010 +0100010000100100 0100001111000010 -0100001100100010 +0100001100100100 0100000000111111 -0100010001000010 +0100010001000100 0001001010110000 -0011101111111010 +0011000110100000 0001001010110000 -0011110001100010 -0011111111010010 +0011110001000000 +0011111111001111 0100000000110000 -0011111111100110 +0011111111001010 0100000000110001 1111111100000000 0100000000110000 @@ -184,41 +187,79 @@ 0100101101101010 0100101001001111 0001001010110000 -0011000101001100 +0011000101010010 0101001100011011 1001001101001010 0010001111111001 0100000001111111 0000000000001101 0001001010110000 -0011000101001100 +0011000101010010 0100000001111111 0000000000001010 0001001010110000 -0011000101001100 +0011000101010010 0100000100111010 0100000100111011 0100000100110000 -0001001000001011 -0001001000001010 -0100111100001011 -0100101101101010 -0100101001001111 -0001001010010010 -0100000000000010 -0101001100011011 -1001001101001010 -0010001111111001 -0100000001111111 -0000000000001101 -0001001010010010 -0100000000000010 -0100000001111111 +0111001101101101 +0011010001110000 +0110100001110100 +0000000000100001 +0100111100100110 +0100111100010111 +0000000000000010 +0100011010000010 +0100000000010110 +0100011110000010 +0100000000011010 +0100111110010010 +0000000000000100 +0100000000001000 +0100111110010010 +0000000000000110 +0100000000100000 +0100111110010010 +0000000000001000 +0100000000011110 +0100111110010010 0000000000001010 -0001001010010010 +0100000000000000 +0100111110010010 +0000000000001100 +0100000000010010 +0100111110010010 +0000000000001110 +0100000000000110 +0100111110010010 +0000000000010000 +0100000000001110 +0100111110010010 +0000000000010010 0100000000000010 -0100000100111010 -0100000100111011 +0100111110010010 +0000000000010100 +0100000000010000 +0100111100011110 +0000000000010110 +0100111010000010 +0100000000011000 +0100001110000010 +0100000000000100 +0100001110010010 +0100000000001100 +0100000010110010 +0010011100010000 +0100000000011100 +0100001110010010 +0100000000100010 +0100001110000010 +0100000000010100 +0100001110000010 +0100000000001010 +0100000000111111 +0011000110011000 +0001001010001110 0100000100110000 0001001000001011 0001001000001010 @@ -348,7 +389,7 @@ 1001001101001111 0010000000001011 0001001010110000 -0011000110111100 +0011001000001110 0100001000011110 0100000000001010 0100001000011111 @@ -361,34 +402,34 @@ 0100000100110000 0001001000001011 0001001010110000 -0011001010100100 +0011001011110110 0100000001111011 0000000000100000 0011110000000010 0001001010110000 -0011001010100100 +0011001011110110 1001111101001011 0010111111111100 0100000100111011 0100000100110000 0001001010110000 -0011001010100100 +0011001011110110 1001000001111111 0000000000101001 0010001111111011 0001001010110000 -0011001011010010 +0011001100100100 0100000100110000 0001001000001011 0001001000001010 0011110000000101 0001001010110000 -0011001011101010 +0011001100111100 0011110000000100 0001001010110000 -0011000110111100 +0011001000001110 0001001010110000 -0011001011010010 +0011001100100100 1001000001111111 0000000000101000 0010011111110110 @@ -410,7 +451,7 @@ 0100001111001111 0000000000000000 0001001010110000 -0011001010100100 +0011001011110110 1001111101001010 0010110000000011 1001001000011011 @@ -420,17 +461,17 @@ 0100000100111011 0100000100110000 0100000000111111 -0011110011000100 -0001001010110000 -0011000110010010 +0011110010100010 +0001001010010010 +0100000000011000 0100000000111111 -0011110111100111 -0001001010110000 -0011000110010010 +0011110111001010 +0001001010010010 +0100000000011000 0100001000011111 -0100000000011100 -0001001010110000 -0011000110010010 +0100000000011110 +0001001010010010 +0100000000011000 0100000100110000 0100011000101111 1001001000010110 @@ -538,10 +579,10 @@ 0100001000011010 0100000000000110 0100000000111110 -0011110011000100 +0011110010100010 0100101000001111 0001001010110000 -0011001110010000 +0011001111100010 0100111100001001 1001001100001111 0010010000000011 @@ -549,10 +590,10 @@ 0100111000100000 0011110000010010 0100000000111110 -0011110111100111 +0011110111001010 0100101000001111 0001001010110000 -0011001110010000 +0011001111100010 0100111100001011 1001100100001111 0010010000000011 @@ -560,17 +601,17 @@ 0010011100010000 0011110000000111 0100001000011110 -0100000000011100 +0100000000011110 0100101000001111 0001001010110000 -0011001110010000 +0011001111100010 1001101100001111 0010010000000011 0001001010110000 -0011001101110000 +0011001111000010 0100001100011111 0001001010110000 -0011001101110000 +0011001111000010 0100000100111001 0100000100111010 0100000100111011 @@ -657,23 +698,23 @@ 0011110000000001 0100001100011011 0001001010110000 -0011001101110000 +0011001111000010 0100101100001111 0001001010110000 -0011001101110000 +0011001111000010 0100000100111010 0100000100111011 0100000100110000 0001001000001011 0100001000011110 -0100000000011010 +0100000000011100 1001000000111110 0010011100010000 0010100000000101 0100111000001101 0101110100001101 0101000000111101 -1110111111011000 +1110111110111100 0011110000000100 0100111000001101 0101110100001101 @@ -682,49 +723,36 @@ 0100110100101011 0101001100011110 0100111010000010 -0100000000011010 +0100000000011100 1001001100011111 0010010000000100 0001001010110000 -0011001101100100 +0011001110110110 1001001100001111 0010000000000010 0100101110000010 -0100000000011010 +0100000000011100 0100000100111011 0100000100110000 -0001001000001011 -0001001000001010 -0001001000001001 -0100111100001001 -0001001010110000 -0011001101111000 -0100111100001011 -0100111100001010 -0101100100001010 -1001001100011001 -0011100000000011 -1001111100001010 +0100011100001110 +0100011100001100 +0101001100101100 +0100111100001101 +0101110000101101 +0100110110001100 +0000000000000000 +1001001100001111 0011100000000101 -0011110000001111 -1001001100001001 -0010010000000010 -1001101000001111 -0011010000001011 -0100101100001111 -0001001010110000 -0011001101111110 -0100101000001111 -0001001010110000 -0011001101111110 -0100101100001111 -0001001010110000 -0011001101111110 -0100101110000010 -0100000000011010 -0100000100111001 -0100000100111010 -0100000100111011 +1001011100011101 +0000000000000100 +0011010000000111 +1001001100001111 +0010000000000011 +1001110110001110 +0000000000000100 +0011010000000010 +0100111010100010 +0100000000011100 0100000100110000 0100011000001110 0101111100001111 @@ -740,14 +768,14 @@ 0000000000000000 0100000100110000 0100001000011110 -0100000000011010 +0100000000011100 1001000000111110 0010011100010000 0010100000000101 0100111000001111 0101111100001111 0101000000111111 -1110111111011000 +1110111110111100 0011110000000100 0100111000001111 0101111100001111 @@ -756,14 +784,14 @@ 0100111100101111 0101001100011110 0100111010000010 -0100000000011010 +0100000000011100 0001001010110000 -0011001101110000 +0011001111000010 0100000100110000 0100011000011111 0000000000000010 0001001010110000 -0011001101110000 +0011001111000010 0100000100110000 0100001100001101 0011110000000111 @@ -781,7 +809,7 @@ 0100001000011111 0100000000010100 0100001000011100 -0100000000011100 +0100000000011110 1001001101001110 0010001111101111 0100110000001101 @@ -793,20 +821,20 @@ 0100111110000010 0100000000010100 0101001000011111 -0100000000011100 +0100000000011110 0100111011001111 0000000000000000 0100001000011110 -0100000000011100 +0100000000011110 0100001000011111 0100000000000110 0001001010110000 -0011001110010000 +0011001111100010 0101111100001111 0101001000011111 -0100000000011110 -0100001010011111 0100000000100000 +0100001010011111 +0100000000100010 0000000000000000 0100000100110000 0001001000001011 @@ -831,7 +859,7 @@ 0100000000111010 0000000000001010 0001001010110000 -0011111100100000 +0011111100000100 0101000001111110 0000000000110000 0100111011001000 @@ -840,7 +868,7 @@ 0100000000111010 0000000000001010 0001001010110000 -0011111100100000 +0011111100000100 0100110000001111 0101001100011001 1001001100001100 @@ -889,10 +917,10 @@ 1100001100010010 0001000000001111 0001001010110000 -0011011011001010 +0011011100000010 0100101100001111 0001001010110000 -0011011011001010 +0011011100000010 0100000100111011 0100000100110000 0001001000001011 @@ -902,10 +930,10 @@ 0001000110001110 0100111000001111 0001001010110000 -0011011011100010 +0011011100011010 0100101100001111 0001001010110000 -0011011011100010 +0011011100011010 0100000100111011 0100000100110000 0001001000001011 @@ -914,101 +942,102 @@ 0001001000001000 0101001100111111 1001000000111111 -0000000001001011 +0000000001001100 0010100000000010 0100000000110000 -0011101110100100 +0011101111110010 0101111100001111 0100111100010000 -0011011100110110 -0011011111001100 -0011011111010100 -0011011111011010 -0011011111100110 -0011100000000010 +0011011101101110 +0011100000000110 +0011100000001110 +0011100000010100 +0011100000100000 +0011100001000000 +0011100001010110 +0011100001100010 0011100000011000 -0011100000100100 -0011011111011110 -0011100000101000 -0011100000111010 -0011100001001000 -0011100001010100 -0011100001101110 +0011100001100110 0011100001111000 -0011100010000000 -0011100010001000 -0011100010100000 +0011100010000110 +0011100010010010 +0011100010101100 +0011100010110110 0011100010111110 -0011100011001110 -0011100011100100 -0011100011111010 -0011100100000010 -0011101110100100 -0011101110100100 -0011100100000110 +0011100011000110 +0011100011011110 +0011100011111100 0011100100001100 -0011100100101000 -0011100101010100 -0011101110100100 -0011100101101000 -0011100101101110 -0011100101110010 -0011100101111010 -0011100110000000 -0011100110000110 -0011100110001100 +0011100100100010 +0011100100111000 +0011100101000000 +0011101111110010 +0011101111110010 +0011100101000100 +0011100101001010 +0011100101100110 0011100110010010 -0011100110010110 -0011100110100000 -0011100110101100 -0011100110110110 -0011100111000010 -0011100111010100 -0011100111011010 -0011100111111010 -0011100111111110 -0011101000001000 -0011101000001110 +0011101111110010 +0011100110100110 +0011100110101110 +0011100110110010 +0011100110111010 +0011100111000000 +0011100111000110 +0011100111001100 +0011100111010010 +0011100111010110 +0011100111100000 +0011100111101100 +0011100111110110 +0011101000000010 0011101000010100 0011101000011010 -0011101000100000 -0011101000100110 -0011101000101100 -0011101000110010 -0011101001110000 -0011101001111000 -0011101010000110 -0011101010001100 -0011101010010000 -0011101010011010 -0011101010101010 -0011101011000000 -0011101011011100 -0011101011111010 +0011101000111010 +0011101000111110 +0011101001001000 +0011101001001110 +0011101001010100 +0011101001011010 +0011101001100000 +0011101001100110 +0011101001101100 +0011101001110010 +0011101010110000 +0011101010111000 +0011101011000110 +0011101011001100 +0011101011010000 +0011101011011010 +0011101011101010 0011101100000000 -0011101100000100 -0011101100011000 -0011101100100010 -0011101100101110 -0011101101000010 -0011101101010000 -0011101101100000 -0011101101110100 +0011101100011100 +0011101100111010 +0011101101000000 +0011101101000100 +0011101101011000 +0011101101100010 +0011101101101110 +0011101110000010 0011101110010000 -0011101110011100 +0011101110100000 +0011101110110100 +0011101111010000 +0011101111011100 +0011101111100110 0100001110010010 0100000000000100 0100000000110000 -0011101110100100 +0011101111110010 0101011010100110 0000000000000010 0011110000000010 1000011010100110 0000000000000010 0001001010110000 -0011001101100100 +0011001110110110 0100000000110000 -0011101110100100 +0011101111110010 1100001000110010 0100011000001110 0101001100101110 @@ -1022,24 +1051,26 @@ 0100001010010110 0000000100111010 0000000000000000 -0011110100110101 +1101001000110010 +0100000000110000 +0011101111110010 0100011000011100 0000000000000010 0100011000101010 0001001010110000 -0011111100111100 +0011111100100000 0100110010000110 0000000000000010 0100111010000110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101100100 +0011001110110110 0001001010110000 -0011011001010110 +0011011010001110 0100000000110000 -0011101110100100 +0011101111110010 0100011000101111 0011110010010010 0100011000101101 @@ -1050,73 +1081,73 @@ 0100110110001110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101100100 +0011001110110110 0100011000001110 1001111110000110 0000000000000000 0011010000010000 0011110000001011 0001001010110000 -0011001101100100 +0011001110110110 0100011000001110 1001011000101111 0011010000001010 0011110000000101 0001001010110000 -0011001101100100 +0011001110110110 0100011000001110 1001011000101111 0010000000000100 0100001110011110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0100001110001110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101100100 +0011001110110110 0001001010110000 -0011011011100010 +0011011100011010 0011110001110010 0001001010110000 -0011001011111010 +0011001101001100 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011010111111110 +0011011000110110 0100000000110000 -0011101110100100 +0011101111110010 0100011000101110 1001001100001110 0011100000000010 0100000000110000 -0011101110100100 +0011101111110010 1110001100111110 0100111010000110 0000000000000000 0101001110010110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0100001000011010 -0100000000100000 +0100000000100010 0100101000001011 0101101100001011 0101001000011011 0100000000001000 0001001010110000 -0011001101100100 +0011001110110110 0100111110001011 0000000000000000 0101001100011010 0100101010000010 -0100000000100000 +0100000000100010 0100000000110000 -0011101110100100 +0011101111110010 0100011000101111 0101111100001111 0101001000011111 @@ -1124,52 +1155,52 @@ 0100111110100110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101100100 +0011001110110110 0100111100001011 0001001010110000 -0011001101100100 +0011001110110110 0100101100001110 0101111000001110 0101001000011110 0100000000001000 0100000000110000 -0011101101011010 +0011101110011010 1001001110000110 0000000000000000 0010010000000100 0100001110000110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0100001110010110 0000000000000000 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101001010 +0011001110011100 0100000000110000 -0011101110100100 +0011101111110010 0100001100001111 -0011110000110111 +0011110000111000 0100001000011111 -0100000000011010 -0011110001110100 +0100000000011100 +0011110001110101 0001001010110000 -0011001101111000 +0011001111001010 0100111100001011 0001001010110000 -0011001101100100 +0011001110110110 1001001100001111 0010010000000010 0100000000110000 -0011101110100100 +0011101111110010 1000001100100111 0100101110000010 -0100000000011010 +0100000000011100 0100000000110000 -0011101110100100 +0011101111110010 0100001000011110 0100000000010110 0100111000001111 @@ -1189,123 +1220,124 @@ 0001000000001110 0100111000001111 0001001010110000 -0011001101110000 +0011001111000010 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011001101100100 +0011001110110110 0001001010110000 -0011011100000010 +0011011100111010 0100000001111111 0000000000100000 0001001010010010 0100000000000010 0100000000110000 -0011101110100100 +0011101111110010 0001001010110000 -0011010010000010 -0011110100011011 +0011010011010100 +0100000000110000 +0011101111110010 0100001100001111 -0011111111101101 +0011111111101100 0100001100011111 0001001010110000 -0011010100110100 -0011110100010101 +0011010110000110 +0011110100011100 0001001010110000 -0011101110101110 -0011110100010010 +0011101111111100 +0011110100011001 0001001010110000 -0011010000101100 -0011110100001111 +0011010001111110 +0011110100010110 0001001010110000 -0011010111001010 -0011110100001100 +0011011000000010 +0011110100010011 0001001010110000 -0011010111110100 -0011110100001001 +0011011000101100 +0011110100010000 0100001100011111 -0011111111011011 +0011111111011010 0100001000011111 0100000000000110 -0001001010110000 -0011000110010010 -0011110100000010 +0001001010010010 +0100000000011000 +0011110100001001 0100001000011011 0100000000000010 0001001010110000 -0011001101100100 +0011001110110110 0001001010001011 -0011110011111100 +0011110100000011 0001001010110000 -0011001101111000 +0011001111001010 0100111110000010 -0100000000011010 -0011110011110111 +0100000000011100 +0011110011111110 0100011000101110 1111000000111110 1111111111111110 0100111010100110 0000000000000000 -0011110011110001 +0011110011111000 0001001010110000 -0011001101100100 +0011001110110110 0100111100001011 0001001010110000 -0011001101100100 +0011001110110110 0100101100001110 1111000000111110 1111111111111110 0011110011000011 0100001000011111 -0100000000100000 -0011111110111001 +0100000000100010 +0011111110111000 0001001010110000 -0011001101100100 +0011001110110110 0100111100001010 0001001010110000 -0011001101100100 +0011001110110110 0100001000011011 -0100000000011010 +0100000000011100 0001001010110000 -0011001101111110 +0011001111010000 0100101000001111 0001001010110000 -0011001101111110 +0011001111010000 0100101100001111 0001001010110000 -0011001101111110 -0011110011010101 +0011001111010000 +0011110011011100 0100001100011111 0011110000000010 0001001010110000 -0011001101100100 +0011001110110110 0001001010110000 -0011010101101110 -0011110011001110 +0011010111000000 +0011110011010101 0100011100011111 0000000000000010 -0011111110011111 +0011111110011110 0100011100011111 0000000000001000 -0011111110011100 +0011111110011011 0100011100011111 0000000000001110 -0011111110011001 +0011111110011000 1110001110110110 0000000000000000 -0011110011000010 +0011110011001001 1110011010100110 0000000000000010 -0011111011011100 +0011111011011001 1111011010100110 0000000000000010 -0011111011011001 +0011111011010110 1101011010100110 0000000000000010 -0011111011010110 +0011111011010011 1100001000110010 0001001010110000 -0011001101100100 +0011001110110110 0100111110000010 0000000100110010 0100011010010010 @@ -1319,6 +1351,7 @@ 0100111000001101 1101111000001100 1101111100001101 +1101001000110010 0100011000101010 0100101000001011 0001000010001011 @@ -1326,35 +1359,34 @@ 0001000010001011 0001000110001011 0001001010110000 -0011111101110010 +0011111101010110 0100110000001011 0001001010110000 -0011001101100100 +0011001110110110 0100101110000110 0000000000000000 -1101001000110010 -0011110010011010 +0011110010100001 0001001010010010 0100000000010000 0100111101001111 -0011111101101010 +0011111101101001 0100000001111111 0000000000001101 0001001010010010 0100000000000010 0100000001111111 0000000000001010 -0011111101101101 +0011111101101100 0101011010100110 0000000000000000 -0011110010001100 +0011110010010011 0001000100100110 -0011110010001010 +0011110010010001 0100011000001011 0001001010100110 0100111110001011 0000000000000000 -0011110010000101 +0011110010001100 0100011000001011 0101001100101011 0100101100101111 @@ -1362,7 +1394,7 @@ 0100111110001011 0000000000000000 0100000000110000 -0011011111011110 +0011100000011000 0100011000001011 0101001000101011 0100011000011110 @@ -1404,72 +1436,72 @@ 0000000000000011 0000000000000000 0001001010110000 -0011001110000110 -0011110001010010 +0011001111011000 +0011110001011001 0001000010000110 -0011110001010000 +0011110001010111 0001001010110000 -0011001101100100 +0011001110110110 0100111100001011 0001001010110000 -0011001101100100 +0011001110110110 0100101100001110 0101111000001110 0101111110001110 0000000000000000 -0011110001000110 +0011110001001101 0001001010110000 -0011001101100100 +0011001110110110 0001001010110000 -0011010110110000 -0011110001000001 +0011010111101000 +0011110001001000 0001001010110000 -0011001101100100 +0011001110110110 0101111100001111 0101011000001111 0100111100101111 -0011111100001111 +0011111100001110 0100011000011011 0000000000000010 0100011000101111 0001001010110000 -0011001101110000 +0011001111000010 0100011010100110 0000000000000100 0100101110000110 0000000000000010 -0011110000110001 +0011110000111000 0001001010110000 -0011001101100100 +0011001110110110 0100011000001110 1001111110000110 0000000000000000 -0011010000101011 +0011010000110010 0011110000000101 0001001010110000 -0011001101100100 +0011001110110110 0100011000001110 1001011000101111 -0011010000100101 +0011010000101100 0100111110001110 0000000000000000 -0011110000100010 +0011110000101001 0100001000011011 0100000000010110 0011110000000100 0100101100101111 0001001010110000 -0011011001010110 +0011011010001110 1000001100101011 1001011000001011 0010111111111010 -0011110000011000 +0011110000011111 0100001000011011 0100000000010110 0011110000001000 0100101100101111 0001001010110000 -0011011100000010 +0011011100111010 0100000001111111 0000000000100000 0001001010010010 @@ -1477,17 +1509,24 @@ 1000001100101011 1001011000001011 0010111111110110 -0011110000001010 +0011110000010001 0100011000101110 1110001100111110 0101001100011110 0100111010000110 0000000000000000 -0011110000000100 +0011110000001011 0001001010110000 -0011001101100100 +0011001110110110 0100111110000010 0100000000001100 +0011110000000110 +0100001110000010 +0100000000000000 +0001001010110000 +0011001110110110 +0001001010110000 +0011000110100000 0100000100111000 0100000100111001 0100000100111010 @@ -1495,7 +1534,7 @@ 0100000100110000 0001001000001011 0001001010110000 -0011001101100100 +0011001110110110 0100111100001011 1001000000111111 0100111000100000 @@ -1503,85 +1542,29 @@ 0101000000111111 1011000111100000 0001001010110000 -0011011100011100 +0011011101010100 0011110000010100 1001000000111111 0010011100010000 0011100000001000 0100001000011111 -0100000000011010 +0100000000011100 0001001010110000 -0011001101111110 +0011001111010000 0101101100001011 0101000000111011 -1110111111010000 +1110111110110100 0011110000000111 0100001000011111 -0100000000011010 +0100000000011100 0001001010110000 -0011001101111110 +0011001111010000 0101101100001011 0101001000011011 -0100000000011110 +0100000000100000 0100101110100010 -0100000000011010 -0100000100111011 -0100000100110000 -0111001101101101 -0011010001110000 -0110100001110100 -0000000000100001 -0100111100100110 -0100111100010111 -0000000000000010 -0100011010000010 -0100000000010110 -0100011110000010 -0100000000011000 -0100111110010010 -0000000000000100 -0100000000001000 -0100111110010010 -0000000000000110 -0100000000011110 -0100111110010010 -0000000000001000 0100000000011100 -0100111110010010 -0000000000001010 -0100000000000000 -0100111110010010 -0000000000001100 -0100000000010010 -0100111110010010 -0000000000001110 -0100000000000110 -0100111110010010 -0000000000010000 -0100000000001110 -0100111110010010 -0000000000010010 -0100000000000010 -0100111110010010 -0000000000010100 -0100000000010000 -0100001110000010 -0100000000000100 -0100001110010010 -0100000000001100 -0100000010110010 -0010011100010000 -0100000000011010 -0100001110010010 -0100000000100000 -0100001110000010 -0100000000010100 -0100001110000010 -0100000000001010 -0100000000111111 -0011101111110010 -0001001010110000 -0011000110010010 +0100000100111011 0100000100110000 0001001000001011 0001001000001010 @@ -1592,13 +1575,13 @@ 0100111000011111 0011110000100010 0100001000011110 -0100000000011010 +0100000000011100 1001111000001001 0010110000000101 0100111000001111 0101111100001111 0101000000111111 -1110111111011000 +1110111110111100 0011110000000100 0100111000001111 0101111100001111 @@ -1608,23 +1591,23 @@ 0100111000001111 0101001100011111 0100111110000010 -0100000000011010 +0100000000011100 1001101100001010 0010110000000110 0100101100001111 0101000000111111 1011000111100000 0001001010110000 -0011011100011100 +0011011101010100 0011110000001000 0001001010110000 -0011001101111110 +0011001111010000 0100101100001111 0101111100001111 0101001000011111 -0100000000011110 +0100000000100000 0100111110100010 -0100000000011010 +0100000000011100 1001001110000010 0100000000000100 0010011111011011 @@ -1777,11 +1760,14 @@ 0110010100100000 0110100001100011 0010000001101111 -0101101100000000 -0011101000100000 -0111011000100000 -0111001001100001 +0110111001101001 +0111010001101001 0000000000100000 +0010000001011011 +0010000000111010 +0110000101110110 +0010000001110010 +0000000000000000 0000000000000000 0010011100010000 0010011100110000 @@ -1962,7 +1948,7 @@ 0101001100011010 1101001000111101 0001001010110000 -0011111100100000 +0011111100000100 0001000000001101 1011001000101101 0010100000000100 @@ -1993,7 +1979,7 @@ 0110001100001011 1101001000111000 0001001010110000 -0011111110111100 +0011111110100000 0001000000001000 1011001000101000 0010010000001000 @@ -2046,3 +2032,17 @@ 0000000000000000 0000000000000000 0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 diff --git a/msp4th/main.c b/msp4th/main.c index 02b876d..f8eb53f 100644 --- a/msp4th/main.c +++ b/msp4th/main.c @@ -134,6 +134,7 @@ static __inline__ void setup_default_msp4th(void) default_config.wordBufferLength = WORD_BUFFER_SIZE; default_config.putchar = &uart_putchar; default_config.getchar = &uart_getchar; + default_config.puts = &uart_puts; // terminate the strings lineBufferArray[0] = 0; diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 31d5b73..4da0291 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -1,22 +1,24 @@ /* + * msp4th * - * TODO: - * - use enum for VM opcodes + * forth-like interpreter for the msp430 + * + * Source originally from Mark Bauer, beginning life in the z80 and earlier. + * Nathan Schemm used and modified for use in his series of msp430-compatible + * processors. * - * X speed up pop/pushMathStack (need bounds check??) - * only bounds check is for mathStack underflow + * This version by Dan White (2013). Cleaned-up, expanded, and given + * capabilities to allow live re-configuration and directly calling user C + * functions. * - * X UART usage is blocking, convert to interrupt-based - * user may provide msp4th_{putchar,getchar} function pointers - * the default one remains blocking + * * Used in Dan's "atoi" chip loaded from flash into RAM. + * * Fabbed in ROM as part of the Gharzai/Schmitz "piranha" imager chip. * - * X allow configurable user-code space - * mathStack[], addrStack[] - * prog[], cmdList[], progOpcodes[] - * array locations come from a vector table instead of hard-coded - * locations in bss space. init_msp4th() populates the pointers - * with values from the table (which can be user-written to effect - * changing user code sizes. + * If cpp symbol "MSP430" is not defined, it compiles to a version for testing + * on PC as a console program via the setup and main() in "test430.c". + * + * TODO: + * - use enum/symbols for VM opcodes (?builtins tagged as negative numbers?) * */ @@ -24,54 +26,91 @@ #if defined(MSP430) #include "ns430.h" #include "ns430-atoi.h" + // our "special" pointer, direct word access to all absolute address space #define dirMemory ((int16_t *) 0) #else // mixins to test msp4th on PC #include - -// the OS does not like direct memory addressing, something about -// segfaulting... just create a sham space for testing +// the OS does not like direct, absolute, memory addressing... +// just create a sham space for testing int16_t dirMemory[65536]; + #endif #include "msp4th.h" +/**************************************************************************** + * + * Module-level global variables (in RAM) + * + ***************************************************************************/ +int16_t xit; // set to 1 to kill program +int16_t echo; // boolean: false -> no interactive echo/prompt +uint16_t progCounter; // value determines builtin/user and opcode to execute -/* - * Local function prototypes +int16_t lineBufferIdx; // input line buffer index +int16_t progIdx; // next open space for user opcodes +int16_t cmdListIdx; // next open space for user word strings + +/* The following allow re-configuring the location/size of all configurable + * arrays. Then the stack sizes and user program space sizes can be + * (re-)specified by changing the table and calling init_msp4th() again. See + * test430.c for a configuration example. + * + * THE ONLY BOUNDARY CHECKS ARE: + * - math stack underflow + * - line buffer overflow + * - word buffer overflow + * + * The user is therefore responsible for: + * - keeping stack depths in range + * - not underflowing the address stack + * - allocating sufficient space in prog[], progOpcodes[], cmdList[] */ -void msp4th_puts(uint8_t *s); -uint8_t getKeyB(void); -void getLine(void); -uint8_t nextPrintableChar(void); -uint8_t skipStackComment(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); -void ndropFunc(void); -int16_t lookupToken(uint8_t *x, uint8_t *l); -void luFunc(void); -void numFunc(void); -void ifFunc(int16_t x); -void loopFunc(int16_t n); -void rollFunc(int16_t n); -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); +#if defined(MSP430) +/* Register notes. + * r0-3 are special (pc, sp, sr, cg) + * In mspgcc: + * r4-5 are (sometimes) used as frame and argument pointers. + * r12-15 are call clobbered. + * * Function arguments are allocated left-to-right assigned r15--r12, others + * are passed on the stack. + * * Return values are passed in r15, r15:r14, r15:r14:r13, or r15:r14:r13:r12 + * depending on size. + */ +int16_t register *mathStackPtr asm("r6"); // used enough to keep in registers +int16_t register *addrStackPtr asm("r7"); +#else +int16_t *mathStackPtr; +int16_t *addrStackPtr; +#endif + +int16_t *mathStackStart; // original locations for calculating stack depth +int16_t *addrStackStart; + +int16_t *prog; // user programs (opcodes) are placed here + +int16_t *progOpcodes; // mapping between cmdList word index and program + // opcodes start index into prog[] + +uint8_t *cmdList; // string containing user-defined words + +uint8_t *lineBuffer; // where interactive inputs are buffered +int16_t lineBufferLength;// to prevent overflow + +uint8_t *wordBuffer; // the currently-parsed word +int16_t wordBufferLength; + +void (*msp4th_putchar)(uint8_t c); // the sole interactive output avenue +uint8_t (*msp4th_getchar)(void); // the sole interactive input avenue +void (*msp4th_puts)(uint8_t *s); // the sole interactive output avenue + + /**************************************************************************** @@ -98,8 +137,9 @@ const uint8_t cmdListBi[] = { "call2 call3 call4 ndrop swpb " // 61 -> 65 "+! roll pick tuck max " // 66 -> 70 "min s. sh. neg echo " // 71 -> 75 + "init " // 76 }; -#define LAST_PREDEFINED 75 // update this when we add commands to the built in list +#define LAST_PREDEFINED 76 // update this when we add commands to the built in list // these commands are interps @@ -307,54 +347,107 @@ const int16_t progBi[] = { // address actually start at 10000 }; + /**************************************************************************** * - * Module-level global variables (in RAM) + * Local function prototypes * ***************************************************************************/ -int16_t xit; // set to 1 to kill program -int16_t echo; // boolean: false -> no interactive echo/prompt - -uint16_t progCounter; +uint8_t getKeyB(void); +void getLine(void); +uint8_t nextPrintableChar(void); +uint8_t skipStackComment(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); +void ndropFunc(void); +int16_t lookupToken(uint8_t *x, uint8_t *l); +void luFunc(void); +void numFunc(void); +void ifFunc(int16_t x); +void loopFunc(int16_t n); +void rollFunc(int16_t n); +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); -int16_t lineBufferIdx; /* input line buffer index */ -int16_t progIdx; // next open space for user opcodes -int16_t cmdListIdx; // next open space for user word strings +/**************************************************************************** + * + * Public functions + * + ***************************************************************************/ -/* The following utilize a vector table to allow re-configuring the - * location/size of these arrays. Then the stack sizes and user program space - * sizes can be (re-)specified by changing the table and calling init_msp4th() - * again. - */ -#if defined(MSP430) -int16_t register *mathStackPtr asm("r6"); -int16_t register *addrStackPtr asm("r7"); -#else -int16_t *mathStackPtr; -int16_t *addrStackPtr; -#endif +void msp4th_init(struct msp4th_config *c) +{ + /* + * Get addresses of user-configurable arrays from the pre-known vector + * table locations. + * + * Changing the values in the msp4th_* locations and calling + * init_msp4th() again restarts the interpreter with the new layout; + */ + mathStackPtr = c->mathStackStart; + addrStackPtr = c->addrStackStart; + mathStackStart = c->mathStackStart; + addrStackStart = c->addrStackStart; + prog = c->prog; + progOpcodes = c->progOpcodes; + cmdList = c->cmdList; + lineBuffer = c->lineBuffer; + lineBufferLength = c->lineBufferLength; + wordBuffer = c->wordBuffer; + wordBufferLength = c->wordBufferLength; + msp4th_putchar = c->putchar; + msp4th_getchar = c->getchar; + msp4th_puts = c->puts; -int16_t *mathStackStart; -int16_t *addrStackStart; -int16_t *prog; // user programs (opcodes) are placed here + xit = 0; + echo = 1; + progCounter = 10000; + progIdx = 1; // this will be the first opcode + cmdListIdx = 0; -int16_t *progOpcodes; // mapping between user word index and program opcodes - // start index into prog[] + lineBufferIdx = 0; + msp4th_puts((uint8_t *)"msp4th!"); +} -uint8_t *cmdList; -uint8_t *lineBuffer; -int16_t lineBufferLength; -uint8_t *wordBuffer; -int16_t wordBufferLength; -void (*msp4th_putchar)(uint8_t c); -uint8_t (*msp4th_getchar)(void); +void msp4th_processLoop() // this processes the forth opcodes. +{ + uint16_t opcode; + uint16_t tmp; + while(xit == 0){ + if(progCounter > 9999){ + tmp = progCounter - 10000; + opcode = progBi[tmp]; + } else { + opcode = prog[progCounter]; + } + progCounter = progCounter + 1; + if(opcode > 19999){ + // this is a built in opcode + execN(opcode - 20000); + } else { + pushAddrStack(progCounter); + progCounter = progOpcodes[opcode]; + } + } // while () +} @@ -362,18 +455,7 @@ uint8_t (*msp4th_getchar)(void); -void msp4th_puts(uint8_t *s) -{ - uint16_t i = 0; - uint8_t c = 1; - while (c != 0) { - c = s[i++]; - msp4th_putchar(c); - } - msp4th_putchar('\r'); - msp4th_putchar('\n'); -} uint8_t getKeyB() @@ -415,6 +497,7 @@ void getLine() } else if ( ((c == 255) || (c == '')) && (lineBufferIdx == 0)) { xit = 1; waiting = 0; + // add a sham word so we make it back to processLoop() to exit lineBuffer[lineBufferIdx++] = 'x'; lineBuffer[lineBufferIdx] = ' '; } else { @@ -544,7 +627,7 @@ void pushMathStack(int16_t n) } -#define ATOS (addrStackPtr) +#define ATOS (*addrStackPtr) #define ANOS (*(addrStackPtr + 1)) #define ASTACK(n) (*(addrStackPtr + n)) @@ -756,21 +839,25 @@ void ifFunc(int16_t x){ // used as goto if x == 1 void loopFunc(int16_t n) { - int16_t j, k, m; - - j = popAddrStack(); // loop address - k = popAddrStack(); // count - m = popAddrStack(); // limit - k = k + n; // up the count - - if ( ! ( ((n > 0) && (k >= m)) - || ((n < 0) && (k <= m)))) { - // put it all back and loop - pushAddrStack(m); - pushAddrStack(k); - pushAddrStack(j); +#define j ATOS // loop address +#define k ANOS // count +#define m ASTACK(2) // limit + + ANOS += n; // inc/dec the count + + if ( ! ( ((n >= 0) && (k >= m)) + || ((n <= 0) && (k <= m)))) { + // loop progCounter = j; + } else { + // done, cleanup + popAddrStack(); + popAddrStack(); + popAddrStack(); } +#undef j +#undef k +#undef m } @@ -950,7 +1037,7 @@ void execN(int16_t opcode){ "mov r14, 0(%[ms])\n" : /* outputs */ : [ms] "r" (mathStackPtr) /* inputs */ - : /* clobbers */ + : /* clobbers */ "r10","r11","r12","r13","r14" ); #else i = NOS; @@ -1020,7 +1107,7 @@ void execN(int16_t opcode){ case 16: // abs ( a -- |a| ) \ -32768 is unchanged if (TOS < 0) { - TOS = ~TOS + 1; + TOS = -TOS; } break; @@ -1207,10 +1294,10 @@ void execN(int16_t opcode){ MPYS = popMathStack(); OP2 = NOS; x = (((int32_t)RESHI << 16) | RESLO); + asm("eint"); x = (x / TOS); popMathStack(); TOS = (int16_t)(x & 0xffff); - asm("eint"); #else i = popMathStack(); j = TOS; @@ -1358,6 +1445,21 @@ void execN(int16_t opcode){ case 75: // echo ( bool -- ) \ ?echo prompts and terminal input? echo = popMathStack(); + break; + + case 76: // init ( &config -- ) \ clears buffers and calls msp4th_init +#if defined(MSP430) + //saves 2 words of ROM + asm("mov.w #0, %[b](r3)\n" + : /* outputs */ + : [b] "m" (lineBuffer) /* inputs */ + : /* clobbers */ + ); +#else + *lineBuffer = 0; +#endif + msp4th_init((struct msp4th_config *)popMathStack()); + break; default: break; @@ -1366,67 +1468,3 @@ void execN(int16_t opcode){ -/* - * Public function prototypes - */ - -void msp4th_init(struct msp4th_config *c) -{ - /* - * Get addresses of user-configurable arrays from the pre-known vector - * table locations. - * - * Changing the values in the msp4th_* locations and calling - * init_msp4th() again restarts the interpreter with the new layout; - */ - mathStackPtr = c->mathStackStart; - addrStackPtr = c->addrStackStart; - mathStackStart = c->mathStackStart; - addrStackStart = c->addrStackStart; - prog = c->prog; - progOpcodes = c->progOpcodes; - cmdList = c->cmdList; - lineBuffer = c->lineBuffer; - lineBufferLength = c->lineBufferLength; - wordBuffer = c->wordBuffer; - wordBufferLength = c->wordBufferLength; - msp4th_putchar = c->putchar; - msp4th_getchar = c->getchar; - - - xit = 0; - echo = 1; - progCounter = 10000; - progIdx = 1; // this will be the first opcode - cmdListIdx = 0; - - lineBufferIdx = 0; - msp4th_puts((uint8_t *)"msp4th!"); -} - - -void msp4th_processLoop() // this processes the forth opcodes. -{ - uint16_t opcode; - uint16_t tmp; - - while(xit == 0){ - if(progCounter > 9999){ - tmp = progCounter - 10000; - opcode = progBi[tmp]; - } else { - opcode = prog[progCounter]; - } - - progCounter = progCounter + 1; - - if(opcode > 19999){ - // this is a built in opcode - execN(opcode - 20000); - } else { - pushAddrStack(progCounter); - progCounter = progOpcodes[opcode]; - } - } // while () -} - diff --git a/msp4th/msp4th.h b/msp4th/msp4th.h index f7a0f4b..2abd4f5 100644 --- a/msp4th/msp4th.h +++ b/msp4th/msp4th.h @@ -18,6 +18,7 @@ struct msp4th_config { int16_t wordBufferLength; void (*putchar)(uint8_t); uint8_t (*getchar)(void); + void (*puts)(uint8_t *); }; void msp4th_init(struct msp4th_config *); diff --git a/msp4th/test4th.c b/msp4th/test4th.c index 8d6e24c..509d175 100644 --- a/msp4th/test4th.c +++ b/msp4th/test4th.c @@ -44,6 +44,11 @@ uint8_t my_getchar(void) } +void my_puts(uint8_t *s) +{ + puts((char *)s); +} + void config_msp4th(void) @@ -59,6 +64,7 @@ void config_msp4th(void) config.wordBufferLength = WORD_BUFFER_SIZE; config.putchar = &my_putchar; config.getchar = &my_getchar; + config.puts = &my_puts; // terminate the strings lineBufferArray[0] = 0; -- 2.25.1