コード例 #1
0
ファイル: main.c プロジェクト: ruuvi/ruuvitag_fw
/**@brief Function for handling NFC events.
 * Schedulers call to handler.
 */
void app_nfc_callback(void* p_context, nfc_t2t_event_t event, const uint8_t* p_data, size_t data_length)
{
  NRF_LOG_INFO("NFC\r\n");
  switch (event)
  {
    case NFC_T2T_EVENT_FIELD_ON:
      // NFC activation causes tag to hang sometimes. Fix this by reseting tag after a delay on NFC read.
      NRF_LOG_INFO("NFC Field detected \r\n");
      app_timer_start(reset_timer_id, APP_TIMER_TICKS(NFC_RESET_DELAY, RUUVITAG_APP_TIMER_PRESCALER), NULL);
      break;

    case NFC_T2T_EVENT_FIELD_OFF:
      NRF_LOG_INFO("NFC Field lost \r\n");
      app_sched_event_put (NULL, 0, reinit_nfc);
      if(APP_GATT_PROFILE_ENABLED)
      {
        app_sched_event_put (NULL, 0, become_connectable);
      }
      break;

    case NFC_T2T_EVENT_DATA_READ:
      NRF_LOG_INFO("Data read\r\n");
      break;
    
    default:
      break;
  }
}
コード例 #2
0
ファイル: key.c プロジェクト: rogerlee0824/SmartAmmeter_STM8L
/***********************************************************************
  * @brief  Initialise the resource for count.
  * @param  None
  * @retval None
************************************************************************/
void key_event_handler(void * p_event_data, uint16_t event_size)
{
	key_event_t * key_event_tmp = p_event_data;
	
	switch(key_event_tmp->eKey_event)
	{
		case KEY_INIT:
			KEY_Init();
			break;

		case KEY_HANDLE:
			#ifdef KEY_DEBUG
				printf("[KEY] KEY_HANDLE...\r\n");
			#endif
			if(key_is_pressed)
			{
				if(DataMem_GetTopGas() < REMAIN_GAS_MIN)
				{
					beeper_event.eBeeper_event = BEEPER;
					beeper_event.beeper_times = BEEPER_TIMES_REMEAN_GAS_LOW;
					app_sched_event_put(&beeper_event,sizeof(beeper_event),beeper_event_handler);
				}
				
				lcd_event.eLcd_event = LCD_DISPLAY_REMAIN_GAS;
            	app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);

				key_is_pressed = 0;
			}
			break;
			
		default:
			break;
	}
}
コード例 #3
0
ファイル: flash_helper.c プロジェクト: qodome/Firmware
// This event handler is invoked from interrupt context, need to do schedule!
void flash_radio_notification_evt_handler_t(bool radio_active)
{
    // Schedule next flash operations
	if (app_sched_event_put(NULL, 0, flash_time_to_shoot) != NRF_SUCCESS) {
		flash_interrupt_schedule_fail_cnt++;
	}
}
コード例 #4
0
void rpc_transport_event_handler(hci_transport_evt_t event)
{
    uint32_t  retval;
    uint16_t  rpc_cmd_length_read;
    uint8_t * p_rpc_cmd_buffer;
    uint8_t   element_index;

    retval = hci_transport_rx_pkt_extract(&p_rpc_cmd_buffer, &rpc_cmd_length_read);
    if (NRF_SUCCESS == retval)
    {
        // Verify if the data queue can buffer the packet.
        retval = data_queue_element_alloc(&element_index, p_rpc_cmd_buffer[0]);
        if (NRF_SUCCESS == retval)
        {
            //subtract 1 since we are interested in payload length and not the type field.
            DATA_QUEUE_ELEMENT_SET_PLEN(element_index,(rpc_cmd_length_read / sizeof(uint32_t)) - 1);
            DATA_QUEUE_ELEMENT_COPY_PDATA(element_index, &p_rpc_cmd_buffer[4]);
            retval = app_sched_event_put(NULL, 0, process_dfu_packet);
        }
    }
    
    if (NRF_SUCCESS != retval)
    {
        // Free the packet that could not be processed.
        retval = hci_transport_rx_pkt_consume(p_rpc_cmd_buffer);
        APP_ERROR_CHECK(retval);
    }
}
コード例 #5
0
bool EventManager::queueEvent( uint8_t eventCode, int eventParam, EventPriority pri )
{
	SEvent loc_s_event = {eventCode, eventParam};
	uint32_t loc_u32_err_code = NRF_SUCCESS;

	/** Event prio not handled */

#if EVENTMANAGER_DEBUG
    if ( !mInterruptSafeMode )
    {
        EVTMGR_DEBUG_PRINT( "queueEvent() enter " )
        EVTMGR_DEBUG_PRINT( eventCode )
        EVTMGR_DEBUG_PRINT( ", " )
        EVTMGR_DEBUG_PRINTLN( eventParam )
    }
#endif

    if(!getInstance()->mListeners.hasActiveListeners(eventCode))
    {
    	/** Do not push an event without any listeners */
    	return false;
    }
    loc_u32_err_code = app_sched_event_put(&loc_s_event, sizeof(loc_s_event), appEventHandler);
	APP_ERROR_CHECK(loc_u32_err_code);

	if(loc_u32_err_code == NRF_SUCCESS)
	{
		return true;
	}
	else
	{
		return false;
	}
}
コード例 #6
0
ファイル: lumen.c プロジェクト: lavallc/ion
void lumen_radio_active_notification_handler(bool radio_is_active) {
	//if the radio is no longer active, send an update to the leds
	if(!radio_is_active){ 	
			nrf_delay_us(250);
			app_sched_event_put(&lumen_event_show_led, sizeof(lumen_event_show_led),lumen_task_led_show);
			
	}
}
コード例 #7
0
uint32_t app_timer_evt_schedule(app_timer_timeout_handler_t timeout_handler,
                                void *                      p_context)
{
    app_timer_event_t timer_event;

    timer_event.timeout_handler = timeout_handler;
    timer_event.p_context       = p_context;

    return app_sched_event_put(&timer_event, sizeof(timer_event), app_timer_evt_get);
}
コード例 #8
0
ファイル: main.c プロジェクト: ruuvi/ruuvitag_fw
/**@brief Function for handling button events.
 * Schedulers call to handler.
 * Use scheduler, do not use peripherals in interrupt context (SPI/Flash writes won't complete.)
 *
 * @param message. A struct containing data about the event. 
 *                 message.payload[0] has pin number (4)
 *                 message.payload[1] has pin state, 1 if high, 0 if low.
 */
ret_code_t button_press_handler(const ruuvi_standard_message_t message)
{
  // Avoid double presses
  static bool pressed = false;
  if(false == message.payload[1] && ((millis() - debounce) > DEBOUNCE_THRESHOLD) && !pressed)
  {
    NRF_LOG_INFO("Button pressed\r\n");
    GREEN_LED_ON;
    RED_LED_ON;
    // Start timer to reboot tag.
    app_timer_start(reset_timer_id, APP_TIMER_TICKS(BUTTON_RESET_TIME, RUUVITAG_APP_TIMER_PRESCALER), NULL);
    pressed = true;
  }
  if(true == message.payload[1] &&  pressed)
  {
     NRF_LOG_INFO("Button released\r\n");
     pressed = false;
     // Cancel reset
     app_timer_stop(reset_timer_id);

     // Clear leds
     GREEN_LED_OFF;
     RED_LED_OFF;

     // Update mode
     tag_mode++;
     if(tag_mode > sizeof(advertising_rates)/sizeof(advertising_rates[0])) { tag_mode = 0; }
     app_sched_event_put (&tag_mode, sizeof(&tag_mode), change_mode);

     //Enter connectable mode if allowed by configuration.
     if(APP_GATT_PROFILE_ENABLED)
     {
       app_sched_event_put (NULL, 0, become_connectable);
     }

     // Schedule store mode to flash
     app_sched_event_put (NULL, 0, store_mode);
  }

  debounce = millis();
  return ENDPOINT_SUCCESS;
}
コード例 #9
0
ファイル: BlueIOMPU9250.cpp プロジェクト: I-SYST/EHAL
static void ImuEvtHandler(Device * const pDev, DEV_EVT Evt)
{

	switch (Evt)
	{
		case DEV_EVT_DATA_RDY:
			app_sched_event_put(NULL, 0, ImuDataChedHandler);
			//ImuDataChedHandler(NULL, 0);
			//g_MotSensor.Read(accdata);
			break;
	}
}
コード例 #10
0
/**@brief IRQHandler used for execution context management. 
  *        Any available handler can be used as we're not using the associated hardware.
  *        This handler is used to notify of received data
  */
void UESB_RX_HANDLE_IRQHandler(void)
{
    uesb_payload_t payload;
    uint32_t       err_code;

    // Get packet from UESB buffer
    uesb_read_rx_payload(&payload);

    // Give packet to main application via the scheduler
    err_code = app_sched_event_put(payload.data, payload.length, m_evt_handler);
    APP_ERROR_CHECK(err_code);
}
コード例 #11
0
ファイル: ser_conn_handlers.c プロジェクト: DanielOld/wlock
void ser_conn_ble_event_handle(ble_evt_t * p_ble_evt)
{
    uint32_t err_code = NRF_SUCCESS;

    /* We can NOT encode and send BLE events here. SoftDevice handler implemented in
     * softdevice_handler.c pull all available BLE events at once but we need to reschedule between
     * encoding and sending every BLE event because sending a response on received packet has higher
     * priority than sending a BLE event. Solution for that is to put BLE events into application
     * scheduler queue to be processed at a later time. */
    err_code = app_sched_event_put(p_ble_evt, sizeof (ble_evt_hdr_t) + p_ble_evt->header.evt_len,
                                   ser_conn_ble_event_encoder);
    APP_ERROR_CHECK(err_code);
}
コード例 #12
0
ファイル: mesh_gatt.c プロジェクト: AlexDM0/bluenet
uint32_t mesh_gatt_value_set(rbc_mesh_value_handle_t handle, uint8_t* data,
		uint8_t length) {

	if (length > RBC_MESH_VALUE_MAX_LEN) {
		return NRF_ERROR_INVALID_LENGTH;
	}
	if (m_active_conn_handle != CONN_HANDLE_INVALID) {

		if (nb_full()) {

			LOGw(FMT_BUFFER_FULL, "Notification");
			return NRF_ERROR_NO_MEM;

		} else {
			if (notifactionsPending && !m_mesh_service.notification_enabled) {
				notifactionsPending = false;
				nb_clear();
			}

			// todo: continue here: check if we can put on the scheduler

			waiting_notification_t* notification = nb_next();

			notification->offset = 0;
			memcpy(notification->data, data, length);
			notification->length = length;
			notification->handle = handle;

			if (!notifactionsPending) {

//				LOGd("put into scheduler");
				app_sched_event_put(NULL, 0, value_set_handler);

//				printArray(notification, sizeof(waiting_notification_t));
			} else {

#ifdef PRINT_MESH_VERBOSE
				LOGd("notification pending already");
#endif

				return BLE_ERROR_NO_TX_BUFFERS;

			}
		}
	} else {
		return BLE_ERROR_INVALID_CONN_HANDLE;
	}
}
コード例 #13
0
ファイル: UartBleDemo.cpp プロジェクト: I-SYST/EHAL
int nRFUartEvthandler(UARTDEV *pDev, UART_EVT EvtId, uint8_t *pBuffer, int BufferLen)
{
	int cnt = 0;
	uint8_t buff[20];

	switch (EvtId)
	{
		case UART_EVT_RXTIMEOUT:
		case UART_EVT_RXDATA:
			app_sched_event_put(NULL, 0, UartRxChedHandler);
			break;
		case UART_EVT_TXREADY:
			break;
		case UART_EVT_LINESTATE:
			break;
	}

	return cnt;
}
コード例 #14
0
/**@brief Function for handling the Application's BLE Stack events.
 *
 * @param[in] p_ble_evt  Bluetooth stack event.
 */
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
		uint32_t err_code;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
						err_code = app_sched_event_put(NULL, NULL, disconnection_alert_event);
						APP_ERROR_CHECK(err_code);
            break;

        default:
            // No implementation needed.
            break;
    }
}
コード例 #15
0
ファイル: nrf_pwr_mgmt.c プロジェクト: CWBudde/Espruino
void nrf_pwr_mgmt_shutdown(nrf_pwr_mgmt_shutdown_t shutdown_type)
{
    if (shutdown_type != NRF_PWR_MGMT_SHUTDOWN_CONTINUE)
    {
        // Check if shutdown procedure is not started.
        if (!nrf_pwr_mgmt_guard_lock())
        {
            return;
        }
        m_pwr_mgmt_evt = (nrf_pwr_mgmt_evt_t)shutdown_type;
    }
    ASSERT(m_sysoff_guard);
    NRF_LOG_INFO("Shutdown request %d\r\n", shutdown_type);

#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
    ret_code_t ret_code = app_sched_event_put(NULL, 0, scheduler_shutdown_handler);
    APP_ERROR_CHECK(ret_code);
#else
    shutdown_process();
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
}
コード例 #16
0
ファイル: main.c プロジェクト: glocklueng/SmartAmmeter_STM8L
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
	CLK_Config();
	FlashInit();

	sim();									// disable interrupts

	GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOG, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);

	delay1s(5);

	#ifdef DEBUG
		AppTrace_Init();
    	printf("\r\nSTM8L152 Start ...\r\n");
	#endif
	
	LED_Init();
    LED1_ON();
	scheduler_init();

	// Build count init event 
	count_event.eCount_event = COUNT_INIT;
	app_sched_event_put(&count_event,sizeof(count_event),count_event_handler);
	
	// Build key init event 
	key_event.eKey_event = KEY_INIT;
	app_sched_event_put(&key_event,sizeof(key_event),key_event_handler);
	
	// Build the valve standby event 
	valve_event.eValve_event = VALVE_STANDBY_EVENT;
	app_sched_event_put(&valve_event,sizeof(valve_event),valve_event_handler);
    
    // Build the LCD init event 
	lcd_event.eLcd_event = LCD_INIT;
	app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);

	// Build the beeper init event 
	beeper_event.eBeeper_event = BEEPER_INIT;
	app_sched_event_put(&beeper_event,sizeof(beeper_event),beeper_event_handler);

	// Build the cc1120 Init event 
	cc112x_event.eCC112x_event = CC112X_INIT_EVENT;
	app_sched_event_put(&cc112x_event,sizeof(cc112x_event),cc112x_event_handler);

	// Build the IC card Init event 
	ic_card_event.eIC_event = IC_CARD_INIT;
	app_sched_event_put(&ic_card_event,sizeof(ic_card_event),ic_event_handler);

	// Build the IC card Init event 
	battery_event.eBattery_event = INT_BATTERY_EVENT;
	app_sched_event_put(&battery_event,sizeof(battery_event),battery_event_handler);

    // enable interrupts 
	rim();
    LED1_OFF();
	 
	// Infinite loop 
  	while (1)
  	{
		app_sched_execute();
		app_evt_wait();
  	}
}
コード例 #17
0
ファイル: main.c プロジェクト: sloboste/eecs473-fitness-watch
// This executes in interrupt context
static void timer_1_handler(void * p_context)
{
    app_sched_event_put(
        (void *) &task_led_1_arg, sizeof(task_led_1_arg), task_led);
}
コード例 #18
0
ファイル: dfu_transport_ble.c プロジェクト: 1072258106/duband
/**@brief   Function for passing BLE events to the scheduler
 *
 * @return  NRF_SUCCESS if the BLE event was passed successfully to the scheduler. Otherwise an
 *          error code.
 */
static uint32_t stack_evt_schedule(void)
{
    return app_sched_event_put(NULL, 0, stack_evt_get);
}
コード例 #19
0
ファイル: main.c プロジェクト: ruuvi/ruuvitag_fw
/**@brief Timeout handler for the repeated timer
 */
static void main_timer_handler(void * p_context)
{
  app_sched_event_put (NULL, 0, main_sensor_task);
}
コード例 #20
0
/**@brief Function for handling Peer Manager events.
 *
 * @param[in] p_evt  Peer Manager event.
 */
static void pm_evt_handler(pm_evt_t const * p_evt)
{
    ret_code_t err_code;

    switch (p_evt->evt_id)
    {
        case PM_EVT_BONDED_PEER_CONNECTED:
        {
            NRF_LOG_INFO("Connected to a previously bonded device.\r\n");
        } break;

        case PM_EVT_CONN_SEC_SUCCEEDED:
        {
            NRF_LOG_INFO("Connection secured. Role: %d. conn_handle: %d, Procedure: %d\r\n",
                         ble_conn_state_role(p_evt->conn_handle),
                         p_evt->conn_handle,
                         p_evt->params.conn_sec_succeeded.procedure);
        } break;

        case PM_EVT_CONN_SEC_FAILED:
        {
            /* Often, when securing fails, it shouldn't be restarted, for security reasons.
             * Other times, it can be restarted directly.
             * Sometimes it can be restarted, but only after changing some Security Parameters.
             * Sometimes, it cannot be restarted until the link is disconnected and reconnected.
             * Sometimes it is impossible, to secure the link, or the peer device does not support it.
             * How to handle this error is highly application dependent. */
        } break;

        case PM_EVT_CONN_SEC_CONFIG_REQ:
        {
            // Reject pairing request from an already bonded peer.
            pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};
            pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
        } break;

        case PM_EVT_STORAGE_FULL:
        {
            // Run garbage collection on the flash.
            err_code = fds_gc();
            if (err_code == FDS_ERR_BUSY || err_code == FDS_ERR_NO_SPACE_IN_QUEUES)
            {
                // Retry.
            }
            else
            {
                APP_ERROR_CHECK(err_code);
            }
        } break;

        case PM_EVT_PEERS_DELETE_SUCCEEDED:
        {
            advertising_start();
        } break;

        case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
        {
            // The local database has likely changed, send service changed indications.
            pm_local_database_has_changed();
        } break;

        case PM_EVT_PEER_DATA_UPDATE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peer_data_update_failed.error);
        } break;

        case PM_EVT_PEER_DELETE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peer_delete_failed.error);
        } break;

        case PM_EVT_PEERS_DELETE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peers_delete_failed_evt.error);
        } break;

        case PM_EVT_ERROR_UNEXPECTED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
        } break;

        case PM_EVT_CONN_SEC_START:
        case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:
        case PM_EVT_PEER_DELETE_SUCCEEDED:
        case PM_EVT_LOCAL_DB_CACHE_APPLIED:
        case PM_EVT_SERVICE_CHANGED_IND_SENT:
        case PM_EVT_SERVICE_CHANGED_IND_CONFIRMED:
        default:
            break;
    }
}


/**@brief Function for performing battery measurement and updating the Battery Level characteristic
 *        in Battery Service.
 */
static void battery_level_update(void)
{	
    NRF_LOG_INFO("\r\n    Triggering battery level update...\r\n");          //Indicate on UART that Button 4 is pressed
	app_sched_event_put(0,0,(app_sched_event_handler_t)adc_sample);    //Put adc_sample function into the scheduler queue, which will then be executed in the main context (lowest priority) when app_sched_execute is called in the main loop
}
コード例 #21
0
ファイル: main.c プロジェクト: ruuvi/ruuvitag_fw
/**  This is where it all starts ++++++++++++++++++++++++++++++++++++++++++ 
 main is entered as a result of one of SEVERAL events:
  - Normal startup from press of reset button.
  - Battery inserted.
  - After DFU (Device Firmware Upgrade) at manufacturing Quality Assurance or user DFU.
  - WatchDogTimer expiration and its interrupt handler didn't feed new value.
  - Some error occured and
  - Spontenous unknown reset.
 All subsystems are initalized and any failures are noted and available later in init_status
 Since some events occur after tag is deployed and no one can see the LEDs the system continues operating.

 After initalizition (including setting up interrupts)
    we loop here calling app_sched_execute and sd_app_evt_wait 
*/
int main(void)
{
   // LEDs first (they're easy and cannot fail)  drivers/init/init.c
  init_leds();
  RED_LED_ON;

  if( init_log() ) { init_status |=LOG_FAILED_INIT; }
  else { NRF_LOG_INFO("LOG initalized \r\n"); } // subsequent initalizations assume log is working

  // start watchdog now in case program hangs up.
  // watchdog_default_handler logs error and resets the tag.
  init_watchdog(NULL);

  // Battery voltage initialization cannot fail under any reasonable circumstance.
  battery_voltage_init(); 
  vbat = getBattery();

  if( vbat < BATTERY_MIN_V ) { init_status |=BATTERY_FAILED_INIT; }
  else NRF_LOG_INFO("BATTERY initalized \r\n"); 

  if(init_sensors() == NRF_SUCCESS )
  {
    model_plus = true;
    NRF_LOG_INFO("Sensors initialized \r\n");  
  }

  // Init NFC ASAP in case we're waking from deep sleep via NFC (todo)
  // outputs ID:DEVICEID ,MAC:DEVICEADDR, SW:REVision
  set_nfc_callback(app_nfc_callback);
  if( init_nfc() ) { init_status |= NFC_FAILED_INIT; } 
  else { NRF_LOG_INFO("NFC init \r\n"); }

  pin_interrupt_init(); 

  if( pin_interrupt_enable(BSP_BUTTON_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIO_PIN_PULLUP, button_press_handler) ) 
  {
    init_status |= BUTTON_FAILED_INIT;
  }

  // Initialize BLE Stack. Starts LFCLK required for timer operation.
  if( init_ble() ) { init_status |= BLE_FAILED_INIT; }
  bluetooth_configure_advertisement_type(STARTUP_ADVERTISEMENT_TYPE);
  bluetooth_tx_power_set(BLE_TX_POWER);
  bluetooth_configure_advertising_interval(ADVERTISING_INTERVAL_STARTUP);
  advertisement_delay = NRF_FICR->DEVICEID[0]&0x0F;

  // Priorities 2 and 3 are after SD timing critical events. 
  // 6, 7 after SD non-critical events.
  // Triggers ADC, so use 3. 
  ble_radio_notification_init(3,
                              NRF_RADIO_NOTIFICATION_DISTANCE_800US,
                              on_radio_evt);

  // If GATT is enabled BLE init inits peer manager which uses flash.
  // BLE init should handle insufficient space gracefully (i.e. erase flash and proceed). 
  // Flash must be initialized after softdevice. 
  if(flash_init())
  {
    NRF_LOG_ERROR("Failed to init flash \r\n");
  }
  size_t flash_space_remaining = 0;
  flash_free_size_get(&flash_space_remaining);
  NRF_LOG_INFO("Largest continuous space remaining %d bytes\r\n", flash_space_remaining);
  if(4000 > flash_space_remaining)
  {
    NRF_LOG_INFO("Flash space is almost used, running gc\r\n")
    flash_gc_run();
    flash_free_size_get(&flash_space_remaining);
    NRF_LOG_INFO("Continuous space remaining after gc %d bytes\r\n", flash_space_remaining);
  }
  else if (flash_record_get(FDS_FILE_ID, FDS_RECORD_ID, sizeof(tag_mode), &tag_mode))
  {
   NRF_LOG_INFO("Did not find mode in flash, is this first boot? \r\n");
  }
  else 
  {
    NRF_LOG_INFO("Loaded mode %d from flash\r\n", tag_mode);
  }

  if( init_rtc() ) { init_status |= RTC_FAILED_INIT; }
  else { NRF_LOG_INFO("RTC initialized \r\n"); }

  // Initialize lis2dh12 and BME280 - TODO: Differentiate LIS2DH12 and BME280 
  if (model_plus)    
  {
    lis2dh12_reset(); // Clear memory.
    
    // Enable Low-To-Hi rising edge trigger interrupt on nRF52 to detect acceleration events.
    if (pin_interrupt_enable(INT_ACC2_PIN, NRF_GPIOTE_POLARITY_LOTOHI, NRF_GPIO_PIN_NOPULL, lis2dh12_int2_handler) )
    {
      init_status |= ACC_INT_FAILED_INIT;
    }
    
    nrf_delay_ms(10); // Wait for LIS reboot.
    // Enable XYZ axes.
    lis2dh12_enable();
    lis2dh12_set_scale(LIS2DH12_SCALE);
    lis2dh12_set_sample_rate(LIS2DH12_SAMPLERATE_RAWv1);
    lis2dh12_set_resolution(LIS2DH12_RESOLUTION);

    lis2dh12_set_activity_interrupt_pin_2(LIS2DH12_ACTIVITY_THRESHOLD);
    NRF_LOG_INFO("Accelerometer configuration done \r\n");

    // oversampling must be set for each used sensor.
    bme280_set_oversampling_hum  (BME280_HUMIDITY_OVERSAMPLING);
    bme280_set_oversampling_temp (BME280_TEMPERATURE_OVERSAMPLING);
    bme280_set_oversampling_press(BME280_PRESSURE_OVERSAMPLING);
    bme280_set_iir(BME280_IIR);
    bme280_set_interval(BME280_DELAY);
    bme280_set_mode(BME280_MODE_NORMAL);
    NRF_LOG_INFO("BME280 configuration done \r\n");
  }

  // Enter stored mode after boot - or default mode if store mode was not found
  app_sched_event_put (&tag_mode, sizeof(&tag_mode), change_mode);
  
  // Initialize repeated timer for sensor read and single-shot timer for button reset
  if( init_timer(main_timer_id, APP_TIMER_MODE_REPEATED, MAIN_LOOP_INTERVAL_RAW, main_timer_handler) )
  {
    init_status |= TIMER_FAILED_INIT;
  }
  
  if( init_timer(reset_timer_id, APP_TIMER_MODE_SINGLE_SHOT, BUTTON_RESET_TIME, reboot) )
  {
    init_status |= TIMER_FAILED_INIT;
  }
  // Init starts timers, stop the reset
  app_timer_stop(reset_timer_id);

  // Log errors, add a note to NFC, blink RED to visually indicate the problem
  if (init_status)
  { 
    snprintf((char* )NFC_message, NFC_message_length, "Error: %X", init_status);
    NRF_LOG_WARNING (" -- Initalization error :  %X \r\n", init_status);
    for ( int16_t i=0; i<13; i++)
    { 
      RED_LED_ON;
      nrf_delay_ms(500u);
      RED_LED_OFF;
      nrf_delay_ms(500u); 
    }
  }
  
  // Turn green led on if model+ with no errors.
  // Power manage turns led off
  if (model_plus & !init_status)
  {
    GREEN_LED_ON;
  }

  // Turn off red led, leave green on to signal model+ without errors
  RED_LED_OFF;

  // Wait for sensors to take first sample
  nrf_delay_ms(1000);
  // Get first sample from sensors
  app_sched_event_put (NULL, 0, main_sensor_task);
  app_sched_execute();

  // Start advertising 
  bluetooth_advertising_start(); 
  NRF_LOG_INFO("Advertising started\r\n");

  // Enter main loop. Executes tasks scheduled by timers and interrupts.
  for (;;)
  {
    app_sched_execute();
    // Sleep until next event.
    power_manage();
  }
}
コード例 #22
0
ファイル: buzzer.c プロジェクト: foldedtoad/trackr
/*---------------------------------------------------------------------------*/
void buzzer_play(buzzer_play_t * playlist)
{
    app_sched_event_put(&playlist, sizeof(playlist), buzzer_play_execute);
}
コード例 #23
0
ファイル: main.c プロジェクト: sloboste/eecs473-fitness-watch
// This executes in interrupt context
static void timer_0_handler(void * p_context)
{
    //app_sched_event_put(&pin, sizeof(pin), button_scheduler_event_handler);
    app_sched_event_put(
        (void *) &task_led_0_arg, sizeof(task_led_0_arg), task_led);
}
コード例 #24
0
uint32_t softdevice_evt_schedule(void)
{
    return app_sched_event_put(NULL, 0, softdevice_evt_get);
}
コード例 #25
0
/***********************************************************************
  * @brief  Handles the event for LCD displaying.
  * @param  None
  * @retval None
************************************************************************/
void lcd_event_handler(void * p_event_data, uint16_t event_size)
{
	lcd_event_t * lcd_event_tmp = p_event_data;
	uint8_t temp[6] = {8,8,8,8,5,6};
	uint32_t u32temp = 654321;
	
	switch(lcd_event_tmp->eLcd_event)
	{
        case LCD_INIT:
			#ifdef LCD_DEBUG
				printf("LCD_INIT ...\r\n");
			#endif
			LCD_SC_Init_A();
			LCD_SC_DeInit();
            break;
            
        case lCD_HANDLE:
			#ifdef LCD_DEBUG
				printf("lCD_HANDLE ...\r\n");
			#endif
			if(!lcd_is_on)
			{
				LCD_SC_Init();
				lcd_is_on = 1;
			}
			disp_icon |= (DISP_VALVE_CLOSE_ICON | DISP_STERE_ICON);
			lcd_disp_info.is_disp_digits = 1;
			lcd_disp_info.is_disp_dot = 1;
			lcd_disp_info.is_disp_icon = 1;
			lcd_disp_info.p_disp_contex = temp;
			lcd_disp_info.disp_contex_len = sizeof(temp);
			lcd_disp_info.disp_dot_num = 2;
			lcd_disp_info.p_disp_icon = &disp_icon;
			
			LCD_SC_Init();
			LCD_SC_Display(&lcd_disp_info);
            LCD_SC_DoDisp();

			delay1s(2);

			disp_icon &= 0;
			memset(&lcd_disp_info, 0, sizeof(lcd_disp_info_t));
			LCD_SC_Display(&lcd_disp_info);
			
			/* Initialize the LCD */
			LCD_Cmd(DISABLE);
			LCD_DeInit();
			
			lcd_event.eLcd_event = LCD_DEINIT;
			app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);
            break;

		case LCD_DISPLAY_REMAIN_GAS:
			#ifdef LCD_DEBUG
				printf("LCD_DISPLAY_REMAIN_GAS ...\r\n");
			#endif
			LCD_SC_DisplayRemainGas();
			
			lcd_event.eLcd_event = LCD_DEINIT;
			app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);
            break;

		case LCD_DEINIT:
			#ifdef LCD_DEBUG
				printf("LCD_DEINIT ...\r\n");
			#endif
			
			/* Initialize the LCD */
			LCD_Cmd(DISABLE);
			LCD_DeInit();
			LCD_SC_DeInit();
			lcd_is_on = 0;
			break;
        
		default:
			break;
	}
}