Beispiel #1
0
/*!
 @brief Program entry point
 */
int main (void) {
	Mode currentMode;
	mainThread_ID = osThreadGetId();
	
	// start threads. Low priority ensures main will finish
	osThreadDef (tM_run, osPriorityBelowNormal, 1, 0);
	tempThread_ID = osThreadCreate( osThread (tM_run), NULL);
	osThreadDef (aM_run, osPriorityBelowNormal, 1, 0);
	accThread_ID = osThreadCreate( osThread (aM_run), NULL);
	
	LED_init();
	buttonInit();
	tM_init();
	aM_init();
	
	// lock both mode semaphores, they are both in "used" mode
	osSemaphoreWait( tempSema, osWaitForever);
	osSemaphoreWait( accSema, osWaitForever);
	

	
	// start in TEMP_MODE
	currentMode = TEMP_MODE;
	osSemaphoreRelease( tempSema);
	
	TIM3_Init(ACC_FREQ);
	
	while(1) {
        //will start and wait for a tap before anything happends
        //it will run the threads though
		osSignalWait(0x1, osWaitForever);
        
        // once we're past here, it means a tap has been detected!
        
		switch( currentMode) {
			case TEMP_MODE:
                // we wait until the semaphore becomes available
				osSemaphoreWait( tempSema, osWaitForever);
				osDelay	(500);
				acc_clearLatch();
				osSemaphoreRelease(accSema);
				currentMode = ACC_MODE;           
			break;
			case ACC_MODE:                
				osSemaphoreWait( accSema, osWaitForever);
				osDelay	(500);
				acc_clearLatch();
				osSemaphoreRelease(tempSema);
				currentMode = TEMP_MODE;
			break;
		}		
	}
}
Beispiel #2
0
static void interruptEnable() {
	EXTI_InitTypeDef   EXTI_InitStructure;
	NVIC_InitTypeDef   NVIC_InitStructure;
	
	uint8_t ctrl;
	
	//enable single click interrupt
	ctrl=0x7;
	LIS302DL_Write( &ctrl,LIS302DL_CTRL_REG3_ADDR, 1);
	
	//initialise the interrupt for values bigger than that threshold on Z threshold
	ctrl=0x04;
	LIS302DL_Write( &ctrl, LIS302DL_CLICK_THSZ_REG_ADDR, 1);
	
	//set the timing
	ctrl=0x01;
	LIS302DL_Write( &ctrl, LIS302DL_CLICK_TIMELIMIT_REG_ADDR, 1);
	
	ctrl = 0x00;
	LIS302DL_Write( &ctrl, LIS302DL_CLICK_LATENCY_REG_ADDR, 1);
	// ctrl = 0x00;
	// LIS302DL_Write( &ctrl, LIS302DL_CLICK_WINDOW_REG_ADDR, 1);	
	
	
	
	/* Enable SYSCFG clock */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	/* Connect PE0 pin to EXTI Line0*/
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource0);

	/* Configure EXTI Line0 */
	EXTI_InitStructure.EXTI_Line = EXTI_Line0;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);
	
	/* Enable and set EXTI Line0 Interrupt to the lowest priority */
	NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	
	acc_clearLatch();
}