|

楼主 |
发表于 2022-11-11 13:43:21
|
显示全部楼层
static void app_gui_task(unsigned long para);
static void app_user_task(unsigned long para);
#define task_stack_gui_size 2048
#define task_stack_user_task_size 2048
#define user_task_stack_buf_size (task_stack_gui_size + task_stack_user_task_size + 256)
uint32_t user_task_stack_buf[user_task_stack_buf_size / 4];
#define task_gui_prio 3u
#define task_user_task_prio 4u
volatile uint8_t IsTransmittingBlock_;
static TX_THREAD app_tcb_gui;
static TX_THREAD app_tcb_user_task;
/**
*/
void user_thread_define(void *first_unused_memory)
{
CHAR *pointer = TX_NULL;
TX_BYTE_POOL byte_pool_0;
volatile uint32_t result;
if (tx_byte_pool_create(&byte_pool_0, "Tx App memory pool", user_task_stack_buf, user_task_stack_buf_size) != TX_SUCCESS)
{
return;
}
result = tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, task_stack_user_task_size, TX_NO_WAIT);
result = tx_thread_create(&app_tcb_user_task , \
"app user task",
app_user_task,
0,\
pointer, \
task_stack_user_task_size, \
task_user_task_prio , \
task_user_task_prio , \
TX_NO_TIME_SLICE , \
TX_AUTO_START );
result = tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, task_stack_gui_size, TX_NO_WAIT);
result = tx_thread_create(&app_tcb_gui , \
"app gui",
app_gui_task,
0,\
pointer, \
task_stack_gui_size, \
task_gui_prio , \
task_gui_prio , \
TX_NO_TIME_SLICE , \
TX_AUTO_START );
}
void app_gui_task(ULONG para)
{
uint8_t str[] = {"this test program display update"};
modbus_rtu_init(&mod_rs232 , &mod_rs232_info);
i2c_eeprom_init(&hi2c3 , i2c_read , i2c_write , HAL_GetTick);
eep_read(reg_offset(reg_buf ,®_buf[100]) * 2 , (500-100)*2 , (uint8_t*)®_buf[100] , 200);
update_set_dis_buf();
//give_framebuffer_semaphore();
request_read_reg(1, 20 ,40, -1, &mod_master_ins);
request_read_reg(1, 100 ,40, -1, &mod_master_ins);
touch_drv_init(&touch_drv , 480 , 320, pen_down_detect , sample_x_y);
touch_drv.calibrated = touch_calib_valid;
touch_drv.pfn_thread_sleep = HAL_Delay;
touch_drv.dis_dev = &dis_dev;
// user_para_sensor_1_type = 1;// (*((uint16_t*)®_buf[107])) //0-关闭,1-拉力,2-扭力,3-应力
// user_para_sensor_2_type = 2;// (*((uint16_t*)®_buf[108]))
// user_para_sensor_3_type = 3;// (*((uint16_t*)®_buf[109]))
if(touch_calib_valid == 1)
{
touch_drv.y_top = touch_y_top;
touch_drv.y_bottom = touch_y_bottom;
touch_drv.x_left = touch_x_left;
touch_drv.x_right = touch_x_right;
touch_drv.mark_y_top = touch_mark_y_top;
touch_drv.mark_y_bottom = touch_mark_y_bottom;
touch_drv.mark_x_left = touch_mark_x_left;
touch_drv.mark_x_right = touch_mark_x_right;
}
//等待gui 进入初始化
while((dev_sta & sys_init) == 0)
{
tx_thread_sleep(10);
}
//等待初始化结束
while((dev_sta & sys_init))
{
tx_thread_sleep(10);
if(touch_drv.pfn_pen_down_detect() == 0)
{
dev_sta &= ~sys_init;
touch_drv.y_top = 1543;
touch_drv.y_bottom = 458;
touch_drv.x_left = 485;
touch_drv.x_right = 1536;
touch_drv.mark_y_top = touch_drv.y_range / 5;
touch_drv.mark_y_bottom = touch_drv.y_range - touch_drv.mark_y_top;
touch_drv.mark_x_left = touch_drv.x_range / 5;
touch_drv.mark_x_right = touch_drv.x_range - touch_drv.mark_x_left;
if(0 == touch_drv_calibrate(&touch_drv))
{
touch_y_top = touch_drv.y_top;
touch_y_bottom = touch_drv.y_bottom;
touch_x_left = touch_drv.x_left;
touch_x_right = touch_drv.x_right;
touch_mark_y_top = touch_drv.mark_y_top;
touch_mark_y_bottom = touch_drv.mark_y_bottom;
touch_mark_x_left = touch_drv.mark_x_left;
touch_mark_x_right = touch_drv.mark_x_right;
touch_calib_valid = 1;
eeprom_queue_append((void*)&touch_y_top , reg_offset(reg_buf , &touch_y_top) * 2 , 9*2 , &eep_queue);
}
dev_sta |= calib_touch_end;
break;
}
}
void *p = malloc(10);
free(p);
//HAL_TIM_Base_Start_IT(&htim9);
for(;;)
{
tx_thread_sleep(1);
uart_rxd_task(&rs485_comm);
uart_rxd_task(&rs232_comm);
mod_master_task(&mod_master_ins);
force_sample();
touch_drv_update(&touch_drv);
real_pos = touch_drv.current_touch_coord.x % 1000;
real_pos += touch_drv.current_touch_coord.y * 1000;
p = malloc(30);
eeprom_task(&eep_queue);
free(p);
}
}
__IO float monitor_f;
extern void DisplayDriver_TransferCompleteCallback();
extern void touchgfxSignalVSync(void);
void app_user_task(unsigned long para)
{
volatile uint32_t base ,tick ,acculate;
uint32_t lcd_frame_tick;
uint8_t str_buf[32];
beep_on(1);
uint8_t *p;
for(;;)
{
tx_thread_sleep(1);
if(++acculate >= 100)
{
acculate = 0;
tick = HAL_GetTick() - base;
base = HAL_GetTick();
}
p = malloc(12);
if((HAL_GetTick() - lcd_frame_tick ) >= 1000)
{
lcd_frame_tick = HAL_GetTick();
float *fx = (float *)®_buf[20];
monitor_f = *fx;
f_to_str(monitor_f, 2, str_buf);
//st7796_dis_str_26x48(20, 100, str_buf , 0);
uint16_t x = user_para_f_unit;
if(++x >= 3)
{
x = 0;
}
uint16_t o = (uint32_t)&user_para_f_unit - (uint32_t)®_buf[0];
//request_write_reg(1 , o >> 1 , 1 , 1, &x ,&mod_master_ins);
}
s1_sample();
key_scan_task(&key_tick);
beep_tick_pro(&beep_tick);
key_process(&key_tick);
if(writing == 1 )
{
if(0 == st7796_draw_rect(wr_x , wr_y , wr_w, wr_h, (void*)pix))
{writing = 2;}
else
{
writing = 3;
}
}
free(p);
p = 0;
}
} |
|