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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [board/] [exstartup.c] - Blame information for rev 52

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 36 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    exstartup.c
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     A fun example program that runs on the Arty, just to show
8
//              that the minimum set of peripherals (LEDs, color LEDs, buttons,
9
//      switches, etc.) work.
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40 52 dgisselq
#include <stdio.h>
41
 
42
#include "artyboard.h"
43 49 dgisselq
#include "zipcpu.h"
44
#include "zipsys.h"
45 30 dgisselq
 
46 52 dgisselq
#define sys     _sys
47
 
48 30 dgisselq
void    idle_task(void) {
49
        while(1)
50
                zip_idle();
51
}
52
 
53 49 dgisselq
void    wait_on_interrupt(int mask) {
54
        zip->z_pic = DALLPIC|mask;
55
        zip->z_pic = EINT(mask);
56
        zip_rtu();
57
}
58
 
59
void    main(int argc, char **argv) {
60 30 dgisselq
        const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
61
                white = 0x070707, black = 0, dimgreen = 0x1f00,
62 49 dgisselq
                second = CLOCKFREQHZ;
63 30 dgisselq
        int     i, sw;
64
 
65
        int     user_context[16];
66
        for(i=0; i<15; i++)
67
                user_context[i] = 0;
68
        user_context[15] = (unsigned)idle_task;
69
        zip_restore_context(user_context);
70
 
71 52 dgisselq
        printf("Starting exstartup\r\n");
72
 
73 30 dgisselq
        for(i=0; i<4; i++)
74 52 dgisselq
                _sys->io_b.i_clrled[i] = red;
75
        sys->io_b.i_leds = 0x0ff;
76 30 dgisselq
 
77
        // Clear the PIC
78
        //
79
        //      Acknowledge all interrupts, turn off all interrupts
80
        //
81 49 dgisselq
        zip->z_pic = CLEARPIC;
82 52 dgisselq
        while(sys->io_b.i_pwrcount < (second >> 4))
83 30 dgisselq
                ;
84
 
85
        // Repeating timer, every 250ms
86 49 dgisselq
        zip->z_tma = TMR_INTERVAL | (second/4);
87
        wait_on_interrupt(SYSINT_TMA);
88 30 dgisselq
 
89 52 dgisselq
        sys->io_b.i_clrled[0] = green;
90
        sys->io_b.i_leds = 0x010;
91 30 dgisselq
 
92 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
93 30 dgisselq
 
94 52 dgisselq
        sys->io_b.i_clrled[0] = dimgreen;
95
        sys->io_b.i_clrled[1] = green;
96
        sys->io_scope[0].s_ctrl = WBSCOPE_NO_RESET | 32;
97
        sys->io_b.i_leds = 0x020;
98 30 dgisselq
 
99 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
100 30 dgisselq
 
101 52 dgisselq
        sys->io_b.i_clrled[1] = dimgreen;
102
        sys->io_b.i_clrled[2] = green;
103
        sys->io_b.i_leds = 0x040;
104 30 dgisselq
 
105 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
106 30 dgisselq
 
107 52 dgisselq
        sys->io_b.i_clrled[2] = dimgreen;
108
        sys->io_b.i_clrled[3] = green;
109
        sys->io_b.i_leds = 0x080;
110 30 dgisselq
 
111 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
112 30 dgisselq
 
113 52 dgisselq
        sys->io_b.i_clrled[3] = dimgreen;
114 30 dgisselq
 
115 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
116 30 dgisselq
 
117
        for(i=0; i<4; i++)
118 52 dgisselq
                sys->io_b.i_clrled[i] = black;
119 30 dgisselq
 
120
        // Wait one second ...
121 49 dgisselq
        for(i=0; i<4; i++)
122
                wait_on_interrupt(SYSINT_TMA);
123 30 dgisselq
 
124 52 dgisselq
        sw = sys->io_b.i_btnsw & 0x0f;
125 30 dgisselq
        for(int i=0; i<4; i++)
126 52 dgisselq
                sys->io_b.i_clrled[i] = (sw & (1<<i)) ? white : black;
127 30 dgisselq
 
128
 
129 49 dgisselq
        // Wait another two seconds ...
130
        for(i=0; i<8; i++)
131
                wait_on_interrupt(SYSINT_TMA);
132 30 dgisselq
 
133
        // Blink all the LEDs
134
        //      First turn them on
135 52 dgisselq
        sys->io_b.i_leds = 0x0ff;
136 30 dgisselq
        // Then wait a quarter second
137 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
138 30 dgisselq
        // Then turn the back off
139 52 dgisselq
        sys->io_b.i_leds = 0x0f0;
140 30 dgisselq
        // and wait another quarter second
141 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
142 30 dgisselq
 
143
        // Now, read buttons, and flash an LED on any button being held
144
        // down ... ? neat?
145
 
146
        while(1) {
147
                unsigned        btn, ledc;
148
 
149
                zip_rtu();
150 49 dgisselq
                zip->z_pic = EINT(SYSINT_TMA)|SYSINT_TMA;
151 30 dgisselq
                // If the button is pressed, toggle the LED
152
                // Otherwise, turn the LED off.
153
                //
154
                // First, get all the pressed buttons
155 52 dgisselq
                btn = (sys->io_b.i_btnsw >> 4) & 0x0f;
156 32 dgisselq
                // Now, acknowledge the button presses that we just read
157 52 dgisselq
                sys->io_b.i_btnsw = (btn<<4);
158 30 dgisselq
 
159
                // Of any LEDs that are on, or buttons on, toggle their values
160 52 dgisselq
                ledc = (sys->io_b.i_leds)&0x0f;
161 32 dgisselq
                ledc = (ledc | btn)&0x0f ^ ledc;
162 30 dgisselq
                // Make sure we set everything
163
                ledc |= 0x0f0;
164
                // Now issue the command
165 52 dgisselq
                sys->io_b.i_leds = ledc;
166 30 dgisselq
                // That way, at the end, the toggle will leave them in the
167
                // off position.
168 52 dgisselq
                // sys->io_b.i_leds = 0xf0 | ((sys->io_b.i_leds&1)^1);
169 30 dgisselq
 
170 52 dgisselq
                sw = sys->io_b.i_btnsw & 0x0f;
171 30 dgisselq
                for(int i=0; i<4; i++)
172 52 dgisselq
                        sys->io_b.i_clrled[i] = (sw & (1<<i)) ? white : black;
173 30 dgisselq
 
174
        }
175
 
176
        zip_halt();
177
}

powered by: WebSVN 2.1.0

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