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

Subversion Repositories openarty

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

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 32 dgisselq
        zip->tma = (second/4) | 0x80000000;
128
        // zip->tma = 1024 | 0x80000000;
129 30 dgisselq
        // Restart the PIC -- listening for SYSINT_TMA only
130
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
131
        zip_rtu();
132 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
133 30 dgisselq
 
134
        sys->io_clrled[0] = green;
135
        sys->io_ledctrl = 0x010;
136
 
137 32 dgisselq
        zip_rtu();
138 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
139
 
140
        sys->io_clrled[0] = dimgreen;
141
        sys->io_clrled[1] = green;
142 32 dgisselq
        sys->io_scope[0].s_ctrl = 32 | 0x80000000; // SCOPE_TRIGGER;
143 30 dgisselq
        sys->io_ledctrl = 0x020;
144
 
145 32 dgisselq
        zip_rtu();
146 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
147
 
148
        sys->io_clrled[1] = dimgreen;
149
        sys->io_clrled[2] = green;
150
        sys->io_ledctrl = 0x040;
151
 
152
        zip_rtu();
153 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
154 30 dgisselq
 
155
        sys->io_clrled[2] = dimgreen;
156
        sys->io_clrled[3] = green;
157
        sys->io_ledctrl = 0x080;
158
 
159
        zip_rtu();
160 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
161 30 dgisselq
 
162
        sys->io_clrled[3] = dimgreen;
163
 
164
        zip_rtu();
165 32 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
166 30 dgisselq
 
167
        for(i=0; i<4; i++)
168
                sys->io_clrled[i] = black;
169
 
170
        // Wait one second ...
171
        for(i=0; i<4; i++) {
172
                zip_rtu();
173 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
174 30 dgisselq
        }
175
 
176
        sw = sys->io_btnsw & 0x0f;
177
        for(int i=0; i<4; i++)
178
                sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
179
 
180
 
181
        // Wait another two second ...
182
        for(i=0; i<8; i++) {
183
                zip_rtu();
184 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
185 30 dgisselq
        }
186
 
187
        // Blink all the LEDs
188
        //      First turn them on
189
        sys->io_ledctrl = 0x0ff;
190
        // Then wait a quarter second
191 32 dgisselq
        zip_rtu();
192 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
193
        // Then turn the back off
194
        sys->io_ledctrl = 0x0f0;
195
        // and wait another quarter second
196 32 dgisselq
        zip_rtu();
197 30 dgisselq
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
198
 
199
        // Now, read buttons, and flash an LED on any button being held
200
        // down ... ? neat?
201
 
202
        // zip->tma = 20000000; // 1/4 second -- already set
203
        while(1) {
204
                unsigned        btn, ledc;
205
 
206
                zip_rtu();
207 32 dgisselq
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
208 30 dgisselq
                // If the button is pressed, toggle the LED
209
                // Otherwise, turn the LED off.
210
                //
211
                // First, get all the pressed buttons
212
                btn = (sys->io_btnsw >> 4) & 0x0f;
213 32 dgisselq
                // Now, acknowledge the button presses that we just read
214
                sys->io_btnsw = (btn<<4);
215 30 dgisselq
 
216
                // Of any LEDs that are on, or buttons on, toggle their values
217 32 dgisselq
                ledc = (sys->io_ledctrl)&0x0f;
218
                ledc = (ledc | btn)&0x0f ^ ledc;
219 30 dgisselq
                // Make sure we set everything
220
                ledc |= 0x0f0;
221
                // Now issue the command
222
                sys->io_ledctrl = ledc;
223
                // That way, at the end, the toggle will leave them in the
224
                // off position.
225
                // sys->io_ledctrl = 0xf0 | ((sys->io_ledctrl&1)^1);
226
 
227
                sw = sys->io_btnsw & 0x0f;
228
                for(int i=0; i<4; i++)
229
                        sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
230
 
231
        }
232
 
233
        zip_halt();
234
}
235
 

powered by: WebSVN 2.1.0

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