예제 #1
0
파일: main.c 프로젝트: hunt978/vatdma
int main(void) 
{
	// Set the MCU clock to 8MHz
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	// Enable interrupts
	eint();

	// Swtich of LEDs
	LEDS_INIT();
	LEDS_OFF();

	/** Initialization of timer A
	 *  This has to be done before using any of the timer A manipulation routine
	 */
	timerA_init();

	/** Callbacks registration
	 *  Two callbacks are registered, one for alarm 0 and another one for alarm 1.
	 *  Alarm 2 and overflow are not used. Therefore a NULL callback is registers.
	 *  This disables the two interrupts
	 */
	timerA_register_cb(TIMERA_ALARM_CCR0, callback0);
	timerA_register_cb(TIMERA_ALARM_CCR1, callback1);
	timerA_register_cb(TIMERA_ALARM_CCR2, 0);
	timerA_register_cb(TIMERA_ALARM_OVER, 0);

	/** Alarm periods definition
	 *  Alarm 0 is triggered every 32768 ticks (i.e. every 1s as ACLK is 32768Hz
	 *  on WSN430). Its first call will happen 1 tick after the routine call.
	 *  Alarm 1 is triggered every 16384 ticks (i.e. every 500ms). Its first call
	 *  will happen 10 ticks after the routine call.
	 */
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 1, 32768); 
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR1, 10, 16384); 

	/** Timer start
	 *  Starts the timer with a frequency of ACK/TIMERA_DIV_1, i.e. 32768Hz
	 */
	timerA_start_ACLK_div(TIMERA_DIV_1);

	// Main loop
	while (1) 
	{
		// Put the processor in low power mode (only ACLK is active)
		LPM3;
		// Toggles the blue LED and go back to LPM
		toggle_led(2);
	}

	return 0;
}
예제 #2
0
파일: main.c 프로젝트: saveriob/RandSync
int main( void )
{

	// Stop the watchdog timer.
	WDTCTL = WDTPW + WDTHOLD;
    
	// Clock settings
	set_mcu_speed_xt2_mclk_8MHz_smclk_8MHz();	// used by CDMA
	set_aclk_div(1); // ACKL is at 32768Hz		// used for clock synchronization
    
	// Initialize the UART0
	uart0_init(UART0_CONFIG_8MHZ_115200);	// 115kbaud, SMCLK is at 8MHz
	uart0_register_callback(char_rx);	// Set the UART callback function

	// Initialize random number
	ds2411_init();
	rnd = (((uint16_t)ds2411_id.serial0) << 8) + (uint16_t)ds2411_id.serial1;

	// Timer settings
	time_1w = 0;
	timerA_init();
	timerA_start_ACLK_div(TIMERA_DIV_1);			// timerA period = 2s
	timerA_register_cb(TIMERA_ALARM_OVER, timer_overflow);	// timerA overflow event
	timerA_register_cb(TIMERA_ALARM_CCR0, run_algorithm);	// run algorithm at CCR0
	timerA_register_cb(TIMERA_ALARM_CCR1, skew_correction); // compensate skew error at CCR1
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, rnd, 54983);	// same period 1.678s, different phase
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR1, 35000, skew);	// skew compensation happens every 'skew' ticks

	// Initialize the MAC layer (radio)
	mac_init(11);
	mac_set_rx_cb(frame_rx);
	mac_set_error_cb(frame_error);
	mac_set_sent_cb(frame_sent);

	// Enable Interrupts
	eint();
    
 	while (1) {
	}

	return 0;
}
예제 #3
0
파일: main.c 프로젝트: EDAyele/wsn430
/**
 * The main function.
 */
int main( void )
{
    /* Stop the watchdog timer */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup the MSP430 micro-controller clock frequency: MCLK, SMCLK and ACLK */

    /* Set MCLK at 8MHz and SMCLK at 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	/* Set ACKL at 4096Hz (32 768Hz / 8) */
    set_aclk_div(8);

    /* Initialize the LEDs */
    LEDS_INIT();
    LEDS_OFF();

    /* Initialize the temperature sensor */
    ds1722_init();
    ds1722_set_res(12);
    ds1722_sample_cont();

    /* Initialize the Luminosity sensor */
    tsl2550_init();
    tsl2550_powerup();
    tsl2550_set_standard();
    tsl2550_read_adc0();

    /* Initialize the UART0 */

	/* We want 115kbaud, and SMCLK is running at 1MHz */
    uart0_init(UART0_CONFIG_1MHZ_115200);

	/* Set the UART callback function it will be called every time a character is received. */
    uart0_register_callback(char_rx);

    /* Print first message */
    printf("\n\nSenslab Simple Demo program\n");

    /* Enable Interrupts */
    eint();

    /* Print information */
    printf("Type command\n");
    printf("\tt:\ttemperature measure\n");
    printf("\tl:\tluminosity measure\n");

    /* Initialize the timer for the LEDs */
    timerA_init();

	/*  TimerA clock is at 512Hz (4096Hz / 8) */
    timerA_start_ACLK_div(TIMERA_DIV_8);

    /* Configure the first timerA period to 1s (periodic) */
    timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 512, 512);

	/* Set the first timerA callback */
    timerA_register_cb(TIMERA_ALARM_CCR0, alarm);

    // Declare 2 variables for storing the different values
    int16_t value_0=0, value_1=1;
    while (1) {
        printf("cmd > ");
        cmd = 0;

        while (cmd==0) {
            LPM0; // Low Power Mode 1: SMCLK remains active for UART
        }

        switch (cmd) {
        case 't':
            value_0 = ds1722_read_MSB();
            value_1 = ds1722_read_LSB();
            value_1 >>= 5;
            value_1 *= 125;
            printf("Temperature measure: %i.%i\n", value_0, value_1);
            break;
        case 'l':
            tsl2550_init();
            value_0 = tsl2550_read_adc0();
            value_1 = tsl2550_read_adc1();
            uart0_init(UART0_CONFIG_1MHZ_115200);
            uart0_register_callback(char_rx);
            printf("Luminosity measure: %i:%i\n", value_0, value_1);
            break;
        default:
            break;
        }
    }

    return 0;
}