Ejemplo n.º 1
0
int main ()
{
    uint8_t ds;
    nrk_setup_ports ();
    nrk_setup_uart (UART_BAUDRATE_115K2);


    ds=nrk_eeprom_read_byte(EEPROM_SLEEP_STATE_ADDR);
    if(ds==1) deep_sleep_button();

    nrk_init ();

    nrk_led_clr (0);
    nrk_led_clr (1);
    nrk_led_clr (2);
    nrk_led_clr (3);

    nrk_time_set (0, 0);

    tdma_set_error_callback(&tdma_error);
    tdma_task_config();

    nrk_register_drivers();
    nrk_create_taskset ();
    nrk_start ();

    return 0;
}
Ejemplo n.º 2
0
int main ()
{
    uint16_t div;

    nrk_int_disable();
    // Configure relay port directions
    DDRE |= 0x10;
    socket_0_enable();
    // Configure led port directions
    DDRE |= 0x0c;
    DDRD |= 0x00;
    PORTD |= 0xff;
    DDRF = 0;

    socket_0_active=nrk_eeprom_read_byte(EEPROM_STATE_ADDR);
    // turn outlet on if active or throttled for testing
    if(socket_0_active==1 || socket_0_active==2)
    {
        socket_0_enable();
        plug_led_green_set();
    } else
    {
        socket_0_disable();
        plug_led_green_clr();
    }
    // If PUD value set, then we expect it wasn't a clean reboot (unexpected restart).
    // Try to force a proper watchdog reboot
    if((MCUCR&0x10)!=0 )
    {
        //nrk_watchdog_enable();
        nrk_int_disable();
        MCUSR &= ~(1<<WDRF);
        WDTCSR |= (1<<WDCE) | (1<<WDE);
        WDTCSR = (1<<WDE) | (1<<WDP2) | (1<<WDP0);

        // Disable interrupts to stop pending timers etc
        while(1);
    }

    nrk_setup_uart (UART_BAUDRATE_115K2);

    MCUCR |= BM(PUD);

    nrk_init ();
    nrk_time_set (0, 0);

    tdma_set_error_callback(&tdma_error);
    tdma_task_config();

    nrk_create_taskset ();
    nrk_start ();

    return 0;
}
Ejemplo n.º 3
0
int main ()
{
    uint16_t div;

    // Configure relay port directions
    DDRE |= 0x10;
    socket_0_enable();
    // Configure led port directions
    DDRE |= 0x0c;
    DDRD |= 0x00;
    PORTD |= 0xff;
    DDRF = 0;

    socket_0_active=nrk_eeprom_read_byte(EEPROM_STATE_ADDR);
    if(socket_0_active==1)
    {
        socket_0_enable();
        plug_led_green_set();
    } else
    {
        socket_0_disable();
        plug_led_green_clr();
    }

    MCUCR |= BM(PUD);

    nrk_setup_uart (UART_BAUDRATE_115K2);

    nrk_init ();

    nrk_time_set (0, 0);

    tdma_set_error_callback(&tdma_error);
    tdma_task_config();

    nrk_create_taskset ();
    nrk_start ();

    return 0;
}
Ejemplo n.º 4
0
void tx_task ()
{
    uint8_t j, i, val, cnt;
    int8_t len;
    int8_t v;
    nrk_sig_t tx_done_signal;
    nrk_sig_mask_t ret;


    send_ack=0;
    cal_done=0;
    printf ("tx_task PID=%d\r\n", nrk_get_pid ());

    // Wait until the tx_task starts up bmac
    // This should be called by all tasks using bmac that


    power_init ();

#ifndef DISABLE_BUTTON
    nrk_gpio_direction(NRK_BUTTON,NRK_PIN_INPUT );
    nrk_ext_int_configure(NRK_EXT_INT_0, NRK_FALLING_EDGE, &button_handler );
    nrk_ext_int_enable(NRK_EXT_INT_0);
#endif

    v_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_V_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_V_LSB_ADDR);
    c_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C1_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C1_LSB_ADDR);
    c2_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C2_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C2_LSB_ADDR);


    if(((PIND & 0x1) == 0) || (v_center==0xffff) || (v_center==0x0) )
    {
        // Get v_center and c_centers enough to grab calibration values
        v_center=512;
        c_center=512;
        c2_center=512;
        power_socket_enable(0);
        socket_0_disable();

        plug_led_green_clr();
        plug_led_red_clr();
        for(i=0; i<3; i++ ) {
            plug_led_green_set();
            nrk_wait_until_next_period();
            plug_led_green_clr();
            nrk_wait_until_next_period();
        }
        plug_led_green_clr();
        plug_led_red_clr();
        for(i=0; i<5; i++ )
            nrk_wait_until_next_period();

        v_center=(v_p2p_high+v_p2p_low)/2;
        c_center=(c_p2p_high+c_p2p_low)/2;
        c2_center=(c_p2p_high2+c_p2p_low2)/2;
        nrk_eeprom_write_byte(EEPROM_CAL_V_MSB_ADDR, (uint8_t)(v_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_V_LSB_ADDR, (uint8_t)v_center&0xff);
        nrk_eeprom_write_byte(EEPROM_CAL_C1_MSB_ADDR, (uint8_t)(c_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_C1_LSB_ADDR, (uint8_t)c_center&0xff);
        nrk_eeprom_write_byte(EEPROM_CAL_C2_MSB_ADDR, (uint8_t)(c2_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_C2_LSB_ADDR, (uint8_t)c2_center&0xff);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_0_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_1_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_2_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_3_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_4_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_5_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_6_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_7_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_0_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_1_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_2_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_3_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_4_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_5_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_6_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_7_ADDR, 0);
        //plug_led_green_set();
        //socket_0_enable();
        //power_socket_enable(0);


        // Set default power threshold
        set_power_thresh(DEFAULT_POWER_THRESH);
        power_socket_disable(0);
        socket_0_disable();
    }
Ejemplo n.º 5
0
        nrk_eeprom_write_byte(EEPROM_ENERGY2_3_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_4_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_5_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_6_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_7_ADDR, 0);
        //plug_led_green_set();
        //socket_0_enable();
        //power_socket_enable(0);


        // Set default power threshold
        set_power_thresh(DEFAULT_POWER_THRESH);
        power_socket_disable(0);
        socket_0_disable();
    }
    cummulative_energy.byte[0]=nrk_eeprom_read_byte(EEPROM_ENERGY1_0_ADDR);
    cummulative_energy.byte[1]=nrk_eeprom_read_byte(EEPROM_ENERGY1_1_ADDR);
    cummulative_energy.byte[2]=nrk_eeprom_read_byte(EEPROM_ENERGY1_2_ADDR);
    cummulative_energy.byte[3]=nrk_eeprom_read_byte(EEPROM_ENERGY1_3_ADDR);
    cummulative_energy.byte[4]=nrk_eeprom_read_byte(EEPROM_ENERGY1_4_ADDR);
    cummulative_energy.byte[5]=nrk_eeprom_read_byte(EEPROM_ENERGY1_5_ADDR);
    cummulative_energy.byte[6]=nrk_eeprom_read_byte(EEPROM_ENERGY1_6_ADDR);
    cummulative_energy.byte[7]=nrk_eeprom_read_byte(EEPROM_ENERGY1_7_ADDR);
    cummulative_energy2.byte[0]=nrk_eeprom_read_byte(EEPROM_ENERGY2_0_ADDR);
    cummulative_energy2.byte[1]=nrk_eeprom_read_byte(EEPROM_ENERGY2_1_ADDR);
    cummulative_energy2.byte[2]=nrk_eeprom_read_byte(EEPROM_ENERGY2_2_ADDR);
    cummulative_energy2.byte[3]=nrk_eeprom_read_byte(EEPROM_ENERGY2_3_ADDR);
    cummulative_energy2.byte[4]=nrk_eeprom_read_byte(EEPROM_ENERGY2_4_ADDR);
    cummulative_energy2.byte[5]=nrk_eeprom_read_byte(EEPROM_ENERGY2_5_ADDR);
    cummulative_energy2.byte[6]=nrk_eeprom_read_byte(EEPROM_ENERGY2_6_ADDR);
    cummulative_energy2.byte[7]=nrk_eeprom_read_byte(EEPROM_ENERGY2_7_ADDR);
Ejemplo n.º 6
0
void tx_task ()
{
    uint8_t j, i, val, cnt;
    int8_t len;
    int8_t v;
    nrk_sig_t tx_done_signal;
    nrk_sig_mask_t ret;


    cal_done=0;
    printf ("tx_task PID=%d\r\n", nrk_get_pid ());

    // Wait until the tx_task starts up bmac
    // This should be called by all tasks using bmac that


    power_init ();



    v_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_V_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_V_LSB_ADDR);
    c_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C1_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C1_LSB_ADDR);
    c2_center=((uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C2_MSB_ADDR))<<8 | (uint16_t)nrk_eeprom_read_byte(EEPROM_CAL_C2_LSB_ADDR);


    if(((PIND & 0x1) == 0) || (v_center==0xffff) || (v_center==0x0) )
    {
        // Get v_center and c_centers enough to grab calibration values
        v_center=512;
        c_center=512;
        c2_center=512;
        power_socket_enable(0);
        socket_0_disable();

        plug_led_green_clr();
        plug_led_red_clr();
        for(i=0; i<3; i++ ) {
            plug_led_green_set();
            nrk_wait_until_next_period();
            plug_led_green_clr();
            nrk_wait_until_next_period();
        }
        plug_led_green_clr();
        plug_led_red_clr();
        for(i=0; i<5; i++ )
            nrk_wait_until_next_period();

        v_center=(v_p2p_high+v_p2p_low)/2;
        c_center=(c_p2p_high+c_p2p_low)/2;
        c2_center=(c_p2p_high2+c_p2p_low2)/2;
        nrk_eeprom_write_byte(EEPROM_CAL_V_MSB_ADDR, (uint8_t)(v_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_V_LSB_ADDR, (uint8_t)v_center&0xff);
        nrk_eeprom_write_byte(EEPROM_CAL_C1_MSB_ADDR, (uint8_t)(c_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_C1_LSB_ADDR, (uint8_t)c_center&0xff);
        nrk_eeprom_write_byte(EEPROM_CAL_C2_MSB_ADDR, (uint8_t)(c2_center>>8));
        nrk_eeprom_write_byte(EEPROM_CAL_C2_LSB_ADDR, (uint8_t)c2_center&0xff);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_0_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_1_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_2_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_3_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_4_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_5_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_6_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY1_7_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_0_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_1_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_2_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_3_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_4_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_5_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_6_ADDR, 0);
        nrk_eeprom_write_byte(EEPROM_ENERGY2_7_ADDR, 0);
        plug_led_green_set();
        socket_0_enable();
        power_socket_enable(0);
    }
Ejemplo n.º 7
0
     nrk_eeprom_write_byte(EEPROM_ENERGY1_5_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY1_6_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY1_7_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_0_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_1_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_2_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_3_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_4_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_5_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_6_ADDR, 0);
     nrk_eeprom_write_byte(EEPROM_ENERGY2_7_ADDR, 0);
     plug_led_green_set();
     socket_0_enable();
     power_socket_enable(0);
 }
 cummulative_energy.byte[0]=nrk_eeprom_read_byte(EEPROM_ENERGY1_0_ADDR);
 cummulative_energy.byte[1]=nrk_eeprom_read_byte(EEPROM_ENERGY1_1_ADDR);
 cummulative_energy.byte[2]=nrk_eeprom_read_byte(EEPROM_ENERGY1_2_ADDR);
 cummulative_energy.byte[3]=nrk_eeprom_read_byte(EEPROM_ENERGY1_3_ADDR);
 cummulative_energy.byte[4]=nrk_eeprom_read_byte(EEPROM_ENERGY1_4_ADDR);
 cummulative_energy.byte[5]=nrk_eeprom_read_byte(EEPROM_ENERGY1_5_ADDR);
 cummulative_energy.byte[6]=nrk_eeprom_read_byte(EEPROM_ENERGY1_6_ADDR);
 cummulative_energy.byte[7]=nrk_eeprom_read_byte(EEPROM_ENERGY1_7_ADDR);
 cummulative_energy2.byte[0]=nrk_eeprom_read_byte(EEPROM_ENERGY2_0_ADDR);
 cummulative_energy2.byte[1]=nrk_eeprom_read_byte(EEPROM_ENERGY2_1_ADDR);
 cummulative_energy2.byte[2]=nrk_eeprom_read_byte(EEPROM_ENERGY2_2_ADDR);
 cummulative_energy2.byte[3]=nrk_eeprom_read_byte(EEPROM_ENERGY2_3_ADDR);
 cummulative_energy2.byte[4]=nrk_eeprom_read_byte(EEPROM_ENERGY2_4_ADDR);
 cummulative_energy2.byte[5]=nrk_eeprom_read_byte(EEPROM_ENERGY2_5_ADDR);
 cummulative_energy2.byte[6]=nrk_eeprom_read_byte(EEPROM_ENERGY2_6_ADDR);
 cummulative_energy2.byte[7]=nrk_eeprom_read_byte(EEPROM_ENERGY2_7_ADDR);