int main(void) { OSInit(); volatile short * pixel_ctrl_ptr = pixel_buffer_start; volatile char * char_ctrl_ptr = character_buffer; int err = ALT_SEM_CREATE(&display,1); if(err != 0) printf("Semaphore not created\n"); err = ALT_SEM_CREATE(&audio,1); if(err != 0) printf("Semaphore not created\n"); *(dma_control) &= (1<<2); //Enable DMA controller clearscreen(pixel_ctrl_ptr); drawbox(pixel_ctrl_ptr, 34*4, 9*4, 48, 10,0xFA01); wait_for_vsync(buffer_register,dma_control); OSTaskCreateExt(task1, pixel_ctrl_ptr, (void *)&task1_stk[TASK_STACKSIZE-1], TASK1_PRIORITY, TASK1_PRIORITY, task1_stk, TASK_STACKSIZE, NULL, 0); OSTaskCreateExt(task2, char_ctrl_ptr, (void *)&task2_stk[TASK_STACKSIZE-1], TASK2_PRIORITY, TASK2_PRIORITY, task2_stk, TASK_STACKSIZE, NULL, 0); OSTaskCreateExt(getcontrols, char_ctrl_ptr, (void *)&getcontrols_stk[TASK_STACKSIZE-1], GETCONTROLS_PRIORITY, GETCONTROLS_PRIORITY, getcontrols_stk, TASK_STACKSIZE, NULL, 0); OSStart(); return 0; }
/* * lcd_16207_init is called at boot time to initialise the LCD driver */ void alt_lcd_16207_init(alt_LCD_16207_dev * dev) { unsigned int base = dev->base; /* Mark the device as functional */ dev->broken = 0; ALT_SEM_CREATE (&dev->write_lock, 1); /* TODO: check that usleep can be called in an initialisation routine */ /* The initialisation sequence below is copied from the datasheet for * the 16207 LCD display. The first commands need to be timed because * the BUSY bit in the status register doesn't work until the display * has been reset three times. */ /* Wait for 15 ms then reset */ usleep(15000); IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT); /* Wait for another 4.1ms and reset again */ usleep(4100); IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT); /* Wait a further 1 ms and reset a third time */ usleep(1000); IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT); /* Setup interface parameters: 8 bit bus, 2 rows, 5x7 font */ lcd_write_command(dev, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE); /* Turn display off */ lcd_write_command(dev, LCD_CMD_ONOFF); /* Clear display */ lcd_clear_screen(dev); /* Set mode: increment after writing, don't shift display */ lcd_write_command(dev, LCD_CMD_MODES | LCD_CMD_MODE_INC); /* Turn display on */ lcd_write_command(dev, LCD_CMD_ONOFF | LCD_CMD_ENABLE_DISP); dev->esccount = -1; memset(dev->escape, 0, sizeof(dev->escape)); dev->scrollpos = 0; dev->scrollmax = 0; dev->active = 0; dev->period = alt_ticks_per_second() / 10; /* Call every 100ms */ alt_alarm_start(&dev->alarm, dev->period, &alt_lcd_16207_timeout, dev); /* make the device available to the system */ alt_dev_reg(&dev->dev); }
void fifoed_avalon_uart_init (fifoed_avalon_uart_state* sp,alt_u32 irq_controller_id, alt_u32 irq) { void* base = sp->base; int error; /* * Initialise the read and write flags and the semaphores used to * protect access to the circular buffers when running in a multi-threaded * environment. */ error = ALT_FLAG_CREATE (&sp->events, 0) || ALT_SEM_CREATE (&sp->read_lock, 1) || ALT_SEM_CREATE (&sp->write_lock, 1); if (!error) { /* enable interrupts at the device */ sp->ctrl = FIFOED_AVALON_UART_CONTROL_RTS_MSK | FIFOED_AVALON_UART_CONTROL_RRDY_MSK | FIFOED_AVALON_UART_CONTROL_DCTS_MSK; IOWR_FIFOED_AVALON_UART_CONTROL(base, sp->ctrl); /* register the interrupt handler */ // alt_irq_register (irq, sp, fifoed_avalon_uart_irq); #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT alt_ic_isr_register(irq_controller_id, irq, fifoed_avalon_uart_irq, sp, 0x0); #else alt_irq_register (irq, sp, fifoed_avalon_uart_irq); #endif } }
void alt_main (void) { #ifndef ALT_NO_EXIT int result; #endif /* ALT LOG - please see HAL/sys/alt_log_printf.h for details */ ALT_LOG_PRINT_BOOT("[alt_main.c] Entering alt_main, calling alt_irq_init.\r\n"); /* Initialize the interrupt controller. */ alt_irq_init (NULL); /* Initialize the operating system */ ALT_LOG_PRINT_BOOT("[alt_main.c] Done alt_irq_init, calling alt_os_init.\r\n"); ALT_OS_INIT(); /* * Initialize the semaphore used to control access to the file descriptor * list. */ ALT_LOG_PRINT_BOOT("[alt_main.c] Done OS Init, calling alt_sem_create.\r\n"); ALT_SEM_CREATE (&alt_fd_list_lock, 1); /* Initialize the device drivers/software components. */ ALT_LOG_PRINT_BOOT("[alt_main.c] Calling alt_sys_init.\r\n"); alt_sys_init(); ALT_LOG_PRINT_BOOT("[alt_main.c] Done alt_sys_init.\r\n"); #if !defined(ALT_USE_DIRECT_DRIVERS) && (defined(ALT_STDIN_PRESENT) || defined(ALT_STDOUT_PRESENT) || defined(ALT_STDERR_PRESENT)) /* * Redirect stdio to the apropriate devices now that the devices have * been initialized. This is only done if the user has requested these * devices be present (not equal to /dev/null) and if direct drivers * aren't being used. */ ALT_LOG_PRINT_BOOT("[alt_main.c] Redirecting IO.\r\n"); alt_io_redirect(ALT_STDOUT, ALT_STDIN, ALT_STDERR); #endif #ifndef ALT_NO_C_PLUS_PLUS /* * Call the C++ constructors */ ALT_LOG_PRINT_BOOT("[alt_main.c] Calling C++ constructors.\r\n"); _do_ctors (); #endif /* ALT_NO_C_PLUS_PLUS */ #if !defined(ALT_NO_C_PLUS_PLUS) && !defined(ALT_NO_CLEAN_EXIT) && !defined(ALT_NO_EXIT) /* * Set the C++ destructors to be called at system shutdown. This is only done * if a clean exit has been requested (i.e. the exit() function has not been * redefined as _exit()). This is in the interest of reducing code footprint, * in that the atexit() overhead is removed when it's not needed. */ ALT_LOG_PRINT_BOOT("[alt_main.c] Calling atexit.\r\n"); atexit (_do_dtors); #endif /* * Finally, call main(). The return code is then passed to a subsequent * call to exit() unless the application is never supposed to exit. */ ALT_LOG_PRINT_BOOT("[alt_main.c] Calling main.\r\n"); #ifdef ALT_NO_EXIT main (alt_argc, alt_argv, alt_envp); #else result = main (alt_argc, alt_argv, alt_envp); close(STDOUT_FILENO); exit (result); #endif ALT_LOG_PRINT_BOOT("[alt_main.c] After main - we should not be here?.\r\n"); }