Ejemplo n.º 1
0
/**@brief Timer callback used for controlling board LEDs to represent application state.
 *
 */
static void blink_timeout_handler(iot_timer_time_in_ms_t wall_clock_value)
{
    UNUSED_PARAMETER(wall_clock_value);

    switch (m_display_state)
    {
        case LEDS_INACTIVE:
        {
            LEDS_OFF((LED_ONE | LED_TWO));
            break;
        }
        case LEDS_BLE_ADVERTISING:
        {
            LEDS_INVERT(LED_ONE);
            LEDS_OFF(LED_TWO);
            break;
        }
        case LEDS_IPV6_IF_DOWN:
        {
            LEDS_ON(LED_ONE);
            LEDS_INVERT(LED_TWO);
            break;
        }
        case LEDS_IPV6_IF_UP:
        {
            LEDS_OFF(LED_ONE);
            LEDS_ON(LED_TWO);
            break;
        }
        default:
        {
            break;
        }
    }
}
Ejemplo n.º 2
0
static void coap_response_handler(uint32_t status, void * arg, coap_message_t * p_response)
{
    if (status == NRF_SUCCESS)
    {
        if (coap_message_opt_present(p_response, COAP_OPT_OBSERVE) == NRF_SUCCESS)
        {
            // It is an notification or result of a GET response
            LEDS_ON(LED_FOUR);
        }
        else
        {
            LEDS_OFF(LED_FOUR);
        }


        APPL_LOG("[APPL]: Response Code : %d\r\n", p_response->header.code);
        if (p_response->header.code == COAP_CODE_205_CONTENT)
        {
            switch (p_response->p_payload[0])
            {
                case STATUS_ON:
                    LEDS_ON(LED_THREE);
                    break;

                case STATUS_OFF:
                    LEDS_OFF(LED_THREE);
                    break;

                default:
                    break;
            }
        }
    }
}
Ejemplo n.º 3
0
void gptimer1_handler(int id) {
	uint32_t irq = reg32r(GPTIMER1_BASE, GPT_TISR);

	{
		static int blink = 0;

		if (blink & (1<<2)) {
			LEDS_OFF(LED0);
			LEDS_ON(LED1);
		} else {
			LEDS_ON(LED0);
			LEDS_OFF(LED1);
		}
		blink++;
	}

	// check for overflow int
	if (irq & OVF_IT_FLAG) {
		Remove(&thistask->Node);
		AddTail(&tasks, &thistask->Node);

		thistask = (struct task *)tasks.Head;
		irq_new_task(tcb_to_sp(&thistask->tcb));
	}

	// clear ints
	reg32w(GPTIMER1_BASE, GPT_TISR, ~0);
}
Ejemplo n.º 4
0
/**@brief Timer callback used for controlling board LEDs to represent application state.
 *
 */
static void blink_timeout_handler(iot_timer_time_in_ms_t wall_clock_value)
{
    UNUSED_PARAMETER(wall_clock_value);

#ifdef COMMISSIONING_ENABLED
    static bool id_mode_previously_enabled;
#endif // COMMISSIONING_ENABLED

    switch (m_display_state)
    {
        case LEDS_INACTIVE:
        {
            LEDS_OFF((LED_ONE | LED_TWO));
            break;
        }
        case LEDS_CONNECTABLE_MODE:
        {
            LEDS_INVERT(LED_ONE);
            LEDS_OFF(LED_TWO);
            break;
        }
        case LEDS_IPV6_IF_DOWN:
        {
            LEDS_ON(LED_ONE);
            LEDS_INVERT(LED_TWO);
            break;
        }
        case LEDS_IPV6_IF_UP:
        {
            LEDS_OFF(LED_ONE);
            LEDS_ON(LED_TWO);
            break;
        }
        default:
        {
            break;
        }
    }

#ifdef COMMISSIONING_ENABLED
    if ((id_mode_previously_enabled == false) && (m_identity_mode_active == true))
    {
        LEDS_OFF(LED_THREE | LED_FOUR);
    }

    if ((id_mode_previously_enabled == true) && (m_identity_mode_active == true))
    {
        LEDS_INVERT(LED_THREE | LED_FOUR);
    }

    if ((id_mode_previously_enabled == true) && (m_identity_mode_active == false))
    {
        LEDS_OFF(LED_THREE | LED_FOUR);
    }

    id_mode_previously_enabled = m_identity_mode_active;
#endif // COMMISSIONING_ENABLED
}
Ejemplo n.º 5
0
/**@brief Timer callback used for controlling board LEDs to represent application state.
 *
 * @param[in]   p_context   Pointer used for passing context. No context used in this application.
 */
static void blink_timeout_handler(void * p_context)
{
    switch (m_display_state)
    {
        case LEDS_INACTIVE:
        {
            LEDS_OFF((LED_ONE | LED_TWO));
            break;
        }
        case LEDS_BLE_ADVERTISING:
        {
            LEDS_INVERT(LED_ONE);
            LEDS_OFF(LED_TWO);
            break;
        }
        case LEDS_IPV6_IF_DOWN:
        {
            LEDS_ON(LED_ONE);
            LEDS_INVERT(LED_TWO);
            break;
        }
        case LEDS_TX_ECHO_RESPONSE:
        {
            LEDS_ON(LED_ONE);
            LEDS_OFF(LED_TWO);
            break;
        }
        case LEDS_TX_UDP_PACKET:
        {
            LEDS_ON(LED_TWO);
            if (LED_IS_ON(LED_ONE) == 0)
            {
                if (m_udp_tx_occured)
                {
                    // If UDP transmission stops, LED_ONE should stop blinking in off state. 
                    LEDS_ON(LED_ONE);
                    m_udp_tx_occured = false;
                }
            }
            else
            {
                LEDS_OFF(LED_ONE);
            }

            break;
        }
        default:
        {
            break;
        }
    }
}
Ejemplo n.º 6
0
/**@brief Timer callback used for controlling board LEDs to represent application state.
 *
 */
static void blink_timeout_handler(iot_timer_time_in_ms_t wall_clock_value)
{
    UNUSED_PARAMETER(wall_clock_value);

    switch (m_display_state)
    {
        case LEDS_INACTIVE:
        {
            LEDS_OFF(ALL_APP_LED);
            break;
        }
        case LEDS_BLE_ADVERTISING:
        {
            LEDS_INVERT(LED_ONE);
            LEDS_OFF((LED_TWO | LED_THREE | LED_FOUR));
            break;
        }
        case LEDS_IPV6_IF_DOWN:
        {
            LEDS_INVERT(LED_TWO);
            LEDS_OFF((LED_ONE | LED_THREE | LED_FOUR));
            break;
        }
        case LEDS_IPV6_IF_UP:
        {
            LEDS_ON(LED_ONE);
            LEDS_OFF((LED_TWO | LED_THREE | LED_FOUR));
            break;
        }
        case LEDS_CONNECTED_TO_BROKER:
        {
            LEDS_ON(LED_TWO);
            LEDS_OFF((LED_ONE | LED_THREE | LED_FOUR));
            m_display_state = LEDS_PUBLISHING;
            break;
        }
        case LEDS_PUBLISHING:
        {
            LEDS_OFF(LED_ONE);
            LEDS_ON(LED_TWO);
            break;
        }
        default:
        {
            break;
        }
    }
}
Ejemplo n.º 7
0
/**@brief Publishes LED state to MQTT broker.
 *
 * @param[in]   led_state   LED state being published.
 */
static void app_mqtt_publish(bool led_state)
{
    mqtt_topic_t topic;
    mqtt_data_t  data;

    char topic_desc[] = "led/state";

    topic.p_topic = (uint8_t *)topic_desc;
    topic.topic_len = strlen(topic_desc);

    data.data_len = 1;
    data.p_data = (uint8_t *)&led_state;

    uint32_t err_code = mqtt_publish(&m_app_mqtt_id,&topic, &data);
    APPL_LOG("[APPL]: mqtt_publish result 0x%08lx\r\n", err_code);
    if (err_code == MQTT_SUCCESS)
    {
        LEDS_INVERT(LED_FOUR);
        m_led_state = !m_led_state;
    }
    else
    {
        // Flash LED_THREE if error occurs.
        LEDS_ON(LED_THREE);
        err_code = app_timer_start(m_led_blink_timer, LED_BLINK_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    }
}
Ejemplo n.º 8
0
static void nfc_callback(void * p_context, nfc_t2t_event_t event, const uint8_t * p_data, size_t data_length)
{
    (void) p_context;
    uint32_t err_code;

    switch (event)
    {
        case NFC_T2T_EVENT_FIELD_ON:
        {
            NRF_LOG_INFO("NFC_EVENT_FIELD_ON\r\n");
            LEDS_ON(BSP_LED_3_MASK);
            /* Start advertising to become connectable. */
            if (!m_advertising_flag)
            {
                m_advertising_flag  = 1;
                advertising_enable();
                err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
                APP_ERROR_CHECK(err_code);
            }
        }
        break;

        case NFC_T2T_EVENT_FIELD_OFF:
            NRF_LOG_INFO("NFC_EVENT_FIELD_OFF\r\n");
            LEDS_OFF(BSP_LED_3_MASK);
            break;

        default:
            break;
    }
    return;
}
Ejemplo n.º 9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(wget_process, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("wget: fetching %s\n", file);
#if STATS
  fetch_counter = 0;
  fetch_started = clock_time();
#endif /* STATS */
  LEDS_ON(LEDS_YELLOW);
  if(webclient_get(server, port, file) == 0) {
    PRINTF("wget: failed to connect\n");
    LEDS_OFF(LEDS_YELLOW);
    fetch_running = 0;
    call_done(WGET_CONNECT_FAILED);
  } else {
    while(fetch_running) {
      PROCESS_WAIT_EVENT();
      if(ev == tcpip_event) {
        webclient_appcall(data);
      }
    }
  }

  PROCESS_END();
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: IOIOI/nRF51
/**@brief Function for error handling, which demonstrates usage of the ANT debug
 * module to output debug information over the debug channel on an assertion
 *
 * @param[in] error_code  Error code supplied to the handler.
 * @param[in] line_num    Line number where the handler is called.
 * @param[in] p_file_name Pointer to the file name.
 */
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
    #if defined(INCLUDE_DEBUG_CHANNEL)
    error_info_t * p_error_info = (error_info_t *)info;
    char     file_name[2];
    uint32_t file_name_len = strlen((char *)p_error_info->p_file_name);

    file_name[0] = '\0';
    file_name[1] = '\0';

    for (uint32_t i = 0; i < file_name_len; i++)
    {
        if ((p_error_info->p_file_name[i] != '.')
         && (p_error_info->p_file_name[i] != '/')
         && (p_error_info->p_file_name[i] != '\\'))
        {
            file_name[0] = p_error_info->p_file_name[i + 1];
            file_name[1] = p_error_info->p_file_name[i];
            break;
        }
    }

    ad_force_error_page((uint8_t)p_error_info->err_code, (uint16_t)p_error_info->line_num, file_name);
    #endif

    LEDS_ON(LEDS_MASK);

    for (;;)
    {
        // No implementation needed.
    }
}
Ejemplo n.º 11
0
void vBlinkerRequest(uint8_t cmd)
{
    switch (cmd & CMD_MASK)
    {
        case CMD_LED_ON:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_ON();
                    break;
                case LED_GREEN:
                    LED_GREEN_ON();
                    break;
                case LED_BLUE:
                    LED_BLUE_ON();
                    break;
                case LED_ALL:
                    LEDS_ON();
                    break;
            }
            break;

        case CMD_LED_OFF:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_OFF();
                    break;
                case LED_GREEN:
                    LED_GREEN_OFF();
                    break;
                case LED_BLUE:
                    LED_BLUE_OFF();
                    break;
                case LED_ALL:
                    LEDS_OFF();
                    break;
            }
            break;
        case CMD_LED_TOGGLE:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_TOGGLE();
                    break;
                case LED_GREEN:
                    LED_GREEN_TOGGLE();
                    break;
                case LED_BLUE:
                    LED_BLUE_TOGGLE();
                    break;
                case LED_ALL:
                    LED_RED_TOGGLE();
                    LED_GREEN_TOGGLE();
                    LED_BLUE_TOGGLE();
                    break;
            }
            break;
    }
}
Ejemplo n.º 12
0
int main(void) 
{
    int i;

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    uart0_init(UART0_CONFIG_1MHZ_115200);

    LEDS_INIT();
    LEDS_ON();
    delay(DELAY);
    LEDS_OFF();

    led_state = 0;

    while (1) 
    {
        for (i=0; i<99; i++)
        {
            printf("Salam Aleikoum\n");
            uart0_getchar_polling();
            led_change();
        }
    }
}
/*---------------------------------------------------------------------------*/
int
cc2420_off(void)
{
  /* Don't do anything if we are already turned off. */
  if(receive_on == 0) {
    return 1;
  }

  /* If we are called when the driver is locked, we indicate that the
     radio should be turned off when the lock is unlocked. */
  if(locked) {
    /*    printf("Off when locked (%d)\n", locked);*/
    LEDS_ON(LEDS_GREEN + LEDS_BLUE);
    lock_off = 1;
    return 1;
  }

  GET_LOCK();
  /* If we are currently receiving a packet (indicated by SFD == 1),
     we don't actually switch the radio off now, but signal that the
     driver should switch off the radio once the packet has been
     received and processed, by setting the 'lock_off' variable. */
  if(status() & BV(CC2420_TX_ACTIVE)) {
    lock_off = 1;
  } else {
    off();
  }
  RELEASE_LOCK();
  return 1;
}
Ejemplo n.º 14
0
Archivo: main.c Proyecto: IOIOI/nRF51
/**@brief Function for application main entry. Does not return.
 */ 
int main(void)
{

    utils_setup();
    softdevice_setup();
    ant_channel_tx_broadcast_setup();

    // Main loop. 
    for (;;)
    {
#ifdef CPU_LOAD_TRACE
        // Disabling interrupts in this way is highly not recommended. It has an impact on the work
        // of the softdecive and it is used only in order to show CPU load.
        __disable_irq();
        LEDS_OFF(BSP_LED_0_MASK);
        __WFI();
        LEDS_ON(BSP_LED_0_MASK);
        __enable_irq();
#else
        // Put CPU in sleep if possible. 
        uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
#endif // CPU_LOAD_TRACE
    }
}
Ejemplo n.º 15
0
/**@brief Function for toggling LEDS based on received notifications.
 *
 * @param[in] p_ble_evt Event to handle.
 */
static void on_evt_hvx(ble_evt_t * p_ble_evt, client_t * p_client, uint32_t index)
{
    if ((p_client != NULL) && (p_client->state == STATE_RUNNING))
    {
        if (
                (
                        p_ble_evt->evt.gattc_evt.params.hvx.handle
                        ==
                                p_client->srv_db.services[0].charateristics[p_client->char_index].characteristic.handle_value
                )
                &&
                (p_ble_evt->evt.gattc_evt.params.hvx.len == 1)
        )
        {
            if(index < LEDS_NUMBER)
            {
                uint8_t leds[] = LEDS_LIST;

                if (p_ble_evt->evt.gattc_evt.params.hvx.data[0] == 0)
                {
                    LEDS_OFF(1<<leds[index]);
                }
                else
                {
                    LEDS_ON(1<<leds[index]);
                }
            }
        }
    }
}
Ejemplo n.º 16
0
/**@brief Function for error handling, which is called when an error has occurred.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 *          how your product is supposed to react in case of error.
 *
 * @param[in] error_code  Error code supplied to the handler.
 * @param[in] line_num    Line number where the handler is called.
 * @param[in] p_file_name Pointer to the file name.
 */
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
    LEDS_ON((LED_ONE | LED_TWO | LED_THREE | LED_FOUR));
    APPL_LOG("[** ASSERT **]: Error 0x%08lX, Line %ld, File %s\r\n", error_code, line_num, p_file_name);

    // Variables used to retain function parameter values when debugging.
    static volatile uint8_t  s_file_name[MAX_LENGTH_FILENAME];
    static volatile uint16_t s_line_num;
    static volatile uint32_t s_error_code;

    strncpy((char *)s_file_name, (const char *)p_file_name, MAX_LENGTH_FILENAME - 1);
    s_file_name[MAX_LENGTH_FILENAME - 1] = '\0';
    s_line_num                           = line_num;
    s_error_code                         = error_code;
    UNUSED_VARIABLE(s_file_name);
    UNUSED_VARIABLE(s_line_num);
    UNUSED_VARIABLE(s_error_code);

    // This call can be used for debug purposes during application development.
    // @note CAUTION: Activating this code will write the stack to flash on an error.
    //                This function should NOT be used in a final product.
    //                It is intended STRICTLY for development/debugging purposes.
    //                The flash write will happen EVEN if the radio is active, thus interrupting
    //                any communication.
    //                Use with care. Un-comment the line below to use.
    // ble_debug_assert_handler(error_code, line_num, p_file_name);

    // On assert, the system can only recover on reset.
    //NVIC_SystemReset();

    for(;;)
    {
        // Infinite loop.
    }
}
static void lock_control_handler(ble_doorlock_t * p_doorlock, uint8_t state) 
{ 
    uint32_t             err_code;
    if (state) 
    { 
        // Open door
        LEDS_ON((BSP_LED_3_MASK));
        // Start timer
        if (m_lock_timer_id != 0xFFFFFFFF) {
            err_code = app_timer_stop(m_lock_timer_id);
            APP_ERROR_CHECK(err_code);
        } else {
            err_code = app_timer_create(&m_lock_timer_id, 
                                        APP_TIMER_MODE_SINGLE_SHOT, 
                                        lock_timeout_handler); 
            APP_ERROR_CHECK(err_code); 
        }
        err_code = app_timer_start(m_lock_timer_id, APP_TIMER_TICKS(APP_CFG_CHAR_LOCK_TIMEOUT, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    } 
    else 
    { 
        // Lock door
        LEDS_OFF((BSP_LED_3_MASK));
    } 
} 
Ejemplo n.º 18
0
int main(void)
{
    ret_code_t err_code;

    err_code = NRF_LOG_INIT();
    APP_ERROR_CHECK(err_code);
    NRF_LOG_PRINTF("[APP]: Multilink Example\r\n");
    leds_init();
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
    buttons_init();
    ble_stack_init();

    db_discovery_init();
    lbs_c_init();

    // Start scanning for peripherals and initiate connection to devices which
    // advertise.
    scan_start();

    // Turn on the LED to signal scanning.
    LEDS_ON(CENTRAL_SCANNING_LED);

    for (;;)
    {
        // Wait for BLE events.
        power_manage();
    }
}
Ejemplo n.º 19
0
int main(void) 
{
  int i;

  WDTCTL = WDTPW + WDTHOLD;

  P1IE   = 0x00;        // Interrupt enable
  P2IE   = 0x00;        // 0:disable 1:enable

  LEDS_INIT();
  LEDS_ON();
  delay(DELAY);
  LEDS_OFF();

  led_state = 0;

  while (1) 
    {                         
      for (i=0; i<99; i++)
	{
	  led_change();
	  delay(DELAY >> 2);
	}
    }
}
Ejemplo n.º 20
0
/**@brief Function for handling the Application's BLE Stack events.
 *
 * @param[in] p_ble_evt  Bluetooth stack event.
 */
static void on_ble_peripheral_evt(ble_evt_t * p_ble_evt)
{
    uint32_t err_code;

    switch (p_ble_evt->header.evt_id)
            {
        case BLE_GAP_EVT_CONNECTED:
            LEDS_OFF(PERIPHERAL_ADVERTISING_LED);
            LEDS_ON(PERIPHERAL_CONNECTED_LED);
            m_conn_handle_peripheral = p_ble_evt->evt.gap_evt.conn_handle;
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            LEDS_OFF(PERIPHERAL_CONNECTED_LED);
            m_conn_handle_peripheral = BLE_CONN_HANDLE_INVALID;
            break;

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle_peripheral, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle_peripheral, NULL, 0, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
            APP_ERROR_CHECK(err_code);
            break;
                
        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 21
0
/*lint -save -e14 */
__WEAK void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
    // On assert, the system can only recover with a reset.
#ifndef DEBUG
    NVIC_SystemReset();
#else
    
#ifdef BSP_DEFINES_ONLY 
    LEDS_ON(LEDS_MASK);
#else
    UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR));
    // This call can be used for debug purposes during application development.
    // @note CAUTION: Activating this code will write the stack to flash on an error.
    //                This function should NOT be used in a final product.
    //                It is intended STRICTLY for development/debugging purposes.
    //                The flash write will happen EVEN if the radio is active, thus interrupting
    //                any communication.
    //                Use with care. Uncomment the line below to use.
    //ble_debug_assert_handler(error_code, line_num, p_file_name);
#endif // BSP_DEFINES_ONLY

    m_error_code = error_code;
    m_line_num = line_num;
    m_p_file_name = p_file_name;

    UNUSED_VARIABLE(m_error_code);
    UNUSED_VARIABLE(m_line_num);
    UNUSED_VARIABLE(m_p_file_name);
    __disable_irq();
    while(1) ;
#endif // DEBUG
}
Ejemplo n.º 22
0
Archivo: main.c Proyecto: tkadom/TWBLE
int main(void)
{

    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    nrf_gpio_cfg_output(WAVE_ON_PIN_NUMBER); // on this pin 2Hz wave will be generated

#ifdef BSP_BUTTON_0
    // configure pull-up on first button
    nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP);
#endif

    APP_GPIOTE_INIT(1);

    uart_config();

    lpcomp_init();

    printf("\n\rLPCOMP driver usage example\r\n");

    while (true)
    {
        print_statistics();
        LEDS_ON(BSP_LED_1_MASK);
        NRF_GPIO->OUTCLR = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(100); // generate 100 ms pulse on selected pin
        print_statistics();
        LEDS_OFF(BSP_LED_1_MASK);
        NRF_GPIO->OUTSET = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(400);
    }
}
Ejemplo n.º 23
0
static void show_error(void)
{   
    LEDS_ON(LEDS_MASK);
    while(1)
    {
        // Do nothing.
    }
}
Ejemplo n.º 24
0
/**@brief Function for starting advertising.
 */
static void advertising_start(void)
{
    uint32_t err_code;

    err_code = sd_ble_gap_adv_start(&m_adv_params);
    APP_ERROR_CHECK(err_code);

    LEDS_ON(ADVERTISING_LED);
}
Ejemplo n.º 25
0
void set_led(int led, int value) {
	if (led < LEDS_NUMBER) {
		if (value) {
			LEDS_ON(1 << leds_list[led]);
		} else {
			LEDS_OFF(1 << leds_list[led]);
		}
	}
}
Ejemplo n.º 26
0
/*---------------------------------------------------------------------------*/
static void
on(void)
{
  if(xmac_is_on && radio_is_on == 0) {
    radio_is_on = 1;
    NETSTACK_RADIO.on();
    LEDS_ON(LEDS_RED);
  }
}
Ejemplo n.º 27
0
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
#ifdef DEBUG
    app_error_print(id, pc, info);
#endif

    LEDS_ON(LEDS_MASK);
    while(1);
}
Ejemplo n.º 28
0
/**@brief Function to start scanning.
 */
static void scan_start(void)
{
    ble_gap_whitelist_t   whitelist;
    ble_gap_addr_t      * p_whitelist_addr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
    ble_gap_irk_t       * p_whitelist_irk[BLE_GAP_WHITELIST_IRK_MAX_COUNT];
    uint32_t              err_code;
    uint32_t              count;

    // Verify if there is any flash access pending, if yes delay starting scanning until 
    // it's complete.
    err_code = pstorage_access_status_get(&count);
    APP_ERROR_CHECK(err_code);

    if (count != 0)
    {
        m_memory_access_in_progress = true;
        return;
    }

    // Initialize whitelist parameters.
    whitelist.addr_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
    whitelist.irk_count  = 0;
    whitelist.pp_addrs   = p_whitelist_addr;
    whitelist.pp_irks    = p_whitelist_irk;

    // Request creating of whitelist.
    err_code = dm_whitelist_create(&m_dm_app_id,&whitelist);
    APP_ERROR_CHECK(err_code);

    if (((whitelist.addr_count == 0) && (whitelist.irk_count == 0)) ||
        (m_scan_mode != BLE_WHITELIST_SCAN)                         ||
        (m_whitelist_temporarily_disabled))
    {
        // No devices in whitelist, hence non selective performed.
        m_scan_param.active       = 0;            // Active scanning set.
        m_scan_param.selective    = 0;            // Selective scanning not set.
        m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
        m_scan_param.window       = SCAN_WINDOW;  // Scan window.
        m_scan_param.p_whitelist  = NULL;         // No whitelist provided.
        m_scan_param.timeout      = 0x0000;       // No timeout.
    }
    else
    {
        // Selective scanning based on whitelist first.
        m_scan_param.active       = 0;            // Active scanning set.
        m_scan_param.selective    = 1;            // Selective scanning not set.
        m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
        m_scan_param.window       = SCAN_WINDOW;  // Scan window.
        m_scan_param.p_whitelist  = &whitelist;   // Provide whitelist.
        m_scan_param.timeout      = 0x001E;       // 30 seconds timeout.
    }

    err_code = sd_ble_gap_scan_start(&m_scan_param);
    APP_ERROR_CHECK(err_code);

    LEDS_ON(CENTRAL_SCANNING_LED);
}
Ejemplo n.º 29
0
/**@brief Function for starting connectable mode.
 */
static void connectable_mode_enter(void)
{
    uint32_t err_code = ipv6_medium_connectable_mode_enter(m_ipv6_medium.ipv6_medium_instance_id);
    APP_ERROR_CHECK(err_code);

    APPL_LOG("[APPL]: Physical layer in connectable mode.\r\n");
    LEDS_OFF(LED_TWO);
    LEDS_ON(LED_ONE);
}
Ejemplo n.º 30
0
/**@brief Timer callback used for controlling board LEDs to represent application state.
 *
 * @param[in]   p_context   Pointer used for passing context. No context used in this application.
 */
static void blink_timeout_handler(void * p_context)
{
    uint32_t err_code;
    switch (m_display_state)
    {
        case LEDS_INACTIVE:
        {
            LEDS_OFF(ALL_APP_LED);
            break;
        }
        case LEDS_BLE_ADVERTISING:
        {
            LEDS_INVERT(LED_ONE);
            LEDS_OFF((LED_TWO | LED_THREE | LED_FOUR));
            err_code = app_timer_start(m_led_blink_timer, LED_BLINK_INTERVAL, NULL);
            APP_ERROR_CHECK(err_code);
            break;
        }
        case LEDS_IPV6_IF_DOWN:
        {
            LEDS_INVERT(LED_TWO);
            LEDS_OFF((LED_ONE | LED_THREE | LED_FOUR));
            err_code = app_timer_start(m_led_blink_timer, LED_BLINK_INTERVAL, NULL);
            APP_ERROR_CHECK(err_code);
            break;
        }
        case LEDS_IPV6_IF_UP:
        {
            LEDS_ON(LED_ONE);
            LEDS_OFF((LED_TWO | LED_THREE | LED_FOUR));
            break;
        }
        case LEDS_CONNECTED_TO_BROKER:
        {
            LEDS_ON(LED_TWO);
            LEDS_OFF((LED_ONE | LED_THREE));
            break;
        }
        default:
        {
            break;
        }
    }
}