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

Subversion Repositories openarty

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

Go to most recent revision | 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 49 dgisselq
#include "zipcpu.h"
41
#include "zipsys.h"
42 30 dgisselq
#include "artyboard.h"
43
 
44
void    idle_task(void) {
45
        while(1)
46
                zip_idle();
47
}
48
 
49 49 dgisselq
void    wait_on_interrupt(int mask) {
50
        zip->z_pic = DALLPIC|mask;
51
        zip->z_pic = EINT(mask);
52
        zip_rtu();
53
}
54
 
55
 
56
void    main(int argc, char **argv) {
57 30 dgisselq
        const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
58
                white = 0x070707, black = 0, dimgreen = 0x1f00,
59 49 dgisselq
                second = CLOCKFREQHZ;
60 30 dgisselq
        int     i, sw;
61
 
62
        int     user_context[16];
63
        for(i=0; i<15; i++)
64
                user_context[i] = 0;
65
        user_context[15] = (unsigned)idle_task;
66
        zip_restore_context(user_context);
67
 
68
        for(i=0; i<4; i++)
69
                sys->io_clrled[i] = red;
70
        sys->io_ledctrl = 0x0ff;
71
 
72
        // Clear the PIC
73
        //
74
        //      Acknowledge all interrupts, turn off all interrupts
75
        //
76 49 dgisselq
        zip->z_pic = CLEARPIC;
77 30 dgisselq
        while(sys->io_pwrcount < (second >> 4))
78
                ;
79
 
80
        // Repeating timer, every 250ms
81 49 dgisselq
        zip->z_tma = TMR_INTERVAL | (second/4);
82
        wait_on_interrupt(SYSINT_TMA);
83 30 dgisselq
 
84
        sys->io_clrled[0] = green;
85
        sys->io_ledctrl = 0x010;
86
 
87 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
88 30 dgisselq
 
89
        sys->io_clrled[0] = dimgreen;
90
        sys->io_clrled[1] = green;
91 49 dgisselq
        sys->io_scope[0].s_ctrl = SCOPE_NO_RESET | 32;
92 30 dgisselq
        sys->io_ledctrl = 0x020;
93
 
94 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
95 30 dgisselq
 
96
        sys->io_clrled[1] = dimgreen;
97
        sys->io_clrled[2] = green;
98
        sys->io_ledctrl = 0x040;
99
 
100 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
101 30 dgisselq
 
102
        sys->io_clrled[2] = dimgreen;
103
        sys->io_clrled[3] = green;
104
        sys->io_ledctrl = 0x080;
105
 
106 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
107 30 dgisselq
 
108
        sys->io_clrled[3] = dimgreen;
109
 
110 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
111 30 dgisselq
 
112
        for(i=0; i<4; i++)
113
                sys->io_clrled[i] = black;
114
 
115
        // Wait one second ...
116 49 dgisselq
        for(i=0; i<4; i++)
117
                wait_on_interrupt(SYSINT_TMA);
118 30 dgisselq
 
119
        sw = sys->io_btnsw & 0x0f;
120
        for(int i=0; i<4; i++)
121
                sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
122
 
123
 
124 49 dgisselq
        // Wait another two seconds ...
125
        for(i=0; i<8; i++)
126
                wait_on_interrupt(SYSINT_TMA);
127 30 dgisselq
 
128
        // Blink all the LEDs
129
        //      First turn them on
130
        sys->io_ledctrl = 0x0ff;
131
        // Then wait a quarter second
132 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
133 30 dgisselq
        // Then turn the back off
134
        sys->io_ledctrl = 0x0f0;
135
        // and wait another quarter second
136 49 dgisselq
        wait_on_interrupt(SYSINT_TMA);
137 30 dgisselq
 
138
        // Now, read buttons, and flash an LED on any button being held
139
        // down ... ? neat?
140
 
141
        while(1) {
142
                unsigned        btn, ledc;
143
 
144
                zip_rtu();
145 49 dgisselq
                zip->z_pic = EINT(SYSINT_TMA)|SYSINT_TMA;
146 30 dgisselq
                // If the button is pressed, toggle the LED
147
                // Otherwise, turn the LED off.
148
                //
149
                // First, get all the pressed buttons
150
                btn = (sys->io_btnsw >> 4) & 0x0f;
151 32 dgisselq
                // Now, acknowledge the button presses that we just read
152
                sys->io_btnsw = (btn<<4);
153 30 dgisselq
 
154
                // Of any LEDs that are on, or buttons on, toggle their values
155 32 dgisselq
                ledc = (sys->io_ledctrl)&0x0f;
156
                ledc = (ledc | btn)&0x0f ^ ledc;
157 30 dgisselq
                // Make sure we set everything
158
                ledc |= 0x0f0;
159
                // Now issue the command
160
                sys->io_ledctrl = ledc;
161
                // That way, at the end, the toggle will leave them in the
162
                // off position.
163
                // sys->io_ledctrl = 0xf0 | ((sys->io_ledctrl&1)^1);
164
 
165
                sw = sys->io_btnsw & 0x0f;
166
                for(int i=0; i<4; i++)
167
                        sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
168
 
169
        }
170
 
171
        zip_halt();
172
}
173
 

powered by: WebSVN 2.1.0

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