Exemplo n.º 1
0
INT8U resume_network_tasks()
{
  INT8U err = OS_NO_ERR;
  err = ( OSTaskResume( TK_NETMAIN_TPRIO )|
        OSTaskResume( TK_NETTICK_TPRIO )|
        OSTaskResume( SSS_NIOS_II_SIMPLE_SOCKET_SERVER_TASK_PRIORITY ) );
  return( err );
}
Exemplo n.º 2
0
/*
* This function is called to resume a previously suspended task
*/
extern  status_t taskResume
    (
    uint8_t tid                   /* task ID of task to resume */
    )
{
    return OSTaskResume(tid);
}
Exemplo n.º 3
0
//浮点测试任务
void float_task(void *p_arg)
{
	OS_ERR err;
	CPU_SR_ALLOC();
	static float float_num = 0.01;
	//uint32_t temp = &float_num;
	while(1)
	{
		float_num+=0.01f;
		OS_CRITICAL_ENTER();	//进入临界区
		//printf("float_num的值为: %.4f\r\n",float_num);
		OS_CRITICAL_EXIT();		//退出临界区
		if(float_num > 0.901f && float_num < 0.919f)
		{
				OSTaskSuspend((OS_TCB*)&Led0TaskTCB,&err);
				printf("挂起LED任务\n\r");
		}
		if(float_num > 1.991f && float_num < 2.001f)
		{
				OSTaskResume((OS_TCB*)&Led0TaskTCB,&err);
				printf("恢复LED任务\n\r");
				float_num = 0.0f;
		}
		OSTimeDlyHMSM(0,0,0,300,OS_OPT_TIME_HMSM_STRICT,&err); //延时300ms	
	}
}
Exemplo n.º 4
0
static void task1(void *pdata)
{
	int timeout;
	int i;
	INT8U err;
	char *p;

    while(1)
    {
        dprintf("task1,%s\r\n",pdata);
		//dprintf("sys_jiffies:%d\r\n",sys_jiffies());
		//dprintf("sys_now:%dms\r\n",sys_now());
		//p = OSQPend(mbox, 1, &err);
		timeout = sys_arch_mbox_fetch(&sys_mbox, (void **)&p, 0);
		sys_mutex_lock(&sys_mutex);
		if(timeout != -1)
			dprintf("task1 received mbox: %s\r\n",p);
		sys_mutex_unlock(&sys_mutex);
		//else
			//OSTaskResume(9);
#if 0
		if(err != OS_NO_ERR)
		{
			dprintf("task1 OSQPend err:%d\r\n",err);
			OSTaskResume(9);
		}
		else
			dprintf("task1 received mbox: %s\r\n",p);
#endif
    }
}
Exemplo n.º 5
0
/* Handle the commands for each gesture */
static void handleGestureCommands(int gesture_code) {
	INT8U err;

	static int state = PAUSE;
	static int volume = 70;

	char *message = (char *) calloc(LARGE_BUF_SIZE, sizeof(char));

	// Pause
	if ((state == PLAY) && (gesture_code == GCODE_DOWN_LEFT)) {
		OSTaskSuspend(AUDIO_TASK_PRIORITY);
		state = PAUSE;
		snprintf(message, LARGE_BUF_SIZE, "RECOGNIZED DOWN-LEFT: PAUSE");
	// Play
	} else if ((state == PAUSE) && (gesture_code == GCODE_UP_LEFT)) {
		OSTaskResume(AUDIO_TASK_PRIORITY);
		state = PLAY;
		snprintf(message, LARGE_BUF_SIZE, "RECOGNIZED UP-LEFT: PLAY");
	// Volume down
	} else if ((state == PLAY) && (gesture_code == GCODE_DOWN_RIGHT)) {
		volume = decreaseVolume(volume);
		audio_set_headphone_volume(av_dev, volume);
		snprintf(message, LARGE_BUF_SIZE, "RECOGNIZED DOWN-RIGHT: VOL-DOWN");
	// Volume up
	} else if ((state == PLAY) && (gesture_code == GCODE_UP_RIGHT)) {
		volume = increaseVolume(volume);
		audio_set_headphone_volume(av_dev, volume);
		snprintf(message, LARGE_BUF_SIZE, "RECOGNIZED UP-RIGHT: VOL-UP");
	}

	printf("%s\n", message);
	if ((err = OSQPost(lcd_queue, message)) != OS_NO_ERR) {
		printf("Error %d: message not put on LCD queue.\n", err);
	}
}
Exemplo n.º 6
0
/*********************************************************************************************************
** Function name:           zyThreadResume
** Descriptions:            恢复任务
** input parameters:        ulThreadId: 线程ID
** output parameters:       none
** Returned value:          zy_OK: 成功
**                          负数:  错误,绝对值参考zy_if.h
** Created by:              chenmingji
** Created Date:            2009-07-23
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
*********************************************************************************************************/
INT32S zyThreadResume (unsigned long ulThreadId)
{
    OS_TCB *ptcbTask;                                                   /*  任务TCB                     */

    ptcbTask = (OS_TCB *)ulThreadId;

    OSTaskResume(ptcbTask->OSTCBPrio);
    return ZY_OK;
}
Exemplo n.º 7
0
static void task3(void *pdata)
{
	unsigned char *p;
	
    while(1)
	{
		dprintf("task3,%s\r\n",pdata);
		OSTaskResume(10);
    }
}
Exemplo n.º 8
0
/* prio:10 */
static void task2(void *pdata)
{
	
    while(1)
    {
		dprintf("task2,%s\r\n",pdata);
		OSTaskSuspend(OS_PRIO_SELF);
		OSTaskResume(9);
    }
}
Exemplo n.º 9
0
void board_control_task(void *pdata)
{
  INT8U error_code = OS_NO_ERR;
  board_control_mbox = OSMboxCreate((void *)NULL);

  struct http_form_data* board_control_mbox_contents;
  
  while(1)
  {
      board_control_mbox_contents = (void*)OSMboxPend(board_control_mbox, 0, &error_code);
      
      if (board_control_mbox_contents->LED_ON)
      {
        OSTaskResume(LED_PRIO);
      }
      else
      {
        /* Suspend the task and clear the LED. */
        OSTaskSuspend(LED_PRIO);
        IOWR_ALTERA_AVALON_PIO_DATA( LEDG_BASE, 0 );
      }
      
      if (board_control_mbox_contents->SSD_ON)
      {
        OSTaskResume(SSD_PRIO);
      }
      else
      {
        /* Suspend the task and set SSD to all zeros. */
        OSTaskSuspend(SSD_PRIO);
		#ifdef SEG7_NAME
        //sevenseg_set_hex(0); 
		#endif
      }  

      /* Always dump text to the LCD... */
	  #ifdef LCD_NAME
      lcd_output_text( board_control_mbox_contents->LCD_TEXT );
      usleep(500*1000);
	  #endif
  }
}
Exemplo n.º 10
0
/*
 * timerCheck - If there are any expired timers, wake up the timer task.
 * This is designed to be called from within the Jiffy timer interrupt so
 * it has to have minimal overhead.
 */
void timerCheck(void)
{
#ifdef OS_DEPENDENT
	if ((long)(timerHead.timerNext->expiryTime - OSTimeGet()) <= 0)
		(void) OSTaskResume(PRI_TIMER);
#endif
#if ONETASK_SUPPORT > 0
  // Support for non multitasking environment
  // Call timerTask if a timer has expired
	if ((long)(timerHead.timerNext->expiryTime - OSTimeGet()) <= 0)	timerTask(NULL);
#endif
}
Exemplo n.º 11
0
//任务3
//按键检测  
 void TaskKey(void *pdata)
 {	u8  key=0;
    while(1){
	  key=KEY_Scan();
	  if(key==1) 
	  {
		OSTaskSuspend(LED_TASK_Prio);
		OSTaskSuspend(LCD_TASK_Prio);
	  }
	  else if(key==2)
	  {
	    OSTaskResume(LED_TASK_Prio);
		OSTaskResume(LCD_TASK_Prio);	
	  }				
	  else if(key==3)
	  {
	    OSTaskDelReq(LED_TASK_Prio);
		OSTaskDelReq(LCD_TASK_Prio);
	  }
	  OSTimeDlyHMSM(0,0,0,20);		 
	}
 }
Exemplo n.º 12
0
void StartAllTasks ( void )
{
	int i;

	for (i = 0x00; i < N_TASKS; i ++)
	{
		if (!sRunning[i])
		{
			OSTaskResume(i + 1);
			sRunning[i] = 0x01;
		}
	}
}
Exemplo n.º 13
0
void TK_OSTaskResume(u_char * Id)
{
INT8U err;

   err = OSTaskResume(*Id);
   
   if ((err != OS_NO_ERR) && (err != OS_TASK_NOT_SUSPENDED))
   {
      dprintf("ChronOS API call failure, to Resume Suspended Task!\n");
      dtrap();
      panic("TK_OSTaskResume");      
   }
   return;
}
Exemplo n.º 14
0
void LedFont_ScrollText(char *text, bool scrollOnce, bool waitForFinish) {
  INT8U err;
  
  UTIL1_strcpy((uint8_t*)LedFont_Text, sizeof(LedFont_Text), (const unsigned char*)text);
  LedFont_ScrollOnce = scrollOnce;
  while (!(OSFlagQuery(LedFont_Flags, &err)&LEDFONT_FLAG_READY)) {
    (void)OSTimeDlyHMSM(0,0,0,100); /* wait task to be ready */
  }
  OSTaskResume(TASK_PRIO_SCROLLER);
  if (scrollOnce && waitForFinish) {
    while (!(OSFlagQuery(LedFont_Flags, &err)&LEDFONT_FLAG_FINISHED_SCROLLING)) {
      (void)OSTimeDlyHMSM(0,0,0,100); /* wait for scrolling to be finished */
    }
    OSFlagPost(LedFont_Flags, LEDFONT_FLAG_FINISHED_SCROLLING, OS_FLAG_CLR, &err); /* clear flag */
  }
}
Exemplo n.º 15
0
void turn_master_id(u8 id)//改变当前整个系统中主机的ID号
{
   u8 i,flag=0;
	{ 
	  flag=cont;
      if(id==(flag)){
	  	for(i=1;i<33;i++)
			{ order_trans_rs485(mybox.myid,i,0,0,0);
		     delay_us(10000);
			}//及时告知其他slave机器,已有主机
         mybox.master=1;
	    OSTaskResume(MASTER_TASK_PRIO);
		cont=1;
	  }
	 //  LED1=!LED1;
	  
      }
   }
Exemplo n.º 16
0
Arquivo: bcr.c Projeto: ericzhc/pdale
/******************************************************
  Enable bar code reader
*******************************************************/
void BCR_Enable()
{
	COM_BUFF_INFO RxBuff = GetTaskRxComBuff();

	if(enable == 0)
	{
		GPS_Disable();
		BCR_Init();
	}
	else
	{
		GPS_Disable();
		//SetCTS();
		OSTaskResume(TASK_BCR_PRIO);
	}

	*(RxBuff.ptrCurrent) = *(RxBuff.ptrEnd);
}
Exemplo n.º 17
0
int HandleCommand ( WORD index )
{
	char   sMsg[80];

	if (index > 0x100 && index < 0x200)
	{
		switch(index)
		{
			case 0x101:
				DisplayMessage("Start all tasks just now ...");
				StartAllTasks();   break;
			case 0x102:
				DisplayMessage("Stop all tasks just now ...");
				StopAllTasks();    break;
		}
	}
	else if (index > 0x00 && index <= 0x0a)
	{
		if (sRunning[index - 1])
		{
			sprintf(sMsg, "Suspend task%d just now ...", index);
			DisplayMessage(sMsg);
			OSTaskSuspend(index);
			sRunning[index - 1] = 0x00;
		}
		else
		{
			sprintf(sMsg, "Resume task%d just now ...", index);
			DisplayMessage(sMsg);
			OSTaskResume(index);
			sRunning[index - 1] = 0x01;
		}
	}
	else if (index > 0x200)
	{
		if (index == 0x201)
			DoHelp();
		else if (index == 0x202)
			DoAbout();

	}

	return 0x00;
}
Exemplo n.º 18
0
//闹铃处理(尺寸:44*20)
//x,y:坐标
//返回值,处理结果
u8 calendar_alarm_msg(u16 x,u16 y)
{
	u8 rval=0;  			  	
  	u16 *lcdbuf=0;							//LCD显存 
   	lcdbuf=(u16*)gui_memin_malloc(44*20*2);	//申请内存 
 	if(lcdbuf)								//申请成功
	{
		app_read_bkcolor(x,y,44,20,lcdbuf);	//读取背景色
		gui_fill_rectangle(x,y,44,20,LIGHTBLUE);
		gui_draw_rectangle(x,y,44,20,BROWN);
		gui_show_num(x+2,y+2,2,RED,16,alarm.hour,0X81); 
 		gui_show_ptchar(x+2+16,y+2,x+2+16+8,y+2+16,0,RED,16,':',1);
		gui_show_num(x+2+24,y+2,2,RED,16,alarm.min,0X81); 
  		OSTaskSuspend(6); //挂起主任务
		while(rval==0)
		{
			tp_dev.scan(0);
			if(tp_dev.sta&TP_PRES_DOWN)//触摸屏被按下
			{
				if(app_tp_is_in_area(&tp_dev,x,y,44,20))//判断某个时刻,触摸屏的值是不是在某个区域内
				{
					rval=0XFF;//取消
					break;
				} 
			 }
			delay_ms(5);  
    		if(system_task_return)break;			//需要返回	 
		}	 
		app_recover_bkcolor(x,y,44,20,lcdbuf);	//读取背景色
	}else rval=1;
	system_task_return=0;
	alarm.ringsta&=~(1<<7);	//取消闹铃   
	calendar_alarm_init((_alarm_obj*)&alarm,&calendar);	//重新初始化闹钟
	gui_memin_free(lcdbuf); 
	OSTaskResume(6); 		//恢复主任务
	system_task_return=0;
	return rval;
} 
Exemplo n.º 19
0
INT8U  CTask::Resume()
{
	return OSTaskResume(m_nPrio);
}
Exemplo n.º 20
0
/*
*********************************************************************************************************
*                                             App_SuspendResumeTask()
*
* Description : 机器人动作挂起和恢复任务
*
* Argument(s) : pdata.
*
* Return(s)   : none.
*********************************************************************************************************
*/
static void App_SuspendResumeTask(void *pdata)
{
		static uint8_t SuspendResume = 0;
	//临界区
// 	OS_CPU_SR  cpu_sr;
	while(1)
	{
// 		OS_ENTER_CRITICAL();				//进入临界区
		if((SuspendResume==0) && ((PDropL==1) || (PDropR==1) || (UltrTask==1)))
		{	
			  //suspend the tasks
			  OSTaskSuspend(9); //动作执行任务(RW: Robot Walk)
			  OSTaskSuspend(10); //动作步骤任务(RFS: Robot Forward Step)
			  OSTaskSuspend(11); //动作步骤任务(RBS: Robot Backward Step)
			  OSTaskSuspend(12); //右臂复位任务(RRA: Reset Right Arm)
			  OSTaskSuspend(13); //左臂复位任务(RLA: Reset Left Arm)
			  OSTaskSuspend(14); //右摆臂任务(SRA: Swing Right Arm)
			  OSTaskSuspend(15); //左摆臂任务(SLA: Swing Left Arm)
			
			//stop all motors
				HeadMove(70);
				LeftWristMove(70);
				RightWristMove(70);
				
				WaistMove(50);

				LeftArmMove(50);
				RightArmMove(50);
				
				LeftKneeMove(50);
				RightKneeMove(50);

				LeftFootMove(50);
				RightFootMove(50);

				if((PDropL==1) && (PDropR==0))
				{
						//左转矫正
						LeftFootMove(90);
						RightFootMove(5);
				}
				else if((PDropR==1) && (PDropL==0))
				{
						//右转矫正
						LeftFootMove(5);
						RightFootMove(90);
				}
				SuspendResume = 1;	
		}
		else if((SuspendResume==1) && (PDropL==0) && (PDropR==0) && (UltrTask==0))
		{
				//resume the tasks
				OSTaskResume(9);  //动作执行任务(RW: Robot Walk)
				OSTaskResume(10); //动作步骤任务(RFS: Robot Forward Step)
				OSTaskResume(11); //动作步骤任务(RBS: Robot Backward Step)
	 		  OSTaskResume(12); //右臂复位任务(RRA: Reset Right Arm)
				OSTaskResume(13); //左臂复位任务(RLA: Reset Left Arm)
				OSTaskResume(14); //右摆臂任务(SRA: Swing Right Arm)
				OSTaskResume(15); //左摆臂任务(SLA: Swing Left Arm)
			
				if(robotMode == SlideForward)
				{
						LeftFootMove(5);
						RightFootMove(5);
				}
				SuspendResume = 0;
		}
// 		OS_EXIT_CRITICAL();					//退出临界区
		OSTimeDlyHMSM(0,0,0,10);
	}
}
Exemplo n.º 21
0
void Input_Task(void *parg)
{
	u8 err;
	u8 OK=0;
	u8 buffer[4]={0};
	u8 LEN=0;
	u8 flag=0;
	u16 e=0;
	OS_CPU_SR cpu_sr;
	(void)parg;
	for(;;)
	{
		OSSemPend(PENIRQ,0,&err);
		Exti_Set(0);
		OS_ENTER_CRITICAL();
		touch.FLAG=Read_XY_2(&touch.AD_X,&touch.AD_Y);
		OS_EXIT_CRITICAL();
		if(touch.FLAG)
		{
			Led_On(1);
			touch.FLAG=0;
			touch.LCD_X=CalcXY(touch.AD_X,0);
			touch.LCD_Y=CalcXY(touch.AD_Y,1);
			touch.KEY=Get_Key(touch.PID,touch.LCD_X,touch.LCD_Y);
			if(touch.KEY<=10)
			{
				OS_ENTER_CRITICAL();
				Set_Color(WHITE,BLACK);
				if(touch.KEY==10)
					Show_Char('.',cursor.x,cursor.y);
				else
				{
					Show_Dec(touch.KEY,1,cursor.x,cursor.y);
					if(LEN<4)
					{
						buffer[LEN]=touch.KEY;
						LEN++;
					}
				}
				if(cursor.x<224)
				{
					cursor.x+=8;
					if(cursor.x>=224)
						cursor.x=224;
				}
				OS_EXIT_CRITICAL();
			}
		
			else if(touch.KEY==11)
			{
				OK++;
				if(OK==1)
				{
					VALUE1=CalcDec(buffer,LEN);
					Set_Color(BLACK,GREEN);
					Show_String(">>VALUE1:",2,22);
					Show_Dec(VALUE1,LEN,82,22);
					OS_ENTER_CRITICAL();
					LCD_Clear(4,121,232,38,WHITE);
					cursor.x=8;
					cursor.y=132;
					OS_EXIT_CRITICAL();
					buffer[0]=0;
					buffer[1]=0;
					buffer[2]=0;
					buffer[3]=0;
					LEN=0;
				}
				else if(OK==2)
				{
					VALUE2=CalcDec(buffer,LEN);
					Set_Color(BLACK,GREEN);
					Show_String(">>VALUE2:",2,38);
					Show_Dec(VALUE2,LEN,82,38);
					OS_ENTER_CRITICAL();
					LCD_Clear(4,121,232,38,WHITE);
					cursor.x=8;
					cursor.y=132;
					OS_EXIT_CRITICAL();
					buffer[0]=0;
					buffer[1]=0;
					buffer[2]=0;
					buffer[3]=0;
					LEN=0;
				}
				else if(OK==3)
				{
					VALUE3=CalcDec(buffer,LEN);
					Set_Color(BLACK,GREEN);
					Show_String(">>VALUE3:",2,54);
					Show_Dec(VALUE3,LEN,82,54);
					OS_ENTER_CRITICAL();
					LCD_Clear(4,121,232,38,WHITE);
					cursor.x=8;
					cursor.y=132;
					OS_EXIT_CRITICAL();
					buffer[0]=0;
					buffer[1]=0;
					buffer[2]=0;
					buffer[3]=0;
					LEN=0;
				}
			
				else if(OK==4)
				{
					if(VALUE2>0&&VALUE2<=5000)
					{
						if(VALUE1<VALUE2&&VALUE1>0)
						{
							if(VALUE3>0&&VALUE3<10000)
							{
								e=0;
								Set_Color(BLACK,GREEN);
								Show_String(">>OK!",2,70);
							}
							else
							{
								e=1;
							}
						}
						else
						{
							e=1;
						}
					}
					else
					{
						e=1;
					}

					if(e)	
					{
						Set_Color(BLACK,GREEN);
						Show_String(">>ERROR!",2,70);
					}
				}
				else if(OK==5)
				{
					if(!e)
					{
						OK=0;
						OSTaskSuspend(CURSOR_TASK_PRIO);
						Show_Main(VALUE1,VALUE2,VALUE3,1);
					}
					else
					{
						OK=0;
						e=0;
						LCD_Clear(2,20,236,100,BLACK);
						LCD_DrawEdit(input);
						Set_Cursor(8,132);
					}
					VALUE1=0;
					VALUE2=0;
					VALUE3=0;
				}
				else;
			}
		
			else if(touch.KEY==12)
			{
				OS_ENTER_CRITICAL();
			
				if(LEN>0)
				{
					LEN--;
				}
						
				if(cursor.x>=8) 
				{	
					LCD_Clear(cursor.x,cursor.y,8,16,WHITE);
					cursor.x-=8;
					if(cursor.x<8)
					{
						cursor.x=8;
					}
				}	
				OS_EXIT_CRITICAL();
			}
		
			else if(touch.KEY==13)
			{
				if(flag==0)
				{
					flag=1;
					button1.str="stop";
					button1.len=4;
					button1.line_color=GREEN;
					LCD_DrawButton(button1);
					OSTaskResume(TIMER_TASK_PRIO);
				}
				else
				{
					flag=0;
					button1.str="start";
					button1.len=5;
					button1.line_color=BLACK;
					LCD_DrawButton(button1);
					OSTaskSuspend(TIMER_TASK_PRIO);
				}
			}
		
			else if(touch.KEY==14)
			{
				OSTaskSuspend(TIMER_TASK_PRIO);
				Show_KeyMap();
				OSTaskResume(CURSOR_TASK_PRIO);
			}
			
			else if(touch.KEY==99)//無效輸入
			{}
			else;
			OSTimeDlyHMSM(0,0,0,50);
			Led_Off(1);
		}
		Exti_Set(1);
	}
}
Exemplo n.º 22
0
/*
*********************************************************************************************************
*                                                  RESUMETASKS
*********************************************************************************************************
*/
void  TaskResume(void) {
	INT8U i;
	for ( i = 1; i <= N_TASKS+1; i++)
		OSTaskResume(i);
}
Exemplo n.º 23
0
void MainTask(void *arg) {
  ADI_AFE_DEV_HANDLE hDevice;
  int16_t dft_results[DFT_RESULTS_COUNT];
  q15_t dft_results_q15[DFT_RESULTS_COUNT];
  q31_t dft_results_q31[DFT_RESULTS_COUNT];
  q31_t magnitude[DFT_RESULTS_COUNT / 2];
  q15_t phase[DFT_RESULTS_COUNT / 2];
  fixed32_t magnitude_result[DFT_RESULTS_COUNT / 2 - 1];
  fixed32_t phase_result[DFT_RESULTS_COUNT / 2 - 1];
  char msg[MSG_MAXLEN];
  uint8_t err;
  done = 0;
  uint16_t pressure_analog;
  uint32_t pressure;
  nummeasurements = 0;
  uint32_t rtcCount;
  ADI_I2C_RESULT_TYPE i2cResult;

  // Initialize driver.
  rtc_Init();

  // Calibrate.
  rtc_Calibrate();

  // Initialize UART.
  if (uart_Init()) {
    FAIL("ADI_UART_SUCCESS");
  }

  // Initialize I2C.
  i2c_Init(&i2cDevice);
  
  // Initialize flags.
  bRtcAlarmFlag = bRtcInterrupt = bWdtInterrupt = false;

  // Get the current count.
  if (adi_RTC_GetCount(hRTC, &rtcCount)) {
    FAIL("adi_RTC_GetCount failed");
  }

  // Initialize the AFE API.
  if (adi_AFE_Init(&hDevice)) {
    FAIL("adi_AFE_Init");
  }

  // AFE power up.
  if (adi_AFE_PowerUp(hDevice)) {
    FAIL("adi_AFE_PowerUp");
  }

  // Excitation Channel Power-up.
  if (adi_AFE_ExciteChanPowerUp(hDevice)) {
    FAIL("adi_AFE_ExciteChanPowerUp");
  }

  // TIA Channel Calibration.
  if (adi_AFE_TiaChanCal(hDevice)) {
    FAIL("adi_AFE_TiaChanCal");
  }

  // Excitation Channel Calibration (Attenuation Enabled).
  if (adi_AFE_ExciteChanCalAtten(hDevice)) {
    FAIL("adi_AFE_ExciteChanCalAtten");
  }

  // Update FCW in the sequence.
  seq_afe_acmeas2wire[3] = SEQ_MMR_WRITE(REG_AFE_AFE_WG_FCW, FCW);
  // Update sine amplitude in the sequence.
  seq_afe_acmeas2wire[4] =
      SEQ_MMR_WRITE(REG_AFE_AFE_WG_AMPLITUDE, SINE_AMPLITUDE);

  // Recalculate CRC in software for the AC measurement, because we changed.
  // FCW and sine amplitude settings.
  adi_AFE_EnableSoftwareCRC(hDevice, true);

  // Perform the impedance measurement.
  if (adi_AFE_RunSequence(hDevice, seq_afe_acmeas2wire, (uint16_t *)dft_results,
                          DFT_RESULTS_COUNT)) {
    FAIL("Impedance Measurement");
  }

  // Set RTC alarm.
  printf("rtcCount: %d\r\n", rtcCount);
  if (ADI_RTC_SUCCESS != adi_RTC_SetAlarm(hRTC, rtcCount + 120)) {
    FAIL("adi_RTC_SetAlarm failed");
  }

  // Enable RTC alarm.
  if (ADI_RTC_SUCCESS != adi_RTC_EnableAlarm(hRTC, true)) {
    FAIL("adi_RTC_EnableAlarm failed");
  }

  // Read the initial impedance.
  q31_t magnitudecal;
  q15_t phasecal;

  convert_dft_results(dft_results, dft_results_q15, dft_results_q31);
  arm_cmplx_mag_q31(dft_results_q31, &magnitudecal, 2);

  phasecal = arctan(dft_results[1], dft_results[0]);

  printf("raw rcal data: %d, %d\r\n", dft_results[1], dft_results[0]);
  printf("rcal (magnitude, phase) = (%d, %d)\r\n", magnitudecal, phasecal);

  // Create the message queue for communicating between the ISR and this task.
  dft_queue = OSQCreate(&dft_queue_msg[0], DFT_QUEUE_SIZE);

  // Hook into the DFT interrupt.
  if (ADI_AFE_SUCCESS !=
      adi_AFE_RegisterAfeCallback(
          hDevice, ADI_AFE_INT_GROUP_CAPTURE, AFE_DFT_Callback,
          BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN)) {
    FAIL("adi_AFE_RegisterAfeCallback");
  }
  if (ADI_AFE_SUCCESS !=
      adi_AFE_ClearInterruptSource(
          hDevice, ADI_AFE_INT_GROUP_CAPTURE,
          BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN)) {
    FAIL("adi_AFE_ClearInterruptSource (1)");
  }

  packed32_t q_result;
  void *q_result_void;
  OS_Q_DATA q_data;
  uint16_t q_size;
  bool inflated = false;
  while (true) {
    // Wait for the user to press the button.
    printf("MainTask: waiting for button.\n");
    OSSemPend(ux_button_semaphore, 0, &err);
    if (err != OS_ERR_NONE) {
      FAIL("OSSemPend: MainTask");
    }
    
    // TODO: fix bug when pressing button multiple times.
    // Have the pump task inflate the cuff.
    printf("MainTask: button detected. Resuming pump task.\n");
    err = OSTaskResume(TASK_PUMP_PRIO);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskResume: MainTask (1)");
    }
    
    // Wait a bit.
    printf("MainTask: waiting a bit.\n");
    err = OSTimeDlyHMSM(0, 0, 1, 0);
    if (err != OS_ERR_NONE) {
      FAIL("OSTimeDlyHMSM: MainTask (3)");
    }
    
    // Enable the DFT interrupt.
    printf("MainTask: enabling DFT interrupt.\n");
    if (ADI_AFE_SUCCESS !=
        adi_AFE_EnableInterruptSource(
            hDevice, ADI_AFE_INT_GROUP_CAPTURE,
            BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN, true)) {
      FAIL("adi_AFE_EnableInterruptSource");
    }
    
    PRINT("START\r\n");
    printf("START\r\n");

    while (true) {
      // Wait on the queue to get DFT data from the ISR (~76 Hz).
      //printf("MainTask: pending on DFT queue.\n");
      q_result_void = OSQPend(dft_queue, 0, &err);
      q_result.pointer = q_result_void;
      if (err != OS_ERR_NONE) {
        FAIL("OSQPend: dft_queue");
      }
      OSQQuery(dft_queue, &q_data);
      q_size = q_data.OSNMsgs;
    
      // Right after we get this data, get the transducer's value from the
      // Arduino.
      //printf("MainTask: getting transducer value via I2C.\n");
      i2cResult = adi_I2C_MasterReceive(i2cDevice, I2C_PUMP_SLAVE_ADDRESS, 0x0,
                                        ADI_I2C_8_BIT_DATA_ADDRESS_WIDTH,
                                        i2c_rx, 3, false);
      if (i2cResult != ADI_I2C_SUCCESS) {
        FAIL("adi_I2C_MasterReceive: get pressure from Arduino");
      }

      // Get the analog pressure value from the Arduino.
      if (i2c_rx[0] == ARDUINO_PRESSURE_AVAILABLE
          || i2c_rx[0] == ARDUINO_STILL_INFLATING) {
        pressure_analog = i2c_rx[1] | (i2c_rx[2] << 8);
      } else {
        FAIL("Corrupted or unexpected data from Arduino.");
      }
      
      // Convert the analog value to mmHg.
      pressure = transducer_to_mmhg(pressure_analog);
      //printf("MainTask: got pressure value: %d mmHg.\n", pressure);
      
      // If the pressure is below the threshold, we're done; break the loop.
      if (inflated && pressure < LOWEST_PRESSURE_THRESHOLD_MMHG) {
        PRINT("END\r\n");
        printf("END\r\n");
        inflated = false;
        break;
      } else if (pressure > LOWEST_PRESSURE_THRESHOLD_MMHG * 1.1) {
        inflated = true;
      }

      // Convert DFT results to 1.15 and 1.31 formats.
      dft_results[0] = q_result.parts.magnitude;
      dft_results[1] = q_result.parts.phase;
      convert_dft_results(dft_results, dft_results_q15, dft_results_q31);

      // Compute the magnitude using CMSIS.
      arm_cmplx_mag_q31(dft_results_q31, magnitude, DFT_RESULTS_COUNT / 2);

      // Calculate final magnitude values, calibrated with RCAL.
      fixed32_t magnituderesult;
      magnituderesult = calculate_magnitude(magnitudecal, magnitude[0]);
      q15_t phaseresult;
      phaseresult = arctan(dft_results[1], dft_results[0]);
      fixed32_t phasecalibrated;

      // Calibrate with phase from rcal.
      phasecalibrated = calculate_phase(phasecal, phaseresult);
      
      // TODO: dispatch to another thread?
      //printf("MainTask: sending data via UART.\n");;
      print_PressureMagnitudePhase("", pressure, magnituderesult, phasecalibrated,
                                   q_size);
      nummeasurements++;
    }

    
    // We're done measuring, for now. Disable the DFT interrupts.
    printf("MainTask: disabling DFT interrupts.\n");
    if (ADI_AFE_SUCCESS !=
        adi_AFE_EnableInterruptSource(
            hDevice, ADI_AFE_INT_GROUP_CAPTURE,
            BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN, false)) {
      FAIL("adi_AFE_EnableInterruptSource (false)");
    }
    
    // Tell the pump task to deflate the cuff.
    printf("MainTask: resuming pump task to deflate the cuff.\n");
    err = OSTaskResume(TASK_PUMP_PRIO);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskResume: MainTask (2)");
    }

    // Suspend until the pump finishes deflating. We can then go back to
    // listening for the user input.
    printf("MainTask: suspending to wait for pump task.\n");
    err = OSTaskSuspend(OS_PRIO_SELF);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskSuspend: MainTask (3)");
    }

    // Tell the UX that we're done for now.
    UX_Disengage();
  }
}
Exemplo n.º 24
0
void protocol_task(void *p_arg)
{
	OS_ERR err;
	static uint8_t Date_Handle_Flag = 0;
	uint8_t temp = 0;
	p_arg = p_arg;
	while(1)
	{
		
		OSTaskSemPend(0,OS_OPT_PEND_BLOCKING,0,&err);	
		if( !Date_Handle_Flag)  //Uart3_Recv_STA &&
		{
			Date_Handle_Flag = 1;
			//Uart3_Recv_STA = 0;
		}
		if(Date_Handle_Flag)
		{
			temp = Hekr_RecvData_Handle(Uart3_Recv_Buffer);
			if(Valid_Data_Update == temp)
			{
				//接收的数据保存在 Valid_Data 数组里
				//User Code
				if(Valid_Data[0] == 0x01)
				{
					LED0 = 1;
					OSTaskSuspend((OS_TCB*)&Led0TaskTCB,&err);
					printf("挂起LED任务\n\r");	
				}
				else
				{
					LED0 = 0;
					OSTaskResume((OS_TCB*)&Led0TaskTCB,&err);
					printf("恢复LED任务\n\r");	
				}
				if(Valid_Data[1] == 0x01)
				{
					OSTaskDel((OS_TCB*)&FloatTaskTCB,&err);
					printf("删除float任务\n\r");	
				}
				else
				{
										//创建浮点测试任务
						OSTaskCreate((OS_TCB 	* )&FloatTaskTCB,		
									 (CPU_CHAR	* )"float test task", 		
													 (OS_TASK_PTR )float_task, 			
													 (void		* )0,					
													 (OS_PRIO	  )FLOAT_TASK_PRIO,     	
													 (CPU_STK   * )&FLOAT_TASK_STK[0],	
													 (CPU_STK_SIZE)FLOAT_STK_SIZE/10,	
													 (CPU_STK_SIZE)FLOAT_STK_SIZE,		
													 (OS_MSG_QTY  )0,					
													 (OS_TICK	  )0,					
													 (void   	* )0,				
													 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, 
													 (OS_ERR 	* )&err);		
				}
			}
			if(Hekr_Module_State_Update == temp)
			{
				//接收的数据保存在 Module_Status 数组里
				//User Code
			}
			Date_Handle_Flag = 0;		
		}
		OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_HMSM_STRICT,&err); //延时10ms
	}
}
Exemplo n.º 25
0
void  OSStatTaskCPUUsageInit (OS_ERR  *p_err)
{
    OS_ERR   err;
    OS_TICK  dly;
    CPU_SR_ALLOC();



#ifdef OS_SAFETY_CRITICAL
    if (p_err == (OS_ERR *)0) {
        OS_SAFETY_CRITICAL_EXCEPTION();
        return;
    }
#endif

#if (OS_CFG_TMR_EN > 0u)
    OSTaskSuspend(&OSTmrTaskTCB, &err);
    if (err != OS_ERR_NONE) {
       *p_err = err;
        return;
    }
#endif

    OSTimeDly((OS_TICK )2,                                  /* Synchronize with clock tick                            */
              (OS_OPT  )OS_OPT_TIME_DLY,
              (OS_ERR *)&err);
    if (err != OS_ERR_NONE) {
       *p_err = err;
        return;
    }
    CPU_CRITICAL_ENTER();
    OSStatTaskCtr = (OS_TICK)0;                             /* Clear idle counter                                     */
    CPU_CRITICAL_EXIT();

    dly = (OS_TICK)0;
    if (OSCfg_TickRate_Hz > OSCfg_StatTaskRate_Hz) {
        dly = (OS_TICK)(OSCfg_TickRate_Hz / OSCfg_StatTaskRate_Hz);
    }
    if (dly == (OS_TICK)0) {
        dly =  (OS_TICK)(OSCfg_TickRate_Hz / (OS_RATE_HZ)10);
    }

    OSTimeDly(dly,                                          /* Determine MAX. idle counter value                      */
              OS_OPT_TIME_DLY,
              &err);

#if (OS_CFG_TMR_EN > 0u)
    OSTaskResume(&OSTmrTaskTCB, &err);
    if (err != OS_ERR_NONE) {
       *p_err = err;
        return;
    }
#endif

    CPU_CRITICAL_ENTER();
    OSStatTaskTimeMax = (CPU_TS)0;

    OSStatTaskCtrMax  = OSStatTaskCtr;                      /* Store maximum idle counter count                       */
    OSStatTaskRdy     = OS_STATE_RDY;
    CPU_CRITICAL_EXIT();
   *p_err             = OS_ERR_NONE;
}