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

Subversion Repositories openarty

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

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 30 dgisselq
#include "artyboard.h"
41
#include "zipsys.h"
42
 
43
asm("\t.section\t.start\n"
44
        "\t.global\t_start\n"
45
"_start:\n"
46
        "\tLDI\t_top_of_stack,SP\n"
47
        "\tMOV\t_after_bootloader(PC),R0\n"
48
        "\tBRA\tbootloader\n"
49
"_after_bootloader:\n"
50
        "\tLDI\t_top_of_stack,SP\n"
51
        "\tOR\t0x4000,CC\n"     // Clear the data cache
52
        "\tMOV\t_kernel_exit(PC),R0\n"
53
        "\tBRA\tentry\n"
54
"_kernel_exit:\n"
55
        "\tHALT\n"
56
        "\tBRA\t_kernel_exit\n"
57
        "\t.section\t.text");
58
 
59
extern int      _sdram_image_end, _sdram_image_start, _sdram,
60
        _blkram, _flash, _bss_image_end,
61
        _kernel_image_start, _kernel_image_end;
62
 
63
extern  void    bootloader(void) __attribute__ ((section (".boot")));
64
 
65
// #define      USE_DMA
66
void    bootloader(void) {
67
        int     zero = 0;
68
 
69
#ifdef  USE_DMA
70
        zip->dma.ctrl= DMACLEAR;
71
        zip->dma.rd = _kernel_image_start;
72
        if (_kernel_image_end != _sdram_image_start) {
73
                zip->dma.len = _kernel_image_end - _blkram;
74
                zip->dma.wr  = _blkram;
75
                zip->dma.ctrl= DMACCOPY;
76
 
77
                zip->pic = SYSINT_DMAC;
78
                while((zip->pic & SYSINT_DMAC)==0)
79
                        ;
80
        }
81
 
82
        zip->dma.len = &_sdram_image_end - _sdram;
83
        zip->dma.wr  = _sdram;
84
        zip->dma.ctrl= DMACCOPY;
85
 
86
        zip->pic = SYSINT_DMAC;
87
        while((zip->pic & SYSINT_DMAC)==0)
88
                ;
89
 
90
        if (_bss_image_end != _sdram_image_end) {
91
                zip->dma.len = _bss_image_end - _sdram_image_end;
92
                zip->dma.rd  = &zero;
93
                // zip->dma.wr // Keeps the same value
94
                zip->dma.ctrl = DMACCOPY;
95
 
96
                zip->pic = SYSINT_DMAC;
97
                while((zip->pic & SYSINT_DMAC)==0)
98
                        ;
99
        }
100
#else
101
        int     *rdp = &_kernel_image_start, *wrp = &_blkram;
102
 
103
        //
104
        // Load any part of the image into block RAM, but *only* if there's a
105
        // block RAM section in the image.  Based upon our LD script, the
106
        // block RAM should be filled from _blkram to _kernel_image_end.
107
        // It starts at _kernel_image_start --- our last valid address within
108
        // the flash address region.
109
        //
110
        if (&_kernel_image_end != &_sdram_image_start) {
111
                for(int i=0; i< &_kernel_image_end - &_blkram; i++)
112
                        *wrp++ = *rdp++;
113
        }
114
 
115
        //
116
        // Now, we move on to the SDRAM image.  We'll here load into SDRAM
117
        // memory up to the end of the SDRAM image, _sdram_image_end.
118
        // As with the last pointer, this one is also created for us by the
119
        // linker.
120
        // 
121
        wrp = &_sdram;
122
        for(int i=0; i< &_sdram_image_end - &_sdram; i++)
123
                *wrp++ = *rdp++;
124
 
125
        //
126
        // Finally, we load BSS.  This is the segment that only needs to be
127
        // cleared to zero.  It is available for global variables, but some
128
        // initialization is expected within it.  We start writing where
129
        // the valid SDRAM context, i.e. the non-zero contents, end.
130
        //
131
        for(int i=0; i<&_bss_image_end - &_sdram_image_end; i++)
132
                *wrp++ = 0;
133
#endif
134
}
135
 
136
void    idle_task(void) {
137
        while(1)
138
                zip_idle();
139
}
140
 
141
void    entry(void) {
142
        const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
143
                white = 0x070707, black = 0, dimgreen = 0x1f00,
144
                second = 81250000;
145
        int     i, sw;
146
 
147
        int     user_context[16];
148
        for(i=0; i<15; i++)
149
                user_context[i] = 0;
150
        user_context[15] = (unsigned)idle_task;
151
        zip_restore_context(user_context);
152
 
153
        for(i=0; i<4; i++)
154
                sys->io_clrled[i] = red;
155
        sys->io_ledctrl = 0x0ff;
156
 
157
        // Clear the PIC
158
        //
159
        //      Acknowledge all interrupts, turn off all interrupts
160
        //
161
        zip->pic = 0x7fff7fff;
162
        while(sys->io_pwrcount < (second >> 4))
163
                ;
164
 
165
        // Repeating timer, every 250ms
166 32 dgisselq
        zip->tma = (second/4) | 0x80000000;
167
        // zip->tma = 1024 | 0x80000000;
168 30 dgisselq
        // Restart the PIC -- listening for SYSINT_TMA only
169
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
170
        zip_rtu();
171 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
172 30 dgisselq
 
173
        sys->io_clrled[0] = green;
174
        sys->io_ledctrl = 0x010;
175
 
176 32 dgisselq
        zip_rtu();
177 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
178
 
179
        sys->io_clrled[0] = dimgreen;
180
        sys->io_clrled[1] = green;
181 32 dgisselq
        sys->io_scope[0].s_ctrl = 32 | 0x80000000; // SCOPE_TRIGGER;
182 30 dgisselq
        sys->io_ledctrl = 0x020;
183
 
184 32 dgisselq
        zip_rtu();
185 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
186
 
187
        sys->io_clrled[1] = dimgreen;
188
        sys->io_clrled[2] = green;
189
        sys->io_ledctrl = 0x040;
190
 
191
        zip_rtu();
192 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
193 30 dgisselq
 
194
        sys->io_clrled[2] = dimgreen;
195
        sys->io_clrled[3] = green;
196
        sys->io_ledctrl = 0x080;
197
 
198
        zip_rtu();
199 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
200 30 dgisselq
 
201
        sys->io_clrled[3] = dimgreen;
202
 
203
        zip_rtu();
204 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
205 30 dgisselq
 
206
        for(i=0; i<4; i++)
207
                sys->io_clrled[i] = black;
208
 
209
        // Wait one second ...
210
        for(i=0; i<4; i++) {
211
                zip_rtu();
212 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
213 30 dgisselq
        }
214
 
215
        sw = sys->io_btnsw & 0x0f;
216
        for(int i=0; i<4; i++)
217
                sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
218
 
219
 
220
        // Wait another two second ...
221
        for(i=0; i<8; i++) {
222
                zip_rtu();
223 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
224 30 dgisselq
        }
225
 
226
        // Blink all the LEDs
227
        //      First turn them on
228
        sys->io_ledctrl = 0x0ff;
229
        // Then wait a quarter second
230 32 dgisselq
        zip_rtu();
231 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
232
        // Then turn the back off
233
        sys->io_ledctrl = 0x0f0;
234
        // and wait another quarter second
235 32 dgisselq
        zip_rtu();
236 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
237
 
238
        // Now, read buttons, and flash an LED on any button being held
239
        // down ... ? neat?
240
 
241
        // zip->tma = 20000000; // 1/4 second -- already set
242
        while(1) {
243
                unsigned        btn, ledc;
244
 
245
                zip_rtu();
246 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
247 30 dgisselq
                // If the button is pressed, toggle the LED
248
                // Otherwise, turn the LED off.
249
                //
250
                // First, get all the pressed buttons
251
                btn = (sys->io_btnsw >> 4) & 0x0f;
252 32 dgisselq
                // Now, acknowledge the button presses that we just read
253
                sys->io_btnsw = (btn<<4);
254 30 dgisselq
 
255
                // Of any LEDs that are on, or buttons on, toggle their values
256 32 dgisselq
                ledc = (sys->io_ledctrl)&0x0f;
257
                ledc = (ledc | btn)&0x0f ^ ledc;
258 30 dgisselq
                // Make sure we set everything
259
                ledc |= 0x0f0;
260
                // Now issue the command
261
                sys->io_ledctrl = ledc;
262
                // That way, at the end, the toggle will leave them in the
263
                // off position.
264
                // sys->io_ledctrl = 0xf0 | ((sys->io_ledctrl&1)^1);
265
 
266
                sw = sys->io_btnsw & 0x0f;
267
                for(int i=0; i<4; i++)
268
                        sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
269
 
270
        }
271
 
272
        zip_halt();
273
}
274
 

powered by: WebSVN 2.1.0

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