/*!
    \file    readme.txt
    \brief   description of the EEMUL functional demo

    \version 2026-07-01, V1.0.0, firmware for gd32c2x1
*/

/*
    Copyright (c) 2026, GigaDevice Semiconductor Inc.

    Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this 
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice, 
       this list of conditions and the following disclaimer in the documentation 
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors 
       may be used to endorse or promote products derived from this software without 
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
*/

  This example is based on the GD32C231C-EVAL-V1.0 board, it provides a description of how to
use the EEMUL (Flash-backed EEPROM emulation) middleware and demonstrates that it
works correctly through a sequence of self-checking functional scenarios. SysTick
is configured and the results of every test step are printed on EVAL_COM
(USART0, 115200-8-N-1). Connect the board's USB-to-UART / COM port to a terminal
to watch the demo run.

  The demo builds a small device-parameter store (boot counter, mode, threshold,
calibration vector and firmware version) on top of EEMUL and exercises it the way
a real application would. It is the on-target counterpart of the host functional
test (tests/host/host_functional_test.c): several scenarios deliberately tamper
with the emulation Flash through the bound port operations to reproduce torn
writes and data corruption, then verify that EEMUL recovers safely.

  EEMUL configuration used by this demo (see eemul_config.h):
    - block header   : full (with CRC32)
    - program align  : 8 bytes
    - block mode     : sub-blocks
    - bad-block policy: retry
    - region         : two Flash pages reserved at the top of the main array

  Functional scenarios printed over the UART:
    S1  first boot + factory defaults : a blank region auto-formats, all
        parameters read as zero, then factory defaults are written via the
        batch API.
    S2  persistence across reboot     : a fresh init recovers the last committed
        values; the boot counter is bumped as on a real start-up.
    S3  differential (no-op) write    : writing an unchanged value commits no new
        block; writing a changed value advances the sequence.
    S4  wear / block rotation         : many sequential writes rotate across the
        region and the final value survives a reboot.
    S5  torn-write / power-loss       : the latest block's header magic is cleared
        directly in Flash; on recovery the damaged block is rejected, the previous
        good value is restored, and the store stays writable.
    S6  payload tamper detection      : a committed block's payload bytes are
        corrupted in Flash; the block CRC rejects it on recovery and the previous
        good block is restored (full-header builds only).

  Each step prints "OK" or "FAIL"; every scenario ends with "=> PASS" or
"=> FAIL", and a final summary line reports how many scenarios passed. A correct
build prints PASS for all scenarios.

