Exemple #1
0
void S640K1_TP_respond(int x,int y)
{
  unsigned char n;
  for(n=0;n<21;n++)
  {
    if(x>S640K1_TP[n][0]&&x<S640K1_TP[n][2]&&y>S640K1_TP[n][1]&&y<S640K1_TP[n][3])
    {
      if(n==19)//模式切换
      {
        //sys_flag=main_panel;
        //return;
        auto_scan_flag=~auto_scan_flag;
        if(auto_scan_flag==0xff)
        {
          skq_scan_thread_create();
          LCD_str(671,352,"自动模式",32,Blue2,Black);
        }
        else if(auto_scan_flag==0x00)
        {
          rt_thread_delete(skq_scan_thread);
          LCD_str(671,352,"手动模式",32,Blue2,Black);
        }
        return;
      }
      else if(n==20)//(退出)
      {
        rt_thread_delete(skq_scan_thread);
        ADC_R_stop();
        ADC_V_stop();
        PowerA_DIS();
        CD4067_DIS();
        sys_flag=main_panel;
        draw_main_panel();
        return;
      }
      else if(n==16)
      {
        ;
      }
      else 
      {        
        LCD_DrawFullRect( S640K1_TP[n][0],   S640K1_TP[n][1],   S640K1_TP[n][2],   S640K1_TP[n][3],  Black, 0);
        S640K1_measure_levels(n);
        LCD_DrawFullRect( S640K1_TP[n][0],   S640K1_TP[n][1],   S640K1_TP[n][2],   S640K1_TP[n][3],  Blue2, 0);
      } 
    }
  }
}
Exemple #2
0
void init_thread(void* parameter)
{
    rt_thread_t tid;

    rt_system_comonent_init();
    rt_hw_uart_init("uart0", 0);
    rt_console_set_device("uart0");
    rt_hw_sd_init("sd0");
    rt_hw_rtc_init();
    rt_hw_spi_init();
    rt_hw_pin_init("gpio");
    rt_hw_i2c_bit_ops_bus_init("i2c0");
    at24cxx_init("at24c02", "i2c0");
    rt_hw_ads7843_init("ads7843", "spi20");
    w25qxx_init("sf0", "spi21");
    rt_hw_lcd_init("lcd0");
    
    finsh_system_init();
 //   tid = rt_thread_create("usb", usb_thread_entry, RT_NULL, 1024, 9, 20);
   // rt_thread_startup(tid);
    
    if((*(uint32_t*)0x60000) != 0xFFFFFFFF)
    {
        tid = rt_thread_create("init", (void*)(0x60000), RT_NULL, 1024, 8, 20);
        rt_thread_startup(tid);
    }
    else
    {
        printf("addr:0x%X has no application\r\n", 0x60000);
    }
    rt_hw_enet_phy_init();

    tid = rt_thread_self();
    rt_thread_delete(tid); 
}
/* 线程2的入口函数 */
static void thread2_entry(void* parameter)
{
	/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */

	/* 线程2启动后先睡眠10个OS Tick */
	rt_thread_delay(10);

	/*
	 * 线程2唤醒后直接删除线程1,删除线程1后,线程1自动脱离就绪线程
	 * 队列
	 */
	rt_thread_delete(tid1);
	tid1 = RT_NULL;

	/*
	 * 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
	 * idle线程将执行真正的线程1控制块和线程栈的删除
	 */
	rt_thread_delay(10);

	/*
	 * 线程2运行结束后也将自动被删除(线程控制块和线程栈依然在idle线
	 * 程中释放)
	 */
	tid2 = RT_NULL;
}
Exemple #4
0
int main(void)
{
	RT_TASK *Main_Task;
	long msg;

	if (!(Main_Task = rt_thread_init(nam2num("MNTSK"), 10, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT MAIN TASK\n");
		exit(1);
	}

	if (!(hard_timer_running = rt_is_hard_timer_running())) {
		start_rt_timer(0);
	}
	barrier = rt_sem_init(nam2num("PREMS"), 4);
	latency_thread = rt_thread_create(latency_fun, NULL, 0);
	fast_thread    = rt_thread_create(fast_fun, NULL, 0);
	slow_thread    = rt_thread_create(slow_fun, NULL, 0);
	start = rt_get_time() + nano2count(200000000);
	rt_sem_wait_barrier(barrier);
	rt_receive(0, &msg);
	end = 1;
	rt_sem_wait_barrier(barrier);
	rt_thread_join(latency_thread);
	rt_thread_join(fast_thread);
	rt_thread_join(slow_thread);
	if (!hard_timer_running) {
		stop_rt_timer();
	}
	rt_sem_delete(barrier);
	rt_thread_delete(Main_Task);
	return 0;
}
Exemple #5
0
static void *fast_fun(void *arg)
{
	int jit, period;
	RTIME expected;

	if (!(Fast_Task = rt_thread_init(nam2num("FSTSK"), 2, 0, SCHED_FIFO, CPUMAP))) {
		printf("CANNOT INIT FAST TASK\n");
		exit(1);
	}

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sem_wait_barrier(barrier);
	period = nano2count(FASTMUL*TICK_TIME);
	expected = start + 6*nano2count(TICK_TIME);
	rt_task_make_periodic(Fast_Task, expected, period);
	while (!end) {
		jit = abs(count2nano(rt_get_time() - expected));
		if (jit > fastjit) {
			fastjit = jit;
		}
		rt_busy_sleep((FASTMUL*TICK_TIME*USEDFRAC)/100);
		expected += period;
		END("FE\n");
		rt_task_wait_period();
		BEGIN("FB\n");
	}
	rt_sem_wait_barrier(barrier);
	rt_make_soft_real_time();
	rt_thread_delete(Fast_Task);
	return 0;
}
Exemple #6
0
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 删除线程 */
	if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid1);
	if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid2);

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
Exemple #7
0
static void thread2_entry(void* parameter)
{
    rt_kprintf("thread2 dynamicly created ok\n");

    rt_thread_delay(RT_TICK_PER_SECOND * 4);
    
    rt_thread_delete(tid1);
    rt_kprintf("thread1 deleted ok\n");
}
static void _tc_cleanup()
{
	/* lock scheduler */
	rt_enter_critical();

	/* delete t1, t2 and worker thread */
	rt_thread_delete(t1);
	rt_thread_delete(t2);
	rt_thread_delete(worker);

	if (t1_count > t2_count)
		tc_stat(TC_STAT_FAILED);
	else
		tc_stat(TC_STAT_PASSED);

	/* unlock scheduler */
	rt_exit_critical();
}
Exemple #9
0
static void *latency_fun(void *arg)
{
	struct sample { long min, max, avrg, jitters[2]; } samp;
	int diff;
	int skip;
	int average;
	int min_diff;
	int max_diff;
	int period;
	RT_TASK *chktsk;
	RTIME expected;

	min_diff = 1000000000;
	max_diff = -1000000000;
	if (!(Latency_Task = rt_thread_init(nam2num("PRETSK"), 0, 0, SCHED_FIFO, CPUMAP))) {
		printf("CANNOT INIT LATENCY TASK\n");
		exit(1);
	}

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sem_wait_barrier(barrier);
	period = nano2count(TICK_TIME);
	expected = start + 3*period;
	rt_task_make_periodic(Latency_Task, expected, period);
	while (!end) {
		average = 0;
		for (skip = 0; skip < NAVRG && !end; skip++) {
			expected += period;
			END("HE\n");
			rt_task_wait_period();
			BEGIN("HB\n");
			diff = count2nano(rt_get_time() - expected);
			if (diff < min_diff) {
				min_diff = diff;
			}
			if (diff > max_diff) {
				max_diff = diff;
			}
			average += diff;
		}
		samp.min = min_diff;
		samp.max = max_diff;
		samp.avrg = average/NAVRG;
		samp.jitters[0] = fastjit;
		samp.jitters[1] = slowjit;
		if ((chktsk = rt_get_adr(nam2num("PRECHK")))) {
			rt_sendx_if(chktsk, &samp, sizeof(samp));
		}
	}
	rt_sem_wait_barrier(barrier);
	rt_make_soft_real_time();
	rt_thread_delete(Latency_Task);
	return 0;
}
/// Terminate execution of a thread and remove it from ActiveThreads
osStatus osThreadTerminate(osThreadId thread_id)
{
	rt_err_t result;

	result = rt_thread_delete(thread_id);

	if (result == RT_EOK)
		return osOK;
	else
		return osErrorOS;
}
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
static void keypress( unsigned int key )
{
	if(fupgrading)	return;
	switch( KeyValue )
	{
		case KeyValueMenu:
			pMenuItem=&Menu_5_other;
			pMenuItem->show();
			CounterBack=0;
			
			if(tid_upgrade) /*正在升级中*/
			{
				rt_thread_delete(tid_upgrade);
			}
			
			break;
		case KeyValueOk:
			if(BD_upgrad_contr==1)
				menu_set();
			if(menu_pos==0)
			{
				tid_upgrade = rt_thread_create( "upgrade", thread_gps_upgrade_uart, (void*)msg, 1024, 5, 5 );
				if( tid_upgrade != RT_NULL )
				{
					msg("I等待串口升级");
					rt_thread_startup( tid_upgrade );
				}else
				{
					msg("E线程创建失败");
				}
			}else /*U盘升级*/
			{
				tid_upgrade = rt_thread_create( "upgrade", thread_gps_upgrade_udisk, (void*)msg, 1024, 5, 5 );
				if( tid_upgrade != RT_NULL )
				{
					msg("I等待U盘升级");
					rt_thread_startup( tid_upgrade );
				}else
				{
					msg("E线程创建失败");
				}
			}
			break;
		case KeyValueUP:
			menu_pos=menu_pos^0x01;
			menu_set();
			break;
		case KeyValueDown:
			menu_pos=menu_pos^0x01;
			menu_set();
			break;
	}
	KeyValue = 0;
}
static void _tc_cleanup()
{
    /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
    rt_enter_critical();

    /* 删除信号量 */
    if (sem != RT_NULL)
        rt_sem_delete(sem);

    /* 删除线程 */
    if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
        rt_thread_delete(tid);
    if (worker != RT_NULL && worker->stat != RT_THREAD_CLOSE)
        rt_thread_delete(worker);

    /* 调度器解锁 */
    rt_exit_critical();

    /* 设置TestCase状态 */
    tc_done(TC_STAT_PASSED);
}
Exemple #13
0
void udpecho(rt_uint32_t startup)
{
	if (startup && echo_tid == RT_NULL) {
		echo_tid = rt_thread_create("uecho",
									udpecho_entry, RT_NULL,
									512, 30, 5);
		if (echo_tid != RT_NULL)
			rt_thread_startup(echo_tid);
	} else {
		if (echo_tid != RT_NULL)
			rt_thread_delete(echo_tid); /* delete thread */
		echo_tid = RT_NULL;
	}
}
Exemple #14
0
/**
 * System initialization thread.
 *
 * @param parameter parameter
 */
void sys_init_thread(void* parameter){
	set_system_status(SYSTEM_STATUS_INIT);

    /* EasyFlash initialization */
    if (flash_init() == FLASH_NO_ERR) {
        /* initialize OK and switch to running status */
        set_system_status(SYSTEM_STATUS_RUN);
		/* test Env demo */
		test_env();
    } else {
        /* initialize fail and switch to fault status */
        set_system_status(SYSTEM_STATUS_FAULT);
    }

    rt_thread_delete(rt_thread_self());
}
/* 线程2的入口函数 */
static void thread2_entry(void* parameter)
{
	/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */

	/* 线程2启动后先睡眠10个OS Tick */
	rt_thread_delay(10);

	/*
	 * 线程2唤醒后直接删除线程1,删除线程1后,线程1自动脱离就绪线程
	 * 队列
	 */
	rt_thread_delete(tid1);

	/*
	 * 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
	 * idle线程将执行真正的线程1控制块和线程栈的删除
	 */
	rt_thread_delay(10);
}
Exemple #16
0
/**
 * System initialization thread.
 *
 * @param parameter parameter
 */
void sys_init_thread(void* parameter){
	set_system_status(SYSTEM_STATUS_INIT);

    /* EasyLogger initialization */
    if (elog_init() == ELOG_NO_ERR) {
        /* set enabled format */
        elog_set_fmt(ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME /*| ELOG_FMT_P_INFO*/ | ELOG_FMT_T_INFO | ELOG_FMT_DIR
                /*| ELOG_FMT_FUNC*/ | ELOG_FMT_LINE);
        /* set EasyLogger assert hook */
        elog_assert_set_hook(elog_user_assert_hook);
        /* set hardware exception hook */
        rt_hw_exception_install(exception_hook);
        /* set RT-Thread assert hook */
        rt_assert_set_hook(rtt_user_assert_hook);
        /* initialize OK and switch to running status */
        set_system_status(SYSTEM_STATUS_RUN);
    } else {
        /* initialize fail and switch to fault status */
        set_system_status(SYSTEM_STATUS_FAULT);
    }

    rt_thread_delete(rt_thread_self());
}
/*GPRS串口发送和接收*/
rt_bool_t gprs_send_data_package(char *cmd,char *ack,uint16_t waittime, uint8_t retrytime)
{
  rt_bool_t res = RT_FALSE; 
  rt_err_t result = RT_EOK;
  rt_uint32_t event;
  char gprs_rx_buffer[512]={0x00};
  rt_thread_t thread;
  
  thread = rt_thread_find("gprswatch");
  if( thread != RT_NULL)
    rt_thread_delete(thread);
  
  do 
  {
    rt_device_write(gprs_device, 0, cmd, rt_strlen(cmd));   
    result = rt_event_recv(&rev_event, 
       REV_MASK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 
       waittime*RT_TICK_PER_SECOND, &event);
    if (result == RT_EOK)
    {
      if (event & REV_DATA)
      {
        rt_memset(gprs_rx_buffer,0x00,sizeof(gprs_rx_buffer));
        rt_thread_delay(RT_TICK_PER_SECOND*2);
        rt_device_read(gprs_device, 0, gprs_rx_buffer, 512);
        rt_kprintf(gprs_rx_buffer);
        if((rt_strstr(gprs_rx_buffer,ack))||(rt_strstr(gprs_rx_buffer,"OK")))
          res = RT_TRUE;
        else
          res = RT_FALSE;
      }
    }
    retrytime--;
  }while((!res)&&(retrytime>=1));
  gprswatch();
  return res;
} 
Exemple #18
0
void usb_thread_entry(void* parameter)
{
    int i;
    rt_thread_t tid;
    msd_msg_t msg;
    
    dev = rt_device_find(MOUNT_DEVICE);
    
    if(!dev)
    {
        rt_kprintf("no %s device found!\r\n", MOUNT_DEVICE);
        tid = rt_thread_self();
        rt_thread_delete(tid); 
    }
    
    rt_device_init(dev);
    rt_device_open(dev, RT_DEVICE_OFLAG_RDWR);
    
    usbd_init();                          /* USB Device Initialization          */
    usbd_connect(__TRUE);                 /* USB Device Connect                 */
    while (!usbd_configured ())
    {
        rt_thread_delay(10);
    }
    
    rt_kprintf("usb enum complete\r\n");
    
    while(1)
    {
        if(rt_mq_recv(msd_mq, &msg, sizeof(msd_msg_t), RT_WAITING_FOREVER) == RT_EOK)
        {
            if(msg.dir == 0) USBD_MSC_EP_BULKOUT_Event(0);
                else USBD_MSC_EP_BULKIN_Event (0);
        }
    }
}
Exemple #19
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
static void keypress( unsigned int key )
{
#if 0
	switch( key )
	{
		case KEY_MENU:

			if( ( data_fetch_comp == 1 ) || ( usb_error == 1 ) )
			{
				usb_error		= 0;
				data_fetch_comp = 0;
				pMenuItem		= &Menu_5_other;
				pMenuItem->show( );

				//if(tid_write_file)						///测试会复位
				//if(tid_write_file != RT_NULL)			///测试OK
				/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断*/
				rt_enter_critical( );
				if( tid_write_file != RT_NULL && tid_write_file->stat != RT_THREAD_CLOSE ) ///测试OK
				{
					rt_thread_delete( tid_write_file );
				}
				/* 调度器解锁*/
				rt_exit_critical( );
			}

			DataOutStartFlag	= 0;
			DataOutStartFlag	= 0;
			OUT_DataCounter		= 0;
			DataOutInFlag		= 0;
			break;
		case KEY_OK:
			//本地升级
			if( DataOutInFlag == 1 )
			{
				DataOutInFlag = 2; //导出数据类型选择标志
				USB_OUTFileSe( OUT_DataCounter );
			}
			//文件导出
			else if( DataOutInFlag == 2 )
			{
				DataOutInFlag = 0;

				if( ( OUT_DataCounter >= 1 ) && ( OUT_DataCounter <= 3 ) )
				{
					DataOutStartFlag = OUT_DataCounter; //在timetick中显示导出过程
				}
				tid_write_file = rt_thread_create( "writefile", thread_usbout_udisk, (void*)msg, 1024, 8, 5 );
				if( tid_write_file != RT_NULL )
				{
					msg( "I导出存储的数据" );
					rt_thread_startup( tid_write_file );
				}else
				{
					msg( "E错误按菜单键" );
					usb_error = 1;
				}
			}
			break;
		case KEY_UP:
			if( DataOutInFlag == 2 )
			{
				if( OUT_DataCounter <= 1 )
				{
					OUT_DataCounter = 3;
				} else
				{
					OUT_DataCounter--;
				}
				USB_OUTFileSe( OUT_DataCounter );
			}
			break;
		case KEY_DOWN:
			if( DataOutInFlag == 2 )
			{
				if( OUT_DataCounter >= 3 )
				{
					OUT_DataCounter = 1;
				} else
				{
					OUT_DataCounter++;
				}
				USB_OUTFileSe( OUT_DataCounter );
			}
			break;
	}
#endif	
}
Exemple #20
0
void lcd1602_FileNameRollExit()
{
    rt_thread_delete(lcd_thread_filename);
}
Exemple #21
0
void lcd1602_ConectExit()
{
    rt_thread_delete(lcd_thread_connect);
}
	static void keypress(unsigned int key)
	{ 
		switch(KeyValue)
			{
			case KeyValueMenu:
				DF_LOCK=0;
				CounterBack=0;
				USB_data_flag=0;
                if(Exit_updata==1)
                	{
                	Exit_updata=2;
					lcd_fill(0);
					lcd_text12(0,3,"是否退出U盘本地更新",19,LCD_MODE_SET);
					lcd_text12(24,18,"按确认键退出",12,LCD_MODE_SET);
					lcd_update_all();
                	}
				else if((check_error==1)||(data_fetch_comp==1))
					{
					check_error=0;
					data_fetch_comp=0;
					pMenuItem=&Menu_5_other;
					pMenuItem->show();

					if(tid_write_file)
						rt_thread_delete(tid_write_file);
					if(tid_file_update)
						rt_thread_delete(tid_file_update);
					}
				
                DataOutStartFlag=0;
				DataOutStartFlag=0;
				OUT_DataCounter=0;
				DataOutInFlag=0;
                in_out=1;
				break;
			case KeyValueOk:
				//退出本地U盘升级
				if(Exit_updata==2)
                	{
                	Exit_updata=0;
					pMenuItem=&Menu_5_other;
					pMenuItem->show();

					if(tid_write_file)
						rt_thread_delete(tid_write_file);
					if(tid_file_update)
						rt_thread_delete(tid_file_update);
                	}
				//本地升级
				if(DataOutInFlag==1)
					{
					if(in_out==1)
						{
						DataOutInFlag=2;//导出数据类型选择标志
						USB_OUTFileSe(OUT_DataCounter);
						}
					else if(in_out==2)
						{
						
						tid_file_update= rt_thread_create( "fileupdate", thread_usb_update, (void*)msg, 1024, 9, 5 );
						if( tid_file_update != RT_NULL )
							{
							Exit_updata=1;
							msg("I文件升级");							
							rt_thread_startup(tid_file_update);
							}
						else
							{
							Exit_updata=0;
							msg("E升级线程创建失败");
							}
						}
					}
				//文件导出
				else if(DataOutInFlag==2)
					{
					DataOutInFlag=0;

					if((OUT_DataCounter>=1)&&(OUT_DataCounter<=3))
						DataOutStartFlag=OUT_DataCounter;//在timetick中显示导出过程

					tid_write_file= rt_thread_create( "writefile", thread_usbout_udisk, (void*)msg, 1024, 8, 5 );
					if( tid_write_file != RT_NULL )
						{
						msg("I导出存储的数据");
						rt_thread_startup( tid_write_file);
						}
					else
						{
						msg("E线程创建失败");
						}
					}  
				break;
			case KeyValueUP:
				if(!Exit_updata)
					{
					if(DataOutInFlag==1)
						{
						in_out=1;
						DataInOutSe(1);
						}
					else if(DataOutInFlag==2)
						{
						OUT_DataCounter--;
						if(OUT_DataCounter<=1)
							OUT_DataCounter=1;
						USB_OUTFileSe(OUT_DataCounter);
						}
					}
				break;
			case KeyValueDown:
				if(!Exit_updata)
					{
					if(DataOutInFlag==1)
						{
						in_out=2;
						DataInOutSe(2);
						}
					else if(DataOutInFlag==2)
						{
						OUT_DataCounter++;
						if(OUT_DataCounter>=3)
							OUT_DataCounter=3;
						USB_OUTFileSe(OUT_DataCounter);
						}
					}
				break;
			}
	KeyValue=0;
	}