/**************************************************************************** * Copyright (c) 2011 by Michael Fischer. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ***************************************************************************** * History: * * 27.11.2011 mifi First Version, tested with an Altera DE1 board. * Used for the ChibiOS tutorial here: * http://www.yagarto.de/howto.html ****************************************************************************/ #define __MAIN_C__ /*=========================================================================*/ /* Includes */ /*=========================================================================*/ #include #include #include #include "ch.h" #include "altera_avalon_pio_regs.h" /*=========================================================================*/ /* DEFINE: All Structures and Common Constants */ /*=========================================================================*/ /* * Priority and stack size of the task. */ #define TASK_HP_PRIORITY (NORMALPRIO + 3) #define TASK_LP_PRIORITY (NORMALPRIO + 2) #define TASK_HP_STK_SIZE 64 #define TASK_LP_STK_SIZE 64 /*=========================================================================*/ /* DEFINE: Definition of all local Data */ /*=========================================================================*/ static WORKING_AREA(HPStack, TASK_HP_STK_SIZE); static WORKING_AREA(LPStack, TASK_LP_STK_SIZE); /*=========================================================================*/ /* DEFINE: Definition of all local Procedures */ /*=========================================================================*/ /***************************************************************************/ /* HardwareInit */ /* */ /* In : none */ /* Out : none */ /* Return: none */ /***************************************************************************/ static void HardwareInit (void) { /* Clear 7-segment display */ IOWR(PIO_7SEG_BASE, 0, 0x0000); /* Switch of all green LEDs */ IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_GREEN_BASE, 0x0000); /* Switch of all red LEDs */ IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_RED_BASE, 0x0000); } /* HardwareInit */ /***************************************************************************/ /* HPTask */ /* */ /* In : task parameter */ /* Out : none */ /* Return: never */ /***************************************************************************/ static msg_t HPTask (void *p) { uint16_t Counter = 0; uint16_t Value = 0x0001; p = p; while(1) { IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_GREEN_BASE, Value); Value = Value << 1; Counter++; if (8 == Counter) { Counter = 0; Value = 1; } chThdSleepMilliseconds(100); } /* * This return here make no sense. * But prevent a compiler warning. */ return(0); } /* HPTask */ /***************************************************************************/ /* LPTask */ /* */ /* In : task parameter */ /* Out : none */ /* Return: never */ /***************************************************************************/ static msg_t LPTask (void *p) { uint16_t Counter = 0; uint16_t Value = 0x0100; p = p; while(1) { IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_RED_BASE, Value); Value = Value >> 1; Counter++; if (9 == Counter) { Counter = 0; Value = 0x0100; } chThdSleepMilliseconds(100); } /* * This return here make no sense. * But prevent a compiler warning. */ return(0); } /* LPTask */ /*=========================================================================*/ /* DEFINE: All code exported */ /*=========================================================================*/ /***************************************************************************/ /* main */ /* */ /* Note: ChibiOS/RT initialization. */ /* The ChibiOS/RT system was still init (chSysInit) before */ /* by the Nios system (ALT_OS_INIT). At this point all ChibiOS/RT */ /* function can be used. */ /* */ /* In : none */ /* Out : none */ /* Return: never */ /***************************************************************************/ int main (void) { /* * Before the application which is using ChibiOS/RT can be started, * the hardware of the target must be initialized. */ HardwareInit(); /* * Create our threads */ chThdCreateStatic(HPStack, sizeof(HPStack), TASK_HP_PRIORITY, HPTask, NULL); chThdCreateStatic(LPStack, sizeof(LPStack), TASK_LP_PRIORITY, LPTask, NULL); /* * Normal main() thread activity. */ while(1) { chThdSleepMilliseconds(500); } /* * This return here make no sense. But to prevent the compiler warning: * "return type of 'main' is not 'int' * An int as return is used :-) */ return(0); } /* main */ /*** EOF ***/