Advertisement
saarilp

main.c

Mar 20th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.37 KB | None | 0 0
  1. /**
  2.  * This software is subject to the ANT+ Shared Source License
  3.  * www.thisisant.com/swlicenses
  4.  * Copyright (c) Dynastream Innovations, Inc. 2012
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or
  8.  * without modification, are permitted provided that the following
  9.  * conditions are met:
  10.  * 1) Redistributions of source code must retain the above
  11.  *    copyright notice, this list of conditions and the following
  12.  *    disclaimer.
  13.  *
  14.  * 2) Redistributions in binary form must reproduce the above
  15.  *    copyright notice, this list of conditions and the following
  16.  *    disclaimer in the documentation and/or other materials
  17.  *    provided with the distribution.
  18.  *
  19.  * 3) Neither the name of Dynastream nor the names of its
  20.  *    contributors may be used to endorse or promote products
  21.  *    derived from this software without specific prior
  22.  *    written permission.
  23.  *
  24.  * The following actions are prohibited:
  25.  * 1) Redistribution of source code containing the ANT+ Network
  26.  *    Key. The ANT+ Network Key is available to ANT+ Adopters.
  27.  *    Please refer to http://thisisant.com to become an ANT+
  28.  *    Adopter and access the key.
  29.  *
  30.  * 2) Reverse engineering, decompilation, and/or disassembly of
  31.  *    software provided in binary form under this license.
  32.  *
  33.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  34.  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  35.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  36.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE HEREBY
  37.  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  38.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
  40.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  41.  * SERVICES; DAMAGE TO ANY DEVICE, LOSS OF USE, DATA, OR
  42.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  43.  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  45.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46.  * OF THE POSSIBILITY OF SUCH DAMAGE. SOME STATES DO NOT ALLOW
  47.  * THE EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
  48.  * ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
  49.  *
  50.  */
  51. /**@file
  52.  * @defgroup ant_bpwr_sensor_main ANT Bicycle Power sensor example
  53.  * @{
  54.  * @ingroup nrf_ant_bicycle_power
  55.  *
  56.  * @brief Example of ANT Bicycle Power profile display.
  57.  *
  58.  * Before compiling this example for NRF52, complete the following steps:
  59.  * - Download the S212 SoftDevice from <a href="https://www.thisisant.com/developer/components/nrf52832" target="_blank">thisisant.com</a>.
  60.  * - Extract the downloaded zip file and copy the S212 SoftDevice headers to <tt>\<InstallFolder\>/components/softdevice/s212/headers</tt>.
  61.  * If you are using Keil packs, copy the files into a @c headers folder in your example folder.
  62.  * - Make sure that @ref ANT_LICENSE_KEY in @c nrf_sdm.h is uncommented.
  63.  */
  64.  
  65. #include <stdio.h>
  66. #include "nrf.h"
  67. #include "bsp.h"
  68. #include "hardfault.h"
  69. #include "app_error.h"
  70. #include "app_timer.h"
  71. #include "nrf_pwr_mgmt.h"
  72. #include "nrf_sdh.h"
  73. #include "nrf_sdh_ant.h"
  74. #include "ant_key_manager.h"
  75. #include "diy_fec.h"
  76. #include "ant_state_indicator.h"
  77.  
  78. #include "nrf_log.h"
  79. #include "nrf_log_ctrl.h"
  80. #include "nrf_log_default_backends.h"
  81.  
  82. #include "ant_interface.h"
  83. #include "ant_search_config.h"
  84. #include "trainer_ctrl.h"
  85.  
  86. #define APP_ANT_OBSERVER_PRIO       1  
  87.  
  88. static ant_diy_fec_profile_t m_ant_diy_fec;
  89.  
  90. static const ant_channel_config_t  m_diy_fec_channel_config =
  91.     {                                                                          
  92.         .channel_number    = DIY_FEC_CHANNEL_NUM,                                  
  93.         .channel_type      = DIY_FEC_CHANNEL_TYPE,                            
  94.         .ext_assign        = DIY_FEC_EXT_ASSIGN,                                  
  95.         .rf_freq           = DIY_FEC_ANTPLUS_RF_FREQ,                              
  96.         .transmission_type = CHAN_ID_TRANS_TYPE,                              
  97.         .device_type       = 0x11,                                  
  98.         .device_number     = CHAN_ID_DEV_NUM,                                  
  99.         .channel_period    = DIY_FEC_MSG_PERIOD,                                  
  100.         .network_number    = ANTPLUS_NETWORK_NUM,                                  
  101.     };
  102.  
  103.  
  104.  
  105. NRF_SDH_ANT_OBSERVER(m_ant_observer, ANT_BPWR_ANT_OBSERVER_PRIO,
  106.                      ant_diy_fec_evt_handler, &m_ant_diy_fec);
  107.  
  108.  
  109.  
  110.  
  111. void local_ant_diy_fec_evt_handler(ant_diy_fec_profile_t * p_profile, ant_diy_fec_evt_t event)
  112. {
  113.     nrf_pwr_mgmt_feed();
  114.  
  115.     switch (event)
  116.     {
  117.         case ANT_DIY_FEC_PAGE_80_UPDATED:
  118.             /* fall through */
  119.         case ANT_DIY_FEC_PAGE_81_UPDATED:
  120.             NRF_LOG_INFO("Update %d\n",event);
  121.             //ant_bpwr_simulator_one_iteration(&m_ant_bpwr_simulator, event);
  122.             break;
  123.  
  124.         default:
  125.             break;
  126.     }
  127. }
  128.  
  129. void bsp_evt_handler(bsp_event_t event)
  130. {
  131.     switch (event)
  132.     {
  133.         case BSP_EVENT_KEY_0:
  134.            // ant_bpwr_simulator_increment(&m_ant_bpwr_simulator);
  135.             break;
  136.  
  137.         case BSP_EVENT_KEY_1:
  138.            // ant_bpwr_simulator_decrement(&m_ant_bpwr_simulator);
  139.             break;
  140.  
  141.         case BSP_EVENT_KEY_2:
  142.            // ant_bpwr_calib_response(&m_ant_bpwr);
  143.             break;
  144.  
  145.         default:
  146.             break;
  147.     }
  148. }
  149. /**
  150.  * @brief Function for setup all thinks not directly associated with ANT stack/protocol.
  151.  * @desc Initialization of: @n
  152.  *         - app_tarce for debug.
  153.  *         - app_timer, pre-setup for bsp.
  154.  *         - bsp for signaling LEDs and user buttons.
  155.  */
  156. static void utils_setup(void)
  157. {
  158.     ret_code_t err_code = NRF_LOG_INIT(NULL);
  159.     APP_ERROR_CHECK(err_code);
  160.  
  161.     // Initialize and start a single continuous mode timer, which is used to update the event time
  162.     // on the main data page.
  163.     err_code = app_timer_init();
  164.     APP_ERROR_CHECK(err_code);
  165.  
  166.     err_code = nrf_pwr_mgmt_init();
  167.     APP_ERROR_CHECK(err_code);
  168.  
  169.     NRF_LOG_DEFAULT_BACKENDS_INIT();
  170.  
  171.     err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
  172.                         bsp_evt_handler);
  173.     APP_ERROR_CHECK(err_code);
  174.  
  175.  
  176.    // err_code = ant_state_indicator_init(m_ant_diy_fec.channel_number, DIY_FEC_CHANNEL_TYPE);
  177.    // APP_ERROR_CHECK(err_code);
  178. }
  179.  
  180.  
  181.  
  182. /**
  183.  * @brief Function for ANT stack initialization.
  184.  *
  185.  * @details Initializes the SoftDevice and the ANT event interrupt.
  186.  */
  187. static void softdevice_setup(void)
  188. {
  189.     ret_code_t err_code = nrf_sdh_enable_request();
  190.     APP_ERROR_CHECK(err_code);
  191.  
  192.     ASSERT(nrf_sdh_is_enabled());
  193.  
  194.     err_code = nrf_sdh_ant_enable();
  195.     APP_ERROR_CHECK(err_code);
  196.  
  197.     err_code = ant_plus_key_set(ANTPLUS_NETWORK_NUM);
  198.     APP_ERROR_CHECK(err_code);
  199. }
  200.  
  201.  
  202.  
  203. /**
  204.  * @brief Function for Bicycle Power profile initialization.
  205.  *
  206.  * @details Initializes the Bicycle Power profile and open ANT channel.
  207.  */
  208. static void profile_setup(void)
  209. {
  210. /** @snippet [ANT BPWR TX Profile Setup] */
  211.     ret_code_t err_code;
  212.     NRF_LOG_INFO("profile_setup");
  213.     #if 1
  214.     err_code = ant_diy_fec_init(&m_ant_diy_fec,&m_diy_fec_channel_config);
  215.  
  216.     APP_ERROR_CHECK(err_code);
  217.  
  218.     // fill manufacturer's common data page.
  219.     m_ant_diy_fec.page_80 = ANT_COMMON_page80(BPWR_HW_REVISION,
  220.                                            BPWR_MANUFACTURER_ID,
  221.                                            BPWR_MODEL_NUMBER);
  222.     // fill product's common data page.
  223.     m_ant_diy_fec.page_81 = ANT_COMMON_page81(BPWR_SW_REVISION_MAJOR,
  224.                                            BPWR_SW_REVISION_MINOR,
  225.                                            BPWR_SERIAL_NUMBER);
  226.  
  227.     err_code = ant_diy_fec_open(&m_ant_diy_fec);
  228.     APP_ERROR_CHECK(err_code);
  229. #endif
  230.  
  231.    
  232.  
  233.  
  234.     //err_code = ant_state_indicator_channel_opened();
  235.     //APP_ERROR_CHECK(err_code);
  236.  
  237.  
  238. /** @snippet [ANT BPWR TX Profile Setup] */
  239. }
  240.  
  241. /**@brief Function for application main entry, does not return.
  242.  */
  243. int main(void)
  244. {
  245.  
  246.     utils_setup();
  247.    
  248.     NRF_LOG_INFO("DIY FEC main\n");
  249.  
  250.     trainer_ctrl_init();
  251.    
  252.     softdevice_setup();
  253.  
  254.     profile_setup();
  255.        
  256.     ant_search_uplink_setup();
  257.  
  258.  
  259.     for (;;)
  260.     {
  261.         NRF_LOG_FLUSH();
  262.         nrf_pwr_mgmt_run();
  263.         //nrf_gpio_pin_toggle(led_pin1);
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement