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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [altera_de0_nano_soc/] [software/] [apps/] [leds/] [main.c] - Blame information for rev 221

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 221 olivier.gi
#include "omsp_system.h"
2
#include "timerA.h"
3
 
4
/*
5
Watchdog interrupt
6
Change LED blinking type every 327ms * 30 = 9.8seconds
7
 */
8
volatile unsigned int  lfsr = 0xACEB;
9
volatile unsigned char wdt_irq_cnt;
10
volatile unsigned char led_blink_type;
11
volatile unsigned char led_blink_type_init;
12
 
13
wakeup interrupt (WDT_VECTOR) INT_watchdog(void) {
14
 
15
  unsigned int lfsr_lsb;
16
 
17
  if (wdt_irq_cnt<15) {
18
    wdt_irq_cnt++;
19
  } else {
20
    wdt_irq_cnt=0;
21
 
22
    // Update lfsr to select random LED algo
23
    lfsr_lsb = lfsr & 1;                           /* Get LSB (i.e., the output bit). */
24
    lfsr     >>= 1;                                /* Shift register */
25
    lfsr     ^= (-lfsr_lsb) & 0xB400u;             /* If the output bit is 1, apply toggle mask.
26
                                                    * The value has 1 at bits corresponding
27
                                                    * to taps, 0 elsewhere. */
28
    led_blink_type      = (unsigned char) (lfsr & 0x0007);
29
    led_blink_type_init = 1;
30
  }
31
}
32
 
33
 
34
/**
35
Main function with some blinking leds
36
*/
37
int main(void) {
38
 
39
  unsigned char temp, temp2;
40
  unsigned char direction;
41
 
42
  // Init global variables
43
  wdt_irq_cnt         = 0;
44
  led_blink_type      = 0;
45
  led_blink_type_init = 1;
46
  direction           = 0;
47
  temp                = 0;
48
 
49
  // Configure watchdog timer to generate an IRQ every 327ms
50
  WDTCTL = WDTPW | WDTSSEL | WDTCNTCL | WDTTMSEL | WDTIS0;  // Select ACLK | Clear timer | Enable interval timer mode | div32768
51
  IE1_set_wdtie();
52
 
53
  eint();
54
 
55
  while (1) {                        // Main loop, never ends...
56
 
57
    switch(led_blink_type) {
58
    case 0 :                         // Double-counter (type1)
59
      if (led_blink_type_init) {
60
        LED_CTRL = 0x00;
61
        temp     = 0x00;
62
        led_blink_type_init=0;
63
      } else {
64
        temp     = (temp+1) & 0x0f;
65
        temp2    = (temp<<4) | temp;
66
        LED_CTRL = temp2;
67
      }
68
      ta_wait(WT_200MS);
69
      break;
70
 
71
 
72
    case 1 :                         // Double-counter (type2)
73
      if (led_blink_type_init) {
74
        LED_CTRL = 0x00;
75
        temp     = 0x00;
76
        led_blink_type_init=0;
77
      } else {
78
        temp     = (temp-1) & 0x0f;
79
        temp2    = (temp<<4) | temp;
80
        LED_CTRL = temp2;
81
      }
82
      ta_wait(WT_200MS);
83
      break;
84
 
85
 
86
    case 2 :                         // Interleaved
87
      if (led_blink_type_init) {
88
        LED_CTRL = 0x55;
89
        led_blink_type_init=0;
90
      } else {
91
        LED_CTRL ^= 0xFF;
92
      }
93
      ta_wait(WT_500MS);
94
      break;
95
 
96
 
97
    case 3 :                         // Blink
98
      if (led_blink_type_init) {
99
        LED_CTRL = 0x00;
100
        led_blink_type_init=0;
101
      } else {
102
        LED_CTRL ^= 0xFF;
103
      }
104
      ta_wait(WT_500MS);
105
      ta_wait(WT_200MS);
106
      break;
107
 
108
 
109
    case 4 :                         // Inverted Ping-pong
110
      if (led_blink_type_init) {
111
        LED_CTRL  = 0x3F;
112
        led_blink_type_init=0;
113
        direction = 0;
114
      } else {
115
        if (direction==0) {
116
          temp     = (LED_CTRL >> 1) | 0x80;
117
          if (temp==0xFC) {direction=1;}
118
        } else {
119
          temp     = (LED_CTRL << 1) | 0x01;
120
          if (temp==0x3F) {direction=0;}
121
        }
122
        LED_CTRL = temp;
123
      }
124
      ta_wait(WT_100MS);
125
      break;
126
 
127
 
128
    case 5 :                         // Ping-pong
129
      if (led_blink_type_init) {
130
        LED_CTRL  = 0x80;
131
        led_blink_type_init=0;
132
        direction = 0;
133
      } else {
134
        if (direction==0) {
135
          temp     = LED_CTRL >> 1;
136
          if (temp==0x01) {direction=1;}
137
        } else {
138
          temp     = LED_CTRL << 1;
139
          if (temp==0x80) {direction=0;}
140
        }
141
        LED_CTRL = temp;
142
      }
143
      ta_wait(WT_100MS);
144
      break;
145
 
146
 
147
    case 6 :                         // Inverted Shift -->
148
      if (led_blink_type_init) {
149
        LED_CTRL = 0x3f;
150
        led_blink_type_init=0;
151
      } else {
152
        temp     = (LED_CTRL >> 1) | 0x80;
153
        LED_CTRL = temp;
154
        if (temp==0xfe) {led_blink_type_init = 1;}
155
      }
156
      ta_wait(WT_100MS);
157
      break;
158
 
159
 
160
    default:                         // Shift -->
161
      if (led_blink_type_init) {
162
        LED_CTRL = 0x80;
163
        led_blink_type_init=0;
164
      } else {
165
        temp     = LED_CTRL >> 1;
166
        LED_CTRL = temp;
167
        if (temp==0x01) {led_blink_type_init = 1;}
168
      }
169
      ta_wait(WT_100MS);
170
    }
171
  }
172
}

powered by: WebSVN 2.1.0

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