Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
int main ()
{
    watchdog_stop();

    set_mcu_speed_dco_mclk_16MHz_smclk_8MHz(); // set global clock

    /* Initialisation begin */
    leds_init();	// leds :')
    spi_init();	//
    cc2500_init();	// radio init
    #if defined(USER_RFCONFIG)
    cc2500_configure(& USER_RFCONFIG );
    #endif

    timerA_init(); // global timer
    timerA_register_cb(&timer_tick_cb); // protothread timer increment callback
    timerA_start_milliseconds(TIMER_PERIOD_MS);

    uart_init(UART_9600_SMCLK_8MHZ); // serial link

    printf("adc test application: temperature\n\n");

    adc10_start(); // temperature sensor

    __enable_interrupt();
        
    /* Initialisation end */

    while(1)
    {
        thread_periodic_capture(&pt[0]);
        thread_periodic_radio(&pt[1]);
        //do something
    }

    return 0;
}
Exemple #4
0
/**
 * 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;
}
Exemple #5
0
int main(void)
{
    watchdog_stop();

    TIMER_ID_INPUT = UINT_MAX;
    node_id = NODE_ID_UNDEFINED;

    /* protothreads init */
    int i;
    for(i = 0; i < NUM_PT; i++)
    {
        PT_INIT(&pt[i]);
    }

    /* clock init */
    set_mcu_speed_dco_mclk_16MHz_smclk_8MHz();

    /* LEDs init */
    leds_init();
    led_red_on();
    led_green_flag = 0;

    /* timer init */
    timerA_init();
    timerA_register_cb(&timer_tick_cb);
    timerA_start_milliseconds(TIMER_PERIOD_MS);

    /* button init */
    button_init();
    button_register_cb(button_pressed_cb);
    antibouncing_flag = 0;
    button_pressed_flag = 0;

    /* UART init (serial link) */
    uart_init(UART_9600_SMCLK_8MHZ);
    uart_register_cb(uart_cb);
    uart_flag = 0;
    uart_data = 0;

    /* ADC10 init (temperature) */
    adc10_start();

    /* radio init */
    spi_init();
    cc2500_init();
    cc2500_rx_register_buffer(radio_tx_buffer, PKTLEN);
    cc2500_rx_register_cb(radio_cb);
    cc2500_rx_enter();
    radio_rx_flag = 0;

    /* retrieve node id from flash */
    node_id = *((char *) NODE_ID_LOCATION);
    //printf("node id retrieved from flash: %d\r\n", node_id);

    button_enable_interrupt();
    __enable_interrupt();

    /* simple cycle scheduling */
    while(1) {
        /*thread_led_red(&pt[0]);
        thread_led_green(&pt[1]);
        thread_uart(&pt[2]);
        thread_antibouncing(&pt[3]);*/
        thread_process_msg(&pt[4]);
        thread_periodic_send(&pt[5]);
        /*thread_button(&pt[6]);*/
    }
}