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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_diligent_s3board/] [software/] [ta_uart/] [main.c] - Blame information for rev 212

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olivier.gi
/*
2
see README.txt for details.
3
 
4
chris <cliechti@gmx.net>
5
*/
6 212 olivier.gi
#include "omsp_system.h"
7 2 olivier.gi
#include "hardware.h"
8
#include <stdlib.h>
9
#include <stdio.h>
10
#include "swuart.h"
11 212 olivier.gi
#include "cprintf.h"
12 2 olivier.gi
 
13 153 olivier.gi
volatile int rxdata;
14
 
15 2 olivier.gi
/**
16
Delay function.
17
*/
18
void delay(unsigned int d) {
19
   while(d--) {
20 212 olivier.gi
      __nop();
21
      __nop();
22 2 olivier.gi
   }
23
}
24
 
25
/**
26
Main function with init an an endless loop that is synced with the
27
interrupts trough the lowpower mode.
28
*/
29
int main(void) {
30
    int reading = 0;
31
    int pos = 0;
32
    char buf[40];
33
    int led = 0;
34 212 olivier.gi
 
35 2 olivier.gi
    WDTCTL = WDTCTL_INIT;               //Init watchdog timer
36
 
37
    P1OUT  = P1OUT_INIT;                //Init output data of port1
38
    P1SEL  = P1SEL_INIT;                //Select port or module -function on port1
39
    P1DIR  = P1DIR_INIT;                //Init port direction register of port1
40
    P1IES  = P1IES_INIT;                //init port interrupts
41
    P1IE   = P1IE_INIT;
42
 
43
    P2OUT  = P2OUT_INIT;                //Init output data of port2
44
    P2SEL  = P2SEL_INIT;                //Select port or module -function on port2
45
    P2DIR  = P2DIR_INIT;                //Init port direction register of port2
46
    P2IES  = P2IES_INIT;                //init port interrupts
47
    P2IE   = P2IE_INIT;
48
 
49
    P3DIR  = 0xff;
50
    P3OUT  = 0xff;                      //light LED during init
51 153 olivier.gi
//    delay(65535);                       //Wait for watch crystal startup
52
    delay(10);
53 2 olivier.gi
//  fllInit();                          //Init FLL to desired frequency using the 32k768 cystal as reference.
54
    P3OUT  = 0x00;                      //switch off LED
55 212 olivier.gi
 
56 2 olivier.gi
    TACTL  = TACTL_AFTER_FLL;           //setup timer (still stopped)
57
    CCTL0  = CCIE|CAP|CM_2|CCIS_1|SCS;  //select P2.2 with UART signal
58
    CCTL1  = 0;                         //
59
    CCTL2  = 0;                         //
60
    TACTL |= MC1;                       //start timer
61 212 olivier.gi
 
62 2 olivier.gi
    eint();                             //enable interrupts
63 212 olivier.gi
 
64
    cprintf("\r\n====== openMSP430 in action ======\r\n");   //say hello
65
    cprintf("\r\nSimple Line Editor Ready\r\n");   //say hello
66
 
67 2 olivier.gi
    while (1) {                         //main loop, never ends...
68 212 olivier.gi
        cprintf("> ");                   //show prompt
69 2 olivier.gi
        reading = 1;
70
        while (reading) {               //loop and read characters
71
            LPM0;                       //sync, wakeup by irq
72
 
73
            led++;                      // Some lighting...
74
            if (led==9) {
75
              led = 0;
76
            }
77
            P3OUT = (0x01 << led);
78
 
79
            switch (rxdata) {
80
                //process RETURN key
81
                case '\r':
82
                //case '\n':
83 212 olivier.gi
                    cprintf("\r\n");     //finish line
84
                    buf[pos++] = 0;     //to use cprintf...
85
                    cprintf(":%s\r\n", buf);
86 2 olivier.gi
                    reading = 0;        //exit read loop
87
                    pos = 0;            //reset buffer
88
                    break;
89
                //backspace
90
                case '\b':
91
                    if (pos > 0) {      //is there a char to delete?
92
                        pos--;          //remove it in buffer
93 212 olivier.gi
                        tty_putc((int)'\b');  //go back
94
                        tty_putc((int)' ');   //erase on screen
95
                        tty_putc((int)'\b');  //go back
96 2 olivier.gi
                    }
97
                    break;
98
                //other characters
99
                default:
100
                    //only store characters if buffer has space
101
                    if (pos < sizeof(buf)) {
102 212 olivier.gi
                        tty_putc(rxdata);     //echo
103 153 olivier.gi
                        buf[pos++] = (char)rxdata; //store
104 2 olivier.gi
                    }
105
            }
106
        }
107
    }
108
}
109
 
110 153 olivier.gi
interrupt (TIMERA0_VECTOR) INT_ccr0(void) {
111
 
112
  int rx_done;
113
  rx_done = ccr0();
114
 
115
  if (rx_done!=-1) {
116
    LPM0_EXIT;
117
    rxdata = rx_done;
118
  }
119
}

powered by: WebSVN 2.1.0

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