OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_diligent_s3board/] [software/] [hw_uart/] [main.c] - Diff between revs 143 and 212

Show entire file | Details | Blame | View Log

Rev 143 Rev 212
Line 6... Line 6...
//--------------------------------------------------//
//--------------------------------------------------//
//                   Delay function                 //
//                   Delay function                 //
//--------------------------------------------------//
//--------------------------------------------------//
void delay(unsigned int d) {
void delay(unsigned int d) {
   while(d--) {
   while(d--) {
      nop();
      __nop();
      nop();
      __nop();
   }
   }
}
}
 
 
//--------------------------------------------------//
//--------------------------------------------------//
//                 putChar function                 //
//                 tty_putc function                 //
//            (Send a byte to the UART)             //
//            (Send a byte to the UART)             //
//--------------------------------------------------//
//--------------------------------------------------//
int putchar (int txdata) {
int tty_putc (int txdata) {
 
 
  // Wait until the TX buffer is not full
  // Wait until the TX buffer is not full
  while (UART_STAT & UART_TX_FULL);
  while (UART_STAT & UART_TX_FULL);
 
 
  // Write the output character
  // Write the output character
Line 69... Line 69...
    //    delay(65535);                       // Some delay
    //    delay(65535);                       // Some delay
    //delay(65535);
    //delay(65535);
 
 
    P3OUT  = 0x00;                      // Switch off LED
    P3OUT  = 0x00;                      // Switch off LED
 
 
    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");
    cprintf("\r\nSimple Line Editor Ready\r\n");
 
 
    eint();                             // Enable interrupts
    eint();                             // Enable interrupts
 
 
    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
 
 
Line 92... Line 92...
 
 
            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('\b');  //go back
                        tty_putc('\b');  //go back
                        putchar(' ');   //erase on screen
                        tty_putc(' ');   //erase on screen
                        putchar('\b');  //go back
                        tty_putc('\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++] = rxdata; //store
                        buf[pos++] = rxdata; //store
                    }
                    }
            }
            }
        }
        }
    }
    }
}
}
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.