Ejemplo n.º 1
0
void uifLcdPrintJoystickInfo(void) {
    halLcdPrintLine("L: Mouse left    ", 4, OVERWRITE_TEXT );
    halLcdPrintLine("R: Mouse right   ", 5, OVERWRITE_TEXT );
    halLcdPrintLine("U: Mouse up      ", 6, OVERWRITE_TEXT );
    halLcdPrintLine("D: Mouse down    ", 7, OVERWRITE_TEXT );
    halLcdPrintLine("C: Mouse L-button", 8, OVERWRITE_TEXT );
} // uifLcdPrintJoystickInfo
Ejemplo n.º 2
0
void main(void)
{	

  	WDTCTL = WDTPW+WDTHOLD;       	// Paramos el watchdog timer
  
  	init_botons();					// Iniciamos los botones y Leds.
    _enable_interrupt(); 			// Activamos las interrupciones a nivel global del chip
    init_LCD();						// Inicializamos la pantalla
    init_UCS();						//Inicialitzem UCS
    init_UART();					//Inicialitzem UART
  
  	halLcdPrintLine( saludo,linea,textstyle);
  	linea++;
  	sprintf(cadena,"bID = %d",bID); 
  	halLcdPrintLine( cadena,linea,textstyle);
  	
  	Encendre_LED();
  	TxPacket(0xFE, 2, 0x19);

  	do
   	{
    	P1OUT ^= 0x03; 
    	i = 25000;      
     		do 	{
    		i--;
    		}   	
    	while (i != 0);
   	}

  	while(1);
}
void uifLcdPrintJoystickInfo(void) {
    halLcdPrintLine("L: Skip previous ", 4, OVERWRITE_TEXT );
    halLcdPrintLine("R: Skip next     ", 5, OVERWRITE_TEXT );
    halLcdPrintLine("U: Volume up     ", 6, OVERWRITE_TEXT );
    halLcdPrintLine("D: Volume down   ", 7, OVERWRITE_TEXT );
    halLcdPrintLine("C: Play - Pause  ", 8, OVERWRITE_TEXT );
} // uifLcdPrintJoystickInfo
Ejemplo n.º 4
0
void main()
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer (good dog)

    _disable_interrupt();

    cron.seconds = 0;
    cron.minutes = 0;
    cron.hours = 0;

    alarm.seconds = 30;
    alarm.minutes = 2;
    alarm.hours = 0;

    initialize_leds();
    initialize_lcd();
    initialize_buttons();
    initialize_timer_b();
    initialize_timer_a1();

    _enable_interrupt();

    halLcdPrintLine(lcd_line, 0, OVERWRITE_TEXT);

    write_time_base();
    write_cron();

    while ( 1 );
}
Ejemplo n.º 5
0
void doLCD(void){
    //Initialize LCD and backlight    
    // 138 x 110, 4-level grayscale pixels.
    halLcdInit();       
    // halLcdBackLightInit();  
    // halLcdSetBackLight(0);  // 8 for normal
    halLcdSetContrast(100);
    halLcdClearScreen(); 
    halLcdImage(TI_TINY_BUG, 4, 32, 104, 12 );

    halLcdPrintLine("BTstack on ", 0, 0);
    halLcdPrintLine("TI MSP430", 1, 0);
    halLcdPrintLine("Keyboard", 2, 0);
    halLcdPrintLine("Init...", 3, 0);
    row = 4;
}
Ejemplo n.º 6
0
static void prvSetupHardware( void )
{
	taskDISABLE_INTERRUPTS();
	
	/* Disable the watchdog. */
	WDTCTL = WDTPW + WDTHOLD;
  
	halBoardInit();

	LFXT_Start( XT1DRIVE_0 );
	hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );

	hal430SetSubSystemMasterClock( );

	halButtonsInit( BUTTON_ALL );
	halButtonsInterruptEnable( BUTTON_SELECT );

	/* Initialise the LCD, but note that the backlight is not used as the
	library function uses timer A0 to modulate the backlight, and this file
	defines	vApplicationSetupTimerInterrupt() to also use timer A0 to generate
	the tick interrupt.  If the backlight is required, then change either the
	halLCD library or vApplicationSetupTimerInterrupt() to use a different
	timer.  Timer A1 is used for the run time stats time base6. */
	halLcdInit();
	halLcdSetContrast( 100 );
	halLcdClearScreen();
	
	halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );
}
Ejemplo n.º 7
0
/**********************************************************************//**
 * @brief  Disables the recording peripherals and the microphone.
 * 
 * @param  none
 * 
 * @return none
 *************************************************************************/
static void shutdownRecord(void)
{ 
  halLcdSetBackLight(lcdBackLightLevelSettingLOCAL);
  
  TBCTL &= ~MC0;
  ADC12CTL0 &= ~( ADC12ENC + ADC12ON );
  
  FCTL1 = FWKEY;                            // Disable Flash write
  FCTL3 = FWKEY + LOCK;                     // Lock Flash memory
  
  // Power-down MSP430 modules
  ADC12CTL1 &= ~ADC12CONSEQ_2;              // Stop conversion immediately
  ADC12CTL0 &= ~ADC12ENC;                   // Disable ADC12 conversion
  ADC12CTL0 = 0;                            // Switch off ADC12 & ref voltage
  
  TBCTL = 0;                                // Disable Timer_B
  LED_PORT_OUT &= ~LED_1;                   // Turn off LED  

  AUDIO_PORT_OUT &= ~MIC_POWER_PIN;         // Turn of MIC   
  AUDIO_PORT_SEL &= ~MIC_INPUT_PIN;   

  saveSettings();                           // Store lastAudioByte to Flash

  halLcdPrintLine("    DONE    ",  6, INVERT_TEXT | OVERWRITE_TEXT);  
  halLcdPrintLineCol("Record",  8, 1,  OVERWRITE_TEXT);
  halLcdPrintLineCol("Play",  8, 12,  OVERWRITE_TEXT);
  buttonsPressed = 0;

  halButtonsInterruptEnable( BUTTON_S1);
}
Ejemplo n.º 8
0
static void prvSetupHardware( void )
{
    /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle()
    function. */
    unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL );

    halBoardInit();

    LFXT_Start( XT1DRIVE_0 );
    Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 );

    halButtonsInit( BUTTON_ALL );
    halButtonsInterruptEnable( BUTTON_SELECT );

    /* Initialise the LCD, but note that the backlight is not used as the
    library function uses timer A0 to modulate the backlight, and this file
    defines	vApplicationSetupTimerInterrupt() to also use timer A0 to generate
    the tick interrupt.  If the backlight is required, then change either the
    halLCD library or vApplicationSetupTimerInterrupt() to use a different
    timer.  Timer A1 is used for the run time stats time base6. */
    halLcdInit();
    halLcdSetContrast( 100 );
    halLcdClearScreen();

    halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );
}
Ejemplo n.º 9
0
/**********************************************************************//**
 * @brief  Plays back the audio data stored in Flash memory using 
 *         the integrated DMA controller and the DAC12 module.
 * 
 * @param  mode The mode of audio record 
 * 
 * - AUDIO_TEST_MODE ...for production test
 * - AUDIO_DEMO_MODE ...called for user sample code
 * 
 * @return none
 *************************************************************************/
void audioPlayBack(unsigned char mode)
{  
  // Power-up external hardware
  AUDIO_PORT_DIR |= AUDIO_OUT_PWR_PIN;
  AUDIO_PORT_OUT &= ~AUDIO_OUT_PWR_PIN;
  AUDIO_OUT_SEL |= AUDIO_OUT_PIN;           // P4.4 = TB4  
  LED_PORT_OUT |= LED_1;                    // Turn on LED  

  if (mode == AUDIO_TEST_MODE)
    PlaybackPtr = (unsigned long)(MemstartTest);
  else
    PlaybackPtr = (unsigned long)(Memstart);
 
  PlaybackPtr ++;
  
  /* Setup Timer0_A for playback */
  // Use SMCLK as Timer0_A source, enable overflow interrupt
  TBCTL = TBSSEL_2 + TBIE;                  
  // Set output resolution (8 bit. Add 10 counts of headroom for loading TBCCR1  
  TBCCR0 = 255 ;                              
  TBCCR4 = 255 >> 1;                        // Default output ~Vcc/2
  // Reset OUT1 on EQU1, set on EQU0. Load TBCCR1 when TBR counts to 0.
  TBCCTL4 = OUTMOD_7 + CLLD_1;              
  // Start Timer_B in UP mode (counts up to TBCCR0)
  TBCTL |= MC0;                             
  
  halLcdPrintLine("   Playing  ", 6, INVERT_TEXT | OVERWRITE_TEXT);
  halLcdPrintLineCol(" Stop ", 8, 1,  OVERWRITE_TEXT);
  halButtonsInterruptDisable( BUTTON_S2 );
  
  // Activate LPM during DMA playback, wake-up when finished
  __bis_SR_register(LPM0_bits + GIE);       // Enable interrupts, enter LPM0
  __no_operation(); 
  
  halLcdPrintLine("    DONE    ", 6, INVERT_TEXT | OVERWRITE_TEXT); 
  halButtonsInterruptEnable( BUTTON_S2 );
  halLcdPrintLineCol("Record", 8, 1,  OVERWRITE_TEXT);
  halLcdPrintLineCol("Play", 8, 12,  OVERWRITE_TEXT);
  
  // Power-down MSP430 modules
  TBCTL = 0;                                // Disable Timer_B PWM generation  
  AUDIO_OUT_SEL &= ~AUDIO_OUT_PIN;          // P4.4 = TB4
  LED_PORT_OUT &= ~LED_1;                   // Turn off LED
  buttonsPressed = 0;
}
Ejemplo n.º 10
0
/**********************************************************************//**
 * @brief  Global API call to record audio on the mike. 
 * 
 * - Initializes the record using setupRecord()
 * - Erases the memory reserved for audio recording
 * - Records until the memory is full using record()
 * - Shuts down the record using shutdownRecord()
 * 
 * @param  mode The mode of audio record 
 * 
 * - AUDIO_TEST_MODE ...for production test
 * - AUDIO_DEMO_MODE ...called for user sample code
 * 
 * @return none
 *************************************************************************/
void audioRecord(unsigned char mode)
{
  unsigned char i;
    
  setupRecord(); 

  halLcdPrintLine("   Erasing  ", 6, INVERT_TEXT | OVERWRITE_TEXT);  
  halLcdPrintLineCol("----", 8, 12,  OVERWRITE_TEXT);
  
  // Not used in User Experience sample code 
  if (mode == AUDIO_TEST_MODE)
  {
    flashErase(MemstartTest, Memend);
    __data16_write_addr((unsigned short)&DMA0DA, MemstartTest);      
    DMA0SZ = (long) (Memend - MemstartTest);
    
    record();
    
    if (DMA0SZ != ( long) (Memend - MemstartTest))
      lastAudioByte = Memend - DMA0SZ;
    else
      lastAudioByte = Memend;
  }
  // Always used in User Experience sample code 
  else
  {
    flashEraseBank(AUDIO_MEM_START[0]);
    flashEraseBank(AUDIO_MEM_START[1]);
    flashEraseBank(AUDIO_MEM_START[2]);
    flashErase(AUDIO_MEM_START[3], AUDIO_MEM_START[4]);    
    
    for (i=0;i<3;i++)
    {  
      __data16_write_addr((unsigned short)&DMA0DA, AUDIO_MEM_START[i]);               
      DMA0SZ = AUDIO_MEM_START[i+1] - AUDIO_MEM_START[i] - 1;
      
      record();
      
      if (DMA0SZ != AUDIO_MEM_START[i+1] - AUDIO_MEM_START[i] - 1)
      {
        lastAudioByte = AUDIO_MEM_START[i+1] - DMA0SZ;
        break;
      }
      else lastAudioByte = AUDIO_MEM_START[i+1]-1;      
    }
  }
  
  shutdownRecord();
}
Ejemplo n.º 11
0
__interrupt void Port2_ISR(void)
{
	//Inicializamos los leds para que parpadeen en fase (S1) o alternando (S2):
	P2IE &= 0xC0; 	//interrupciones botones S1 y S2 (P2.6 y P2.7) desactivadas
	P2IE &= 0x3E;  //interrupciones joystick (2.1-2.5) desactivadas
	switch (P2IFG) {
	case 0x40: //Boton S1
		    txchar=chartest;
	    	P1OUT |= 0x03; //Leds parpadean a la vez
	    	estado_botones=1;
		break;
	case 0x80: //Boton S2
			txchar=~chartest;
	    	P1OUT |= 0x01; //Leds parpadean en alternancia
	    	estado_botones=2;
		break;
	case 0x02: // joystick left
		    if (bID > 0x00) bID--;
	    	else bID = 0xFE;
		break;
	case 0x04: // joystick right
			if (bID < 0xFE) bID++;
	    	else bID = 0;
		break;
	case 0x08: // joystick center
			P1OUT |= 0x01;P1OUT &= 0xFD;//Leds parpadean alternando
		break;
	case 0x10: // joystick up
			if (bID < 0xF0) bID+=0x0F;
	    	else bID = 0;
		break;
	case 0x20: // joystick down
		    if (bID > 0x0F) bID-=0x0F;
	    	else bID = 0xFE;
		break;

	default: break;
	}
	
	sprintf(cadena,"bID = %d",bID);
	halLcdPrintLine( cadena,linea,OVERWRITE_TEXT );
	
	P2IFG = 0;		//limpiamos todas las interrupciones
	P2IE |= 0xC0; 	//interrupciones botones S1 y S2 (P2.6 y P2.7) reactivadas
	P2IE |= 0x3E;  //interrupciones joystick (2.1-2.5) reactivadas
 return;
}
Ejemplo n.º 12
0
__interrupt void update_cron()
{
    halTimer_a1_disableInterruptCCR0();

    // Update the chronometer
    {
        if ( !stop_cron )
        {
            cron.seconds++;

            if ( cron.seconds == 60 )
            {
                cron.seconds = 0;
                cron.minutes++;
            }

            if ( cron.minutes == 60 )
            {
                cron.minutes = 0;
                cron.hours++;
            }

            if ( cron.hours == 24 )
                cron.hours = 0;

            write_cron();
        }
    }

    // Update alarm! ACHTUNG!
    {
        if ( !disabled_alarm && cron.seconds == alarm.seconds
                && cron.minutes == alarm.minutes && cron.hours == alarm.hours )
        {
            halLcdPrintLine("ALARM ALARM ALARM", LINE_ALARM, OVERWRITE_TEXT);
            disabled_alarm = TRUE;
        }
    }

    halTimer_a1_enableInterruptCCR0();
}
Ejemplo n.º 13
0
/**********************************************************************//**
 * @brief  Executes the record. 
 * 
 * - Unlocks the Flash and initialize to long-word write mode 
 * - Initializes the Timer to trigger ADC12 samples
 * - When the operation is done, locks the flash, disables the DMA, and stops
 *   the timer
 * 
 * @param  none
 * 
 * @return none
 *************************************************************************/
static void record(void)
{  
  halLcdPrintLine("  Recording ", 6, INVERT_TEXT | OVERWRITE_TEXT);
  halLcdPrintLineCol("Stop", 8, 12,  OVERWRITE_TEXT);  

  FCTL3 = FWKEY;                            // Unlock the flash for write
  FCTL1 = FWKEY + BLKWRT;                        
  
  DMA0CTL = DMADSTINCR_3 + DMAEN + DMADSTBYTE +  DMASRCBYTE + DMAIE;
  // Enable Long-Word write, all 32 bits will be written once 
  // 4 bytes are loaded
  
  TBCCTL1 &= ~CCIFG;
  TBCTL |= MC0;                             
  
  __bis_SR_register(LPM0_bits + GIE);       // Enable interrupts, enter LPM0  
  __no_operation(); 
  
  TBCTL &= ~MC0;
  DMA0CTL &= ~( DMAEN + DMAIE);
  
  FCTL3 = FWKEY + LOCK;                     // Lock the flash from write 
}
Ejemplo n.º 14
0
static void onProgramStart()
{
    halAccelerometerInit();

    halTimer_b_enableInterruptCCR0();

    halLcdPrintLine("ACCEL. VECTOR", 0, INVERT_TEXT);

    /*   012345
     * 0 ACCEL.VECTOR
     * 1
     * 2   X: 0000
     * 3   Y: 0000
     * 4   Z: 0000
     * */
    halLcdPrintLineCol("X:", 2, 2, OVERWRITE_TEXT);
    halLcdPrintLineCol("Y:", 3, 2, OVERWRITE_TEXT);
    halLcdPrintLineCol("Z:", 4, 2, OVERWRITE_TEXT);

    __test_accel_killProgram = FALSE;
    __test_accel_updateVector = FALSE;

    TB0CCR0 = 32 * 25; // Each 25 milliseconds it will update the window state
}
Ejemplo n.º 15
0
/**********************************************************************//**
 * @brief  Executes the "PMM-MCLK" menu option in the User Experience
 *         example code. This menu option allows one to change the frequency
 *         of operation for the MSP430 and the VCore setting. 
 * 
 * @param  none 
 * 
 * @return none 
 *************************************************************************/
void menuPMMMCLK( void )
{
  unsigned char menuLeftPos = 2, menuRightPos = 0, menuRightMaxAllowed = 5;
  unsigned char ledOn, quit = 0;
  volatile unsigned int i;
  
  halButtonsInterruptDisable( BUTTON_ALL );
  halButtonsInterruptEnable( BUTTON_SELECT + BUTTON_S1 +   \
                             BUTTON_S2 + BUTTON_RIGHT );
  halAccelerometerShutDown();
  halLcdClearScreen();
  
  halBoardOutputSystemClock();
  halLcdPrintLineCol(&VcoreText[0], 0, 1,  OVERWRITE_TEXT );

  for (i=0;i < MCLK_MENU_MAX+1; i++)
    halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );
  
  halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6],        \
                     menuLeftPos+1, 1, INVERT_TEXT | OVERWRITE_TEXT);
  halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],        \
                     menuRightPos+1, 12, INVERT_TEXT | OVERWRITE_TEXT);    
  buttonsPressed = 0;  
  
  for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
  {
    halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
    halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);     
  }
  ledOn = 0;
  halLcdPrintLine("      LED", 6, 0);  
  halLcdPrintLine("      OFF", 7, 0);
  halLcdImage(IMG_RIGHT_FILLED, 4, 32, 10, 75);
  
  halBoardSetVCore(menuLeftPos);
  halBoardSetSystemClock(menuRightPos);  

  while (!quit)
  {
  	// The LED can be enabled to show the relative difference between
  	// frequencies of operation. 
    while (!buttonsPressed)    
      if (ledOn)
      {
        LED_PORT_OUT ^= LED_1;
        for (i=0; i < 0xFFFF; i++)
          if (buttonsPressed)
            break;
      }      
      else
      {
      	// To emulate a real application instead of continuous jumps, use nops 
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
      }
    if (buttonsPressed & BUTTON_S1)
    {
      /*
       * Disabled for MSP430F5438 RTM Silicon
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,      \
                         1,  OVERWRITE_TEXT);
      if (++ menuLeftPos >= VCORE_MENU_MAX)
      {
        menuLeftPos = 0;
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[ menuLeftPos ];
        if (menuRightPos >= menuRightMaxAllowed)
        {
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12,  OVERWRITE_TEXT);                
          menuRightPos = menuRightMaxAllowed - 1;
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12, INVERT_TEXT | OVERWRITE_TEXT);  
        }        
        for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
        {
          halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
          halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);        
        }
      } 
         
      else            
      {
        for (i=menuRightMaxAllowed+1; i< MAX_MCLK_ALLOWED[menuLeftPos]+1; i ++)
          halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );          
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[menuLeftPos];
      }      
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,       \
                         1, INVERT_TEXT | OVERWRITE_TEXT);
      */
    }
    if ( buttonsPressed & BUTTON_S2 )
    {
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12,  OVERWRITE_TEXT);        
      
      if ( ++menuRightPos >= menuRightMaxAllowed )      
        menuRightPos = 0;
        
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12, INVERT_TEXT| OVERWRITE_TEXT);              
    }
    if ( buttonsPressed & BUTTON_RIGHT )
    {
      ledOn = 1 - ledOn;
      if ( ledOn )        
        halLcdPrintLineCol("ON ", 7, 6, OVERWRITE_TEXT);
      else
      {
      	halLcdPrintLineCol("OFF", 7, 6, OVERWRITE_TEXT);
        LED_PORT_OUT &= ~LED_1;
      }         
    }    
    
    if ( buttonsPressed & (BUTTON_S1 | BUTTON_S2) )
    {
      halBoardSetVCore(menuLeftPos);
  		halBoardSetSystemClock(menuRightPos);  
  		//halBoardDisableSVS();
    }
    if ( buttonsPressed & BUTTON_SELECT )    
      quit = 1;
    buttonsPressed = 0;
  }
  
  halBoardSetSystemClock( SYSCLK_16MHZ );
  halBoardStopOutputSystemClock();
  LED_PORT_OUT &= ~LED_1;
}
Ejemplo n.º 16
0
static void prvLCDTask( void *pvParameters )
{
    xQueueMessage xReceivedMessage;

    /* Buffer into which strings are formatted and placed ready for display on the
    LCD.  Note this is a static variable to prevent it being allocated on the task
    stack, which is too small to hold such a variable.  The stack size is configured
    when the task is created. */
    static char cBuffer[ 512 ];
    unsigned char ucLine = 1;


    /* This function is the only function that uses printf().  If printf() is
    used from any other function then some sort of mutual exclusion on stdout
    will be necessary.

    This is also the only function that is permitted to access the LCD.

    First print out the number of bytes that remain in the FreeRTOS heap.  This
    can be viewed in the terminal IO window within the IAR Embedded Workbench. */
    printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() );

    /* Just as a test of the port, and for no functional reason, check the task
    parameter contains its expected value. */
    if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
    {
        halLcdPrintLine( "Invalid parameter", ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }

    for( ;; )
    {
        /* Wait for a message to be received.  Using portMAX_DELAY as the block
        time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
        set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
        function return value and the function will only return when a value
        has been received. */
        xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

        /* Clear the LCD if no room remains for any more text output. */
        if( ucLine > mainMAX_LCD_LINES )
        {
            halLcdClearScreen();
            ucLine = 0;
        }

        /* What is this message?  What does it contain? */
        switch( xReceivedMessage.cMessageID )
        {
        case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
            sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button was pressed.
												Generate a table of task run time
												statistics and output this to
												the terminal IO window in the IAR
												embedded workbench. */
            printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );
            vTaskGetRunTimeStats( ( signed char * ) cBuffer );
            printf( cBuffer );

            /* Also print out a message to
            the LCD - in this case the
            pointer to the string to print
            is sent directly in the
            ulMessageValue member of the
            message.  This just demonstrates
            a different communication
            technique. */
            sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
            prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
            break;

        default							:
            sprintf( cBuffer, "Unknown message" );
            break;
        }

        /* Output the message that was placed into the cBuffer array within the
        switch statement above, then move onto the next line ready for the next
        message to arrive on the queue. */
        halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }
}
Ejemplo n.º 17
0
/**************************************************************************
 * ESCRIBIR LINEA
 * 
 * Datos de entrada: Linea, indica la linea a escribir
 *           String, cadena de caracteres que vamos a introducir
 * 
 * Sin datos de salida
 * 
 **************************************************************************/
void write(char string[], unsigned char line)
{
    halLcdPrintLine(string, line, OVERWRITE_TEXT); //superponemos la nueva palabra introducida, haya o no algo.
}
Ejemplo n.º 18
0
int main(void) {
    uint8_t  currState;
    uint8_t  targetState;
    uint16_t readbcLength;
    uint32_t nwkId;
    uint8_t  errorCheckInterval = 100;

    // Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // Initialize the MCU and board peripherals
    halBoardInit();
    halBoardStartXT1();	
    halBoardSetSystemClock(SYSCLK_16MHZ);
    halButtonsInit(BUTTON_ALL);
    halLcdInit();
    halLcdBackLightInit();
    halLcdSetContrast(90);
    halLcdSetBackLight(10);
    halLcdClearScreen();

    halLcdPrintLine("  CC85XX SLAVE   ", 0, OVERWRITE_TEXT );
    halLcdPrintLine("                 ", 1, OVERWRITE_TEXT );
    halLcdPrintLine("S1: Power toggle ", 2, OVERWRITE_TEXT );
    halLcdPrintLine("S2: Pairing start", 3, OVERWRITE_TEXT );
    uifLcdPrintJoystickInfo();

    // Wipe remote control information
    memset(&ehifRcSetDataParam, 0x00, sizeof(ehifRcSetDataParam));

    // Initialize EHIF IO
    ehifIoInit();

    // Reset into the application
    ehifSysResetPin(true);
    currState = CC85XX_STATE_ALONE;
    targetState = CC85XX_STATE_ACTIVE;

    // Get the last used network ID from CC85XX non-volatile storage
    initParam();
    ehifCmdParam.nvsGetData.index = 0;
    ehifCmdExecWithRead(EHIF_EXEC_ALL, EHIF_CMD_NVS_GET_DATA, 
                        sizeof(EHIF_CMD_NVS_GET_DATA_PARAM_T), &ehifCmdParam, 
                        sizeof(EHIF_CMD_NVS_GET_DATA_DATA_T), &ehifCmdData);
    nwkId = ehifCmdData.nvsGetData.data;

    // Handle illegal default network IDs that may occur first time after programming
    if ((nwkId == 0x00000000) || (nwkId == 0xFFFFFFFF)) {
        nwkId = 0xFFFFFFFE;
    }

    // Main loop
    while (1) {

        // Wait 10 ms
        EHIF_DELAY_MS(10);

        // Perform action according to edge-triggered button events (debouncing with 100 ms delay)
        switch (pollButtons()) {

        // POWER TOGGLE
        case BUTTON_S1:
            if (currState == CC85XX_STATE_OFF) {
                targetState = CC85XX_STATE_ACTIVE;
            } else {
                targetState = CC85XX_STATE_OFF;
            }
            break;

        // PAIRING TRIGGER
        case BUTTON_S2:
            if (currState != CC85XX_STATE_OFF) {
                targetState = CC85XX_STATE_PAIRING;
            }
            break;
        }

        // Run the state machine
        if (currState != targetState) {

            if (currState == CC85XX_STATE_OFF) {
                // HANDLE POWER ON

                // Ensure known state (power state 5)
                ehifSysResetPin(true);
                currState = CC85XX_STATE_ALONE;

            } else if (targetState == CC85XX_STATE_OFF) {
                // HANDLE POWER OFF

                // Ensure known state (power state 5)
                ehifSysResetPin(true);
                currState = CC85XX_STATE_ALONE;

                // Set power state 0
                ehifCmdParam.pmSetState.state = 0;
                ehifCmdExec(EHIF_CMD_PM_SET_STATE, sizeof(EHIF_CMD_PM_SET_STATE_PARAM_T), &ehifCmdParam);
                currState = CC85XX_STATE_OFF;

            } else if (targetState == CC85XX_STATE_PAIRING) {
                // HANDLE PAIRING

                // Let the last executed EHIF command complete, with 5 second timeout
                ehifWaitReadyMs(5000);

                // Disconnect if currently connected
                if (ehifGetStatus() & BV_EHIF_STAT_CONNECTED) {
                    initParam();
                    // All parameters should be zero
                    ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam);
                }

                // Search for one protocol master with pairing signal enabled for 10 seconds
                initParam();
                ehifCmdParam.nwmDoScan.scanTo           = 1000;
                ehifCmdParam.nwmDoScan.scanMax          = 1;
                ehifCmdParam.nwmDoScan.reqPairingSignal = 1;
                ehifCmdParam.nwmDoScan.reqRssi          = -128;
                ehifCmdExecWithReadbc(EHIF_EXEC_CMD, EHIF_CMD_NWM_DO_SCAN, 
                                      sizeof(EHIF_CMD_NWM_DO_SCAN_PARAM_T), &ehifCmdParam, 
                                      NULL, NULL);

                // Fetch network information once ready
                ehifWaitReadyMs(12000);
                readbcLength = sizeof(ehifNwmDoScanData);
                ehifCmdExecWithReadbc(EHIF_EXEC_DATA, EHIF_CMD_NWM_DO_SCAN, 
                                      0, NULL, 
                                      &readbcLength, &ehifNwmDoScanData);

                // If found ...
                if (readbcLength == sizeof(EHIF_CMD_NWM_DO_SCAN_DATA_T)) {

                    // Update the network ID to be used next
                    nwkId = ehifNwmDoScanData.deviceId;

                    // Place the new network ID in CC85XX non-volatile storage
                    initParam();
                    ehifCmdParam.nvsSetData.index = 0;
                    ehifCmdParam.nvsSetData.data  = ehifNwmDoScanData.deviceId;
                    ehifCmdExec(EHIF_CMD_NVS_SET_DATA, sizeof(EHIF_CMD_NVS_SET_DATA_PARAM_T), &ehifCmdParam);
                }

                // Done
                currState = CC85XX_STATE_ALONE;
                targetState = CC85XX_STATE_ACTIVE;

            } else if (targetState == CC85XX_STATE_ACTIVE) {

                // We're disconnected. Proceed only if EHIF is ready, so that power toggle and pairing
                // buttons can still be operated
                uint16_t status = ehifGetStatus();
                if (status & BV_EHIF_STAT_CMD_REQ_RDY) {

                    // Perform join operation first and then activate audio channels. We're using remote
                    // volume control
                    if (!(status & BV_EHIF_STAT_CONNECTED)) {

                        // Enable disconnection notification to avoid unnecessary EHIF activity while active
                        initParam();
                        ehifCmdParam.ehcEvtClr.clearedEvents = BV_EHIF_EVT_NWK_CHG;
                        ehifCmdExec(EHIF_CMD_EHC_EVT_CLR, sizeof(EHIF_CMD_EHC_EVT_CLR_PARAM_T), &ehifCmdParam);
                        initParam();
                        ehifCmdParam.ehcEvtMask.irqGioLevel = 0;
                        ehifCmdParam.ehcEvtMask.eventFilter = BV_EHIF_EVT_NWK_CHG;
                        ehifCmdExec(EHIF_CMD_EHC_EVT_MASK, sizeof(EHIF_CMD_EHC_EVT_MASK_PARAM_T), &ehifCmdParam);

                        // Not connected: Start JOIN operation
                        initParam();
                        ehifCmdParam.nwmDoJoin.joinTo = 100;
                        ehifCmdParam.nwmDoJoin.deviceId = nwkId;
                        ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam);

                    } else {
                        // Connected: Subscribe to audio channels (0xFF = unused)
                        memset(&ehifCmdParam, 0xFF, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T));
                        ehifCmdParam.nwmAchSetUsage.pAchUsage[0] = 0; // Front left  -> I2S LEFT
                        ehifCmdParam.nwmAchSetUsage.pAchUsage[1] = 1; // Front right -> I2S RIGHT
                        ehifCmdExec(EHIF_CMD_NWM_ACH_SET_USAGE, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T), &ehifCmdParam);
                        currState = CC85XX_STATE_ACTIVE;
                    }
                }
            }

        } else {

            // Only OFF and ACTIVE are permanent target states. SCAN is only a temporary target state.
            // In the OFF state we do nothing, so only need to handle the ACTIVE state.
            if (currState == CC85XX_STATE_ACTIVE) {

                // Detect network disconnection without generating noise on the SPI interface
                if (EHIF_INTERRUPT_IS_ACTIVE()) {
                    currState = CC85XX_STATE_ALONE;
                }

                // Perform error checking at 10 ms * 100 = 1 second intervals:
                // - No timeouts or SPI errors shall have occurred
                // - We should be connected unless disconnection has been signalized
                if (--errorCheckInterval == 0) {
                    errorCheckInterval = 100;
                    uint16_t status = ehifGetStatus();
                    if (ehifGetWaitReadyError() || (status & BV_EHIF_EVT_SPI_ERROR) ||
                        (!(status & BV_EHIF_STAT_CONNECTED) && !(status & BV_EHIF_EVT_NWK_CHG))) {

                        // The device is in an unknown state -> restart everything
                        ehifSysResetPin(true);
                        currState = CC85XX_STATE_ALONE;
                    }
                }

                // If the network connection is up and running...
                if (currState == CC85XX_STATE_ACTIVE) {

                    // Send remote control commands (mouse or play control, depending on which uif file
                    // is included in the build)
                    if (uifPollFunc(&ehifRcSetDataParam)) {
                        ehifCmdExec(EHIF_CMD_RC_SET_DATA, sizeof(EHIF_CMD_RC_SET_DATA_PARAM_T), &ehifRcSetDataParam);
                    }
                }
            }
        }
    }

} // main
Ejemplo n.º 19
0
__interrupt void on_button_interruption(void)
{
    halButtons_setInterruptions(BUTTON_ALL, OFF);
    halJoystick_setInterruptions(JOYSTICK_ALL, OFF);

    switch ( P2IFG )
    {
        case JOYSTICK_RIGHT:
            edit_mode++;
            if ( edit_mode > EDIT_SECONDS )
                edit_mode = OFF;
            break;
        case JOYSTICK_LEFT:
            edit_mode--;
            if ( edit_mode < 0 )
            	edit_mode = EDIT_SECONDS;
            break;
        case JOYSTICK_UP:
            if ( time_base < 10000 )
                time_base *= 10;
            break;
        case JOYSTICK_DOWN:
            if ( time_base > 1 )
                time_base /= 10;
            break;
        case JOYSTICK_CENTER:
            stop_cron = ~stop_cron;
            break;
        case BUTTON_S1:
            increase_cron_unit();
            halLcdPrintLine(lcd_clear, LINE_CRON, OVERWRITE_TEXT);
            write_cron();
            break;
        case BUTTON_S2:
            decrease_cron_unit();
            halLcdPrintLine(lcd_clear, LINE_CRON, OVERWRITE_TEXT);
            write_cron();
            break;
    }

    write_time_base();

    halLcdPrintLine(lcd_clear, LINE_TIME_UNIT_SEL, OVERWRITE_TEXT);
    if ( edit_mode != OFF )
    {
        switch ( edit_mode )
        {
            case EDIT_HOURS:
                halLcdPrintLineCol("HH", LINE_TIME_UNIT_SEL, 1, OVERWRITE_TEXT);
                break;
            case EDIT_MINUTES:
                halLcdPrintLineCol("MM", LINE_TIME_UNIT_SEL, 4, OVERWRITE_TEXT);
                break;
            case EDIT_SECONDS:
                halLcdPrintLineCol("SS", LINE_TIME_UNIT_SEL, 7, OVERWRITE_TEXT);
                break;
        }
    }

    halTimer_b_setCCRTimedInterruption(TIMER_CCR0, time_multiplier * time_base);

    P2IFG = 0;

    halButtons_setInterruptions(BUTTON_ALL, ON);
    halJoystick_setInterruptions(JOYSTICK_ALL, ON);
}
Ejemplo n.º 20
0
/**************************************************************************
 * BORRAR LINEA
 * 
 * Datos de entrada: Linea, indica la linea a borrar
 * 
 * Sin datos de salida
 * 
 **************************************************************************/
void clearLine(unsigned char line)
{
    halLcdPrintLine(borrado, line, OVERWRITE_TEXT); //incluimos una linea en blanco
}
Ejemplo n.º 21
0
static void prvLCDTask( void *pvParameters )
{
xQueueMessage xReceivedMessage;

/* Buffer into which strings are formatted and placed ready for display on the
LCD.  Note this is a static variable to prevent it being allocated on the task
stack, which is too small to hold such a variable.  The stack size is configured
when the task is created. */
static char cBuffer[ 50 ];
unsigned char ucLine = 1;

	/* Now the scheduler has been started (it must have been for this task to
	be running), start the check timer too.  The call to xTimerStart() will
	block until the command has been accepted. */
	if( xCheckTimer != NULL )
	{
		xTimerStart( xCheckTimer, portMAX_DELAY );
	}

	/* This is the only function that is permitted to access the LCD.
	
	First print out the number of bytes that remain in the FreeRTOS heap.  This
	is done after a short delay to ensure all the demo tasks have created all
	the objects they are going to use.  */
	vTaskDelay( mainTIMER_TEST_PERIOD * 10 );
	sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );
	halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
	ucLine++;
	
	/* Just as a test of the port, and for no functional reason, check the task
	parameter contains its expected value. */
	if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
	{
		halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );
		ucLine++;		
	}

	for( ;; )
	{
		/* Wait for a message to be received.  Using portMAX_DELAY as the block
		time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
		set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
		function return value and the function will only return when a value
		has been received. */
		xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

		/* Clear the LCD if no room remains for any more text output. */
		if( ucLine > mainMAX_LCD_LINES )
		{
			halLcdClearScreen();
			ucLine = 0;
		}
		
		/* What is this message?  What does it contain? */
		switch( xReceivedMessage.cMessageID )
		{
			case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
												sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
												break;

			case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button has been pressed.
												In this case the pointer to the 
												string to print is sent directly 
												in the ulMessageValue member of 
												the	message.  This just 
												demonstrates a different 
												communication technique. */
												sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
												break;
												
			case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
												prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
												break;
												
			default							:	sprintf( cBuffer, "Unknown message" );
												break;
		}
		
		/* Output the message that was placed into the cBuffer array within the
		switch statement above, then move onto the next line ready for the next
		message to arrive on the queue. */
		halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
		ucLine++;
	}
}
Ejemplo n.º 22
0
void write_time_base()
{
    sprintf(lcd_line, " SEC: %07u", time_multiplier * time_base);
    halLcdPrintLine(lcd_line, LINE_TIMER_SECONDS, OVERWRITE_TEXT);
}
Ejemplo n.º 23
0
// put 'lineBuffer' on screen
void showLine(void){
    clearLine(row);
    halLcdPrintLine(lineBuffer, row, 0);
    printf("LCD: %s\n\r", lineBuffer);
}
Ejemplo n.º 24
0
void printLine(char *text){
    printf("LCD: %s\n\r", text);
    halLcdPrintLine(text, row++, 0);
}
Ejemplo n.º 25
0
void write_cron()
{
    sprintf(lcd_line, " %02d:%02d:%02d", cron.hours, cron.minutes, cron.seconds);
    halLcdPrintLine(lcd_line, LINE_CRON, OVERWRITE_TEXT);
}