This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

change to new app_timer.c

Hi, I'm porting my project from SDK8.1 to SDK10.

I replace static app_timer_id_t m_beacon_timer_id; to APP_TIMER_DEF(m_beacon_timer_id); to avoid hardfault when creat timer.

But I have a struct like this

typedef struct
{
    a4wp_ptu_reg_item_state_t   state;                      /**< Item state */
    uint8_t                     adv_flags;                  /**< ADV flags */
    ble_gap_addr_t              address;                    /**< Device peer address */
    ble_a4wps_c_t               ble_a4wps_c;                /**< Collection of handles */
    a4wp_pru_static_t           prev_pru_static;            /**< Previous received PRU static parameters */
    a4wp_pru_dynamic_t          prev_pru_dynamic;           /**< Previous received PRU dynamic parameters */
    a4wp_pru_control_t          prev_ctl;                   /**< Previous control packet being sent to PRU */
    app_timer_id_t              timer_id;                   /**< Registration / reconnection timer for this item */
    a4wp_ctl_adj_power_t        prev_adj_power;             /**< Previous power adjustment level. */
    uint8_t                     idle_conn_cnt;              /**< Idle connection counter */
    uint8_t                     age;                        /**< Number of devices items being added after this one */
    uint8_t                     pre_connect_cnt;            /**< Number of adv packets ignored due to only 1 of 2 criterie fullfilled.  */   
    uint8_t                     connect_attmepts;           /**< Number of connection attempts.  */
    uint32_t                    p_adj_time;                 /**< Current TICKS value of RTC at time of sending power adjust command.  */
    int32_t                     p_rect_before_p_adj;        /**< PRECT in the PRU before we send the power adjust command. */
    uint8_t                     active_p_adj_cooldown:1;    /**< Does this PRU have an active cooldown from a previous power adjust command? */
    uint8_t                     adjusted_power:1;           /**< Has this PRU responded to the previous adjust power command? */
    uint8_t                     pending_dyn_read:1;         /**< Waiting for response on dyn param read */
    uint8_t                     pending_ctl_write:1;        /**< Waiting for response on control write */
    uint8_t                     charged:1;                  /**< True when PRU charged, false otherwise */
    uint8_t                     pending_charge_disable:1;   /**< We are waiting on a Charge disable command to be acknowledged. */
    uint8_t                     link_encrypted:1;           /**< Link is encrypted. */
    uint8_t                     p_adj_disabled:1;           /**< No more power adjust commands should be sent to PRU. */
} a4wp_ptu_reg_item_t;

And initial the item like this

static void m_reg_item_init(a4wp_ptu_reg_item_t * item)
{
    app_timer_id_t temp;
    temp = item->timer_id;
    memset(item, 0, sizeof(a4wp_ptu_reg_item_t));
    item->ble_a4wps_c.conn_handle = BLE_CONN_HANDLE_INVALID;
    item->timer_id = temp;
}

Then it will get HardFault in app_timer_create p_node->is_running = false;

// Instantiate registration and connection timers
for(i = 0; i < A4WP_PTU_MAX_CONNECTIONS; i++)
{
    err_code = a4wp_ptu_reg_item_get_from_index(i, &reg_item);
    APP_ERROR_CHECK(err_code);
    
    err_code = app_timer_create(&(reg_item->timer_id), \
                                APP_TIMER_MODE_SINGLE_SHOT,
                                m_reg_timer_handle);
    APP_ERROR_CHECK(err_code);    
}

I know the app_timer_id_t cause the HardFault, But I have no idea how fix it when there is a struct have app_timer_id_t.

Please give me some tips to solve it >"<

Parents
  • I find some way can work, but not sure it's correct or not. This is what I change :

    static void m_reg_item_init(a4wp_ptu_reg_item_t * item)
    {
        APP_TIMER_DEF(temp);
        memset(item, 0, sizeof(a4wp_ptu_reg_item_t));
        item->ble_a4wps_c.conn_handle = BLE_CONN_HANDLE_INVALID;
        item->timer_id = temp;
    }
    

    and for other function, the original is

    // Initiate time set impedance shift detect timer
    err_code = app_timer_create(&m_status.time_set_check_timer_id,
                                    APP_TIMER_MODE_SINGLE_SHOT,
                                    m_a4wp_ptu_time_set_check_timer_handler);
    

    need modify to

    // Initiate time set impedance shift detect timer
    		APP_TIMER_DEF(time_set_check_timer_id);
    		m_status.time_set_check_timer_id = time_set_check_timer_id;
        err_code = app_timer_create(&m_status.time_set_check_timer_id,
                                    APP_TIMER_MODE_SINGLE_SHOT,
                                    m_a4wp_ptu_time_set_check_timer_handler);
    

    Now my project works fine, but I really don't know it's correct or not.

  • This is correct. See the comment from the app_timer developer in this thread: devzone.nordicsemi.com/.../

    Cheers, Håkon

Reply Children
No Data
Related