📄 ucosii_demo.c
字号:
* Parameters:
* data: Task input data value, not used
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
static void Task3(void *data)
{
SWIM_WINDOW_T win;
INT_16 xp[8], yp[8], xinc[8], yinc[8];
INT_32 index;
COLOR_T clrs[8];
/* Create window for this task */
swim_window_open(&win, xsz, ysz, fblog, xmin[3], ymin[3],
xmax[3], ymax[3], 1, WHITE, BLACK, BLUE);
/* Add a title bar */
swim_set_title(&win, "Task #4", YELLOW);
/* Set position of boxes to center of window */
for (index = 0; index < 8; index++)
{
xp[index] = 48 + ((xmax[3] - xmin[3]) / 2) - (index * 12);
yp[index] = 48 + ((ymax[3] - ymin[3]) / 2) - (index * 12);
}
/* Set incremental movement values */
xinc[0] = xinc[1] = yinc[1] = yinc[2] = -1;
xinc[2] = xinc[3] = yinc[0] = yinc[3] = 1;
xinc[4] = xinc[5] = yinc[5] = yinc[6] = 1;
xinc[6] = xinc[7] = yinc[4] = yinc[7] = -1;
/* Set box colors */
clrs[0] = RED;
clrs[1] = GREEN;
clrs[2] = BLUE;
clrs[3] = YELLOW;
clrs[4] = WHITE;
clrs[5] = MAGENTA;
clrs[6] = LIGHTGRAY;
clrs[7] = CYAN;
while(1)
{
for (index = 0; index < 8; index++)
{
/* Remove old box first */
swim_set_pen_color(&win, BLACK);
swim_set_fill_color(&win, BLACK);
swim_put_box(&win, xp[index], yp[index],
(xp[index] + 6), (yp[index] + 6));
/* Update box position */
xp[index] = xp[index] + xinc[index];
if ((xp[index] < 0) ||
(xp[index] >= (swim_get_horizontal_size(&win) - 6)))
{
xinc[index] = -xinc[index];
xp[index] = xp[index] + xinc[index];
}
yp[index] = yp[index] + yinc[index];
if ((yp[index] < 0) ||
(yp[index] >= (swim_get_vertical_size(&win) - 10)))
{
yinc[index] = -yinc[index];
yp[index] = yp[index] + yinc[index];
}
/* Draw new box */
swim_set_pen_color(&win, WHITE);
swim_set_fill_color(&win, clrs[index]);
swim_put_box(&win, xp[index], yp[index],
(xp[index] + 6), (yp[index] + 6));
}
OSTimeDly(2);
}
}
/***********************************************************************
*
* 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 #2 with priority 4 */
OSTaskCreate(Task1, (void *) 0, &TaskStk[1][TASK_STK_SIZE - 1], 4);
/* Create task #3 with priority 2 */
OSTaskCreate(Task2, (void *) 0, &TaskStk[2][TASK_STK_SIZE - 1], 2);
/* Create task #4 with priority 8 */
OSTaskCreate(Task3, (void *) 0, &TaskStk[3][TASK_STK_SIZE - 1], 8);
/* 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, "Task #1", 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 *) cp15_get_ttb());
/* 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);
/* Initialize the CPLD interface driver */
cpld_init();
/* Initialize the interrupt system */
int_initialize(0xC0000000);
/* Attach the uCos-II interrupt handler to the IRQ vector */
int_install_handler(IRQ_VEC, (PFV) &ucos_irq_handler);
/* Setup LCD muxing for all 16 data bits */
gpio_lcd_signal_select(GPIO_LCDV_0_15);
/* Setup LCD paramaters in the LCD controller */
lcddev = abl_open((INT_32) CLCDC, (INT_32) &LCDPANEL);
/* Save logical and physical addresses of frame buffer */
fblog = (COLOR_T *) FBLOG;
fbphy = (UNS_32 *) cp15_map_virtual_to_physical(fblog);
/* Set frame buffer address */
abl_ioctl(lcddev, LCD_SET_UP_FB, (INT_32) fbphy);
/* Make sure shared JTAG signal on PA2 is not active */
gpio_set_data_dir(GPIO_PORT_A, 0x04, GPIO_OUTPUT);
gpio_data_write(GPIO_PORT_A, 0x04);
/* Turn on the LCD backlight */
cpld_enable_lcd_veeen(TRUE);
/* 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);
}
/* Enable LCD controller and power signals */
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 4 equal sections for SWIM windows */
xmin[0] = xmin[1] = ymin[0] = ymin[2] = 0;
xmax[2] = xmax[3] = xsz - 1;
ymax[1] = ymax[3] = ysz - 1;
xmax[0] = xmax[1] = (xsz / 2) - 1;
ymax[0] = ymax[2] = (ysz / 2) - 1;
xmin[2] = xmin[3] = xmax[0] + 1;
ymin[1] = ymin[3] = ymax[0] + 1;
/* 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 */
int_enable(INT_TC1UINTR);
/* Initialize uC/OS-II */
OSInit();
/* Start the first task as the background task */
OSTaskCreate(TaskFirst, (void *) 0,
&TaskStk[0][TASK_STK_SIZE - 1], 32);
/* Start uC/OS-II */
OSStart();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -