X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=boards%2Fsam3n-ek%2Ftemplates%2Fsam3n-ek_kernel%2Fmain.c;fp=boards%2Fsam3n-ek%2Ftemplates%2Fsam3n-ek_kernel%2Fmain.c;h=55740793672cf6bd61455fb8928faca897b5e3c4;hb=61171d95e604185c26236fc9f3cba4ef77312c67;hp=0000000000000000000000000000000000000000;hpb=b6b7cb68fe5f979418b595c667bf714fee90b787;p=bertos.git diff --git a/boards/sam3n-ek/templates/sam3n-ek_kernel/main.c b/boards/sam3n-ek/templates/sam3n-ek_kernel/main.c new file mode 100644 index 00000000..55740793 --- /dev/null +++ b/boards/sam3n-ek/templates/sam3n-ek_kernel/main.c @@ -0,0 +1,159 @@ +/** + * \file + * + * + * \author Daniele Basile + * + * \brief Empty project. + * + * This is a minimalist project, it just initializes the hardware of the + * supported board and proposes an empty main. + */ + +#include "hw/hw_led.h" +#include "hw/hw_lcd.h" + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +/* Bitmap to display on the OLED display */ +static Bitmap lcd_bitmap; +/* Raster associated to the Bitmap image */ +static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)]; +/* LCD spi context with DMA access */ +struct SpiDma spi; + +static void init(void) +{ + /* Enable all the interrupts */ + IRQ_ENABLE; + + /* Initialize debugging module (allow kprintf(), etc.) */ + kdbg_init(); + /* Initialize LED driver */ + LED_INIT(); + /* Initialize system timer */ + timer_init(); + + /* + * Kernel initialization: processes (allow to create and dispatch + * processes using proc_new()). + */ + proc_init(); + + /* Init spi on dma to drive lcd */ + spi_dma_init(&spi); + spi_dma_setclock(LCD_SPICLOCK); + /* Initialize the dispaly */ + lcd_ili9225_init(&spi.fd); + /* Init the backligth display leds */ + LCD_BACKLIGHT_INIT(); + lcd_setBacklight(LCD_BACKLIGHT_MAX); + /* Draw an empty Bitmap on the screen */ + gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT); + /* Refresh the display */ + lcd_ili9225_blitBitmap(&lcd_bitmap); + /* Initialize the keypad driver */ + kbd_init(); + +} + + +static void NORETURN led_process(void) +{ + static int i = 0; + static bool turn = true; + + /* Periodically blink the led (toggle each 100 ms) */ + while (1) + { + if (turn) + { + LED_ON(i); + if (i) + LED_OFF(i - 1); + + if (i == 2) + { + turn = false; + timer_delay(70); + } + else + i++; + } + else + { + LED_OFF(i); + if (i > 0) + LED_ON(i-1); + + if (!i) + { + turn = true; + timer_delay(70); + } + else + i--; + } + timer_delay(300); + } +} + +int main(void) +{ + /* Hardware initialization */ + init(); + + /* Create a new child process */ + proc_new(&led_process, NULL, KERN_MINSTACKSIZE * 2, NULL); + + /* + * The main process is kept to periodically report the stack + * utilization of all the processes (1 probe per second). + */ + while (1) + { + monitor_report(); + timer_delay(1000); + } + + return 0; +} +