コード例 #1
0
ファイル: ke_timer.c プロジェクト: liuyuanbin/ET-smart-band
#include "nrf_drv_timer.h"
#include "app_error.h"
#include "Boards.h"
#include "et_spi_gpio.h"
#include "et_debug.h"
#include "etMotor.h"

/*****************/
struct ke_timer usr_timer[USR_TIMER_MAX] = {{0,0}};
static unsigned char gTimerTickFlg = 0;
static unsigned short gUsrUsingTimerCount = 0;
/*****************/

#define NRF_Timer2Set	1
#if NRF_Timer2Set
const nrf_drv_timer_t TIMER_GSensor = NRF_DRV_TIMER_INSTANCE(2);
//const nrf_drv_timer_t TIMER_PWM = NRF_DRV_TIMER_INSTANCE(1);
//BOOL Timer2flag=FALSE;
/**
 * @brief Handler for timer events.
 */
/*
void timer2_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    	switch(event_type)
    	{
				case NRF_TIMER_EVENT_COMPARE0:
					//gTimerTickFlg = 1;	

					//#if 0
					//if(Timer2flag==FALSE)
コード例 #2
0
ファイル: main.c プロジェクト: Goodjamp/ble_app_template
#include "nrf_gpiote.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "nrf_drv_ppi.h"
#include "nrf_drv_timer.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"

#ifdef BSP_LED_0
    #define GPIO_OUTPUT_PIN_NUMBER BSP_LED_0  /**< Pin number for output. */
#endif
#ifndef GPIO_OUTPUT_PIN_NUMBER
    #error "Please indicate output pin"
#endif

static nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(0);

void timer_dummy_handler(nrf_timer_event_t event_type, void * p_context){}

static void led_blinking_setup()
{
    uint32_t compare_evt_addr;
    uint32_t gpiote_task_addr;
    nrf_ppi_channel_t ppi_channel;
    ret_code_t err_code;
    nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);

    err_code = nrf_drv_gpiote_out_init(GPIO_OUTPUT_PIN_NUMBER, &config);
    APP_ERROR_CHECK(err_code);

コード例 #3
0
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)             /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER)  /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                           /**< Number of attempts before giving up the connection parameter negotiation. */

#define DEAD_BEEF                       0xDEADBEEF                                  /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */

#define UART_TX_BUF_SIZE                512                                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE                64                                         /**< UART RX buffer size. */

#define ADC_BUFFER_SIZE 6                               //Size of buffer for ADC samples. Buffer size should be multiple of number of adc channels located.
#define ADC_SAMPLE_RATE_DIVIDER				0x6000;           //This constant and the TIMER2 prescaler value (TIMER2_CONFIG_FREQUENCY) in nrf_drv_config.h file set the ADC sampling frequency

static nrf_adc_value_t         adc_buffer[ADC_BUFFER_SIZE]; /**< ADC buffer. */
static nrf_ppi_channel_t       m_ppi_channel;
static const nrf_drv_timer_t   m_timer = NRF_DRV_TIMER_INSTANCE(2);
static uint8_t adc_event_counter = 0;
static uint8_t number_of_adc_channels;

static ble_nus_t                        m_nus;                                      /**< Structure to identify the Nordic UART Service. */
static uint16_t                         m_conn_handle = BLE_CONN_HANDLE_INVALID;    /**< Handle of the current connection. */

static ble_uuid_t                       m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}};  /**< Universally unique service identifier. */


/**@brief Function for assert macro callback.
 *
 * @details This function will be called in case of an assert in the SoftDevice.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyse 
 *          how your product is supposed to react in case of Assert.
コード例 #4
0
ファイル: main.c プロジェクト: jrlitzenberger/pocketLab2
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "nrf_delay.h"
#include "app_uart.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_drv_ppi.h"
#include "nrf_drv_timer.h"
#include "nordic_common.h"

#define UART_TX_BUF_SIZE 256                                                          /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 1                                                            /**< UART RX buffer size. */

const nrf_drv_timer_t timer0 = NRF_DRV_TIMER_INSTANCE(0);
const nrf_drv_timer_t timer1 = NRF_DRV_TIMER_INSTANCE(1);
const nrf_drv_timer_t timer2 = NRF_DRV_TIMER_INSTANCE(2);

nrf_ppi_channel_t ppi_channel1, ppi_channel2;

void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_code);
    }
コード例 #5
0
ファイル: app_simple_timer.c プロジェクト: lyncxy119/Sentry
/**@brief States of simple timer state machine.
 */
typedef enum
{
    SIMPLE_TIMER_STATE_IDLE = 0,
    SIMPLE_TIMER_STATE_INITIALIZED,
    SIMPLE_TIMER_STATE_STOPPED,
    SIMPLE_TIMER_STATE_STARTED
}simple_timer_states_t;

static app_simple_timer_mode_t            m_mode;                                               /**< Registered timer mode. */
static app_simple_timer_timeout_handler_t m_timeout_handler          = NULL;                    /**< Registered time-out handler. */
static void *                             mp_timeout_handler_context = NULL;                    /**< Registered time-out handler context. */
static simple_timer_states_t              m_simple_timer_state       = SIMPLE_TIMER_STATE_IDLE; /**< State machine state. */

const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(SIMPLE_TIMER_CONFIG_INSTANCE);

/**
 * @brief Handler for timer events.
 */
static void app_simple_timer_event_handler(nrf_timer_event_t event_type, void * p_context)
{
    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            if (m_mode == APP_SIMPLE_TIMER_MODE_SINGLE_SHOT)
            {
                m_simple_timer_state = SIMPLE_TIMER_STATE_STOPPED;
            }

            //@note: No NULL check required as performed in timer_start(...).
コード例 #6
0
ファイル: timer_blinky.c プロジェクト: pcbreflux/nordic
 */

/** @file timer_blinky.c (changed by pcbreflux)
 * @brief Blinky Example Application main file.
 *
 */
#include <stdlib.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_timer.h"
#include "app_error.h"

// see nrf_drv_config.h for defining TIMER1
// Softdevice S110, S120, S130 blocks TIMER0
const nrf_drv_timer_t mytimer1 = NRF_DRV_TIMER_INSTANCE(1); /**< Declaring an instance of nrf_drv_timer for TIMER1. */

const uint32_t led_pin1 = 19;
static uint32_t tick_pos = 0;

/** @brief Function initialization and configuration of GPIO.
 */
static void gpio_config(void) {
    // Configure LED-pin as outputs and clear.
    nrf_gpio_cfg_output(led_pin1);
    nrf_gpio_pin_clear(led_pin1);
}

/** @brief Function for timer events.
 */
static void timer1_handler(nrf_timer_event_t event_type, void* p_context) {
コード例 #7
0
ファイル: nrf_drv_csense.c プロジェクト: TanekLiang/rt-thread
#endif //ADC_PRESENT
#endif //USE_COMP

#if USE_COMP
/* Number of channels required by PPI. */
#define PPI_REQUIRED_CHANNELS 3

/* Array of PPI channels. */
static nrf_ppi_channel_t m_ppi_channels[PPI_REQUIRED_CHANNELS];


/**
 * @defgroup timer_instances Timer instances.
 * @{
 */
static const nrf_drv_timer_t m_timer0 = NRF_DRV_TIMER_INSTANCE(TIMER0_FOR_CSENSE);
static const nrf_drv_timer_t m_timer1 = NRF_DRV_TIMER_INSTANCE(TIMER1_FOR_CSENSE);
/* @} */
#endif //USE_COMP

/* Configuration of the capacitive sensor module. */
typedef struct
{
    volatile nrf_drv_state_t        module_state;                       /**< State of the module. */
    nrf_drv_csense_event_handler_t  event_handler;                      /**< Event handler for capacitor sensor events. */
    uint16_t                        analog_values[MAX_ANALOG_INPUTS];   /**< Array containing analog values measured on the corresponding COMP/ADC channel. */
    volatile bool                   busy;                               /**< Indicates state of module - busy if there are ongoing conversions. */
    volatile uint8_t                cur_chann_idx;                      /**< Current channel to be read if enabled. */
    volatile uint8_t                adc_channels_input_mask;            /**< Enabled channels. */
    uint8_t                         output_pin;                         /**< Pin to generate signal charging capacitors. */
    uint8_t                         channels_to_read;                   /**< Mask of channels remaining to be read in the current measurement. */
コード例 #8
0
ファイル: qp.c プロジェクト: henrychoi/realtime
    MAX_KERNEL_AWARE_CMSIS_PRI /* keep always last */
};
/* "kernel-aware" interrupts should not overlap the PendSV priority */
Q_ASSERT_COMPILE(MAX_KERNEL_AWARE_CMSIS_PRI <= (0xFF >>(8-__NVIC_PRIO_BITS)));

#ifdef Q_SPY
QSTimeCtr QS_tickTime_;
QSTimeCtr QS_i_getTime;
#endif

uint8_t BSP_readButton() {
#define BTN_PIN 17
	return !nrf_gpio_pin_read(BTN_PIN);
}

const nrf_drv_timer_t TIMER1 = NRF_DRV_TIMER_INSTANCE(1);
void Timer1_handler(nrf_timer_event_t event_type, void* p_context) {
    if (event_type != NRF_TIMER_EVENT_COMPARE0) return;

	//QS_BEGIN(TRACE_SDK_EVT, NULL)
	//	QS_U8(0, 0);
	//QS_END() QS_FLUSH();

#ifdef Q_SPY
    QS_tickTime_ += 1000/BSP_TICKS_PER_SEC;
    QS_i_getTime = 0;//reset
#endif
    QF_tickXISR(0U); /* process time events for rate 0 */
}

コード例 #9
0
ファイル: app_simple_timer.c プロジェクト: 8bitgeek/Espruino
static app_simple_timer_mode_t            m_mode;                                               /**< Registered timer mode. */
static app_simple_timer_timeout_handler_t m_timeout_handler          = NULL;                    /**< Registered time-out handler. */
static void *                             mp_timeout_handler_context = NULL;                    /**< Registered time-out handler context. */
static simple_timer_states_t              m_simple_timer_state       = SIMPLE_TIMER_STATE_IDLE; /**< State machine state. */

#define APP_SIMPLE_TIMER_INSTANCE 1

#if (APP_SIMPLE_TIMER_INSTANCE == 0)
    #if (TIMER_CONFIG_MODE(0) != TIMER_MODE_MODE_Timer)
        #error "Unsupported timer mode."
    #endif
    #if (TIMER_CONFIG_BIT_WIDTH(0) != TIMER_BITMODE_BITMODE_16Bit)
        #error "Unsupported timer bit width."
    #endif
    const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(0);
#elif (APP_SIMPLE_TIMER_INSTANCE == 1)
    #if (TIMER_CONFIG_MODE(1) != TIMER_MODE_MODE_Timer)
        #error "Unsupported timer mode."
    #endif
    #if (TIMER_CONFIG_BIT_WIDTH(1) != TIMER_BITMODE_BITMODE_16Bit)
        #error "Unsupported timer bit width."
    #endif
    const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(1);
#elif (APP_SIMPLE_TIMER_INSTANCE == 2)
    #if (TIMER_CONFIG_MODE(2) != TIMER_MODE_MODE_Timer)
        #error "Unsupported timer mode."
    #endif
    #if (TIMER_CONFIG_BIT_WIDTH(2) != TIMER_BITMODE_BITMODE_16Bit)
        #error "Unsupported timer bit width."
    #endif