Rtos API example

Embed: (wiki syntax)

« Back to documentation index

example1.cpp File Reference

example1.cpp File Reference

Test case to demonstrates each API function works correctly. More...

Go to the source code of this file.


Detailed Description

Test case to demonstrates each API function works correctly.

Example 1 Notes

The example test does the following CFSTORE operations:

  • initialises
  • creates a key-value pair (KV).
  • writes the data for the KV
  • closes KV.
  • flushes the KV to flash
  • opens KV for reading.
  • reads KV and checks the value blob was the same as previously written.
  • closes KV.
  • finds a KV (there is only 1 to find).
  • for the KV returned, get the key name.
  • for the KV returned, get the value length.
  • for the KV returned, delete the KV.
  • find another KV (which fails as there are no more keys to find).
  • flushes the updated state to flash to store the removal of the deleted KV.
  • uninitialises
  • stops

This test is coded so as to work in the following modes:

  • flash sync mode i.e. with caps.asynchronous_ops == false
  • flash async mode i.e. with caps.asynchronous_ops == true

The dual async/sync mode support with the same code is more complicated than if the implementation just supported sync mode for example. However, it has the benefit of being more versatile.

The test leaves the flash in the same state as at the beginning of the test so it can be run a second time on the device without flashing, and the test should still work.

How to Build Example1 as a Stand-alone Application

This example can be build as a stand-alone application as follows:

  • Create a new mbed application using the `mbed new .` command.
  • Copy this file example1.cpp from the to the top level application directory and rename the file to main.cpp.
  • Build the application with `mbed compile -v -m <target> -t <toolchain> -DCFSTORE_EXAMPLE1_APP` e.g. `mbed compile -v -m K64F -t GCC_ARM -DCFSTORE_EXAMPLE1_APP`.

Definition in file example1.cpp.