/* ===================================================================*/
LDD_TError SystemTimer1_ResetCounter(LDD_TDeviceData *DeviceDataPtr)
{
  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  /* {MQXLite RTOS Adapter} Critical section begin (RTOS function call is defined by MQXLite RTOS Adapter property) */
  _int_disable();
  if ((SysTick_PDD_GetEnableDeviceStatus(SysTick_BASE_PTR)) != 0U) {
    SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_DISABLE);
    SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_ENABLE);
  }
  /* {MQXLite RTOS Adapter} Critical section ends (RTOS function call is defined by MQXLite RTOS Adapter property) */
  _int_enable();
  return ERR_OK;                       /* OK */
}
Example #2
0
void enter_vlps(void)
{
  volatile unsigned int dummyread;
	 SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_DISABLE);
  /* The PMPROT register may have already been written by init code
     If so then this next write is not done since  
     PMPROT is write once after RESET 
     allows the MCU to enter the VLPR, VLPW, and VLPS modes.
     If AVLP is already writen to 0 
     Stop is entered instead of VLPS*/
  SMC_PMPROT = SMC_PMPROT_AVLP_MASK;           
  /* Set the STOPM field to 0b010 for VLPS mode */
  SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK; 
  SMC_PMCTRL |=  SMC_PMCTRL_STOPM(0x2); 
  /*wait for write to complete to SMC before stopping core */  
  dummyread = SMC_PMCTRL;
  dummyread++;
	
  SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
  __wfi();
  /* Now execute the stop instruction to go into VLPS */
//  #ifdef CMSIS
//  /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
//  SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
//  __wfi();
//#else
//  stop();
//#endif
}
/* ===================================================================*/
void SystemTimer1_Deinit(LDD_TDeviceData *DeviceDataPtr)
{
  SystemTimer1_TDeviceData *DeviceDataPrv = (SystemTimer1_TDeviceData *)DeviceDataPtr;

  (void)DeviceDataPrv;
  SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_DISABLE);
  /* Interrupt vector(s) deallocation */
  /* {MQXLite RTOS Adapter} Restore interrupt vector (function handler and ISR parameter) */
  /* Note: Exception handler for interrupt is not restored, because it was not modified */
  (void)_int_install_isr(LDD_ivIndex_INT_SysTick, ((SystemTimer1_TDeviceDataPtr)DeviceDataPrv)->SavedISRSettings_TUInterrupt.isrFunction, ((SystemTimer1_TDeviceDataPtr)DeviceDataPrv)->SavedISRSettings_TUInterrupt.isrData);
  /* Unregistration of the device structure */
  PE_LDD_UnregisterDeviceStructure(PE_LDD_COMPONENT_SystemTimer1_ID);
  /* Deallocation of the device structure */
  /* {MQXLite RTOS Adapter} Driver memory deallocation: Dynamic allocation is simulated, no deallocation code is generated */
}
/* ===================================================================*/
LDD_TError SystemTimer1_Disable(LDD_TDeviceData *DeviceDataPtr)
{
  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  SysTick_PDD_EnableDevice(SysTick_BASE_PTR, PDD_DISABLE);
  return ERR_OK;
}
Example #5
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;
	}


	} 
	
}