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

Adding my own ERROR_BASE_NUM

I am defining my own list of errors that my application will use. At the same time, I would like to report the NRF errors as well. What do you think about a solution where I define my own ERROR_BASE_NUM? In nrf_error.h there are some error ranges defined, like this:

// From nrf_error.h
#define NRF_ERROR_BASE_NUM      (0x0)       ///< Global error base
#define NRF_ERROR_SDM_BASE_NUM  (0x1000)    ///< SDM error base
#define NRF_ERROR_SOC_BASE_NUM  (0x2000)    ///< SoC error base
#define NRF_ERROR_STK_BASE_NUM  (0x3000)    ///< STK error base

What if i use those errors, and also expand it with my own range of errors starting at 0xA000, like this:

 #define MY_ERROR_BASE_NUM (0xA000) ///< My own base num
 #define MY_ERROR_OVERFLOW (MY_ERROR_BASE_NUM  + 3)  ///< Overflow Error

 ret_code_t my_func(uint8_t x)
 {
     ret_code_t err_code;

     // NRF error code will be returned
     err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
     if (err_code != NRF_SUCCESS)
     {
        return err_code;
     }

     // My own error code will be returned
     if(x>25)
         return MY_ERROR_OVERFLOW;

     return NRF_SUCCESS;
 }   

For this to work, I need to at least be sure that the range 0xA000 will continue to be reserved for me in the future, and there are probably more cases of trouble that I didn't think of.

Do you have other suggestions on how to handle my own errors as well as NRF errors?

Parents Reply
  • Ok. In that case, wouldn't it be nice if there was a definition, from Nordic, of a certain user-reserved area for this? That would make this more future-proof. For example:

     // From nrf_error.h
     #define NRF_ERROR_BASE_NUM      (0x0)       ///< Global error base
     #define NRF_ERROR_SDM_BASE_NUM  (0x1000)    ///< SDM error base
     #define NRF_ERROR_SOC_BASE_NUM  (0x2000)    ///< SoC error base
     #define NRF_ERROR_STK_BASE_NUM  (0x3000)    ///< STK error base
     #define NRF_ERROR_USER_DEFINED_BASE_NUM (0xA000) ///< 0xA000 - 0xFFFF: Reserved for user error codes
    
Children
No Data
Related