nrf51822 code reading notes one

As a failed embedded programmer, at the rookie level, nodic's nrf1822 chip was used in the project. Due to the maintenance nature, the underlying code was not studied in depth. Here, I mainly read some notes on the underlying code. There is no order to see which note. where.

word alignment check

51822 A word is four of itself. In some operations, it is necessary to check whether the incoming parameters are word-aligned. Use the following functions:

static __INLINE bool is_word_aligned(void * p)
{
    return (((uintptr_t)p & 0x03) == 0);
}

That is, to check whether the lower two bits of the address are 1 to determine whether the address is an integer multiple of 4.
The address of the storage unit is in bytes, a word occupies 4 bytes, 32 bits

CEIL_DIV

/**@brief Perform integer division, making sure the result is rounded up.
 *
 * @details One typical use for this is to compute the number of objects with size B is needed to
 *          hold A number of bytes.
 *
 * @param[in]   A   Numerator.分子
 * @param[in]   B   Denominator.分母
 *
 * @return      Integer result of dividing A by B, rounded up.
 */
#define CEIL_DIV(A, B)   ((((A) - 1) / (B)) + 1)

When allocating space, do you allocate it by word, and if there is a shortage, make up a word.

APP_BUTTON_INIT

#define APP_BUTTON_INIT(BUTTONS, BUTTON_COUNT, DETECTION_DELAY, USE_SCHEDULER)                     \
    do                                                                                             \
    {                                                                                              \
        uint32_t ERR_CODE = app_button_init((BUTTONS),                                             \
                                            (BUTTON_COUNT),                                        \
                                            (DETECTION_DELAY),                                     \
                                            (USE_SCHEDULER) ? app_button_evt_schedule : NULL);     \
        APP_ERROR_CHECK(ERR_CODE);                                                                 \
    } while (0)

The initialization of APP_BUTTON_INIT, in which the USE_SCHEDULER parameter is to confirm whether the scheduler is used. If the software does not want to execute the trigger logic of the button immediately, the trigger event can be placed in the scheduler and then executed. See the answer at the URL below.
https://devzone.nordicsemi.com/f/nordic-qa/9046/app_button_init

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325598396&siteId=291194637