📄 threadx_demo.c
字号:
{
/* Sleep for 2 ticks */
tx_thread_sleep(2);
/* Try to read some data from the UART ring buffer */
idx = 0;
bytes = abl_read(uartdev, str, sizeof(str));
while (idx < bytes)
{
swim_put_char(&win, str[idx]);
idx++;
}
}
}
/***********************************************************************
*
* Function: thread_2_entry
*
* Purpose: Thread 3
*
* Processing:
* Open a SWIM window in the right bottom side of the window. Add a
* title bar to the window. Enter the task loop and loop forever.
* Approximately every 100 ticks, wakeup and print the 1 second
* tick value to the window.
*
* Parameters:
* thread_input: Thread input data value, not used
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void thread_2_entry(ULONG thread_input)
{
SWIM_WINDOW_T win;
CHAR str[64];
INT_32 ticks = 0;
swim_window_open(&win, xsz, ysz, fblog, xmin[2], ymin[2],
xmax[2], ymax[2], 1, WHITE, BLACK, BLUE);
/* Add a title bar */
swim_set_title(&win, "Window #2", MAGENTA);
while(1)
{
/* Sleep for 1 second */
tx_thread_sleep(100);
swim_put_text(&win, "Tick #");
make_number_str(str, ticks);
swim_put_text(&win, str);
swim_put_text(&win, "\n");
ticks++;
}
}
/***********************************************************************
*
* 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 ThreadX interrupt handler to the IRQ vector */
vic_install_arm_handler(IRQ_VEC, (PFV) __tx_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 for a 100Hz (10mS) interrupt */
timer1dev = abl_open((INT_32) TIMER1, 0);
abl_ioctl(timer1dev, TIMER_SET_USECS, (10 * TIMER_MSEC));
/* Normally, we would put the address of the timer interrupt in
the IRQ dispatcher, but the ThreadX interrupt handler in the
tx_ill.s file directly handles the timer 1 interrupt so the
following statement is not needed */
/*
vic_install_handler(VIC_TC1UINTR, VIC_VECTORED, **some_timer_isr**);
*/
/* Enable timer interrupt in the interrupt controller */
vic_int_enable(VIC_TC1UINTR, TRUE);
/* Start timer 1 */
abl_ioctl(timer1dev, TIMER_ENABLE, 1);
/* Enter the ThreadX kernel. */
tx_kernel_enter();
}
/***********************************************************************
*
* Function: tx_application_define
*
* Purpose: Setup ThreadX tasks
*
* Processing:
* See function.
*
* Parameters:
* first_unused_memory: First address of unused memory
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void tx_application_define(void *first_unused_memory)
{
CHAR *pointer;
/* Create a byte memory pool from which to allocate the thread
stacks */
tx_byte_pool_create(&byte_pool_0, "byte pool 0",
first_unused_memory, DEMO_STACK_POOL_SIZE);
/* Allocate the stack for thread 0 */
tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE,
TX_NO_WAIT);
/* Create thread 0 */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
pointer, DEMO_STACK_SIZE, 16, 16, 1, TX_AUTO_START);
/* Allocate the stack for thread 1 */
tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE,
TX_NO_WAIT);
/* Create thread 1 */
tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, DEMO_STACK_SIZE, 16, 16, 1, TX_AUTO_START);
/* Allocate the stack for thread 2 */
tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE,
TX_NO_WAIT);
/* Create thread 2 */
tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, DEMO_STACK_SIZE, 16, 16, 1, TX_AUTO_START);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -