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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [RX600_RX62N-RSK_IAR/] [RSKRX62N_Demo.c] - Blame information for rev 585

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 585 jeremybenn
/*
2
 * Copyright (c) 20010 IAR Systems AB.
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
 
17
/*
18
 * IAR Embedded Workbench tutorial
19
 *
20
 * Test Program for the RSKRX62N Board.
21
 * LED's perform different display according to
22
 * which switch is pressed.
23
 * Used to check that all the LED's, switches,
24
 * clock function and AD trigger are working fine.
25
 *
26
 * $Revision: 2 $
27
 */
28
 
29
#include "iorx62n.h"
30
#include "intrinsics.h"
31
 
32
void ScrollLedsLowHigh(void);
33
void ScrollLedsHighLow(void);
34
 
35
unsigned long pause;
36
unsigned long off_set;
37
 
38
#define ON  0
39
#define OFF 1
40
#define LED0 PORT0.DR.BIT.B2  // P02 LED0
41
#define LED1 PORT0.DR.BIT.B3  // P03 LED1
42
#define LED2 PORT0.DR.BIT.B5  // P05 LED2
43
#define LED3 PORT3.DR.BIT.B4  // P34 LED3
44
#define LED4 PORT6.DR.BIT.B0  // P50 LED4
45
#define LED5 PORT7.DR.BIT.B3  // P73 LED5
46
 
47
/* defined words used in this program */
48
enum {
49
  SW1,
50
  SW2,
51
  SW3,
52
  NONE
53
}GetKey;
54
 
55
/* SW1 ISR */
56
#pragma vector = 72
57
__interrupt void isr_sw1(void)
58
{
59
  GetKey=SW1;
60
 
61
  CMT.CMSTR0.BIT.STR0 = 0; // stop timer
62
  ICU.IR[72].BIT.IR = 0;   // clear interrupt request flag 
63
}
64
 
65
/* SW2 ISR */
66
#pragma vector = 73
67
__interrupt void isr_sw2(void)
68
{
69
  GetKey=SW2;
70
 
71
  CMT.CMSTR0.BIT.STR0 = 0; // stop timer
72
  ICU.IR[73].BIT.IR = 0;   // clear interrupt request flag  
73
}
74
 
75
/* SW3 ISR */
76
#pragma vector = 79
77
__interrupt void isr_sw3(void)
78
{
79
  GetKey=SW3;
80
 
81
  CMT.CMSTR0.BIT.STR0 = 1; // start timer
82
  ICU.IR[79].BIT.IR = 0;   // clear interrupt request flag    
83
}
84
 
85
/* Timer ISR */
86
#pragma vector = 0x1c
87
__interrupt void isr_cmt0(void)
88
{
89
  // Toggle LED's
90
  LED0 = ~LED0;
91
  LED1 = ~LED1;
92
  LED2 = ~LED2;
93
  LED3 = ~LED3;
94
  LED4 = ~LED4;
95
  LED5 = ~LED5;
96
  ICU.IR[70].BIT.IR = 0;         // clear interrupt request flag
97
}
98
 
99
/* Main program. */
100
void main (void)
101
{
102
  // enable modules
103
  SYSTEM.MSTPCRA.BIT.MSTPA23 = 0; // A/D Converter (Unit 0) Module
104
 
105
  // Set up RV1 (potentiometer)
106
  AD0.ADCR.BIT.MODE = 2;  // Continuous scan mode
107
  AD0.ADCSR.BIT.CH = 0;   // only AD0
108
  AD0.ADCSR.BIT.ADST = 1; // Start A/D
109
 
110
  // Set up SW1, SW2, SW3
111
  PORT0.DDR.BIT.B0 = 0; // SW1 input on P00
112
  PORT0.DDR.BIT.B1 = 0; // SW2 input on P01
113
  PORT0.DDR.BIT.B7 = 0; // SW3 input on P07  
114
 
115
  PORT0.ICR.BIT.B0 = 1; // Enable input buffer
116
  PORT0.ICR.BIT.B1 = 1; // Enable input buffer
117
  PORT0.ICR.BIT.B7 = 1; // Enable input buffer
118
 
119
  // IRQ8-A used for SW1
120
  IOPORT.PF8IRQ.BIT.ITS8 = 0; // P00 is designated as the IRQ8-A input pin.
121
  IEN(ICU,IRQ8) = 1;
122
  IPR(ICU,IRQ8) = 3;
123
 
124
  // IRQ9-A used for SW2
125
  IOPORT.PF8IRQ.BIT.ITS9 = 0; // P01 is designated as IRQ9-A input pin.
126
  IEN(ICU,IRQ9) = 1;
127
  IPR(ICU,IRQ9) = 3;
128
 
129
  // IRQ15-A used for SW3
130
  IOPORT.PF8IRQ.BIT.ITS15 = 0; // P07 is designated as the IRQ15-A input pin.
131
  IEN(ICU,IRQ15) = 1;
132
  IPR(ICU,IRQ15) = 3;
133
 
134
  // Set up LED's
135
  PORT0.DDR.BIT.B2 = 1;   // P02 LED0 
136
  PORT0.DDR.BIT.B3 = 1;   // P03 LED1
137
  PORT0.DDR.BIT.B5 = 1;   // P05 LED2
138
  PORT3.DDR.BIT.B4 = 1;   // P34 LED3
139
  PORT6.DDR.BIT.B0 = 1;   // P50 LED4
140
  PORT7.DDR.BIT.B3 = 1;   // P73 LED5
141
 
142
  // Turn al LED's off
143
  LED0 = LED1 = LED2 = LED3 = LED4 = LED5 = OFF;
144
 
145
  // Set up Timer
146
  SYSTEM.MSTPCRA.BIT.MSTPA15 = 0; // CMT timers 0, 
147
  CMT0.CMCR.BIT.CKS = 3;          // 25MHz/512 = 48.8kHz
148
  CMT0.CMCR.BIT.CMIE = 1;         // enable peripheral interrupt source
149
  CMT0.CMCOR = 12212;             // 4 Hz operation
150
  ICU.IER[3].BIT.IEN4 = 1;        // enable timer 0 interrupt  
151
  IPR(CMT0,CMI0) = 1;             // LED level 1
152
 
153
  __enable_interrupt();
154
 
155
  GetKey=SW1;
156
 
157
  for (;;)
158
  {
159
    switch (GetKey)
160
    {
161
      case SW1:
162
        ScrollLedsLowHigh();
163
        break;
164
      case SW2:
165
        ScrollLedsHighLow();
166
        break;
167
      case SW3:
168
        GetKey=NONE;
169
        break;
170
    }
171
  }
172
}
173
 
174
/* scrolls the LED's from low to high */
175
void ScrollLedsLowHigh()
176
{
177
  char led_number = 0;
178
 
179
  while (GetKey == SW1)
180
  {
181
    if (led_number > 5)
182
      led_number = 0;
183
 
184
    switch(led_number)
185
    {
186
    case 0:
187
      LED0=ON;
188
      LED1=LED2=LED3=LED4=LED5=OFF;
189
      break;
190
    case 1:
191
      LED1=ON;
192
      LED0=LED2=LED3=LED4=LED5=OFF;
193
      break;
194
    case 2:
195
      LED2=ON;
196
      LED0=LED1=LED3=LED4=LED5=OFF;
197
      break;
198
    case 3:
199
      LED3=ON;
200
      LED0=LED1=LED2=LED4=LED5=OFF;
201
      break;
202
    case 4:
203
      LED4=ON;
204
      LED0=LED1=LED2=LED3=LED5=OFF;
205
      break;
206
    case 5:
207
      LED5=ON;
208
      LED0=LED1=LED2=LED3=LED4=OFF;
209
      break;
210
    }
211
    led_number++;
212
 
213
    off_set = AD0.ADDRA*1000;
214
    for (pause = off_set; pause != 0; pause --);
215
  }
216
}
217
 
218
/* scrolls the LED's from high to low */
219
void ScrollLedsHighLow()
220
{
221
  signed char led_number = 3;
222
 
223
  while (GetKey == SW2)
224
  {
225
    if (led_number < 0)
226
      led_number = 5;
227
 
228
    switch(led_number)
229
    {
230
    case 0:
231
      LED0=ON;
232
      LED1=LED2=LED3=LED4=LED5=OFF;
233
      break;
234
    case 1:
235
      LED1=ON;
236
      LED0=LED2=LED3=LED4=LED5=OFF;
237
      break;
238
    case 2:
239
      LED2=ON;
240
      LED0=LED1=LED3=LED4=LED5=OFF;
241
      break;
242
    case 3:
243
      LED3=ON;
244
      LED0=LED1=LED2=LED4=LED5=OFF;
245
      break;
246
    case 4:
247
      LED4=ON;
248
      LED0=LED1=LED2=LED3=LED5=OFF;
249
      break;
250
    case 5:
251
      LED5=ON;
252
      LED0=LED1=LED2=LED3=LED4=OFF;
253
      break;
254
    }
255
    led_number--;
256
 
257
    off_set = AD0.ADDRA*1000;
258
    for (pause = off_set; pause != 0; pause --);
259
  }
260
}

powered by: WebSVN 2.1.0

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