示例#1
0
long getCurrentTemperature()
{
	CoEnterMutexSection(I2CMutex);
	long i = 0;
	while(i<100000)
	{
		i++;
	}
	writeDataBmp085(0xF4, 0x2E);
	//wait 4.5ms
	i = 0;
	while(i<1000000)
	{
		i++;
	}
	long ut = getUtBMP085(0xf6);
	CoTickDelay(300);
	short oss = 0;
	uint8_t transmitData = 0x34;
	transmitData += oss<<6;
	writeDataBmp085(0xF4, transmitData);
	i = 0;
	while(i<1000000)
	{
		i++;
	}
	long up = getUpBMP085(0xf6, oss);

	long temp = getTemperature();
	CoLeaveMutexSection(I2CMutex);
	CoEnterMutexSection(currentTemperatureMutex);
	currentTemperature = temp;
	CoLeaveMutexSection(currentTemperatureMutex);
	return temp;
}
示例#2
0
/*Only use this method after calling the gettemperature method max 1 second ago*/
long getCurrentPressure()
{
	long temp = 0;
	CoEnterMutexSection(I2CMutex);
	temp = getPressure();
	CoLeaveMutexSection(I2CMutex);
	CoEnterMutexSection(currentPressureMutex);
	currentPressure = temp;
	CoLeaveMutexSection(currentPressureMutex);
	return temp;
}
示例#3
0
void mixerTask(void * pdata)
{
  s_pulses_paused = true;

  while(1) {

    if (!s_pulses_paused) {
      uint16_t t0 = getTmr2MHz();

      CoEnterMutexSection(mixerMutex);
      doMixerCalculations();
      CoLeaveMutexSection(mixerMutex);

#if defined(FRSKY) || defined(MAVLINK)
      telemetryWakeup();
#endif

      if (heartbeat == HEART_WDT_CHECK) {
        wdt_reset();
        heartbeat = 0;
      }

      t0 = getTmr2MHz() - t0;
      if (t0 > maxMixerDuration) maxMixerDuration = t0 ;
    }

    CoTickDelay(1);  // 2ms for now
  }
}
示例#4
0
float getCurrentAltitude()
{
	CoEnterMutexSection(PressureAtSeaLevelMutex);
	float p0 = pressureAtSeaLevel;
	CoLeaveMutexSection(PressureAtSeaLevelMutex);

	float p = getCurrentPressure()/100;
	float temp = Pow((p0/p),(1/5.257))-1;
	float t = getTemperature()/10;
	temp = temp * (t+273.15);
	return temp/0.0065;
}
示例#5
0
/**
 * -----------------------------------------------------------------------------
 * @brief       mutexTask03	 
 * @param[in]   pdata    A pointer to parameter passed to task.	
 * @param[out]  None
 * @retval      None	 
 * @par Description
 * @details     Mutex test task code. 
 * -----------------------------------------------------------------------------
 */
static void mutexTask03 (void* pdata)
{
	unsigned int  task_para;
	unsigned char err;
	unsigned char mutex_id;
	task_para = (unsigned int)pdata;
	mutex_id = task_para % MUTEX_NUM;
	
	for (;;)
	{
	 err = CoEnterMutexSection (Mutex_Id[mutex_id]);
	 if (err != E_OK) {
	    printf ("\r Enter mutex error: \n");
		printf ("\r Task id = %2d, mutex id = %2d \n",task_para,mutex_id);
	 }
	 
	 if (task_para < MUTEX_NUM) {
	     CoTickDelay (30);
	
		 Flag [Cnt] = task_para+3;
	     Cnt++;
		  
		 err = CoDelTask (Task_Id[MAX_SLAVE_TEST_TASKS-task_para-1]);
		 if (task_para == 1) {
	         if (err == E_OK) {
	             printf ("\r Error: delete task [%d] fail.\n",MAX_SLAVE_TEST_TASKS-task_para-1);
	         }		   
		 }
		 else {
	         if (err != E_OK) {
	             printf ("\r Error: delete task [%d] fail.\n",MAX_SLAVE_TEST_TASKS-task_para-1);
	         }
		 }
	 }
	 else {
	 	 Flag [Cnt] = task_para+3;
	     Cnt++;
	 }
	
	 err = CoLeaveMutexSection (Mutex_Id[mutex_id]);
	 if (err != E_OK) {
	    printf ("\r Leave Mutex error: \n");
		printf ("\r Task id = %2d, mutex id = %2d \n",task_para,mutex_id);
	 }
	
	 if (task_para == 4)
	    Exit_Flag = 1;
	 
	 CoExitTask ();
	 
	}
}
示例#6
0
float calculateCurrentPressureAtSeaLevel(float currentAltitude)
{
	float t = getTemperature()/10;
	float p = getCurrentPressure()/100;
	float temp = 1-((0.0065*currentAltitude)/(t+(0.0065*currentAltitude)+273.15));
	temp = Pow(temp,-5.257);
	temp = p*temp;

	CoEnterMutexSection(PressureAtSeaLevelMutex);
	pressureAtSeaLevel = temp;
	CoLeaveMutexSection(PressureAtSeaLevelMutex);

	return temp;
}
示例#7
0
文件: main.c 项目: MejriTaoufik/CoOS
/**
 *******************************************************************************
 * @brief		Print task.	  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	  	This task print adc value by UART.  
 *******************************************************************************
 */
void uart_print(void *pdata)
{
	int AD_value;	 
	pdata = pdata; 			
	for (;;) 
	{			
		CoEnterMutexSection(mut_uart);			/*!< Enter mutex area.		 */
		
		AD_value = ADC_ConvertedValue;
		uart_printf ("\r AD value = 0x");
		uart_print_hex (AD_value,4);
		
		CoLeaveMutexSection(mut_uart); 			/*!< Leave mutex area.		  */

		CoTickDelay(100);
  	}		
}
示例#8
0
/**
 * -----------------------------------------------------------------------------
 * @brief       mutexTask02	 
 * @param[in]   pdata    A pointer to parameter passed to task.	
 * @param[out]  None
 * @retval      None	 
 * @par Description
 * @details     Mutex test task code. 
 * -----------------------------------------------------------------------------
 */
static void mutexTask02 (void* pdata)
{
	unsigned int  task_para;
	unsigned char err;
	unsigned char mutex_id;
	
	task_para  = (unsigned int)pdata;
	mutex_id = task_para%MUTEX_NUM;
	
	for (;;)
	{
	
	 err = CoEnterMutexSection (Mutex_Id[mutex_id]);
	 if (err != E_OK) {
	    printf ("\r Enter mutex error: \n");
		printf ("\r Task id = %2d, mutex id = %2d \n",task_para,mutex_id);
	 }
	
	 if (task_para < MUTEX_NUM) {
	     CoTickDelay (25);
	 }
	 
	 Flag [Cnt] = task_para +3;
	 Cnt++ ;
	
	 if (Cnt == MAX_SLAVE_TEST_TASKS){
	    Exit_Flag  = 1;
	 }
	
	 if (task_para < MUTEX_NUM)	{
	     Del_Flag = 1;
		 CoExitTask ();
	 }
	
	 err = CoLeaveMutexSection (Mutex_Id[mutex_id]);
	 if (err != E_OK) {
	    printf ("\r Leave Mutex error: \n");
		printf ("\r Task id = %2d, mutex id = %2d \n",task_para,mutex_id);
	 }
	
	 if (Del_Flag == 1) {
	 	CoExitTask ();
	 }
	}
}
示例#9
0
文件: main.c 项目: MejriTaoufik/CoOS
/**
 *******************************************************************************
 * @brief		Task of display adc value in LCD.	  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	   	This task use to display adc value in lcd. 
 *******************************************************************************
 */
void lcd_display_adc(void *pdata)
{
	int AD_value 	 = 0;
	int AD_scaled_ex = 0;
	int AD_scaled 	 = 0;  
	  
	pdata = pdata;
	for (;;) 
	{ 
		AD_value  = ADC_ConvertedValue;  /*!< Read AD value. 			      */
    	AD_scaled = AD_value / 52;       /*!< AD value scaled to 0..78(lines on LCD).	*/

		CoEnterMutexSection(mut_lcd);
		if (AD_scaled != AD_scaled_ex) { /*!< If new AD value different than old.*/
      		AD_scaled_ex = AD_scaled;
      		lcd_bargraphXY(0, 1, AD_scaled); 	 
		}
		CoLeaveMutexSection(mut_lcd);

		CoTickDelay(80);
	}		
}
示例#10
0
文件: main.c 项目: MejriTaoufik/CoOS
/**
 *******************************************************************************
 * @brief		time_display task		  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	    This task use to display time in LCD.
 *******************************************************************************
 */
void time_display(void *pdata)
{
	static unsigned char tim[3] = {0,0,0};
	static unsigned char *ptr;

	pdata = pdata;
	for (;;)
	{
		CoWaitForSingleFlag(time_display_flg,0);
		ptr = (unsigned char *)CoPendMail(mbox0,0,&errinfo[30]);

		CoEnterMutexSection(mut_lcd);
		if (tim[0] != *(ptr+0)) 
		{
			tim[0]   = *(ptr+0);
		   	chart[6] = tim[0]/10 + '0';
			chart[7] = tim[0]%10 + '0';			
		}
		if (tim[1] != *(ptr+1)) 
		{
			tim[1] 	 = *(ptr+1);
		   	chart[3] = tim[1]/10 + '0';
			chart[4] = tim[1]%10 + '0';
		}
		if (tim[2] != *(ptr+2)) 
		{
			tim[2] = *(ptr+2);
		   	chart[0] = tim[2]/10 + '0';
			chart[1] = tim[2]%10 + '0';
		}		

		set_cursor(7, 0);
		lcd_print (chart);

		CoLeaveMutexSection(mut_lcd);
	}		
}
示例#11
0
文件: main.c 项目: MejriTaoufik/CoOS
/**
 *******************************************************************************
 * @brief		lcd_blink task	  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	   	This task use to blink lcd when setting time.  
 *******************************************************************************
 */
void lcd_blink (void *pdata)
{
	char flag = 0;
    pdata = pdata;  
	for (;;)
	{
		CoWaitForSingleFlag(lcd_blink_flg,0);
		CoEnterMutexSection(mut_lcd);

		set_cursor(7, 0);
		lcd_print (chart);

		switch (timeflag) 
		{
			case 0:	
				break;
			case 1:	
				set_cursor (13, 0);
				if (flag == 0) 
				{
					lcd_putchar (0);
					lcd_putchar (0);					      				 
					flag = 1;
				}
				else 
				{
					lcd_putchar (chart[6]);
					lcd_putchar (chart[7]);
					flag = 0;
				}
				break;

			case 2:	
				set_cursor (10, 0);
				if (flag == 0) 
				{
					lcd_putchar (0);
					lcd_putchar (0);					      				 
					flag = 1;
				}
				else 
				{
					lcd_putchar (chart[3]);
					lcd_putchar (chart[4]);
					flag = 0;
				}
				break;
			case 3:
				set_cursor (7, 0);
				if (flag == 0) 
				{
					lcd_putchar (0);
					lcd_putchar (0);					      				 
					flag = 1;
				}
				else 
				{
					lcd_putchar (chart[0]);
					lcd_putchar (chart[1]);
					flag = 0;
				}
				break;
			default: break;
		};
		CoLeaveMutexSection(mut_lcd);
		CoTickDelay (55);
	}	
}
示例#12
0
文件: main.c 项目: MejriTaoufik/CoOS
/**
 *******************************************************************************
 * @brief		Set time task		  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	  	This task use to set time.  
 *******************************************************************************
 */
void time_set(void *pdata)
{
	static unsigned char bct = 0;			/* Button calc 					  */
	U16 evtmp = 0;

	pdata = pdata;
	for (;;)
	{
		evtmp = CoWaitForMultipleFlags(EVT_BUTTON_SEL|EVT_BUTTON_ADD,OPT_WAIT_ANY,0,&errinfo[20]);
		if(errinfo[20] != E_OK)
			uart_printf("\r Flag ERROR:\n");

		if (evtmp == EVT_BUTTON_SEL) 
		{
		 	bct++;
			switch (bct) 
			{	
				case 1: 
					timeflag = 1;
					if(lcd_blink_id == 0)
						lcd_blink_id = CoCreateTask (lcd_blink,(void *)0, LCD_BLINK_PRI ,&lcd_blink_Stk[TASK_STK_SIZE - 1], TASK_STK_SIZE );
					
					DisableRTCInterrupt();

					CoClearFlag(time_display_flg);
					CoSetFlag(lcd_blink_flg);
					break;
				case 2:
					timeflag = 2;
					break;
				case 3:
					timeflag = 3;
					break;
				case 4:	
					bct = 0; 
						
				   	CoClearFlag(lcd_blink_flg);
					CoSetFlag(time_display_flg);

					EnableRTCInterrupt();								
					break;
				default: break;
			};
			CoTickDelay(40);
			CoClearFlag(button_sel_flg);				
		}
		else if(evtmp == EVT_BUTTON_ADD) 
		{			
			CoEnterMutexSection(mut_lcd);			
		 	switch (bct)
			{
				case 1:
					time[0]++;
					if (time[0] >= 60) 
						time[0] = 0;
					chart[6] = time[0]/10 + '0';
					chart[7] = time[0]%10 + '0';
					break;				
				case 2:
					time[1]++;
					if (time[1] >= 60)
						time[1] = 0;
					chart[3] = time[1]/10 + '0';
					chart[4] = time[1]%10 + '0';
					break;				

				case 3:
					time[2]++;
					if (time[2] >= 24)
						time[2] = 0;
					chart[0] = time[2]/10 + '0';
					chart[1] = time[2]%10 + '0';
					break;

				default: break;
			}	
			set_cursor(7, 0);
			lcd_print (chart);
					
			CoLeaveMutexSection(mut_lcd);
			CoTickDelay(40);
			CoClearFlag(button_add_flg);						
		}
					
	}		
}