void main(void) { ENABLE_LCD_LED(); #if ENABLE_WATCHDOG RestartWatchdog(); #else WDTCTL = WDTPW + WDTHOLD; #endif /* clear shipping mode, if set to allow configuration */ PMMCTL0_H = PMMPW_H; PM5CTL0 &= ~LOCKLPM5; /* disable DMA during read-modify-write cycles */ DMACTL4 = DMARMWDIS; DetermineErrata(); #ifdef BOOTLOADER /* * enable RAM alternate interrupt vectors * these are defined in AltVect.s43 and copied to RAM by cstartup */ SYSCTL |= SYSRIVECT; ClearBootloaderSignature(); #endif /* calibration data is used for clock setup */ InitializeCalibrationData(); #ifndef BOOTLOADER SaveResetSource(); #endif SetupClockAndPowerManagementModule(); OsalNvInit(0); /* change the mux settings according to presense of the charging clip */ InitializeMuxMode(); ChangeMuxMode(); InitDebugUart(); TestModeControl(); /* adc is required to get the board configuration */ InitializeAdc(); ConfigureDefaultIO(GetBoardConfiguration()); InitializeDebugFlags(); // InitButton(); InitializeVibration(); InitializeOneSecondTimers(); InitializeBufferPool(); InitializeWrapperTask(); InitializeRealTimeClock(); InitializeDisplayTask(); DISABLE_LCD_LED(); #if CHECK_FOR_PMM15 /* make sure error pmm15 does not exist */ while ( PMM15Check() ); #endif /* Errata PMM17 - automatic prolongation mechanism * SVSLOW is disabled */ *(unsigned int*)(0x0110) = 0x9602; *(unsigned int*)(0x0112) |= 0x0800; WhoAmI(); PrintResetSource(); /* if a watchdog occurred then print and save information about the source */ WatchdogTimeoutHandler(GetResetSource()); PrintString("Starting Task Scheduler\r\n"); SetUartNormalMode(); vTaskStartScheduler(); /* if vTaskStartScheduler exits an error occured. */ PrintString("Program Error\r\n"); ForceWatchdogReset(); }
/*! Initialize the Analog-to-Digital Conversion peripheral. Set the outputs from * the micro to the correct state. The ADC is used to read the * hardware configuration registers, the battery voltage, and the value from the * light sensor. */ void InitAdc(void) { /* * the internal voltage reference is not used ( AVcc is used ) * reference is controlled by ADC12MCTLx register * 2.5 volt reference cannot be used because it requires external AVcc of 2.8 * disable temperature sensor */ REFCTL0 = REFMSTR | REFTCOFF; LIGHT_SENSE_INIT(); BATTERY_SENSE_INIT(); HARDWARE_CFG_SENSE_INIT(); /* allow conditional request for modosc */ UCSCTL8 |= MODOSCREQEN; /* select ADC12SC bit as sample and hold source (00) * and use pulse mode * use modosc / 8 because frequency must be 0.45 MHz to 2.7 MHz (0.625 MHz) */ ADC12CTL1 = ADC12CSTARTADD_0 + ADC12SHP + ADC12SSEL_0 + ADC12DIV_7; /* 12 bit resolution, only use reference when doing a conversion */ ADC12CTL2 = ADC12TCOFF + ADC12RES_2 + ADC12REFBURST; /* setup input channels */ ADC12MCTL0 = HARDWARE_CFG_INPUT_CHANNEL + ADC12EOS; ADC12MCTL1 = BATTERY_SENSE_INPUT_CHANNEL + ADC12EOS; ADC12MCTL2 = LIGHT_SENSE_INPUT_CHANNEL + ADC12EOS; /* init to 0 */ memset(Sample, 0, MAX_SAMPLES << 2); /* control access to adc peripheral */ AdcMutex = xSemaphoreCreateMutex(); xSemaphoreGive(AdcMutex); WarningLevel = DEFAULT_WARNING_LEVEL; RadioOffLevel = DEFAULT_RADIO_OFF_LEVEL; /* * A voltage divider on the board is populated differently * for each revision of the board. * * determine configuration at start-up */ HARDWARE_CFG_SENSE_ENABLE(); ENABLE_REFERENCE(); /* Start Hardware Configuration Cycle */ AdcCheck(); /* setup the ADC channel */ CLEAR_START_ADDR(); ADC12CTL1 |= ADC12CSTARTADD_0; /* enable the ADC to start sampling and perform a conversion */ ENABLE_ADC(); WaitForAdcBusy(); /* Finish HardwareConfiguration Cycle */ /* Convert ADC counts to a voltage (truncates) * ADC12MEM0: Voltage in ADC counts * result: Voltage in millivolts * 10 */ unsigned int HwCfgVolt = (unsigned int)(CONVERSION_FACTOR * (double)ADC12MEM0); HARDWARE_CFG_SENSE_DISABLE(); DISABLE_ADC(); DISABLE_REFERENCE(); BoardType = HW_CONFIG_NUM - 1; for (; BoardType; --BoardType) if (HwCfgVolt > HwConfig[BoardType]) break; ConfigureDefaultIO(); }