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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [board/] [exstartup.c] - Diff between revs 49 and 52

Only display areas with differences | Details | Blame | View Log

Rev 49 Rev 52
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    exstartup.c
// Filename:    exstartup.c
//
//
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
//
//
// Purpose:     A fun example program that runs on the Arty, just to show
// Purpose:     A fun example program that runs on the Arty, just to show
//              that the minimum set of peripherals (LEDs, color LEDs, buttons,
//              that the minimum set of peripherals (LEDs, color LEDs, buttons,
//      switches, etc.) work.
//      switches, etc.) work.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
 
#include <stdio.h>
 
 
 
#include "artyboard.h"
#include "zipcpu.h"
#include "zipcpu.h"
#include "zipsys.h"
#include "zipsys.h"
#include "artyboard.h"
 
 
#define sys     _sys
 
 
void    idle_task(void) {
void    idle_task(void) {
        while(1)
        while(1)
                zip_idle();
                zip_idle();
}
}
 
 
void    wait_on_interrupt(int mask) {
void    wait_on_interrupt(int mask) {
        zip->z_pic = DALLPIC|mask;
        zip->z_pic = DALLPIC|mask;
        zip->z_pic = EINT(mask);
        zip->z_pic = EINT(mask);
        zip_rtu();
        zip_rtu();
}
}
 
 
 
 
void    main(int argc, char **argv) {
void    main(int argc, char **argv) {
        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 = CLOCKFREQHZ;
                second = CLOCKFREQHZ;
        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);
 
 
 
        printf("Starting exstartup\r\n");
 
 
        for(i=0; i<4; i++)
        for(i=0; i<4; i++)
                sys->io_clrled[i] = red;
                _sys->io_b.i_clrled[i] = red;
        sys->io_ledctrl = 0x0ff;
        sys->io_b.i_leds = 0x0ff;
 
 
        // Clear the PIC
        // Clear the PIC
        //
        //
        //      Acknowledge all interrupts, turn off all interrupts
        //      Acknowledge all interrupts, turn off all interrupts
        //
        //
        zip->z_pic = CLEARPIC;
        zip->z_pic = CLEARPIC;
        while(sys->io_pwrcount < (second >> 4))
        while(sys->io_b.i_pwrcount < (second >> 4))
                ;
                ;
 
 
        // Repeating timer, every 250ms
        // Repeating timer, every 250ms
        zip->z_tma = TMR_INTERVAL | (second/4);
        zip->z_tma = TMR_INTERVAL | (second/4);
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        sys->io_clrled[0] = green;
        sys->io_b.i_clrled[0] = green;
        sys->io_ledctrl = 0x010;
        sys->io_b.i_leds = 0x010;
 
 
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        sys->io_clrled[0] = dimgreen;
        sys->io_b.i_clrled[0] = dimgreen;
        sys->io_clrled[1] = green;
        sys->io_b.i_clrled[1] = green;
        sys->io_scope[0].s_ctrl = SCOPE_NO_RESET | 32;
        sys->io_scope[0].s_ctrl = WBSCOPE_NO_RESET | 32;
        sys->io_ledctrl = 0x020;
        sys->io_b.i_leds = 0x020;
 
 
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        sys->io_clrled[1] = dimgreen;
        sys->io_b.i_clrled[1] = dimgreen;
        sys->io_clrled[2] = green;
        sys->io_b.i_clrled[2] = green;
        sys->io_ledctrl = 0x040;
        sys->io_b.i_leds = 0x040;
 
 
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        sys->io_clrled[2] = dimgreen;
        sys->io_b.i_clrled[2] = dimgreen;
        sys->io_clrled[3] = green;
        sys->io_b.i_clrled[3] = green;
        sys->io_ledctrl = 0x080;
        sys->io_b.i_leds = 0x080;
 
 
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        sys->io_clrled[3] = dimgreen;
        sys->io_b.i_clrled[3] = dimgreen;
 
 
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
 
 
        for(i=0; i<4; i++)
        for(i=0; i<4; i++)
                sys->io_clrled[i] = black;
                sys->io_b.i_clrled[i] = black;
 
 
        // Wait one second ...
        // Wait one second ...
        for(i=0; i<4; i++)
        for(i=0; i<4; i++)
                wait_on_interrupt(SYSINT_TMA);
                wait_on_interrupt(SYSINT_TMA);
 
 
        sw = sys->io_btnsw & 0x0f;
        sw = sys->io_b.i_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_b.i_clrled[i] = (sw & (1<<i)) ? white : black;
 
 
 
 
        // Wait another two seconds ...
        // Wait another two seconds ...
        for(i=0; i<8; i++)
        for(i=0; i<8; i++)
                wait_on_interrupt(SYSINT_TMA);
                wait_on_interrupt(SYSINT_TMA);
 
 
        // Blink all the LEDs
        // Blink all the LEDs
        //      First turn them on
        //      First turn them on
        sys->io_ledctrl = 0x0ff;
        sys->io_b.i_leds = 0x0ff;
        // Then wait a quarter second
        // Then wait a quarter second
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(SYSINT_TMA);
        // Then turn the back off
        // Then turn the back off
        sys->io_ledctrl = 0x0f0;
        sys->io_b.i_leds = 0x0f0;
        // and wait another quarter second
        // and wait another quarter second
        wait_on_interrupt(SYSINT_TMA);
        wait_on_interrupt(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?
 
 
        while(1) {
        while(1) {
                unsigned        btn, ledc;
                unsigned        btn, ledc;
 
 
                zip_rtu();
                zip_rtu();
                zip->z_pic = EINT(SYSINT_TMA)|SYSINT_TMA;
                zip->z_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_b.i_btnsw >> 4) & 0x0f;
                // Now, acknowledge the button presses that we just read
                // Now, acknowledge the button presses that we just read
                sys->io_btnsw = (btn<<4);
                sys->io_b.i_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)&0x0f;
                ledc = (sys->io_b.i_leds)&0x0f;
                ledc = (ledc | btn)&0x0f ^ ledc;
                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_b.i_leds = 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_b.i_leds = 0xf0 | ((sys->io_b.i_leds&1)^1);
 
 
                sw = sys->io_btnsw & 0x0f;
                sw = sys->io_b.i_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_b.i_clrled[i] = (sw & (1<<i)) ? white : black;
 
 
        }
        }
 
 
        zip_halt();
        zip_halt();
}
}
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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