Esempio n. 1
0
void Disp_Client_Data()
{
  unsigned char buf;

  while(1)
  {
    while(!WIFI_ReceiveByte(&buf)){};

      if(buf == 'X')
      {
        break;
      }
			if(buf== 'Y' || buf=='y')
			{
					Control_RGB_LEDs(1,1,0);
			    break;
			}
			if(buf== 'P' || buf=='p')
			{
					Control_RGB_LEDs(1,0,1);
					break;
			}
			if(buf== 'W' || buf=='w')
			{
					Control_RGB_LEDs(1,1,1);
					break;
			}
	}
}
Esempio n. 2
0
void WIFI_idle()
{
	Control_RGB_LEDs(1,0,0);
	Delay(90);
		if(!Disable_AutoConnect())
			{
				Control_RGB_LEDs(1,0,0);
      }
		PTC->PSOR = MASK(12);
		if(!DeepSleep())         // Enter DeepSleep
      {
				Control_RGB_LEDs(1,0,0);
      }
}
Esempio n. 3
0
void WIFI_wake()
{
		PTC->PSOR = MASK(12);
	  Delay(90);
		PTC->PCOR  = MASK(12);
		while(!((PTB->PDIR & (0x800))));
		while (!(Echo_Confirm()));   // Confirm a OK response to AT
	  while (!(Echo_Confirm())); 
	  Control_RGB_LEDs(0,1,0);
	if(!Auto_Renable())         // Start Auto Connect
      {
				Control_RGB_LEDs(1,0,0);
      }
		Control_RGB_LEDs(1,0,1);	
}
Esempio n. 4
0
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
	//initiliaze RGB LED
	Init_RGB_LEDs();

if (init_mma() == 0)
{ 
  Control_RGB_LEDs(1,0,0);
  while (1); //stay in the infinite loop to indicate the error with the RED LED
}	
	
//Add Delay (1000); here	
	Delay(1000);
	
	while (1) {
		//Read the data on x, y, and z axis; // Use function call to read the axes data
		//Convert x, y, and z axis to roll and pitch as described in the class 
		// use function call to convert the data
		
		// Light green LED if pitch > 10 ; pick a pitch angle between 10 and 15 degrees
		// Light blue LED if roll > 10 ; pick a roll angle between 10 to 15 degrees
		
		// use LED function call "Control_RGB_LEDs" from previous labs and display  
		// roll and pitch angles using the tri-color LED; you may
		//ignore the yaw angle; for details, see lab manual for roll, pitch, and yaw
		//definitions
		
	}
}
void TPM0_IRQHandler() {
	float v_rail;
	static uint8_t n=0;
	static uint8_t n_clk=2;
	static uint8_t divider = 1;
	
	//clear pending IRQ
	NVIC_ClearPendingIRQ(TPM0_IRQn);
	
	TPM0->SC |= TPM_SC_TOF_MASK; 

	// Do ISR work
	if (n) {
		v_rail = Measure_VRef();
		Light_LEDs(v_rail);
	} else {
		Control_RGB_LEDs(0,0,0);
	}
	n = 1-n;
#if 1		
	if (--n_clk == 0) {
		// change clock frequency
		n_clk = 2;
		SIM->CLKDIV1 = (SIM->CLKDIV1 & ~SIM_CLKDIV1_OUTDIV1_MASK) | 
				SIM_CLKDIV1_OUTDIV1(divider);
		if (++divider == 16) {
			divider = 1;
		}
	}
#endif 
}
void DMA0_IRQHandler(void) {
	// Light green LED in DMA IRQ handler
	Control_RGB_LEDs(0,1,0);
	NVIC_ClearPendingIRQ(DMA0_IRQn);
	// Clear done flag 
	DMA0->DMA[0].DSR_BCR |= DMA_DSR_BCR_DONE_MASK; 

#if 1 // under development for continuous playback
	// Signal event requesting source buffer refill
	isr_evt_set(EV_REFILL_SOUND, t_Refill_Sound_Buffer);
	// Start playback again
	Start_DMA_Playback();
#else
	// Disable DMA
	DMAMUX0->CHCFG[0] &= ~DMAMUX_CHCFG_ENBL_MASK;
#endif 
	
	Control_RGB_LEDs(0,0,0);
}
void LPTimer_IRQHandler(void) {
	float v_rail;
	static uint8_t n=LED_PERIOD;

	PTE->PSOR |= MASK(DEBUG_RUNNING_POS);
	NVIC_ClearPendingIRQ(LPTimer_IRQn);
	LPTMR0->CSR |= LPTMR_CSR_TCF_MASK;

	if (n==0) {
		v_rail = Measure_VRef();
		Light_LEDs(v_rail);
		n = LED_PERIOD;
	} else {
		Control_RGB_LEDs(0,0,0);
	}
	n--;
}
void PIT_IRQHandler() {
	float v_rail;
	static uint8_t n=0;
	static uint8_t n_clk=2;
	static uint8_t divider = 1;
	
	//clear pending IRQ
	NVIC_ClearPendingIRQ(PIT_IRQn);
	// check to see which channel triggered interrupt 
	if (PIT->CHANNEL[0].TFLG & PIT_TFLG_TIF_MASK) {
		// clear status flag for timer channel 0
		PIT->CHANNEL[0].TFLG &= PIT_TFLG_TIF_MASK;
		
		// Do ISR work
		if (n) {
			v_rail = Measure_VRef();
			Light_LEDs(v_rail);
		} else {
			Control_RGB_LEDs(0,0,0);
		}
		n = 1-n;

#if 1		
		if (--n_clk == 0) {
			// change clock frequency
			n_clk = 2;
			SIM->CLKDIV1 = (SIM->CLKDIV1 & ~SIM_CLKDIV1_OUTDIV1_MASK) | 
					SIM_CLKDIV1_OUTDIV1(divider);
			if (++divider == 16) {
				divider = 1;
			}
		}
#endif 
/*
		if (v_rail < 1.8) {
			Control_RGB_LEDs(1, 0, 0);
		}		
*/
	} else if (PIT->CHANNEL[1].TFLG & PIT_TFLG_TIF_MASK) {
		// clear status flag for timer channel 1
		PIT->CHANNEL[1].TFLG &= PIT_TFLG_TIF_MASK;
	} 
}
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {

	Init_Debug_Signals();
	Init_RGB_LEDs();
	Sound_Init();	
	// Sound_Disable_Amp();
	Play_Tone();
	
	TFT_Init();
	TFT_Text_Init(1);
	TFT_Erase();
	TFT_Text_PrintStr_RC(0,0, "Test Code");

/*
	Graphics_Test();
	while (1) 
		;
*/
	
//	TFT_TS_Calibrate();
//	TFT_TS_Test();

	TFT_Text_PrintStr_RC(1,0, "Accel...");

	i2c_init();											// init I2C peripheral
	if (!init_mma()) {							// init accelerometer
		Control_RGB_LEDs(1,0,0);			// accel initialization failed, so turn on red error light
		while (1)
			;
	}
	TFT_Text_PrintStr_RC(1,9, "Done");

	Play_Waveform_with_DMA();

	Delay(70);

	os_sys_init(&Task_Init);

	while (1)
		;
}
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
	#if USE_VLPR == 1
		// enter low power run
		SIM->CLKDIV1 = (0x1 << SIM_CLKDIV1_OUTDIV1_SHIFT) | (0x5 << SIM_CLKDIV1_OUTDIV4_SHIFT);		// reduce core clock < 4 MHz and flash < 1 MHz
		MCG->C6 &= ~MCG_C6_CME0_MASK;			// disable MCG clock monitor
		MCG->C2 |= MCG_C2_IRCS_MASK;			// don't use slow internal reference clock
		MCG->C1 |= MCG_C1_CLKS(2);				// enter BLPE mode
		MCG->C1 &= ~MCG_C1_IREFS_MASK;
		MCG->C6 &= ~MCG_C6_PLLS_MASK;
		while(!(MCG->S & MCG_S_IREFST_MASK >> MCG_S_IREFST_SHIFT));		// wait to ensure clock change
		MCG->C2 |= MCG_C2_LP_MASK;
	#endif
	
	Init_RGB_LEDs();
	
	#if DEBUG_SIGNALS == 1
		Init_Debug_Signals();
	#endif
	
	// I2C and MMA
	i2c_init();																/* init i2c	*/
	if (!init_mma()) {												/* init mma peripheral */
		Control_RGB_LEDs(1, 0, 0);							/* Light red error LED */
		while (1)																/* not able to initialize mma */
			;
	}
	
	#if RUN_I2C_FAST == 1
		// increase i2c baud rate
		I2C_DISABLE;
		I2C0->F = (I2C_F_ICR(0x00) | I2C_F_MULT(0));
		I2C_ENABLE;
	#endif
	
	// configure low power modes
	SMC->PMPROT = SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK;				// allow low leakage stop mode
	SMC->PMCTRL = SMC_PMCTRL_RUNM(2) | SMC_PMCTRL_STOPM(3);	// enable low power run mode (10) and low leakage stop mode (011)
	SMC->STOPCTRL = SMC_STOPCTRL_PSTOPO(0) | SMC_STOPCTRL_VLLSM(3);	// normal stop mode and VLL stop3 (not needed?)
	
	// configure low leakage wakeup unit (LLWU)
	LLWU->ME |= LLWU_ME_WUME0_MASK;						// internal module 0 is wakeup source which is apparently the LPTMR
	
	// enable stop mode (deep sleep)
	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
	
	// LPTMR
	Init_LPTMR();
	Start_LPTMR();

	__enable_irq();
	
	while (1) {				
		// read acceleration every 100 ms
		if (run_Read_Accel){
			run_Read_Accel = 0;
			Read_Accel();
		}
		
		// update LEDs every 500 ms; keep them on for 10 ms
		if (run_Update_LEDs){
			run_Update_LEDs = 0;
			Update_LEDs();
			
			#if USE_PWM == 1
				#if PWM_SLEEP == 1
					SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;		// switch to regular sleep mode
					#if USE_SLEEP_MODES == 1
						#if DEBUG_SIGNALS == 1
							PTE->PSOR |= MASK(30);
						#endif
						__wfi();															// PWM does not work in LLS mode
					#endif
					SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;		// switch back to LLS mode
				#else
					while(led_on_period);									// poll -> bad solution
				#endif
			#endif
		}
				
		#if USE_SLEEP_MODES == 1
			#if DEBUG_SIGNALS == 1
					PTE->PSOR |= MASK(30);
			#endif
			__wfi();			// go to sleep
		#endif
	}
}
Esempio n. 11
0
void Auto_Setup(uint8_t type)
{
	int i=0; 
	Control_RGB_LEDs(0,0,1);
  switch(type)
  {
    case 0:
			Disable_AutoConnect();
      Echo_Disable();             // Disable Echo for each command ( easier to parse)
     while (!(Echo_Confirm()));   // Send AT command till response OK 
     if(!Disassociate())          // Disassociate if currently associated to any network
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
      if(!DHCP_Enable())         // Enable Dynamic IP (or Dynamic Host Configuration Protocol)
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
			/*if(!Set_Password())         // Enable Connection to WPA AP 
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }*/
      if(!Auto_Wifi())           // Configure Auto Connect Wifi settings
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
      if(!Auto_Network())       // Configure Auto Connect Network Settings 
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
      if(!Auto_Enable())        // Enable Auto Connect Profile
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
      if(!Auto_Start())         // Start Auto Connect
      {
				Control_RGB_LEDs(1,0,0);
        break;
      }
			Control_RGB_LEDs(1,0,1); // On Purple LED connect with client
      break;
    default:
      break;
  }
// Auto connection done 
// Now Actual Application  
  Data_handle(CLIENT);    //wait For Client Connection Details
	Control_RGB_LEDs(0,1,0);
	Delay(9000);
	while(i<10)
	{
	WIFI_SendString(outbuf);
	Delay(90);
  Disp_Client_Data();
	WIFI_idle();
	Delay(9000);
	WIFI_wake();
	i++;
	}
	
}