示例#1
0
void main_cbsc_tx_run(void)
{
    // Open the ANT channel and initialize the profile module.        
    channel_open();   
    uint32_t err_code = cbsc_tx_initialize();
    APP_ERROR_CHECK(err_code);
    
    uint8_t ant_channel;        
    uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE];     
    uint8_t event = NO_EVENT;      
    
    // Extract and process all pending events, while maximizing application sleep.     
    for (;;) 
    {             
        err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);
        
        // Extract and process all pending ANT stack events.
        while (sd_ant_event_get(&ant_channel, &event, event_message_buffer) == NRF_SUCCESS)
        {                    
            err_code = cbsc_tx_channel_event_handle(event);
            APP_ERROR_CHECK(err_code);
        }            
    } 
}
示例#2
0
文件: main.c 项目: pilotniq/WordWatch
int main( int argc, char **argv )
{
	// TODO: Disable DC/DC converter to save power
	// enable low power mdoe
	
	// setup GPIO

	// setup task to toggle pin.
	// Configure GPIOTE_CHANNEL_NUMBER to toggle the GPIO pin state with input.
  // @note Only one GPIOTE task can be coupled to an output pin.
  // GPIOTE uses too much power. Asked in support forum why.
	// nrf_gpiote_task_config( GPIOTE_CHANNEL_NUMBER, outPin /* GPIO_OUTPUT_PIN_NUMBER */, \
  //                         NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);

	// NRF_GPIO->OUT[0] = 0; // todo
	// NRF_GPIO->CONFIG[0] = 
	// setup RTC to generate event on tick every second
	// Use crystal as Low frequency clock source
	// while(1)
	//	;
	timers_init();

	erl_ble_init( "WordWatch" );
	

	
	// hfclk_config();
	// lfclk_config(); // Hangs with BLE stack.
	// sd_clock_
	// gpio_config();
	spi_init();
	display_init();
	// NRF_GPIO->OUTSET = (1UL << PIN_VCOM);
	nrf_gpio_cfg_output(PIN_VCOM);

  // use app_timer instead
  // rtc_config();

	// while( 1 )
	// {
	//	updateDisplay();
	
	//	nrf_delay_us( 100 );
	//}
	// NRF_GPIO->OUTSET = (1UL << PIN_VCOM);

	// setup PPI to automatically toggle GPIO pin on tick event

	// Configure PPI channel 0 to stop Timer 0 counter at TIMER1 COMPARE[0] match, which is every even number of seconds.
  // NRF_PPI->CH[0].EEP = (uint32_t)(&NRF_RTC0->EVENTS_COMPARE[0]);
  // NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[GPIOTE_CHANNEL_NUMBER];

  // Enable PPI channel 0
  // NRF_PPI->CHEN = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos);

	// sleep
	while( 1 )
		sd_app_event_wait(); // __WFE();
}
示例#3
0
/**@brief Function for Stride and Distance Monitor RX example main loop.
 *
 * @details The main loop will try to sleep as much as possible. Every time a protocol event 
 * occours, the application will be woken up, polling the ANT stack event queue. When finished 
 * processing all events, the application will go back to sleep.
 */
void sdm_main_loop(void)
{
    uint8_t  event_id;
    uint8_t  ant_channel;    
    uint32_t err_code;
  
    // ANT event message buffer.
    static uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE];
    
    // Main loop.
    for (;;)
    {   
        // Put CPU in sleep if possible.
        err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);
    
        // Extract and process all pending ANT events as long as there are any left.
        do
        {
            // Fetch the event.
            err_code = sd_ant_event_get(&ant_channel, &event_id, event_message_buffer);
            if (err_code == NRF_SUCCESS) 
            {
                // Handle event.
                switch (event_id)
                {
                    case EVENT_RX:
                        err_code = sdm_rx_data_process(
                                           &event_message_buffer[ANT_EVENT_BUFFER_INDEX_PAGE_NUM]);
                        APP_ERROR_CHECK(err_code);
                        
                        err_code = sdm_rx_log(
                                           event_message_buffer[ANT_EVENT_BUFFER_INDEX_PAGE_NUM]);
                        APP_ERROR_CHECK(err_code);
                        break;
                        
                    case EVENT_RX_FAIL:
                        err_code = sdm_rx_log(SDM_PAGE_EVENT_RX_FAIL);
                        APP_ERROR_CHECK(err_code);
                        break;
                        
                    default:
                        break;
                }
            }          
        } 
        while (err_code == NRF_SUCCESS);
    }
}
示例#4
0
文件: main.c 项目: Abdellbar/nrf51
/**@brief Application main function.
 */
int main(void)
{
    uint32_t err_code;

    timers_init();
    gpiote_init();
    buttons_init();

    if (is_first_start())
    {
        // The startup was not because of button presses. This is the first start.
        // Go into System-Off mode.
        // NOTE: This register cannot be set directly after ble_stack_init() because the SoftDevice
        //       will be enabled.
        GPIO_WAKEUP_BUTTON_CONFIG(HR_INC_BUTTON_PIN_NO);
        GPIO_WAKEUP_BUTTON_CONFIG(HR_DEC_BUTTON_PIN_NO);
        NRF_POWER->SYSTEMOFF = 1;
    }

    bond_manager_init();
    ble_stack_init();
    radio_notification_init();

    // Initialize Bluetooth Stack parameters
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
    sec_params_init();

    // Actually start advertising
    advertising_start();

    // Enter main loop
    for (;;)
    {
        // Switch to a low power state until an event is available for the application
        err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);
    }
}
示例#5
0
/**@brief   Function for waiting for events.
 *
 * @details This function will place the chip in low power mode while waiting for events from
 *          the BLE stack or other peripherals. When interrupted by an event, it will call the  @ref
 *          app_sched_execute function to process the received event. This function will return
 *          when the final state of the firmware update is reached OR when a tear down is in
 *          progress.
 */
static void wait_for_events(void)
{
    for (;;)
    {
        // Wait in low power state for any events.
        uint32_t err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);

        // Event received. Process it from the scheduler.
        app_sched_execute();

        if (m_tear_down_in_progress)
        {
            // Wait until disconnected event is received. Once the disconnected event is received
            // from the stack, the macro IS_CONNECTED will return false.
            if (!IS_CONNECTED())
            {
                 err_code = sd_softdevice_disable();
                 APP_ERROR_CHECK(err_code);

                 if (m_activate_img_after_tear_down)
                 {
                     // Start the currently valid application.
                     (void)dfu_image_activate();
                     // Ignoring the error code returned by dfu_image_activate because if the
                     // function fails, there is nothing that can be done to recover, other than
                     // returning and letting the system go under reset. Also since the
                     // tear down of the BLE Transport is already complete and the connection
                     // with the DFU Controller is down. Hence the DFU Controller cannot be informed
                     // about this failure. It is assumed that the DFU Controller is already
                     // aware of a failed update procedure from errors returned by earlier
                     // operations (eg. Validate operation would have returned a failure if there
                     // was a failed image transfer).
                 }
                 return;
            }
        }
    }
}
示例#6
0
文件: main.c 项目: jarodz/otolith
/**@brief Application main function.
 */
int main(void)
{
    uint32_t err_code;

    connected = false;

    mlog_init();
    timers_init();
    gpiote_init();
    buttons_init();
    step_counter_init();
    motor_init();
    led1_init();

    mlog_str("Starting MAIN...\r\n");

    bond_manager_init();
    ble_stack_init();
    radio_notification_init();

    // Initialize Bluetooth Stack parameters
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
    sec_params_init();

    // Actually start advertising
    //advertising_start();
    app_button_enable();

    // Enter main loop
    for (;;)
    {
        // Switch to a low power state until an event is available for the application
        err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);
    }
}
示例#7
0
/**@brief Power manager.
 */
static void power_manage(void)
{
    uint32_t err_code = sd_app_event_wait();
    APP_ERROR_CHECK(err_code);
}
示例#8
0
/**@brief Function for application main entry, does not return.
 */
int main(void)
{   
    uint32_t err_code;
    
    // Setup UART. 
#if defined(TRACE_UART)
    const app_uart_comm_params_t comm_params =  
    {
        RX_PIN_NUMBER, 
        TX_PIN_NUMBER, 
        RTS_PIN_NUMBER, 
        CTS_PIN_NUMBER, 
        APP_UART_FLOW_CONTROL_DISABLED, 
        false, 
        UART_BAUDRATE_BAUDRATE_Baud38400
    }; 
        
    APP_UART_FIFO_INIT(&comm_params, 
                       UART_RX_BUF_SIZE, 
                       UART_TX_BUF_SIZE, 
                       uart_error_handle, 
                       APP_IRQ_PRIORITY_LOW,
                       err_code);
    APP_ERROR_CHECK(err_code);
#endif
  
    err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback);
    APP_ERROR_CHECK(err_code);
  
    // Set application IRQ to lowest priority.
    err_code = sd_nvic_SetPriority(PROTOCOL_EVENT_IRQn, NRF_APP_PRIORITY_LOW);
    APP_ERROR_CHECK(err_code);  
    
    // Enable application IRQ (triggered from protocol). 
    err_code = sd_nvic_EnableIRQ(PROTOCOL_EVENT_IRQn);
    APP_ERROR_CHECK(err_code);    
    
    // Open HRM RX channel.
    hrm_rx_open();

    uint8_t event;
    uint8_t ant_channel;  
    uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE]; 
    
    printf("Enter hrm rx main processing loop...\n");   
    
    // Main loop.   
    for (;;)
    {   
        err_code = sd_app_event_wait(); 
        APP_ERROR_CHECK(err_code);    

        // Extract and process all pending ANT events.      
        do
        {
            err_code = sd_ant_event_get(&ant_channel, &event, event_message_buffer);
            if (err_code == NRF_SUCCESS)
            {
                if (event == EVENT_RX)
                {
                    // We are only interested of RX events.
                    hrm_rx_channel_event_handle(event_message_buffer);            
                }
            }            
        } 
        while (err_code == NRF_SUCCESS);
    }
} 
示例#9
0
/**@brief Function for application main entry. Does not return.
 */
int main(void)
{
    // ANT event message buffer.
    static uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE]; 
    
    // Configure pins LED0 and LED1 as outputs.
    nrf_gpio_range_cfg_output(LED_START, LED_STOP);
  
    // Set LED0 and LED1 high to indicate that the application is running.
    NRF_GPIO->OUTSET = (1 << LED0) | (1 << LED1);
  
    // Enable SoftDevice.
    uint32_t err_code;
    err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback);
    APP_ERROR_CHECK(err_code);

    // Set application IRQ to lowest priority.
    err_code = sd_nvic_SetPriority(PROTOCOL_EVENT_IRQn, NRF_APP_PRIORITY_LOW); 
    APP_ERROR_CHECK(err_code);

    // Enable application IRQ (triggered from protocol).
    err_code = sd_nvic_EnableIRQ(PROTOCOL_EVENT_IRQn);
    APP_ERROR_CHECK(err_code);

    // Setup Channel_0 as a RX Slave.
    ant_channel_rx_broadcast_setup();
  
    // Set LED0 and LED1 low to indicate that stack is enabled.
    NRF_GPIO->OUTCLR = (1 << LED0) | (1 << LED1);
  
    uint8_t event;
    uint8_t ant_channel;
  
    // Main loop.
    // Extract events from the stack below when 
    // availabe and process them in the main loop.
    for (;;)
    {   
        // Light up LED1 to indicate that CPU is going to sleep
        nrf_gpio_pin_set(LED1);
        
        // Put CPU in sleep if possible
        err_code = sd_app_event_wait();        
        APP_ERROR_CHECK(err_code);
        
        // Turn off LED on GPIO 9 to indicate that CPU is going out of sleep
        nrf_gpio_pin_clear(LED1);
    
        // Extract and process all pending ANT events as long as there are any left.      
        do
        {
            // Fetch the event.
            err_code = sd_ant_event_get(&ant_channel, &event, event_message_buffer);
            if (err_code == NRF_SUCCESS)
            {
                // Handle event.
                switch (event)
                {
                    case EVENT_RX:
                        channel_event_handle(event_message_buffer);
                        break;
                        
                    default:
                        break;
                }
            }          
        } 
        while (err_code == NRF_SUCCESS);
    }
}