コード例 #1
0
//* ************************************************************************************************
/// @fn			init_application(void)
/// @brief		Init the watch's program
/// @return		none
//* ************************************************************************************************
void init_application(void)
{
	volatile unsigned char *ptr;
	
	// ---------------------------------------------------------------------
	// Enable watchdog
	
	// Watchdog triggers after 16 seconds when not cleared
#ifdef USE_WATCHDOG
	WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK;
#else
	WDTCTL = WDTPW + WDTHOLD;
#endif
	
	// ---------------------------------------------------------------------
	// Configure PMM
	
	SetVCore(3);
	
	// Set global high power request enable
	PMMCTL0_H  = 0xA5;
	PMMCTL0_L |= PMMHPMRE;
	PMMCTL0_H  = 0x00;
	
	// ---------------------------------------------------------------------
	// Enable 32kHz ACLK
	
	P5SEL |= 0x03;				// Select XIN, XOUT on P5.0 and P5.1
	UCSCTL6 &= ~XT1OFF;			// XT1 On, Highest drive strength
	UCSCTL6 |= XCAP_3;			// Internal load cap
	
	UCSCTL3 = SELA__XT1CLK;		// Select XT1 as FLL reference
	UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV;
	
	// ---------------------------------------------------------------------
	// Configure CPU clock for 12MHz
	
	_BIS_SR(SCG0);				// Disable the FLL control loop
	UCSCTL0 = 0x0000;			// Set lowest possible DCOx, MODx
	UCSCTL1 = DCORSEL_5;		// Select suitable range
	UCSCTL2 = FLLD_1 + 0x16E;	// Set DCO Multiplier
	_BIC_SR(SCG0);				// Enable the FLL control loop
	
	// Worst-case settling time for the DCO when the DCO range bits have been
	// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
	// UG for optimization.
	// 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
	
#if __GNUC_MINOR__ > 5 || __GNUC_PATCHLEVEL__ > 8
	
	__delay_cycles(250000);
	
#else
	
	__delay_cycles(62500);
	__delay_cycles(62500);
	__delay_cycles(62500);
	__delay_cycles(62500);
	
#endif
	
	// Loop until XT1 & DCO stabilizes, use do-while to insure that 
	// body is executed at least once
	do
	{
		UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
		SFRIFG1 &= ~OFIFG;		// Clear fault flags
	}
	while ((SFRIFG1 & OFIFG));
	
	// ---------------------------------------------------------------------
	// Configure port mapping
	
	// Disable all interrupts
	__disable_interrupt();
	// Get write-access to port mapping registers:
	PMAPPWD = 0x02D52;
	// Allow reconfiguration during runtime:
	PMAPCTL = PMAPRECFG;
	
	// P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
	ptr  = &P2MAP0;
	*(ptr + 7) = PM_TA1CCR0A;
	P2OUT &= ~BIT7;
	P2DIR |= BIT7;
	
	// P1.5 = SPI MISO input
	ptr  = &P1MAP0;
	*(ptr + 5) = PM_UCA0SOMI;
	// P1.6 = SPI MOSI output
	*(ptr + 6) = PM_UCA0SIMO;
	// P1.7 = SPI CLK output
	*(ptr + 7) = PM_UCA0CLK;
	
	// Disable write-access to port mapping registers:
	PMAPPWD = 0;
	// Re-enable all interrupts
	__enable_interrupt();
	
	// Init the hardwre real time clock (RTC_A)
	rtca_init();
	
	// ---------------------------------------------------------------------
	// Configure ports
	
	// ---------------------------------------------------------------------
	// Reset radio core
	
	radio_reset();
	radio_powerdown();
	
	// ---------------------------------------------------------------------
	// Init acceleration sensor
	
#ifdef CONFIG_MOD_ACCELEROMETER
	as_init();
#else
	as_disconnect();
#endif
	
	// ---------------------------------------------------------------------
	// Init LCD
	
	lcd_init();
	
	// ---------------------------------------------------------------------
	// Init buttons

	init_buttons();
	
	// ---------------------------------------------------------------------
	// Configure Timer0 for use by the clock and delay functions
	
	timer0_init();
	
	// Init buzzer
	buzzer_init();
	
	// ---------------------------------------------------------------------
	// Init pressure sensor
	
#ifdef CONFIG_PRESSURE_SENSOR
	ps_init();
#endif
	
	// ---------------------------------------------------------------------
	// Init other sensors
	
	// From: "driver/battery"
	battery_init();
	
	// From: "drivers/temperature"
	temperature_init();
	
	/// @todo What is this ?
#ifdef CONFIG_INFOMEM
	
	if (infomem_ready() == -2)
		infomem_init(INFOMEM_C, INFOMEM_C + 2 * INFOMEM_SEGMENT_SIZE);
	
#endif

}
コード例 #2
0
ファイル: ezchronos.c プロジェクト: xawirq/OpenChronos
// *************************************************************************************************
// @fn          init_global_variables
// @brief       Initialize global variables.
// @param       none
// @return      none
// *************************************************************************************************
void init_global_variables(void)
{
	// --------------------------------------------
	// Apply default settings

	menu_L1_position=0;
	menu_L2_position=0;
	// set menu pointers to default menu items
	ptrMenu_L1 = menu_L1[menu_L1_position];
	ptrMenu_L2 = menu_L2[menu_L2_position];

	// Assign LINE1 and LINE2 display functions
	fptr_lcd_function_line1 = ptrMenu_L1->display_function;
	fptr_lcd_function_line2 = ptrMenu_L2->display_function;

	// Init system flags
	button.all_flags 	= 0;
	sys.all_flags 		= 0;
	request.all_flags 	= 0;
	display.all_flags 	= 0;
	message.all_flags	= 0;
	
	// Force full display update when starting up
	display.flag.full_update = 1;

#ifndef ISM_US
	// Use metric units when displaying values
    sys.flag.use_metric_units = 1;
#else 
#ifdef CONFIG_METRIC_ONLY
	sys.flag.use_metric_units = 1;
#endif
#endif
	
	// Read calibration values from info memory
	read_calibration_values();
#ifdef CONFIG_ALTI_ACCUMULATOR
	// By default, don't have the altitude accumulator running
	alt_accum_enable = 0;
#endif
	
	
	#ifdef CONFIG_INFOMEM
	if(infomem_ready()==-2)
	{
		infomem_init(INFOMEM_C, INFOMEM_C+2*INFOMEM_SEGMENT_SIZE);
	}
	#endif
	
	// Set system time to default value
	reset_clock();
	
	// Set date to default value
	reset_date();
	
	#ifdef CONFIG_SIDEREAL
	reset_sidereal_clock();
	#endif
	
	#ifdef CONFIG_ALARM
	// Set alarm time to default value 
	reset_alarm();
	#endif
	
	// Set buzzer to default value
	reset_buzzer();
	
#ifdef CONFIG_STOP_WATCH
	// Reset stopwatch
	reset_stopwatch();
#endif
	
	// Reset altitude measurement
#ifdef CONFIG_ALTITUDE
	reset_altitude_measurement();
#endif
	
	#ifdef FEATURE_PROVIDE_ACCEL
	// Reset acceleration measurement
	reset_acceleration();
	#endif
	
	// Reset BlueRobin stack
	//pfs
	#ifndef ELIMINATE_BLUEROBIN 
	reset_bluerobin();
	#endif

#ifdef CONFIG_EGGTIMER
	init_eggtimer(); // Initialize eggtimer
#endif

#ifdef CONFIG_PROUT
        reset_prout();
#endif

#ifdef CONFIG_PHASE_CLOCK
	// default program
	sPhase.program = 0;
#endif

	// Reset SimpliciTI stack
	reset_rf();
	
	// Reset temperature measurement 
	reset_temp_measurement();

	#ifdef CONFIG_BATTERY
	// Reset battery measurement
	reset_batt_measurement();
	battery_measurement();
	#endif
}
コード例 #3
0
void init_application(void)
{
	volatile unsigned char *ptr;

	// ---------------------------------------------------------------------
	// Enable watchdog

	// Watchdog triggers after 16 seconds when not cleared
#ifdef USE_WATCHDOG
	WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK;
#else
	WDTCTL = WDTPW + WDTHOLD;
#endif

	// ---------------------------------------------------------------------
	// Configure port mapping

	// Disable all interrupts
	__disable_interrupt();
	// Get write-access to port mapping registers:
	PMAPPWD = 0x02D52;
	// Allow reconfiguration during runtime:
	PMAPCTL = PMAPRECFG;

	// P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
	ptr  = &P2MAP0;
	*(ptr + 7) = PM_TA1CCR0A;
	P2OUT &= ~BIT7;
	P2DIR |= BIT7;

	// P1.5 = SPI MISO input
	ptr  = &P1MAP0;
	*(ptr + 5) = PM_UCA0SOMI;
	// P1.6 = SPI MOSI output
	*(ptr + 6) = PM_UCA0SIMO;
	// P1.7 = SPI CLK output
	*(ptr + 7) = PM_UCA0CLK;

	// Disable write-access to port mapping registers:
	PMAPPWD = 0;
	// Re-enable all interrupts
	__enable_interrupt();

	// Init the hardwre real time clock (RTC_A)
	rtca_init();

	// ---------------------------------------------------------------------
	// Configure ports

	// ---------------------------------------------------------------------
	// Reset radio core
	radio_reset();
	radio_powerdown();

#ifdef CONFIG_ACCELEROMETER
	// ---------------------------------------------------------------------
	// Init acceleration sensor
	as_init();
#else
	as_disconnect();
#endif

	// ---------------------------------------------------------------------
	// Init buttons
	init_buttons();

	// ---------------------------------------------------------------------
	// Configure Timer0 for use by the clock and delay functions
	timer0_init();

	/* Init buzzer */
	buzzer_init();

	// ---------------------------------------------------------------------
	// Init pressure sensor
	ps_init();

	/* drivers/battery */
	battery_init();

	/* drivers/temperature */
	temperature_init();

#ifdef CONFIG_INFOMEM
	if (infomem_ready() == -2) {
		infomem_init(INFOMEM_C, INFOMEM_C + 2 * INFOMEM_SEGMENT_SIZE);
	}
#endif
}