Beispiel #1
0
void task_test_lcd(void)
{
  static char count_mode=0;
  if (!ti_task)
  {
    ti_task = 200;
    if (count_mode++>=10)count_mode=0;
    
    switch(count_mode)
    {
    case 0: vfnLCD_Write_Msg("0000");  break;
    case 1: vfnLCD_Write_Msg("1111");  break;
    case 2: vfnLCD_Write_Msg("2222");  break;
    case 3: vfnLCD_Write_Msg("3333");  break;
    case 4: vfnLCD_Write_Msg("4444");  break;
    case 5: vfnLCD_Write_Msg("5555");  break;
    case 6: vfnLCD_Write_Msg("6666");  break;
    case 7: vfnLCD_Write_Msg("7777");  break;
    case 8: vfnLCD_Write_Msg("8888");  break;
    case 9: vfnLCD_Write_Msg("9999");  break;
    }
  
  } 
  
   if (input_rise(SW1_ON, &sw1_aux1)) 
   {
     next_task(task_test_slider);
     printf("\n\r TSI: slider test ");
   }
  
}
/*
   Calibration status percentage

*/
void CalPercentage (void) {
    int iVarPercentage = 0;
    char buffer[10];
    iVarPercentage = (MagBufferCount*100)/MINEQUATIONS;
    sprintf(buffer,"C%03d",iVarPercentage);
    vfnLCD_Write_Msg(buffer);
}
Beispiel #3
0
/*
 LCD module initialization according to LCDConfig.h
 it is used as default configuration of the LCD 
 */
void vfnLCD_Init(void) {

     // enable IRCLK
     /*Enable IRCLK LCD source and disconnect from FLL by clearing IREFS */
     MCG_C1= 0x02;
     
     SIM_SCGC5 |= SIM_SCGC5_SLCD_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
     
     // Enable IRCLK 
     MCG_C1 |= MCG_C1_IRCLKEN_MASK | MCG_C1_IREFSTEN_MASK;
     MCG_C2 |= !MCG_C2_IRCS_MASK ;  //0 32KHZ internal reference clock; 1= 4MHz irc

     
       
     //vfnLCD_interrupt_init();       
     
     LCD_GCR = 0x0;
     LCD_AR  = 0x0;

 //    lcd_pinmux(0); 
     
/* LCD configurartion according to */     
      LCD_GCR =  (  LCD_GCR_RVEN_MASK*_LCDRVEN  
                   | LCD_GCR_RVTRIM(_LCDRVTRIM)    //0-15
                   | LCD_GCR_CPSEL_MASK*_LCDCPSEL 
                 /*  | LCD_GCR_HREFSEL_MASK*_LCDHREF  */
                    |LCD_GCR_LADJ(_LCDLOADADJUST)     //0-3*/
                 /*  | LCD_GCR_VSUPPLY(_LCDSUPPLY)  //0-3*/
                  /* |!LCD_GCR_LCDIEN_MASK */
                   |!LCD_GCR_FDCIEN_MASK
                   | LCD_GCR_ALTDIV(_LCDALTDIV)  //0-3
               /*    |!LCD_GCR_LCDWAIT_MASK  */
                   |!LCD_GCR_LCDSTP_MASK
                   |!LCD_GCR_LCDEN_MASK 
                   | LCD_GCR_SOURCE_MASK*_LCDCLKSOURCE
                   | LCD_GCR_ALTSOURCE_MASK*_LCDALRCLKSOURCE  
                   | LCD_GCR_LCLK(_LCDLCK)   //0-7
                   | LCD_GCR_DUTY(_LCDDUTY)   //0-7
                 );    
     
      lcd_alternate_mode = LCD_NORMAL_MODE;          //Message will be written to default backplanes  if = 4
     
      vfnLCD_EnablePins();         // Enable LCD pins and **Configure BackPlanes**
      
      LCD_GCR |= LCD_GCR_LCDEN_MASK;
   /*   LCD_GCR |= LCD_GCR_LCDIEN_MASK;    // Enable interrupts */
      
      
   /* Configure LCD Auxiliar Register*/   
      LCD_AR  = LCD_AR_BRATE(_LCDBLINKRATE); // all other flags set as zero
      vfnLCD_Write_Msg("1235");

}
/*
** ===================================================================
**     Nombre       :	LcdCounter_task (void *pvParameters)
**
**     Resumen   	:	Tarea que visualiza un contado de 0-9999
**     					en pantalla LCD
**
**     Entradas 	:	Parametro inicial para la tarea
**
**     Retorna  	:	Ningun dato
** ===================================================================
*/
void LcdCounter_task(void *pvParameters){
	portBASE_TYPE MyParameter = (portBASE_TYPE )(pvParameters);

	MySegLCDPtr = SegLCD1_Init(NULL);  //initialize sLCD according to PEx

	for(;;){
		main_counter++;										// Incrementa contador
	    if(main_counter>9999)main_counter=0;				// control de valor maximo en contador
	    (void) sprintf(sLCDBuffer,"%04i",main_counter);		// Genera cadena de texto con valor de contador
	    vfnLCD_Write_Msg((uint8 *)sLCDBuffer);				// Muestra en LCD
		FRTOS1_vTaskDelay(50 / portTICK_RATE_MS);			// Espera de 50mseg
	}

	vTaskDelete(NULL);	// Borra tarea actual
}//Fin de la Tarea "LcdCounter_task" -------------------------------------
Beispiel #5
0
void task_test_slider(void)
{
     static int touch_slider_last_valid_value=50;
     
     
     if (AbsolutePercentegePosition>0) touch_slider_last_valid_value=AbsolutePercentegePosition;
     t_flash = (touch_slider_last_valid_value*2 + 50);
     sprintf((char *)gu8USB_Buffer,"%4i", touch_slider_last_valid_value);
     
#ifdef FRDM_REVA     
     PORTA_PCR6 = PORT_PCR_MUX(3); //enable as TPM0_CH3
     TPM0_C3V=touch_slider_last_valid_value*10;
#else
     PORTD_PCR5 = PORT_PCR_MUX(4); //enable as TPM0_CH5
     TPM0_C5V=touch_slider_last_valid_value*10; 
#endif
         
     
     
     
     vfnLCD_Write_Msg(gu8USB_Buffer);
     printf("\r tsi %%= %03i  ", AbsolutePercentegePosition);
     
     
     
  if (!ti_task)
   {
     ti_task = t_flash;    
     LED1_TOGGLE;
     LED2_TOGGLE;
   }     
 
    if (input_rise(SW1_ON, &sw1_aux1)) 
   {
#ifdef FRDM_REVA
                 PORTA_PCR6 = PORT_PCR_MUX(1); //PTA6 as GPIO LED3
#else
                 PORTD_PCR5 = PORT_PCR_MUX(1); //PTA6 as GPIO LED3
                 
#endif  
     
     
       next_task(task_ecompass);
       printf("\n\r eCompass,  Magenetomer + accelerometer test ");  
   }
  
}
void ControlLoopCompass(void) 
{
 
  
     //printf("\n");
  
  
 // for (i = 0; i < miterations; i++)
 // {

 // call sensor driver simulation to get accel and mag data in integer counts 	
    fSixDOFMyNEDSensorDrivers(); 

// update the magnetometer measurement buffer integer magnetometer data
    fUpdateMagnetometerBuffer();

// remove hard and soft iron terms from Bp (uT) to get calibrated data Bc (uT) 
    fInvertMagCal();

// NED coordinate system
    feCompassNED(fBcx, fBcy, fBcz, fGpx, fGpy, fGpz);
		
    Conversion();
     if (validmagcal !=0)
    {
     APhi6DOF = median(iPhi6DOF, &arr_medianas[0]);
     AThe6DOF = median(iThe6DOF, &arr_medianas[1]);
     APsi6DOF = median(iPsi6DOF, &arr_medianas[2]);
    //    printf("Yaw =%4d Pitch =%4d Roll =%4d \r", APhi6DOF, AThe6DOF, APsi6DOF);
     APsi6DOF = 359 - APsi6DOF;
     
     sprintf(buffer,"%04d",APsi6DOF);
     vfnLCD_Write_Msg(buffer);   //print when it is calibrated
     ecompass_direction = APsi6DOF;
    }
// try to find an improved calibration if update is enabled 
  else 
    {  
     fCalibrationUpdate();
    }
    loopcounter++;
   
 // } 
  

}
Beispiel #7
0
void task_light_sensor(void)
{ 

   char buffer_char[10];
   if (!ti_task)
   {
     ti_task = 200;    

     printf("\r adc: light_sensor %4i",adc_light_sensor);
     sprintf(buffer_char,"%4d",adc_light_sensor);
     vfnLCD_Write_Msg((uint8 *)buffer_char);   //print when it is calibrated
     
   }  

  if (input_rise(SW1_ON, &sw1_aux1)) 
   {
    next_task(task_test_lcd);
    printf("\n\r sLCD test  ");
   }   
   
}
Beispiel #8
0
static portTASK_FUNCTION(MainTask, pvParameters) {
  unsigned char lcdBuf[sizeof("1234")];
  uint16_t cntr;
  
  (void)pvParameters; /* parameter not used */
  TRACE_Init();
  MMA1_Init(); /* enable accelerometer, if not already enabled */
  MAG1_Enable(); /* enable magnetometer */
  SHELL_Init();
  cntr = 0;
  for(;;) {
    UTIL1_Num16uToStrFormatted(lcdBuf, sizeof(lcdBuf), cntr, '0', 4);
    vfnLCD_Write_Msg(lcdBuf);
    cntr++;
    if (cntr>9999) { /* can only display 4 digits */
      cntr = 0;
    }
#if APP_USE_KEY_COMPONENT
    KEY1_ScanKeys(); /* using component in polling mode: poll keys, this will create events as needed. */
    EVNT1_HandleEvent();
#else
    if (SW1_GetVal()==0) { /* button pressed */
      FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* wait to debounce */
      while (SW1_GetVal()==0) { /* still pressed? */
        LED1_On();
      }
    }
    if (SW3_GetVal()==0) { /* button pressed */
      FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* wait to debounce */
      while (SW3_GetVal()==0) { /* still pressed? */
        LED2_On();
      }
    }
#endif
    LED1_Neg();
    FRTOS1_vTaskDelay(50/portTICK_RATE_MS);
  }
}
Beispiel #9
0
void APP_Run(void) {
  MySegLCDPtr = SegLCD1_Init(NULL);  //initialize sLCD according to PEx 
  
  vfnLCD_Write_Msg((uint8 *)"8888");
  _LCD_DP1_ON(); /* dot for first digit */
  _LCD_DP2_ON(); /* dot for second digit */
  _LCD_DP3_ON(); /* dot for third digit */
  _LCD_COL_ON(); /* : between digit two and three */

  if (FRTOS1_xTaskCreate(
        MainTask,  /* pointer to the task */
        (signed char *)"Main", /* task name for kernel awareness debugging */
        configMINIMAL_STACK_SIZE, /* task stack size */
        (void*)NULL, /* optional task startup argument */
        tskIDLE_PRIORITY,  /* initial priority */
        (xTaskHandle*)NULL /* optional task handle to create */
      ) != pdPASS) {
    /*lint -e527 */
    for(;;){}; /* error! probably out of memory */
    /*lint +e527 */
  }
  FRTOS1_vTaskStartScheduler();
}
Beispiel #10
0
int main (void)
{
    	char ch,aux1 ,aux2;
      
     
            int UsbDetected = FALSE;
#ifdef CMSIS  // If we are conforming to CMSIS, we need to call start here
    start();
#endif
         vfnMcuConfig();
         
    
  	printf("\n\rRunning the FRDMKL46_Demo project.\n\r");
        vfnLCD_Init();
        gpio_init();
        Pit_init();
        TSI_Init();
        usb_init();
        next_task(vfn_led_test);
        accel_init();
        mag_init();
        eCompassInit();
        adc_init();        
        tpm_init();  //Green LED 50%SIM_SCGC5_PORTC_MASK
        

        
        
// character test        
        vfnLCD_Write_Msg("8888");
        _LCD_DP1_ON();
        _LCD_DP2_ON();
        _LCD_DP3_ON();
        _LCD_COL_ON();
         
 	while(1)
	{
        
#ifdef FRDM_REVA  
          if (uart_getchar_present(UART1_BASE_PTR))
#else
            
          if (uart0_getchar_present(UART0_BASE_PTR))
#endif
            
          {
            ch = in_char();
            printf("\n\r Received char = %c \n\r",ch);            
           if (ch==' ')
           {     
           printf("\n\r light_sensor  = %i",adc_light_sensor);
         //  printf("\n\r Yaw =%4d Pitch =%4d Roll =%4d \r", APhi6DOF, AThe6DOF, APsi6DOF);
           printf("\n\r Yaw =%4d Pitch =%4d Roll =%4d \r", APsi6DOF, APhi6DOF, AThe6DOF);
           
           printf("\n\r tsi %%= %03i  ", AbsolutePercentegePosition);
           }
         }
          
           if (input_rise(SW1_ON, &aux1))
            {  
              printf("\n\r SW1 \n\r");
            }
          
         
            if (input_rise(SW2_ON, &aux2))
            {  
              printf("\n\r SW2 \n\r ");
            }
          
             ptr_next_task();  // do the actual function
             TSI_SliderRead();
             usb_service();
            if (gu8USB_State == uENUMERATED && !UsbDetected) 
            {
              // next_task(vfn_rgb_test);
               UsbDetected = TRUE;
            }        
            
          adc_light_sensor = adc_read(3);
                
                    
              
                
        }
}
Beispiel #11
0
void task_hello(void)
 {
   vfnLCD_Write_Msg("-HI-");
 }
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */


	  
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  LED_GREEN_NegVal();
  LED_RED_NegVal();
  LED_YELLOW_NegVal();
  LED_ORANGE_NegVal();
  
  MySegLCDPtr = SegLCD1_Init(NULL);  //initialize sLCD according to PEx 
  vfnLCD_Write_Msg("1234");
  
  /*Turn on all special symbols*/
  _FREESCALE_ON();   
  _ONE_ON();         
  _COL_ON();         
  _GRADE_ON();       
  _PERCENTAGE_ON();  
  _AM_ON();          
  _PM_ON();          
         
   for (main_counter=1000000 ; main_counter>0 ;main_counter--){}; //delay to show all symbol ON
  
   /*Turn off all special symbols*/
  _FREESCALE_OFF();   
  _ONE_OFF();         
  _COL_OFF();         
  _GRADE_OFF();       
  _PERCENTAGE_OFF();  
  _AM_OFF();          
  _PM_OFF();          
   	
#ifdef CW
  // If we are using CodeWarrior, we must call this function to change
  // the buffer behavior such that a new line character, "\n", is not 
  // required to print characters to the terminal.  
  setvbuf(stdout, NULL, _IONBF, 0);
#endif
  
  printf("\n\r KL46 sLCD test \n");
  printf("\n\r press a=all symbols on, 0=all symbols Off,  1 to 6 symbols");
  _FREESCALE_ON();   
  for(;;) 
   {
	  /*echoes all received character to terminal */
	  InpData[0] = getchar();
      printf("%c",InpData[0]);
      main_counter++;
      sprintf(sLCDBuffer,"%04i",main_counter%1000);
      vfnLCD_Write_Msg(sLCDBuffer);
      
      LED_GREEN_NegVal();
      LED_RED_NegVal();
      LED_YELLOW_NegVal();
      LED_ORANGE_NegVal();
      
      switch ( InpData[0])
      {
      case 'a': 
    	  _FREESCALE_ON();   
    	  _ONE_ON();         
    	  _COL_ON();         
    	  _GRADE_ON();       
    	  _PERCENTAGE_ON();  
    	  _AM_ON();          
    	  _PM_ON();  
      break;	  

      case '0': 
    	  _FREESCALE_OFF();   
    	  _ONE_OFF();         
    	  _COL_OFF();         
    	  _GRADE_OFF();       
    	  _PERCENTAGE_OFF();  
    	  _AM_OFF();          
    	  _PM_OFF();   
      break;	  
      
      case '1':
    	 _FREESCALE_ON();
    	 break;

      case '2':
    	  _COL_ON();         
    	 break;

      case '3':
    	 _GRADE_ON();       
    	 break;

      case '4':
    	 _PERCENTAGE_ON();
    	 break;

      case '5':
    	 _AM_ON();    
    	 break;
    	 
      case '6':
    	 _PM_ON();    
      break;
      

      default:
    	  _FREESCALE_ON();   
    	  _ONE_OFF();         
    	  _COL_OFF();         
    	  _GRADE_OFF();       
    	  _PERCENTAGE_OFF();  
    	  _AM_OFF();          
    	  _PM_OFF();
      }
   }
  
  
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
int main (void)
{
    	char ch;
        char low_power_mode = MODE_SELECT;
        
         
        SMC_PMPROT = SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_AVLP_MASK ;  
        
#ifdef CMSIS  // If we are conforming to CMSIS, we need to call start here
    start();
#endif
        print_llwu_status();
        gpio_init();
               
        rtc_init();  // driven by 32kHz external oscillator //

        vfnLCD_Init();
        vfnLCD_Write_Msg("1234");      
             
        
    
        PORTC_PCR3 = PORT_PCR_MUX(1) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
        enable_irq(INT_LLW-16);
        llwu_configure(0x0080,0x02,LLWU_ME_WUME5_MASK); //M5= RTC Alarm,  M7 RTC seconds
        
        
   //check if it comes from VLLx mode
        if (PMC_REGSC % PMC_REGSC_ACKISO_MASK)
        {
          if (last_gpio_status&0x01) LED1_ON; else LED1_OFF;  //configure GPIO pin with latest state
          PMC_REGSC |= PMC_REGSC_ACKISO_MASK; //write to release hold on I/O
          last_gpio_status ^= 0x01;  //update state for next work
        }

        
  	printf("\n\rRunning the lcd_rtc_lowpower project.\n\r");
        
        // wait 3 seconds before start entering in low power mode
        while  (rtc_seconds_isrv_count<3){};
        

	while(1)
	{
           LED2_TOGGLE;
           
           ch=  (char)RTC_TSR;
	   sprintf(gu8USB_Buffer,"%4i",ch );
           vfnLCD_Write_Msg(gu8USB_Buffer);	
           printf("\n\r llwu_isrv_counter = %i, rtc_isrv_counter=%i ",llwu_isrv_counter, rtc_isrv_counter );
           printf("                       "); //delay 
          
        
           switch (low_power_mode)
           { 
             case MODE_WAIT:
             enter_wait();
             printf("\n\r exit from WAIT"); 
             break;
             
           case MODE_STOP:
           /* 0x00 = STOP - Normal Stop Mode
              0x40 = PSTOP1 - Partial Stop with both system and bus clocks disabled
              0x80 = PSTOP2 - Partial Stop with system clock disabled and bus clock enabled
           */
             enter_stop(0x00);

             printf("\n\r exit from STOP"); 
           break;
             
           case MODE_LLS:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;  //Disable Clock Monitor before entering in low power mode LLS, VLSSx
            enter_lls();
            op_mode = what_mcg_mode();
            if(op_mode==PBE)
            {
              mcg_clk_hz = pbe_pee(CLK0_FREQ_HZ);
              MCG_C6 |= MCG_C6_CME0_MASK;
            }
            printf("\n\r exit from LLS");  
            break;
            
            case MODE_VLLS3:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls3();
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set
            break;
            
          // VLLS2 mode not supported on KL46       
            
            case MODE_VLLS1:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls1();  //In VLLS1 and VLLS0 no SRAM is retained.
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set            
            break;            
            
           default:
           }          
	} 
}