Revision 1990ae634d0602ff022afc946ef66933e4e4a2dc authored by Santiago Zanella-Beguelin on 09 December 2019, 17:48:55 UTC, committed by Santiago Zanella-Beguelin on 09 December 2019, 17:50:10 UTC
1 parent ae8e182
Raw File
Lib_Memzero.c
#include <stdint.h>

void clear_words(void* mem, unsigned int nwords)
{ // Clear 32-bit words from memory. "nwords" indicates the number of words to be zeroed.
  // This function uses the volatile type qualifier to inform the compiler not to optimize out the memory clearing.
    volatile uint32_t *v = mem;

    for (unsigned int i = 0; i < nwords; i++) {
        v[i] = (uint32_t)0U;
    }
}

void Lib_Memzero_clear_words_u16(unsigned int nwords, uint16_t *mem)
{
  clear_words((void*)mem, nwords/2);
}

void Lib_Memzero_clear_words_u8(unsigned int nwords, uint8_t *mem)
{
  clear_words((void*)mem, nwords/4);
}
back to top