📄 threadx_demo.c
字号:
/***********************************************************************
* $Workfile: threadx_demo.c $
* $Revision: 1.3 $
* $Author: WellsK $
* $Date: Oct 28 2003 14:54:38 $
*
* Project: SDK7A404 simple threadx startup example
*
* Description:
* This file contains a simple threadx demo that will initialize
* the SDK7A404 board and then jump to c_entry(), which will
* initialize ThreadX and start the ThreadX tasks. This demo
* presently only works with the LQ035 ADTFT display.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/startup/examples/threadx/threadx_demo.c-arc $
*
* Rev 1.3 Oct 28 2003 14:54:38 WellsK
* Corrected ioctl functions. SHould be abl_ioctl instead of
* lcd_ioctl.
*
* Rev 1.2 Oct 28 2003 11:32:46 WellsK
* Updated to common LCD driver format.
*
* Rev 1.1 Sep 08 2003 14:28:48 WellsK
* Added support for additional displays with automatic window
* sizing. Added changes needed for updated VIC and CP15
* (MMU) drivers. Updated display power control logic.
*
* Rev 1.0 Jul 01 2003 12:48:48 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "lh7a404_clcdc_driver.h"
#include "lh7a404_gpio_driver.h"
#include "lh7a404_timer_driver.h"
#include "lh7a404_uart_driver.h"
#include "lh7a404_vic_driver.h"
#include "abl_arm922t_cp15_driver.h"
#include "sdk7a404_cpld_driver.h"
#include "abl_swim.h"
#include "abl_swim_font.h"
#include "abl_swim_image.h"
#include "abl_api.h"
#include "tx_api.h"
#include "abl_bmp.h"
#include "abl_heap.h"
/* Pick only 1 panel from the following list of defines */
#define LCD_DISPLAY sharp_lq035
//#define LCDPANEL sharp_lq039
//#define LCDPANEL sharp_lq057
//#define LCDPANEL sharp_lq064
//#define LCDPANEL sharp_lq104
//#define LCDPANEL sharp_lq121
#define DEMO_STACK_SIZE 0x1000 /* Thread stack sizes */
#define DEMO_STACK_POOL_SIZE 0x8000 /* Byte pool size */
/* ThreadX thread object control blocks */
TX_THREAD thread_0, thread_1, thread_2;
/* ThreadX byte pool */
TX_BYTE_POOL byte_pool_0;
/* Timer ThreadX interrupt handler (from tx_ill.s) */
extern void __tx_irq_handler(void);
/* Device handle for LCD driver */
INT_32 lcddev;
/* Device handle for timer driver */
INT_32 timer1dev;
/* Display sections for the 2 windows */
INT_32 xmin[3], xmax[3], ymin[3], ymax[3], xsz, ysz;
/* Pointer to logical frame buffer address */
COLOR_T *fblog;
/* Frame buffer physical and logic addresses - be careful that the
ThreadX byte pool doesn't get too big, as it will collide with
the frame buffer, ThreadX stacks, etc. Ideally, we would like
to use the ThreadX functions to allocate a byte pool for the
frame buffer and then convert the logical address to a physical
address for the LCD hardware. Next build maybe. */
#define FBPHY 0xCC000000 /* Physical address */
/***********************************************************************
*
* Function: make_number_str
*
* Purpose: Convert a number to a positive decimal string
*
* Processing:
* Using successive division, compute the base10 value of a number
* into a string and return the string value to the caller.
*
* Parameters:
* str : Where to place the generated strinjg
* iteration: Number to generate a string from
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void make_number_str(CHAR *str,
INT_32 iteration)
{
UNS_8 tmp[32];
INT_32 dvv1, dvv2;
INT_32 cnt = 0;
/* Number 0 in string */
str[cnt] = '0';
/* Main loop */
while (iteration > 0)
{
dvv1 = iteration / 10;
dvv2 = dvv1 * 10;
dvv1 = iteration - dvv2;
tmp[cnt] = dvv1;
iteration = iteration / 10;
cnt++;
}
if (cnt > 0)
{
for (dvv1 = 0; dvv1 < cnt; dvv1++)
{
str[dvv1] = (CHAR) ('0' + tmp[cnt - (dvv1 + 1)]);
}
}
str[cnt + 1] = '\0';
}
/***********************************************************************
*
* Function: thread_0_entry
*
* Purpose: Thread 1
*
* Processing:
* 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:
* thread_input: Thread input data value, not used
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void thread_0_entry(ULONG thread_input)
{
SWIM_WINDOW_T win;
CHAR str[32];
const CHAR it_str[] = "Iteration #";
COLOR_T clr = BLACK;
INT_32 iteration = 0;
/* 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: thread_1_entry
*
* Purpose: Thread 2
*
* Processing:
* Initialize UART2 for 115K-8-N-1 and create a window on the
* LCD. Periodically wakeup and check for data in the UART2 ring
* buffer. If data exists, output it to the window and go back to
* sleep until the next wakeup period.
*
* Parameters:
* thread_input: Thread input data value, not used
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void thread_1_entry(ULONG thread_input)
{
INT_32 uartdev;
SWIM_WINDOW_T win;
CHAR str[64];
INT_32 bytes, idx;
/* Enable UART2 at 115K-N-8-1 */
uartdev = abl_open((INT_32) UART2, 0);
abl_ioctl(uartdev, UART_SET_BAUD_RATE, BPS_115200);
abl_ioctl(uartdev, UART_SET_PARITY, UART_PARITY_NONE);
abl_ioctl(uartdev, UART_SET_DATA_BITS, 8);
abl_ioctl(uartdev, UART_SET_STOP_BITS, 1);
/* Enable the UART2 receive interrupts in the UART peripheral */
abl_ioctl(uartdev, UART_ENABLE_INTS,
(UART_INTR_RI | UART_INTR_RTI));
/* Place address of UART2 interrupt handler in IRQ router, but use
as a vectored interrupt (for best performance) */
vic_install_handler(VIC_UART2INTR, VIC_IRQ, (PFV) uart2_isr);
/* Enable the UART2 interrupt in the interrupt controller */
vic_int_enable(VIC_UART2INTR, TRUE);
swim_window_open(&win, xsz, ysz, fblog, xmin[1], ymin[1],
xmax[1], ymax[1], 1, WHITE, BLACK, BLUE);
/* Add a title bar */
swim_set_title(&win, "Window #1", GREEN);
while(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -