aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2025-01-27 15:51:03 -0500
committerClyne Sullivan <clyne@bitgloo.com>2025-01-27 15:51:03 -0500
commitf88ad6651b961781d67e79e282cdf2189bc52f2d (patch)
tree7ca8c31b30169667239c9b9769384226a4982363
parent9592fbf2684b1f3f1892bf02404e41f209b0c5ac (diff)
msp430 improvements; fix compname bug
-rw-r--r--Makefile12
-rw-r--r--foci.c9
-rw-r--r--foci.h6
-rw-r--r--msp430/main.c18
4 files changed, 29 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 54338b6..71dce00 100644
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,17 @@ all: x86-64
clean:
rm -f main foci.o
+foci.o: foci.h foci.c
+
x86-64: CC := gcc -DFOCI_X86_64
-x86-64: x86/main.c foci.o
- $(CC) $(CFLAGS) $^ -o main
+x86-64: foci.o x86/main.o
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o main
arm-cm4: CC := arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -DFOCI_ARM
arm-cm4: foci.o
msp430: CC := msp430-elf-gcc -DFOCI_MSP430 -mmcu=msp430g2553
-msp430: msp430/main.c foci.o
- $(CC) $(CFLAGS) -Lmsp430 $^ -o main
+msp430: LDFLAGS += -Lmsp430
+msp430: foci.o msp430/main.o
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o main
+
diff --git a/foci.c b/foci.c
index 107d317..8dedfbd 100644
--- a/foci.c
+++ b/foci.c
@@ -53,7 +53,7 @@ NAKED void compname(void)
}
RESTORE;
- *--sp = *(unsigned char *)here;
+ *--sp = *(unsigned char *)here + 1;
NEXT;
}
@@ -172,18 +172,21 @@ static void dotimpl(intptr_t n)
{
static const char dottbl[16] = "0123456789abcdef";
static char dotbuf[16] = {0};
- int i;
+ int i = 0;
if (n < 0) {
n *= -1;
foci_putchar('-');
}
- for (i = 0; n > 0; n /= 10)
+ do {
dotbuf[i++] = dottbl[n % BASE];
+ n /= BASE;
+ } while (n);
while (--i >= 0)
foci_putchar(dotbuf[i]);
+
foci_putchar(' ');
}
diff --git a/foci.h b/foci.h
index c7d6fcb..9c21c27 100644
--- a/foci.h
+++ b/foci.h
@@ -82,9 +82,9 @@ register intptr_t * sp asm("r4"); // pointer to stack cells
register intptr_t *** rp asm("r5"); // stack of pp
register intptr_t ** pp asm("r6"); // pointer to ip
register intptr_t tmp asm("r7");
-#define STASH asm("push r4; push r5; push r6")
-#define RESTORE asm("pop r6; pop r5; pop r4")
-#define NEXT asm("incd r6;\n br @r6")
+#define STASH asm("push r4\npush r5\npush r6")
+#define RESTORE asm("pop r6\npop r5\npop r4")
+#define NEXT asm("incd r6\nbr @r6")
#endif // FOCI_MSP430
extern void foci_putchar(int);
diff --git a/msp430/main.c b/msp430/main.c
index 1e691d3..fd0489f 100644
--- a/msp430/main.c
+++ b/msp430/main.c
@@ -7,14 +7,14 @@ int main()
WDTCTL = WDTPW | WDTHOLD;
DCOCTL = 0;
- BCSCTL1 = CALBC1_1MHZ;
- DCOCTL = CALDCO_1MHZ;
+ BCSCTL1 = CALBC1_8MHZ;
+ DCOCTL = CALDCO_8MHZ;
P1SEL = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
- UCA0BR0 = 104; // 1MHz 9600
- UCA0BR1 = 0; // 1MHz 9600
+ UCA0BR0 = 208; // 8MHz 38400
+ UCA0BR1 = 0;
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST;
@@ -35,16 +35,22 @@ int main()
void foci_putchar(int ch)
{
- while (!(IFG2 & UCA0TXIFG));
+ do asm("nop");
+ while ((IFG2 & UCA0TXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
UCA0TXBUF = ch;
+ while ((UCA0STAT & UCBUSY) == UCBUSY);
}
int foci_getchar(void)
{
int ch;
- while (!(IFG2 & UCA0RXIFG));
+ do asm("nop");
+ while ((IFG2 & UCA0RXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
ch = UCA0RXBUF;
+ do asm("nop");
+ while ((UCA0STAT & UCBUSY) == UCBUSY);
+
foci_putchar(ch);
return ch;
}