ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
persistent_config.c File Reference
#include "persistent_config.h"
#include <assert.h>
#include <inttypes.h>
#include <malloc.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "boards/pico.h"
#include "hardware/flash.h"
#include "hardware/regs/addressmap.h"
#include "hardware/sync.h"
#include "system/common.h"
Include dependency graph for persistent_config.c:

Go to the source code of this file.

Macros

#define FLASH_TARGET_OFFSET   (PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE)
 
#define CONFIG_MAGIC   0xCAFEBABE
 
#define BYTES_PER_KIBIBYTE   1024U
 
#define RAM_TOTAL_KIBIBYTES   264U
 
#define RAM_BASE_ADDRESS   0x20000000U
 
#define W55RP20_FLASH_TOTAL_BYTES   (2U * BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
 

Functions

void print_memory_usage (void)
 Print RAM usage statistics.
 
void print_flash_usage (void)
 Print flash usage statistics.
 
static const config_tnonsafe_config_read (void)
 
bool config_read (config_t *cfg)
 Read configuration from flash.
 
void config_wipe (void)
 Erase persistent configuration sector.
 
bool config_is_valid (void)
 Check if flash configuration magic marker is valid.
 
void dump_config (void)
 Print current configuration to console/log output.
 
void config_write (const config_t *cfg)
 Write configuration to flash.
 

Macro Definition Documentation

◆ BYTES_PER_KIBIBYTE

#define BYTES_PER_KIBIBYTE   1024U

Definition at line 39 of file persistent_config.c.

◆ CONFIG_MAGIC

#define CONFIG_MAGIC   0xCAFEBABE

Definition at line 38 of file persistent_config.c.

◆ FLASH_TARGET_OFFSET

#define FLASH_TARGET_OFFSET   (PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE)

Definition at line 36 of file persistent_config.c.

◆ RAM_BASE_ADDRESS

#define RAM_BASE_ADDRESS   0x20000000U

Definition at line 41 of file persistent_config.c.

◆ RAM_TOTAL_KIBIBYTES

#define RAM_TOTAL_KIBIBYTES   264U

Definition at line 40 of file persistent_config.c.

◆ W55RP20_FLASH_TOTAL_BYTES

#define W55RP20_FLASH_TOTAL_BYTES   (2U * BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)

Definition at line 42 of file persistent_config.c.

Function Documentation

◆ config_is_valid()

bool config_is_valid ( void  )

Check if flash configuration magic marker is valid.

Returns
true when stored configuration is valid.

Definition at line 123 of file persistent_config.c.

References CONFIG_MAGIC, config_t::magic, and nonsafe_config_read().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_read()

bool config_read ( config_t cfg)

Read configuration from flash.

Parameters
cfgDestination object.
Returns
true when valid config was read.

Definition at line 103 of file persistent_config.c.

References CONFIG_MAGIC, config_t::magic, and nonsafe_config_read().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_wipe()

void config_wipe ( void  )

Erase persistent configuration sector.

Definition at line 114 of file persistent_config.c.

References FLASH_TARGET_OFFSET.

Referenced by event_dispatch().

Here is the caller graph for this function:

◆ config_write()

void config_write ( const config_t cfg)

Write configuration to flash.

Parameters
cfgSource config object.

Definition at line 177 of file persistent_config.c.

References CONFIG_MAGIC, FLASH_TARGET_OFFSET, and config_t::magic.

Referenced by event_dispatch().

Here is the caller graph for this function:

◆ dump_config()

◆ nonsafe_config_read()

static const config_t * nonsafe_config_read ( void  )
static

Definition at line 98 of file persistent_config.c.

References FLASH_TARGET_OFFSET.

Referenced by config_is_valid(), config_read(), and dump_config().

Here is the caller graph for this function:

◆ print_flash_usage()

void print_flash_usage ( void  )

Print flash usage statistics.

Definition at line 78 of file persistent_config.c.

References BYTES_PER_KIBIBYTE, LOG_PLAIN, PRIu32, and W55RP20_FLASH_TOTAL_BYTES.

Referenced by event_dispatch().

Here is the caller graph for this function:

◆ print_memory_usage()

void print_memory_usage ( void  )

Print RAM usage statistics.

Definition at line 44 of file persistent_config.c.

References BYTES_PER_KIBIBYTE, LOG_PLAIN, PRIu32, RAM_BASE_ADDRESS, and RAM_TOTAL_KIBIBYTES.

Referenced by event_dispatch().

Here is the caller graph for this function: