# flash.h File Reference

## Defines
#define | _FLASH_H 1
## Functions
int16_t | flwrite (const void *frombuf, uint16_t size, uint16_t toaddr)
int16_t | flread (uint16_t fromaddr, void *tobuf, uint16_t size)
uint16_t | flsize ()

## Define Documentation

#define _FLASH_H 1

## Function Documentation

int16_t flread | ( | uint16_t | fromaddr,
|  | void * | tobuf,
|  | uint16_t | size |
| ) |  |  |

A system call to provide random read access of the on-chip flash as a non-volatile storage.

Precondition:
  Do not call this inside the interrupt handler context. Caller must maintain its own flash address management to avoid reading unwanted data. 0 is the start address of the flash abstraction.

Postcondition:
  If successful, size number of bytes of fromaddr on the flash is written to tobuf.

Parameters:

  `[in]` | fromaddr | address of the flash where data is read from
  `[out]` | tobuf | address of a the buffer where content will be copied to
  `[in]` | size | size of tobuf in bytes

Returns:
  0 if succeed or -1 if fail and errno is set appropriately.

Errors:
  EINVAL if invalid parameters are passed

  ESIZE if size is too large

uint16_t flsize | ( |  | ) |

A function call that returns the total size of the internal non-volatile storage in bytes that are available for application to use.

Precondition:
  None.

Postcondition:
  returns the total size of the internal non-voltagile storage in bytes that are available to applications.

Returns:
  size of the internal non-voltagile storage in bytes

int16_t flwrite | ( | const void * | frombuf,
|  | uint16_t | size,
|  | uint16_t | toaddr |
| ) |  |  |

A system call to provide random write access to the on-chip flash as a non-volatile storage.

Precondition:
  Do not call this inside the interrupt handler context. Caller must maintain its own flash address management to avoid overwriting previous data. 0 is the start address of the flash abstraction.

Postcondition:
  If successful, size number of bytes of frombuf is written into the flash starting at toaddr.

Parameters:

  `[in]` | frombuf | pointer to the buffer to be written to flash
  `[in]` | size | size of the buffer in bytes
  `[in]` | toaddr | start address on the flash where content will be copied to

Returns:
  0 if succeed or -1 if fail and errno is set appropriately.

Errors:
  EINVAL if invalid parameters are passed

  ESIZE if size is too large