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 ); }
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 ); }
/**********************************************************************//** * @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); }
/****************************************************************************** * @fn main * * @brief Main handles all applications attached to the menu system * * input parameters * * output parameters * *@return */ void main( void ) { /* Stop watchdog timer to prevent time out reset */ WDTCTL = WDTPW + WDTHOLD; /* Settingcapacitor values for XT1, 32768 Hz */ halMcuStartXT1(); /* Clocks: * mclk = mclkFrequency * smclk = mclkFrequency * aclk = 32768 Hz */ mclkFrequency = HAL_MCU_SYSCLK_16MHZ; halMcuSetSystemClock(mclkFrequency); /* Care must be taken when handling power modes * - Peripheral units can request clocks and have them granted even if * the system is in a power mode. Peripheral clock request is enabled * as default. * - Per test only needs ACLK to be enabled to timers * during power mode operation */ halMcuDisablePeripheralClockRequest((MCLKREQEN+SMCLKREQEN)); /* SPI flash uses same SPI interface as LCD -- we'll disable the SPI flash */ P8SEL &= BIT6; /*ioflash_csn = gp. */ P8DIR |= BIT6; /*tpflash_csn = ouut. */ P8OUT |= BIT6; /*flash_csn = 1. */ /* Init leds and turn them on */ halLedInit(); /* Init Buttons */ halButtonsInit(); halButtonsInterruptEnable(); /* Instantiate tranceiver RF spi interface to SCLK = 1 MHz */ trxRfSpiInterfaceInit(0x10); halLedSet(LED_1); initSimpleLink(); halLedSet(LED_2); simpleLinkMaster(); while(1) { halLedSet(LED_3); halTimer32kMcuSleepTicks(3276); halLedClear(LED_3); halTimer32kMcuSleepTicks(3276); } }
/**********************************************************************//** * @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; }
/**********************************************************************//** * @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; }