Line 1... |
Line 1... |
/*
|
/*
|
see README.txt for details.
|
see README.txt for details.
|
|
|
chris <cliechti@gmx.net>
|
chris <cliechti@gmx.net>
|
*/
|
*/
|
|
#include "omsp_system.h"
|
#include "hardware.h"
|
#include "hardware.h"
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include "swuart.h"
|
#include "swuart.h"
|
//#include "fll.h"
|
#include "cprintf.h"
|
|
|
volatile int rxdata;
|
volatile int rxdata;
|
|
|
/**
|
/**
|
Delay function.
|
Delay function.
|
*/
|
*/
|
void delay(unsigned int d) {
|
void delay(unsigned int d) {
|
while(d--) {
|
while(d--) {
|
nop();
|
__nop();
|
nop();
|
__nop();
|
}
|
}
|
}
|
}
|
|
|
/**
|
/**
|
Main function with init an an endless loop that is synced with the
|
Main function with init an an endless loop that is synced with the
|
Line 58... |
Line 59... |
CCTL2 = 0; //
|
CCTL2 = 0; //
|
TACTL |= MC1; //start timer
|
TACTL |= MC1; //start timer
|
|
|
eint(); //enable interrupts
|
eint(); //enable interrupts
|
|
|
printf("\r\n====== openMSP430 in action ======\r\n"); //say hello
|
cprintf("\r\n====== openMSP430 in action ======\r\n"); //say hello
|
printf("\r\nSimple Line Editor Ready\r\n"); //say hello
|
cprintf("\r\nSimple Line Editor Ready\r\n"); //say hello
|
|
|
while (1) { //main loop, never ends...
|
while (1) { //main loop, never ends...
|
printf("> "); //show prompt
|
cprintf("> "); //show prompt
|
reading = 1;
|
reading = 1;
|
while (reading) { //loop and read characters
|
while (reading) { //loop and read characters
|
LPM0; //sync, wakeup by irq
|
LPM0; //sync, wakeup by irq
|
|
|
led++; // Some lighting...
|
led++; // Some lighting...
|
Line 77... |
Line 78... |
|
|
switch (rxdata) {
|
switch (rxdata) {
|
//process RETURN key
|
//process RETURN key
|
case '\r':
|
case '\r':
|
//case '\n':
|
//case '\n':
|
printf("\r\n"); //finish line
|
cprintf("\r\n"); //finish line
|
buf[pos++] = 0; //to use printf...
|
buf[pos++] = 0; //to use cprintf...
|
printf(":%s\r\n", buf);
|
cprintf(":%s\r\n", buf);
|
reading = 0; //exit read loop
|
reading = 0; //exit read loop
|
pos = 0; //reset buffer
|
pos = 0; //reset buffer
|
break;
|
break;
|
//backspace
|
//backspace
|
case '\b':
|
case '\b':
|
if (pos > 0) { //is there a char to delete?
|
if (pos > 0) { //is there a char to delete?
|
pos--; //remove it in buffer
|
pos--; //remove it in buffer
|
putchar((int)'\b'); //go back
|
tty_putc((int)'\b'); //go back
|
putchar((int)' '); //erase on screen
|
tty_putc((int)' '); //erase on screen
|
putchar((int)'\b'); //go back
|
tty_putc((int)'\b'); //go back
|
}
|
}
|
break;
|
break;
|
//other characters
|
//other characters
|
default:
|
default:
|
//only store characters if buffer has space
|
//only store characters if buffer has space
|
if (pos < sizeof(buf)) {
|
if (pos < sizeof(buf)) {
|
putchar(rxdata); //echo
|
tty_putc(rxdata); //echo
|
buf[pos++] = (char)rxdata; //store
|
buf[pos++] = (char)rxdata; //store
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|