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

Subversion Repositories openarty

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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