Esempio n. 1
0
/**@brief Function for setting up ANT module to be ready for SDM RX broadcast.
 *
 * Issues the following commands:
 * - set network key
 * - assign channel
 * - set channel ID 
 * - set channel frequency
 * - set channel period
 * - open channel 
 */
static void ant_channel_sdm_rx_setup(void)
{
    uint32_t err_code;
    
    // Set network key.
    err_code = sd_ant_network_address_set(NETWORK_0, m_network_0_key);
    APP_ERROR_CHECK(err_code);
    
    // Set channel number.
    err_code = sd_ant_channel_assign(CHANNEL_0, 
                                     CHANNEL_TYPE_SLAVE, 
                                     NETWORK_0, 
                                     CHANNEL_0_ANT_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    // Set channel ID.
    err_code = sd_ant_channel_id_set(CHANNEL_0, 
                                     CHANNEL_0_CHAN_ID_DEV_NUM, 
                                     CHANNEL_0_CHAN_ID_DEV_TYPE, 
                                     CHANNEL_0_CHAN_ID_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);
    
    // Set channel radio frequency.
    err_code = sd_ant_channel_radio_freq_set(CHANNEL_0, CHANNEL_0_FREQUENCY);
    APP_ERROR_CHECK(err_code);
    
    // Set channel period.
    err_code = sd_ant_channel_period_set(CHANNEL_0, CHANNEL_0_RX_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);
    
    // Open channel.
    err_code = sd_ant_channel_open(CHANNEL_0);
    APP_ERROR_CHECK(err_code);
}
/**@brief Initialize the ANT HRM reception.
 */
static void ant_hrm_rx_init(void)
{
    uint32_t err_code;
    
    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_ant_network_key);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_assign(ANT_HRMRX_ANT_CHANNEL,
                                     ANT_HRMRX_CHANNEL_TYPE,
                                     ANTPLUS_NETWORK_NUMBER,
                                     ANT_HRMRX_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_channel_id_set(ANT_HRMRX_ANT_CHANNEL,
                                     ANT_HRMRX_DEVICE_NUMBER,
                                     ANT_HRMRX_DEVICE_TYPE,
                                     ANT_HRMRX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_radio_freq_set(ANT_HRMRX_ANT_CHANNEL, ANTPLUS_RF_FREQ);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_period_set(ANT_HRMRX_ANT_CHANNEL, ANT_HRMRX_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 3
0
void ascc_init(void)
{
    uint32_t err_code;

#ifdef BLE_STACK_SUPPORT_REQD
    // Configure the ble stack and callback
    ble_stack_init();

    // Initialize the ble phone connection
    cntrldevice_initialize();
#endif

    err_code = ant_stack_static_config();
    APP_ERROR_CHECK(err_code);

    // Configure the network key for our chosen netowrk number
    err_code = sd_ant_network_address_set(ANT_PUBLIC_NETWORK_NUMBER, m_ant_public_network_key);
    APP_ERROR_CHECK(err_code);

    // Initialise and start the asc, ascmm, and phone modules
    ascm_init(&m_asc_parameters);
    ascmm_init(&m_ascmm_discovery_parameters, &m_ascmm_connection_parameters, DEVICE_NUMBER);
    phc_init(&m_phone_parameters);

    ascm_turn_on();
    ascmm_turn_on();
    phc_turn_on();
}
/**@brief Function for configuring the ANT channel.
 */
static __INLINE void bicycle_power_channel_open(void)
{
    uint32_t err_code;

    // Set network address.
    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);

    // Set channel number.
    err_code = sd_ant_channel_assign(BP_RX_ANT_CHANNEL,
                                     CHANNEL_TYPE_SLAVE,
                                     ANTPLUS_NETWORK_NUMBER,
                                     BP_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    // Set channel ID.
    err_code = sd_ant_channel_id_set(BP_RX_ANT_CHANNEL,
                                     BP_RX_DEVICE_NUMBER,
                                     BP_DEVICE_TYPE,
                                     BP_RX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(BP_RX_ANT_CHANNEL, BP_RF_FREQ);
    APP_ERROR_CHECK(err_code);

    // Set channel period.
    err_code = sd_ant_channel_period_set(BP_RX_ANT_CHANNEL, BP_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Open channel.
    err_code = sd_ant_channel_open(BP_RX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 5
0
/**@brief Function for configuring the ANT channel.
 */
static __INLINE void channel_open(void)
{    
    // Set Network Address.
    uint32_t err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);
    
    // Set Channel Number.
    err_code = sd_ant_channel_assign(CBSC_TX_ANT_CHANNEL, 
                                     CBSC_TX_CHANNEL_TYPE, 
                                     ANTPLUS_NETWORK_NUMBER, 
                                     CBSC_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);
    
    // Set Channel ID.
    err_code = sd_ant_channel_id_set(CBSC_TX_ANT_CHANNEL, 
                                     CBSC_TX_DEVICE_NUMBER, 
                                     CBSC_DEVICE_TYPE, 
                                     CBSC_TX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set Channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(CBSC_TX_ANT_CHANNEL, CBSC_RF_FREQ);
    APP_ERROR_CHECK(err_code);

    // Set Channel period.
    err_code = sd_ant_channel_period_set(CBSC_TX_ANT_CHANNEL, CBSC_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);
  
    // Open Channel.
    err_code = sd_ant_channel_open(CBSC_TX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 6
0
/**@brief Function for setting up the ANT module to be ready for TX broadcast.
 */
static void ant_channel_tx_broadcast_setup(void)
{
    uint32_t err_code;
    uint8_t  m_network_key[] = ANT_NETWORK_KEY;
    uint8_t m_broadcast_data[] = BROADCAST_PAYLOAD;

    // Set Network Key.
    err_code = sd_ant_network_address_set(ANT_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);

    // Assign Channel
    err_code = sd_ant_channel_assign(ANT_CHANNEL_NUMBER,
                                     CHANNEL_TYPE_MASTER,
                                     ANT_NETWORK_NUMBER,
                                     ANT_EXT_ASSIGN);

    APP_ERROR_CHECK(err_code);

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(ANT_CHANNEL_NUMBER,
                                     ANT_DEV_NUM,
                                     ANT_DEV_TYPE,
                                     ANT_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set Channel Period
    err_code = sd_ant_channel_period_set(ANT_CHANNEL_NUMBER, ANT_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Set RF Frequency
    err_code = sd_ant_channel_radio_freq_set(ANT_CHANNEL_NUMBER, ANT_RF_FREQUENCY);
    APP_ERROR_CHECK(err_code);

    //Set Tx Power
    err_code = sd_ant_channel_radio_tx_power_set(ANT_CHANNEL_NUMBER, RADIO_TX_POWER_LVL_3, ANT_TRANSMIT_POWER);
    APP_ERROR_CHECK(err_code);

    // Setup broadcast payload
    err_code = sd_ant_broadcast_message_tx(ANT_CHANNEL_NUMBER,
                                          BROADCAST_DATA_BUFFER_SIZE,
                                          m_broadcast_data);

    if(err_code != NRF_ANT_ERROR_CHANNEL_IN_WRONG_STATE)
    {
        APP_ERROR_CHECK(err_code);
    }

    // Open channel
    err_code = sd_ant_channel_open(ANT_CHANNEL_NUMBER);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 7
0
/**
 * @brief Function for ANT stack initialization.
 *
 * @details Initializes the SoftDevice and the ANT event interrupt.
 */
static void softdevice_setup(void)
{
    uint32_t err_code;
    
    err_code = softdevice_ant_evt_handler_set(ant_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    err_code = softdevice_handler_init(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL, 0, NULL);
    APP_ERROR_CHECK(err_code);

    err_code = ant_stack_static_config(); // set ant resource
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_network_key);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 8
0
File: main.c Progetto: mcanos/nRF51
/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    uint32_t err_code;

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

    // Enable BLE stack.
    ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));

#ifdef S130
    ble_enable_params.gatts_enable_params.attr_tab_size   = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
#endif

    err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for System events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    err_code = softdevice_ant_evt_handler_set(ant_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    // TODO check this
    err_code = ant_stack_static_config();
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_network_key);
    APP_ERROR_CHECK(err_code);

}
Esempio n. 9
0
void hrm_rx_open(void)
{
    printf("Opening hrm rx channel...\n");  

    // Initialize data page structs.
    data_page_init();
  
    // Set Network Address.
    uint32_t err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_network_key);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel Number.
    err_code = sd_ant_channel_assign(HRMRX_ANT_CHANNEL, 
                                     HRMRX_CHANNEL_TYPE, 
                                     ANTPLUS_NETWORK_NUMBER,
                                     HRMRX_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);  

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(HRMRX_ANT_CHANNEL, 
                                     HRMRX_DEVICE_NUMBER, 
                                     HRMRX_DEVICE_TYPE, 
                                     HRMRX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(HRMRX_ANT_CHANNEL, ANTPLUS_RF_FREQ);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel period.
    err_code = sd_ant_channel_period_set(HRMRX_ANT_CHANNEL, HRMRX_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);  

    // Open Channels.
    err_code = sd_ant_channel_open(HRMRX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);  
} 
Esempio n. 10
0
uint32_t ant_fs_key_set(uint8_t network_number)
{
    return sd_ant_network_address_set(network_number, m_ant_fs_network_key);
}
Esempio n. 11
0
uint32_t ant_custom_key_set(uint8_t network_number, uint8_t * network_key)
{
    ASSERT(network_key != NULL);
    return sd_ant_network_address_set(network_number, network_key);
}
Esempio n. 12
0
/**@brief Function for setting up the ANT channels
 *
 */
static void ant_channel_setup(void)
{
    uint32_t err_code;

    // !! GLOBAL ANT CONFIGURATION !! //
    err_code = sd_ant_network_address_set(ANT_CHANNEL_DEFAULT_NETWORK, pm_ant_public_key);
    APP_ERROR_CHECK(err_code);

    // !! CONFIGURE MOBILE CHANNEL !! //
    
    /* The purpose of the mobile channel is to provide an independent link
       to a mobile platform using ANT. The mobile channel will report the 
       status of the LED as well as the status of the slave relay channel 
       (closed/open/searching). The mobile channel will also accept commands
       which emulate the function of the development board. For example, to
       set the the set the state of the led or to put the device into pairing 
       mode.
    */   
    
    //Assign the mobile channel type
    err_code = sd_ant_channel_assign(   ANT_MOBILE_CHANNEL,
                                        ANT_MOBILE_CHANNEL_TYPE,
                                        ANT_CHANNEL_DEFAULT_NETWORK,
                                        0);
    APP_ERROR_CHECK(err_code);

     //Assign channel id
    err_code = sd_ant_channel_id_set(   ANT_MOBILE_CHANNEL,
                                        ANT_MOBILE_DEVICE_NUMBER,
                                        ANT_MOBILE_DEVICE_TYPE,
                                        ANT_MOBILE_TRANSMISSION_TYPE);
    APP_ERROR_CHECK(err_code);

    //Assign channel frequency
    err_code = sd_ant_channel_radio_freq_set(   ANT_MOBILE_CHANNEL,
                                                ANT_MOBILE_FREQUENCY);
    APP_ERROR_CHECK(err_code);

   //Assign channel message period
    err_code = sd_ant_channel_period_set (  ANT_MOBILE_CHANNEL,
                                            ANT_MOBILE_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Open channel right away.
    err_code = sd_ant_channel_open(ANT_MOBILE_CHANNEL);
    APP_ERROR_CHECK(err_code);

    // !! CONFIGURE RELAY MASTER CHANNEL !! //
    
    /* The relay master channel is always on and transmits the 
       status of the LED and the status of the slave relay channel
       (open/closed/searching). It is 100% bi-directional once
       a slave connects to it (status updates from the slave are 
       sent on every message period)
    */

    //Assign the relay master channel type
    err_code = sd_ant_channel_assign(   ANT_RELAY_MASTER_CHANNEL,
                                        ANT_RELAY_MASTER_CHANNEL_TYPE,
                                        ANT_CHANNEL_DEFAULT_NETWORK,
                                        0);
    APP_ERROR_CHECK(err_code);

     //Assign channel id
    err_code = sd_ant_channel_id_set(   ANT_RELAY_MASTER_CHANNEL,
                                        ANT_RELAY_MASTER_DEVICE_NUMBER,
                                        ANT_RELAY_DEVICE_TYPE,
                                        ANT_RELAY_TRANSMISSION_TYPE);
    APP_ERROR_CHECK(err_code);

    //Assign channel frequency
    err_code = sd_ant_channel_radio_freq_set(   ANT_RELAY_MASTER_CHANNEL,
                                                ANT_RELAY_FREQUENCY);
    APP_ERROR_CHECK(err_code);

   //Assign channel message period
    err_code = sd_ant_channel_period_set (  ANT_RELAY_MASTER_CHANNEL,
                                            ANT_RELAY_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Open channel right away.
    err_code = sd_ant_channel_open(ANT_RELAY_MASTER_CHANNEL);
    APP_ERROR_CHECK(err_code);

    // !! CONFIGURE RELAY SLAVE CHANNEL !! //
    
    /* The purpose of the relay slave channel is to find and synchronize 
       to another devices master really channel. The slave channel is only
       opened on a button press and uses proximity pairing to connect to a 
       master channel. Once tracking a master the slave channel will send status
       message back to the master 100% of the time. 
    */

     //Assign the relay slave channel type
    err_code = sd_ant_channel_assign(   ANT_RELAY_SLAVE_CHANNEL,
                                        ANT_RELAY_SLAVE_CHANNEL_TYPE,
                                        ANT_CHANNEL_DEFAULT_NETWORK,
                                        0);
    APP_ERROR_CHECK(err_code);

     //Assign channel id
    err_code = sd_ant_channel_id_set(   ANT_RELAY_SLAVE_CHANNEL,
                                        ANT_RELAY_SLAVE_DEVICE_NUMBER,
                                        ANT_RELAY_DEVICE_TYPE,
                                        ANT_RELAY_TRANSMISSION_TYPE);
    APP_ERROR_CHECK(err_code);

    //Assign channel frequency
    err_code = sd_ant_channel_radio_freq_set(   ANT_RELAY_SLAVE_CHANNEL,
                                                ANT_RELAY_FREQUENCY);
    APP_ERROR_CHECK(err_code);

   //Assign channel message period
    err_code = sd_ant_channel_period_set (  ANT_RELAY_SLAVE_CHANNEL,
                                            ANT_RELAY_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_prox_search_set(ANT_RELAY_SLAVE_CHANNEL, ANT_PROXIMITY_BIN, 0);
    APP_ERROR_CHECK(err_code);

    // DO NOT OPEN THE SLAVE RIGHT AWAY - IT OPENS ON BUTTON PRESS
    // OR MESSAGE FROM MOBILE PHONE
}