⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucosii_demo.c

📁 含t h r e a d x,u c o s 的b s p
💻 C
📖 第 1 页 / 共 2 页
字号:
    swim_set_title(&win, "Window #2", MAGENTA);

    while(1)
    {
        /* Sleep for about 1 second */
        OSTimeDly(OS_TICKS_PER_SEC);

        swim_put_text(&win, "Tick #");
        make_number_str(str, ticks);
        swim_put_text(&win, str);
        swim_put_text(&win, "\n");
        ticks++;
    }
}

/***********************************************************************
 *
 * Function: TaskFirst
 *
 * Purpose: First uCos-II task
 *
 * Processing:
 *     Set the uCos time to 0. Enable timer to start timer interrupts.
 *     Call the OSStatInit() to start uCos statistics. Call the
 *     OSTaskCreate() function to start tassk 1 and 2. Open a SWIM
 *     window in the left side of the window. Add a title bar to the
 *     window. Enter the task loop and loop forever. In the task loop,
 *     increment iteration and clr. Set the new window pen color based
 *     on clr. Output a string to the window with the iteration counter
 *     value.
 *
 * Parameters:
 *     data: Task input data value, not used
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
static void TaskFirst(void *data)
{
    SWIM_WINDOW_T win;
    CHAR str[32];
    const CHAR it_str[] = "Iteration #";
    COLOR_T clr = BLACK;
    INT_32 iteration = 0;
#if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif

    OSTimeSet(0);

    OS_ENTER_CRITICAL();
    /* Start timer 1 */
    abl_ioctl(timer1dev, TIMER_ENABLE, 1);
    OS_EXIT_CRITICAL();

    OSStatInit();

    /* Create task #1 with priority 0 */
    OSTaskCreate(Task1, (void *) 0, &TaskStk[1][TASK_STK_SIZE - 1], 0);

    /* Create task #2 with priority 1 */
    OSTaskCreate(Task2, (void *) 0, &TaskStk[2][TASK_STK_SIZE - 1], 1);

    /* Open a window on the left side of the display */
    swim_window_open(&win, xsz, ysz, fblog, xmin[0], ymin[0],
       xmax[0], ymax[0], 1, WHITE, BLACK, DARKGRAY);

    /* Add a title bar on the window */
    swim_set_title(&win, "Thread #1 - Iteration list", LIGHTGRAY);

    /* Thread task loop */
    while(1)
    {
        /* Increment iteration counter */
        iteration++;

        /* Use a new pen color for the next iteration message */
        clr = clr + 0x2;
        swim_set_pen_color(&win, clr);

        /* Output the next iteration message in the window */
        swim_put_text(&win, it_str);
        make_number_str(str, iteration);
        swim_put_text(&win, str);
        swim_put_text(&win, "\n");
    }
}

/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Main entry point for image - transfers from startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void c_entry()
{
    INT_32 regionsize;
    
    /* Set virtual address of MMU table (needed for VIC driver
       functions) */
    cp15_set_vmmu_addr((UNS_32 *)
        (0xC1C00000 + (0xCD3E0000- 0xCD000000)));

    /* Initialize the IO system */
    abl_api_init((UNS_32 *) NULL);

    /* Register LCD, timer, and UART drivers in API - instead of
       registering, the direct driver functions can also be called
       directly. */
    abl_api_register((INT_32) CLCDC, (void *) lcd_open,
        (void *) lcd_close, (void *) lcd_read,
        (void *) lcd_write, (void *) lcd_ioctl);
    abl_api_register((INT_32) TIMER1, (void *) timer_open,
        (void *) timer_close, (void *) timer_read,
        (void *) timer_write, (void *) timer_ioctl);
    abl_api_register((INT_32) UART2, (void *) uart_open,
        (void *) uart_close, (void *) uart_read_ring,
        (void *) uart_write_ring, (void *) uart_ioctl);

    /* Initialize the CPLD interface driver */
    cpld_init();

    /* Initialize the interrupt system */
    vic_initialize(0xFFFFFFFF);

    /* Attach the uCos-II interrupt handler to the IRQ vector */
    vic_install_arm_handler(IRQ_VEC, (PFV) &ucos_irq_handler);

    /* Install VIC1 and VIC2 handlers (used in IRQ) */
    vic_install_arm_handler(VIC1_IRQ_VEC, (PFV) vic1_irq_dispatcher);
    vic_install_arm_handler(VIC2_IRQ_VEC, (PFV) vic2_irq_dispatcher);

    /* Enable GPIO signals PE4..7 and PD0..7 as LCD signals */
    gpio_lcd_signal_select(GPIO_LCDV_0_15);

    /* Open LCD with display */
    lcddev = abl_open((INT_32) CLCDC, (INT_32) &LCDPANEL);

    /* Set GPIO PE4 high to enable LCD4..7 via CPLD */
    gpio_set_data_dir(GPIO_PORT_E, GPIO_PORT_BIT4, GPIO_OUTPUT);
    gpio_data_write(GPIO_PORT_E, GPIO_PORT_BIT4);

    /* Also make sure that the CPLD_JTAG_OE signal is in the
       correct state */
    gpio_set_data_dir(GPIO_PORT_A, 0x04, GPIO_OUTPUT);
    gpio_data_write(GPIO_PORT_A, 0x04);

    /* Set color depth to 16 bits per pixel */
    abl_ioctl(lcddev, LCD_SET_BPP, 16);
 
    /* For displays that require more bandwidth, set DMA to request
       a transfer on 4 words empty instead of the default 8. This may
       help prevent 'display tearing' due to a starved LCD controller */
    regionsize = abl_ioctl(lcddev, LCD_GET_STATUS, LCD_XSIZE) *
        abl_ioctl(lcddev, LCD_GET_STATUS, LCD_YSIZE) *
        sizeof (COLOR_T);
    if (regionsize >= (800 * 600 * 2))
    {
        /* Displays of 800x600 pixels and 16-bits of color (or larger)
           will use faster DMA requests */
        abl_ioctl(lcddev, LCD_DMA_ON_4MT, 1);
    }

    /* HRTFT/TFT panel board initialization only */
    if ((abl_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == HRTFT) ||
        (abl_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == ADTFT) ||
        (abl_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == TFT))
    {
        /* Enable power to the LCD panel (sets VDDEN on PC3) */
        gpio_set_data_dir(GPIO_PORT_C, 0x08, GPIO_OUTPUT);
        gpio_data_write(GPIO_PORT_C, 0x08);
    }
    else
    {
        /* Other displays - do nothing (yet) */
        ;
    }

    /* Set frame buffer and enable display */
    abl_ioctl(lcddev, LCD_SET_UP_FB, (INT_32) FBPHY);
    abl_ioctl(lcddev, LCD_PWENABLE, 1);

    /* Save display size */
    xsz = abl_ioctl(lcddev, LCD_GET_STATUS, LCD_XSIZE);
    ysz = abl_ioctl(lcddev, LCD_GET_STATUS, LCD_YSIZE);

    /* Break the display into 3 sections for SWIM windows */
    /* First section is left half of the display */
    xmin[0] = ymin[0] = 0;
    xmax[0] = (xsz / 2) - 1;
    ymax[0] = ysz - 1;

    /* Next window sizes */
    xmin[1] = xmin[2] = xmax[0] + 1;
    xmax[1] = xmax[2] = xsz - 1;
    ymin[1] = 0;
    ymax[1] = (ysz / 2) - 1;
    ymin[2] = ymax[1] + 1;
    ymax[2] = ysz - 1;

    /* Save logical address of frame buffer */
    fblog = cp15_map_physical_to_virtual(FBPHY);
    
    /* Setup timer 1 */
    timer1dev = abl_open((INT_32) TIMER1, 0);

    /* Compute the timer tick time based on the uCos OS_TICKS_PER_SEC
       define */
    abl_ioctl(timer1dev, TIMER_SET_USECS,
        ((1000 / OS_TICKS_PER_SEC) * TIMER_MSEC));

    /* Normally, we would put the address of the timer interrupt in
       the IRQ dispatcher, but the uCos-II interrupt handler in the
       os_cpu_a.s file directly handles the timer 1 interrupt so the
       following statement is not needed */
    /*
    vic_install_handler(VIC_TC1UINTR, **some_timer_isr**);
    */

    /* Enable timer interrupt in the interrupt controller - note we do
       not actually start the timer clock yet - it will start in the
       first uCos-II task */
    vic_int_enable(VIC_TC1UINTR, TRUE);

    /* Initialize uC/OS-II */
    OSInit(); 

    /* Start the first task as the (almost) background task */ 
    OSTaskCreate(TaskFirst, (void *) 0,
        &TaskStk[0][TASK_STK_SIZE - 1], 4);

    /* Start uC/OS-II */ 
    OSStart();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -