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 97

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

powered by: WebSVN 2.1.0

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