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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [board/] [exstartup.c] - Diff between revs 30 and 32

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 30 Rev 32
#include "artyboard.h"
#include "artyboard.h"
#include "zipsys.h"
#include "zipsys.h"
 
 
asm("\t.section\t.start\n"
asm("\t.section\t.start\n"
        "\t.global\t_start\n"
        "\t.global\t_start\n"
"_start:\n"
"_start:\n"
        "\tLDI\t_top_of_stack,SP\n"
        "\tLDI\t_top_of_stack,SP\n"
        "\tMOV\t_after_bootloader(PC),R0\n"
        "\tMOV\t_after_bootloader(PC),R0\n"
        "\tBRA\tbootloader\n"
        "\tBRA\tbootloader\n"
"_after_bootloader:\n"
"_after_bootloader:\n"
        "\tLDI\t_top_of_stack,SP\n"
        "\tLDI\t_top_of_stack,SP\n"
        "\tOR\t0x4000,CC\n"     // Clear the data cache
        "\tOR\t0x4000,CC\n"     // Clear the data cache
        "\tMOV\t_kernel_exit(PC),R0\n"
        "\tMOV\t_kernel_exit(PC),R0\n"
        "\tBRA\tentry\n"
        "\tBRA\tentry\n"
"_kernel_exit:\n"
"_kernel_exit:\n"
        "\tHALT\n"
        "\tHALT\n"
        "\tBRA\t_kernel_exit\n"
        "\tBRA\t_kernel_exit\n"
        "\t.section\t.text");
        "\t.section\t.text");
 
 
extern int      _sdram_image_end, _sdram_image_start, _sdram,
extern int      _sdram_image_end, _sdram_image_start, _sdram,
        _blkram, _flash, _bss_image_end,
        _blkram, _flash, _bss_image_end,
        _kernel_image_start, _kernel_image_end;
        _kernel_image_start, _kernel_image_end;
 
 
extern  void    bootloader(void) __attribute__ ((section (".boot")));
extern  void    bootloader(void) __attribute__ ((section (".boot")));
 
 
// #define      USE_DMA
// #define      USE_DMA
void    bootloader(void) {
void    bootloader(void) {
        int     zero = 0;
        int     zero = 0;
 
 
#ifdef  USE_DMA
#ifdef  USE_DMA
        zip->dma.ctrl= DMACLEAR;
        zip->dma.ctrl= DMACLEAR;
        zip->dma.rd = _kernel_image_start;
        zip->dma.rd = _kernel_image_start;
        if (_kernel_image_end != _sdram_image_start) {
        if (_kernel_image_end != _sdram_image_start) {
                zip->dma.len = _kernel_image_end - _blkram;
                zip->dma.len = _kernel_image_end - _blkram;
                zip->dma.wr  = _blkram;
                zip->dma.wr  = _blkram;
                zip->dma.ctrl= DMACCOPY;
                zip->dma.ctrl= DMACCOPY;
 
 
                zip->pic = SYSINT_DMAC;
                zip->pic = SYSINT_DMAC;
                while((zip->pic & SYSINT_DMAC)==0)
                while((zip->pic & SYSINT_DMAC)==0)
                        ;
                        ;
        }
        }
 
 
        zip->dma.len = &_sdram_image_end - _sdram;
        zip->dma.len = &_sdram_image_end - _sdram;
        zip->dma.wr  = _sdram;
        zip->dma.wr  = _sdram;
        zip->dma.ctrl= DMACCOPY;
        zip->dma.ctrl= DMACCOPY;
 
 
        zip->pic = SYSINT_DMAC;
        zip->pic = SYSINT_DMAC;
        while((zip->pic & SYSINT_DMAC)==0)
        while((zip->pic & SYSINT_DMAC)==0)
                ;
                ;
 
 
        if (_bss_image_end != _sdram_image_end) {
        if (_bss_image_end != _sdram_image_end) {
                zip->dma.len = _bss_image_end - _sdram_image_end;
                zip->dma.len = _bss_image_end - _sdram_image_end;
                zip->dma.rd  = &zero;
                zip->dma.rd  = &zero;
                // zip->dma.wr // Keeps the same value
                // zip->dma.wr // Keeps the same value
                zip->dma.ctrl = DMACCOPY;
                zip->dma.ctrl = DMACCOPY;
 
 
                zip->pic = SYSINT_DMAC;
                zip->pic = SYSINT_DMAC;
                while((zip->pic & SYSINT_DMAC)==0)
                while((zip->pic & SYSINT_DMAC)==0)
                        ;
                        ;
        }
        }
#else
#else
        int     *rdp = &_kernel_image_start, *wrp = &_blkram;
        int     *rdp = &_kernel_image_start, *wrp = &_blkram;
 
 
        //
        //
        // Load any part of the image into block RAM, but *only* if there's a
        // Load any part of the image into block RAM, but *only* if there's a
        // block RAM section in the image.  Based upon our LD script, the
        // block RAM section in the image.  Based upon our LD script, the
        // block RAM should be filled from _blkram to _kernel_image_end.
        // block RAM should be filled from _blkram to _kernel_image_end.
        // It starts at _kernel_image_start --- our last valid address within
        // It starts at _kernel_image_start --- our last valid address within
        // the flash address region.
        // the flash address region.
        //
        //
        if (&_kernel_image_end != &_sdram_image_start) {
        if (&_kernel_image_end != &_sdram_image_start) {
                for(int i=0; i< &_kernel_image_end - &_blkram; i++)
                for(int i=0; i< &_kernel_image_end - &_blkram; i++)
                        *wrp++ = *rdp++;
                        *wrp++ = *rdp++;
        }
        }
 
 
        //
        //
        // Now, we move on to the SDRAM image.  We'll here load into SDRAM
        // Now, we move on to the SDRAM image.  We'll here load into SDRAM
        // memory up to the end of the SDRAM image, _sdram_image_end.
        // memory up to the end of the SDRAM image, _sdram_image_end.
        // As with the last pointer, this one is also created for us by the
        // As with the last pointer, this one is also created for us by the
        // linker.
        // linker.
        // 
        // 
        wrp = &_sdram;
        wrp = &_sdram;
        for(int i=0; i< &_sdram_image_end - &_sdram; i++)
        for(int i=0; i< &_sdram_image_end - &_sdram; i++)
                *wrp++ = *rdp++;
                *wrp++ = *rdp++;
 
 
        //
        //
        // Finally, we load BSS.  This is the segment that only needs to be
        // Finally, we load BSS.  This is the segment that only needs to be
        // cleared to zero.  It is available for global variables, but some
        // cleared to zero.  It is available for global variables, but some
        // initialization is expected within it.  We start writing where
        // initialization is expected within it.  We start writing where
        // the valid SDRAM context, i.e. the non-zero contents, end.
        // the valid SDRAM context, i.e. the non-zero contents, end.
        //
        //
        for(int i=0; i<&_bss_image_end - &_sdram_image_end; i++)
        for(int i=0; i<&_bss_image_end - &_sdram_image_end; i++)
                *wrp++ = 0;
                *wrp++ = 0;
#endif
#endif
}
}
 
 
void    idle_task(void) {
void    idle_task(void) {
        while(1)
        while(1)
                zip_idle();
                zip_idle();
}
}
 
 
void    entry(void) {
void    entry(void) {
        const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
        const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
                white = 0x070707, black = 0, dimgreen = 0x1f00,
                white = 0x070707, black = 0, dimgreen = 0x1f00,
                second = 81250000;
                second = 81250000;
        int     i, sw;
        int     i, sw;
 
 
        int     user_context[16];
        int     user_context[16];
        for(i=0; i<15; i++)
        for(i=0; i<15; i++)
                user_context[i] = 0;
                user_context[i] = 0;
        user_context[15] = (unsigned)idle_task;
        user_context[15] = (unsigned)idle_task;
        zip_restore_context(user_context);
        zip_restore_context(user_context);
 
 
        for(i=0; i<4; i++)
        for(i=0; i<4; i++)
                sys->io_clrled[i] = red;
                sys->io_clrled[i] = red;
        sys->io_ledctrl = 0x0ff;
        sys->io_ledctrl = 0x0ff;
 
 
        // Clear the PIC
        // Clear the PIC
        //
        //
        //      Acknowledge all interrupts, turn off all interrupts
        //      Acknowledge all interrupts, turn off all interrupts
        //
        //
        zip->pic = 0x7fff7fff;
        zip->pic = 0x7fff7fff;
        while(sys->io_pwrcount < (second >> 4))
        while(sys->io_pwrcount < (second >> 4))
                ;
                ;
 
 
        // Repeating timer, every 250ms
        // Repeating timer, every 250ms
        // zip->tma = (second/4) | 0x80000000;
        zip->tma = (second/4) | 0x80000000;
        zip->tma = 1024 | 0x80000000;
        // zip->tma = 1024 | 0x80000000;
        // Restart the PIC -- listening for SYSINT_TMA only
        // Restart the PIC -- listening for SYSINT_TMA only
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        sys->io_clrled[0] = green;
        sys->io_clrled[0] = green;
        sys->io_ledctrl = 0x010;
        sys->io_ledctrl = 0x010;
 
 
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        sys->io_clrled[0] = dimgreen;
        sys->io_clrled[0] = dimgreen;
        sys->io_clrled[1] = green;
        sys->io_clrled[1] = green;
        sys->io_scope[0].s_ctrl = 32 | SCOPE_TRIGGER;
        sys->io_scope[0].s_ctrl = 32 | 0x80000000; // SCOPE_TRIGGER;
        sys->io_ledctrl = 0x020;
        sys->io_ledctrl = 0x020;
 
 
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        sys->io_clrled[1] = dimgreen;
        sys->io_clrled[1] = dimgreen;
        sys->io_clrled[2] = green;
        sys->io_clrled[2] = green;
        sys->io_ledctrl = 0x040;
        sys->io_ledctrl = 0x040;
 
 
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA);
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        sys->io_clrled[2] = dimgreen;
        sys->io_clrled[2] = dimgreen;
        sys->io_clrled[3] = green;
        sys->io_clrled[3] = green;
        sys->io_ledctrl = 0x080;
        sys->io_ledctrl = 0x080;
 
 
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA);
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        sys->io_clrled[3] = dimgreen;
        sys->io_clrled[3] = dimgreen;
 
 
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA);
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        for(i=0; i<4; i++)
        for(i=0; i<4; i++)
                sys->io_clrled[i] = black;
                sys->io_clrled[i] = black;
 
 
        // Wait one second ...
        // Wait one second ...
        for(i=0; i<4; i++) {
        for(i=0; i<4; i++) {
                zip->pic = SYSINT_TMA;
 
                zip->pic = EINT(SYSINT_TMA);
 
                zip_rtu();
                zip_rtu();
 
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
        }
        }
 
 
        sw = sys->io_btnsw & 0x0f;
        sw = sys->io_btnsw & 0x0f;
        for(int i=0; i<4; i++)
        for(int i=0; i<4; i++)
                sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
                sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
 
 
 
 
        // Wait another two second ...
        // Wait another two second ...
        for(i=0; i<8; i++) {
        for(i=0; i<8; i++) {
                zip->pic = SYSINT_TMA;
 
                zip->pic = EINT(SYSINT_TMA);
 
                zip_rtu();
                zip_rtu();
 
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
        }
        }
 
 
        // Blink all the LEDs
        // Blink all the LEDs
        //      First turn them on
        //      First turn them on
        sys->io_ledctrl = 0x0ff;
        sys->io_ledctrl = 0x0ff;
        // Then wait a quarter second
        // Then wait a quarter second
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
        // Then turn the back off
        // Then turn the back off
        sys->io_ledctrl = 0x0f0;
        sys->io_ledctrl = 0x0f0;
        // and wait another quarter second
        // and wait another quarter second
        zip->pic = SYSINT_TMA;
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
        zip_rtu();
        zip_rtu();
 
        zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
 
 
        // Now, read buttons, and flash an LED on any button being held
        // Now, read buttons, and flash an LED on any button being held
        // down ... ? neat?
        // down ... ? neat?
 
 
        // zip->tma = 20000000; // 1/4 second -- already set
        // zip->tma = 20000000; // 1/4 second -- already set
        while(1) {
        while(1) {
                unsigned        btn, ledc;
                unsigned        btn, ledc;
 
 
                zip->pic = SYSINT_TMA;
 
                zip->pic = EINT(SYSINT_TMA);
 
                zip_rtu();
                zip_rtu();
 
                zip->pic = EINT(SYSINT_TMA)|SYSINT_TMA;
                // If the button is pressed, toggle the LED
                // If the button is pressed, toggle the LED
                // Otherwise, turn the LED off.
                // Otherwise, turn the LED off.
                //
                //
                // First, get all the pressed buttons
                // First, get all the pressed buttons
                btn = (sys->io_btnsw >> 4) & 0x0f;
                btn = (sys->io_btnsw >> 4) & 0x0f;
                sys->io_btnsw = 0x0f0;
                // Now, acknowledge the button presses that we just read
 
                sys->io_btnsw = (btn<<4);
 
 
                // Of any LEDs that are on, or buttons on, toggle their values
                // Of any LEDs that are on, or buttons on, toggle their values
                ledc = (sys->io_ledctrl | btn)&0x0f;
                ledc = (sys->io_ledctrl)&0x0f;
 
                ledc = (ledc | btn)&0x0f ^ ledc;
                // Make sure we set everything
                // Make sure we set everything
                ledc |= 0x0f0;
                ledc |= 0x0f0;
                // Now issue the command
                // Now issue the command
                sys->io_ledctrl = ledc;
                sys->io_ledctrl = ledc;
                // That way, at the end, the toggle will leave them in the
                // That way, at the end, the toggle will leave them in the
                // off position.
                // off position.
                // sys->io_ledctrl = 0xf0 | ((sys->io_ledctrl&1)^1);
                // sys->io_ledctrl = 0xf0 | ((sys->io_ledctrl&1)^1);
 
 
                sw = sys->io_btnsw & 0x0f;
                sw = sys->io_btnsw & 0x0f;
                for(int i=0; i<4; i++)
                for(int i=0; i<4; i++)
                        sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
                        sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
 
 
        }
        }
 
 
        zip_halt();
        zip_halt();
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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