Пример #1
0
/*
 ** ===================================================================
 **     Event       :  Control_task (module mqx_tasks)
 **
 **     Component   :  Task1 [MQXLite_task]
 **     Description :
 **         MQX task routine. The routine is generated into mqx_tasks.c
 **         file.
 **     Parameters  :
 **         NAME            - DESCRIPTION
 **         task_init_data  - 
 **     Returns     : Nothing
 ** ===================================================================
 */
void Control_task(uint32_t task_init_data) {
	int counter = 0;

	/* init msg queues */
	if (_lwmsgq_init((pointer) controller_msg_queue, NUM_CTRL_MESSAGES,
			MESSAGE_SIZE_MAX_TYPE_ALIGNED) != MQX_OK) {
		DEBUG("Initialize msgq failed\n");
	}
	if (_lwmsgq_init((pointer) rcom_msg_queue, NUM_RCOM_MESSAGES,
			MESSAGE_SIZE_MAX_TYPE_ALIGNED) != MQX_OK) {
		DEBUG("Initialize msgq failed\n");
	}

	if (_task_create_at(0, REMOTE_COM_TASK, 0, Remote_com_task_stack,
			REMOTE_COM_TASK_STACK_SIZE) == MQX_NULL_TASK_ID ) {
		NOTIFY("Error on creating Remote_com task\n");
	}

#if EN_KERNEL_LOG
	if (_task_create_at(0, KERNEL_LOG_TASK, 0, kernel_log_task_stack,
			KERNEL_LOG_TASK_STACK_SIZE) == MQX_NULL_TASK_ID ) {
		NOTIFY("Error on creating kernel_log task\n");
	}
#endif

	while (1) {
		counter++;

		/* Write your code here ... */
		controller_app((pointer) rcom_msg_queue,
				(pointer) controller_msg_queue);
	}
}
// Main task
void Main_task(uint32_t task_init_data)
{
	// switch the red LED on (line low sets LED on)
	LED_RED_ClrVal(NULL);
	LED_GREEN_SetVal(NULL);
	LED_BLUE_SetVal(NULL);

	// create the sensor sampling event (typically 200Hz)
	_lwevent_create(&(mqxglobals.SamplingEventStruct), LWEVENT_AUTO_CLEAR);
	// create the Kalman filter sensor fusion event (typically 25Hz)
	_lwevent_create(&(mqxglobals.RunKFEventStruct), LWEVENT_AUTO_CLEAR);
	// create the magnetic calibration event (typically once per minute)
	_lwevent_create(&(mqxglobals.MagCalEventStruct), LWEVENT_AUTO_CLEAR);

	// create the sensor read task (controlled by sensor sampling event SamplingEventStruct)	
	_task_create_at(0, RDSENSDATA_TASK, 0, RdSensData_task_stack, RDSENSDATA_TASK_STACK_SIZE);
	// create the sensor fusion task (controlled by sensor fusion event RunKFEventStruct)	
	_task_create_at(0, FUSION_TASK, 0, Fusion_task_stack, FUSION_TASK_STACK_SIZE);
	// create the magnetic calibration task (controlled by MagCalEventStruct)	
	_task_create_at(0, MAGCAL_TASK, 0, MagCal_task_stack, MAGCAL_TASK_STACK_SIZE);
	// and this main task uses about 512 bytes stack for a grand total of 3K task stack space

	// set the sensor sampling frequency (typically 200Hz)
	// this is set to 200Hz by default in PE but we want to set it using value in proj_config.h 
	FTM_SetPeriodTicks(FTM_DeviceData, (uint16) (FTM_INCLK_HZ / SENSORFS));
	
	// initialize globals
	mqxglobals.FTMReload = (uint16)(FTM_INCLK_HZ / SENSORFS);
	mqxglobals.FTMTimestamp = 0;
	globals.iPacketNumber = 0;
	globals.AngularVelocityPacketOn = true;
	globals.DebugPacketOn = true;
	globals.RPCPacketOn = true;
	globals.AltPacketOn = true;
	globals.iMPL3115Found = false;
	globals.MagneticPacketID = 0;

	// initialize the BlueRadios Bluetooth module and other user tasks
	UserStartup();
	
	// initialize the incoming command buffer to all '~' = 0x7E and trigger a callback 
	// when any single command character is received into the UART buffer
	iCommand[0] = iCommand[1] = iCommand[2] = iCommand[3] = '~';
	UART_ReceiveBlock(UART_DeviceData, sUARTInputBuf, 1);

	// destroy this task (main task) now that the three new tasks are created
	_task_destroy(MQX_NULL_TASK_ID);

	return;
}
Пример #3
0
void main_task
(
    uint_32 param
)
{   /* Body */
    _task_id tid;

    printf("main_task: Task create at 0x%08x..0x%08x\n",
           test_task_stack, (uchar_ptr)test_task_stack + TEST_STACK_SIZE);

    tid = _task_create_at(0, TEST_TASK1, TEST_TASK1_PARAM, test_task_stack,
                          TEST_STACK_SIZE);

    if (tid == MQX_NULL_TASK_ID) {
        printf("task create at failed");
        _mqx_fatal_error(MQX_INVALID_TASK_ID);
    } /* Endif */

    if (test_task_val != 1) {
        printf("ERROR: test_task_val != 1\n");
    } else {
        printf("PASSED\n");
    }/* Endif */

    _task_block();

} /* Endbody */
Пример #4
0
/*
 ** ===================================================================
 **     Event       :  Remote_com_task (module mqx_tasks)
 **
 **     Component   :  Task2 [MQXLite_task]
 **     Description :
 **         MQX task routine. The routine is generated into mqx_tasks.c
 **         file.
 **     Parameters  :
 **         NAME            - DESCRIPTION
 **         task_init_data  - 
 **     Returns     : Nothing
 ** ===================================================================
 */
void Remote_com_task(uint32_t task_init_data) {
	int counter = 0;

	DEBUG("initializing...\n");
	RCOM_set_uart(&SIM900_uart);
	RCOM_set_rx_buf(rcom_rx_buffer, RCOM_RX_BUFF_MAX_CHAR);
	RCOM_init(get_systick_period_in_ms());
	sim900_init(&sim900_pins);
	sync_buffer_init(&rcom_to_controller_sync_buffer,
			(uint8_t*) rcom_to_controller_buffer,
			RCOM_TO_CONTROLLER_BUFFER_SIZE);

	DEBUG("routing pin setting\n");
	/* route desired pins into peripherals */
	Pin_Settings_Init();

	/* create RI_process task to processing incoming call and received SMS */
	if (_task_create_at(0, RI_PROCCESS_TASK, 0, RI_proccess_task_stack,
			RI_PROCCESS_TASK_STACK_SIZE) == MQX_NULL_TASK_ID ) {
		NOTIFY("Error on creating RI_process task\n");
	}

	while (1) {
		counter++;

		/* Write your code here ... */
		remote_com_app((pointer) rcom_msg_queue, (pointer) controller_msg_queue,
				&rcom_to_controller_sync_buffer);
	}
}
Пример #5
0
void World_task(uint32_t task_init_data)
{
   _task_id hello_task_id;
   hello_task_id = _task_create_at(0, HELLO_TASK, 0, hello_task_stack, HELLO_TASK_STACK_SIZE);

   if (hello_task_id == MQX_NULL_TASK_ID) {
      printf ("\n Could not create hello_task\n");
   } else {
      printf(" World \n");
   }

   _task_block();
}
Пример #6
0
/*
** ===================================================================
**     Event       :  read_task (module mqx_tasks)
**
**     Component   :  Task2 [MQXLite_task]
**     Description :
**         MQX task routine. The routine is generated into mqx_tasks.c
**         file.
**     Parameters  :
**         NAME            - DESCRIPTION
**         task_init_data  - 
**     Returns     : Nothing
** ===================================================================
*/
void read_task(uint32_t task_init_data)
{
   _task_id  task_id;
   _mqx_uint result;
   _mqx_uint i;

   /* Create the lightweight semaphores */
   result = _lwsem_create(&fifo.READ_SEM, 0);
   if (result != MQX_OK) {
      printf("\nCreating read_sem failed: 0x%X", result);
      _task_block();
   }

   result = _lwsem_create(&fifo.WRITE_SEM, 1);
   if (result != MQX_OK) {
      printf("\nCreating write_sem failed: 0x%X", result);
      _task_block();
   }

   /* Create the write tasks */
   for (i = 0; i < NUM_WRITERS; i++) {
		  void *stack = _lwmem_alloc_system_zero(WRITE_TASK_STACK_SIZE);

      task_id = _task_create_at(0, WRITE_TASK, (uint32_t)('A' + i), stack, WRITE_TASK_STACK_SIZE);
      printf("\nwrite_task created, id 0x%lX", task_id);
   }

   while(TRUE) {
      result = _lwsem_wait(&fifo.READ_SEM);
      if (result != MQX_OK) {
         printf("\n_lwsem_wait failed: 0x%X", result);
         _task_block();
      }
      putchar('\n');
      putchar(fifo.DATA);
      _lwsem_post(&fifo.WRITE_SEM);
   }
}
Пример #7
0
void Init_Task(uint32_t task_init_data)
{
		int tester=0;
	//uint_8 sys=0;
	bool bInitOpen=FALSE;
  bool	bInitStill=FALSE;
	bool bInitVLPS=FALSE;
	MQX_TICK_STRUCT ttt;
	 _mqx_uint       mqx_ret;
	  trace_init();
	 show_version_information();
		//////////////zga add
	//Set LPTMR to timeout about 5 seconds
		Lptmr_Init(1000, LPOCLK);	
		ADC_Init();
		Calibrate_ADC();
		ADC_Init();
		DMA1_Init();
	//////////////zga add
		// clear flag  
		APP_TRACE("start 1\n\r");
	 _task_create_at(0, SHELL_TASK, 0, shell_task_stack, SHELL_TASK_STACK_SIZE);
	 _task_create_at(0, MMA8415_TASK, 0, mma8451_task_stack, MMA8451_TASK_STACK_SIZE);
	
		Lptmr_Start();
	

	
for(;;)
	{
		 mqx_ret = _lwsem_wait(&g_lptmr_int_sem);

	
	//	_time_delay_ticks(10);
		tester++;
//_time_delay_ticks(10);
		//APP_TRACE("tester is: %d\r\n",tester);
		_time_get_elapsed_ticks(&ttt);
          APP_TRACE("high ttt %d, low ttt%d\r\n", ttt.TICKS[1],ttt.TICKS[0]);
		if(Measured)
		{	Measured=0;
			APP_TRACE ("light: %d ,%d \r\n", (uint16_t) MeasuredValues[1],tester);
		}
		if((GetTouchON()==TRUE))
			{
				SetSysStatus(ACTIVE_OPEN);
			}
			// for test 
			SetSysStatus(ACTIVE_OPEN);
		switch (sysStatus)
	{
		case ACTIVE_OPEN:
					bInitStill=FALSE;
					bInitVLPS=FALSE;
					APP_TRACE ("ACTIVE_OPEN\r\n");
					if(bInitOpen==FALSE)
					{
						bInitOpen=TRUE;
						putmma8451running();
						SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_ENABLE);
					}
					
					
			break;

    case ACTIVE_STILL:
					bInitOpen=FALSE;
					bInitVLPS=FALSE;
				APP_TRACE ("ACTIVE_still\r\n");
					if(bInitStill==FALSE)
					{
						bInitStill=TRUE;
						putmma8451detect();
					}
					enter_vlps();
		case 	VLPSMODE:
					bInitOpen=FALSE;
					bInitStill=FALSE;
				APP_TRACE ("vlpsmode\r\n");
					if(bInitVLPS==FALSE)
					{
						bInitVLPS=TRUE;
						putmma8451standby();
					}
					enter_vlps();
    default:
            break;
	}


	} 
	
}