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 202

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

powered by: WebSVN 2.1.0

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