# nvm_hal.c File Reference

Non-Volatile Memory HAL. More...

`#include <stdbool.h>`
`#include "em_msc.h"`
`#include "nvm.h"`
`#include "nvm_hal.h"`
Include dependency graph for nvm_hal.c:

Go to the source code of this file.

## Functions

static NVM_Result_t | NVMHAL_ReturnTypeConvert (msc_Return_TypeDef result)
| Prototypes of functions that should be placed in RAM.
void | NVMHAL_Init (void)
| Initialize NVM .
void | NVMHAL_DeInit (void)
| De-initialize NVM .
void | NVMHAL_Read (uint8_t *pAddress, void *pObject, uint16_t len)
| Read data from NVM.
NVM_Result_t | NVMHAL_Write (uint8_t *pAddress, void const *pObject, uint16_t len)
| Write data to NVM.
NVM_Result_t | NVMHAL_PageErase (uint8_t *pAddress)
| Erase a page in the NVM.
void | NVMHAL_Checksum (uint16_t *pChecksum, void *pMemory, uint16_t len)
| Calculate checksum according to CCITT CRC16.

## Detailed Description

Non-Volatile Memory HAL.

Author:
  Energy Micro AS

Version:
  3.20.2

## License

(C) Copyright 2013 Energy Micro AS, http://www.energymicro.com

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. 4. The source and compiled code may only be used on Energy Micro "EFM32" microcontrollers and "EFR4" radios.

DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no obligation to support this Software. Energy Micro AS is providing the Software "AS IS", with no express or implied warranties of any kind, including, but not limited to, any implied warranties of merchantability or fitness for any particular purpose or warranties against infringement of any proprietary rights of a third party.

Energy Micro AS will not be liable for any consequential, incidental, or special damages, or any other relief, or for any claim by any third party, arising from your use of this Software.

Definition in file nvm_hal.c.

## Function Documentation

void NVMHAL_Checksum | ( | uint16_t * | pChecksum,
|  | void * | pMemory,
|  | uint16_t | len |
| ) |  |  |

Calculate checksum according to CCITT CRC16.

This function calculates a checksum of the supplied buffer. The checksum is calculated using CCITT CRC16 plynomial x^16+x^12+x^5+1.

This functionality is also present internally in the API, but is duplicated here to allow for much more efficient calculations specific to the hardware.

Parameters:

  `[in]` | pChecksum | Pointer to where the checksum should be calculated and stored. This buffer should be initialized. A good consistent starting point would be NVM_CHECKSUM_INITIAL.
  `[in]` | pMemory | Pointer to the data you want to calculate a checksum for.
  `[in]` | len | The length of the data.

Definition at line 708 of file nvm_hal.c.

void NVMHAL_DeInit | ( | void |  | ) |

De-initialize NVM .

This function is run when the API deinit function is run. This should be done before any graceful halts.

Definition at line 457 of file nvm_hal.c.

void NVMHAL_Init | ( | void |  | ) |

Initialize NVM .

This function is run upon initialization, at least once before any other functions. It can be used to call necessary startup routines before the hardware can be accessed.

Definition at line 433 of file nvm_hal.c.

Referenced by NVM_Init().

Here is the caller graph for this function:

NVM_Result_t NVMHAL_PageErase | ( | uint8_t * | pAddress | ) |

Erase a page in the NVM.

This function is used to erase a page in the NVM (typically an aligned 512 byte block of memory). It is important that the size and alignment of the page erased is the same as specified in the configuration.

Parameters:

  `[in]` | *pAddress | Memory address pointing to the start of the page to erase.

Returns:
  Returns the result of the erase operation using a NVM_Result_t.

Definition at line 671 of file nvm_hal.c.

References NVMHAL_ReturnTypeConvert().

Referenced by NVM_Erase().

Here is the call graph for this function:

Here is the caller graph for this function:

void NVMHAL_Read | ( | uint8_t * | pAddress,
|  | void * | pObject,
|  | uint16_t | len |
| ) |  |  |

Read data from NVM.

This function is used to read data from the NVM hardware. It should be a blocking call, since the thread asking for data to be read cannot continue without the data.

Another requirement is the ability to read unaligned blocks of data with single byte precision.

Parameters:

  `[in]` | *pAddress | Memory address in hardware for the data to read.
  `[in]` | *pObject | RAM buffer to store the data from NVM.
  `[in]` | len | The length of the data.

Definition at line 483 of file nvm_hal.c.

Referenced by NVM_Erase(), NVM_Init(), NVM_Read(), NVM_WearLevelGet(), and NVM_Write().

Here is the caller graph for this function:

static NVM_Result_t NVMHAL_ReturnTypeConvert | ( | msc_Return_TypeDef | result | ) | `[static]`

Prototypes of functions that should be placed in RAM.

Since it operate on the flash they cannot be read out during operation.

Convert return type.

This function converts between the return type of the emlib and the NVM API.

Parameters:

  `[in]` | result | Operation result in a msc_Return_TypeDef.

Returns:
  Returns the corresponding NVM_Result_t.

Definition at line 403 of file nvm_hal.c.

References nvmResultAddrInvalid, nvmResultError, nvmResultInputInvalid, and nvmResultOk.

Referenced by NVMHAL_PageErase(), and NVMHAL_Write().

Here is the caller graph for this function:

NVM_Result_t NVMHAL_Write | ( | uint8_t * | pAddress,
|  | void const * | pObject,
|  | uint16_t | len |
| ) |  |  |

Write data to NVM.

This function is used to write data from the NVM. It should be a blocking call. This may be changed in the future, but this is currently a requirement made due to the design of the API code.

Another requirement is the ability to write unaligned blocks of data with single byte precision.

Parameters:

  `[in]` | *pAddress | Memory address to write to.
  `[in]` | *pObject | Pointer to data to write..
  `[in]` | len | The length of the data.

Returns:
  Returns the result of the write operation using a NVM_Result_t.

Definition at line 574 of file nvm_hal.c.

References NVMHAL_ReturnTypeConvert().

Referenced by NVM_Erase(), and NVM_Write().

Here is the call graph for this function:

Here is the caller graph for this function: