Example #1
0
void tdma_error(void)
{
    static uint16_t debounce;

    debounce++;
    if(debounce>50) debounce=50;
    if(debounce==50 )
    {
        if((PIND & 0x1) == 0 )
        {
            debounce=0;
            if(socket_0_active==1)
            {
                plug_led_green_clr();
                power_socket_disable(0);
            }
            else
            {
                plug_led_green_set();
                power_socket_enable(0);
            }

        }

    }
    if(tdma_sync_ok()==0) plug_led_red_set();
    else plug_led_red_clr();


}
Example #2
0
// This function gets called in a loop if sync is lost.
// It is passed a counter indicating how long it has gone since the last synchronization.
int8_t tdma_error(uint16_t cons_error_cnt)
{

// TDMA error handler just controls the LED in this case.
// Button is still handled by interrupt
    if(tdma_sync_ok()==0) plug_led_red_set();
    else plug_led_red_clr();
// Return NRK_OK to force the error counter to be reset
    return NRK_ERROR;
}
Example #3
0
void io_task()
{

    DDRD=0;
    while(cal_done==0) nrk_wait_until_next_period();

    // Crappy polling IO task that reads the button to toggle the outlet
    while(1) {
        if(tdma_sync_ok()==0) plug_led_red_set();
        else plug_led_red_clr();

        if((PIND & 0x1) == 0 )
        {

            if(socket_0_active==1)
            {
                plug_led_green_clr();
                power_socket_disable(0);
            }
            else
            {
                plug_led_green_set();
                power_socket_enable(0);
            }

            // After press, wait until user lets go
            do {
                nrk_wait_until_next_period();
            } while((PIND & 0x1) == 0 );

        }
        nrk_wait_until_next_period();

    }



}
Example #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();
    }
Example #5
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);
    }