takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers example1.cpp Source File

example1.cpp

Go to the documentation of this file.
00001 /*
00002  * mbed Microcontroller Library
00003  * Copyright (c) 2006-2016 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  *
00017  */
00018 
00019 /** @file example1.cpp Test case to demonstrates each API function works correctly.
00020  *
00021  * \par Example 1 Notes
00022  *
00023  * The example test does the following CFSTORE operations:
00024  * - initialises
00025  * - creates a key-value pair (KV).
00026  * - writes the data for the KV
00027  * - closes KV.
00028  * - flushes the KV to flash
00029  * - opens KV for reading.
00030  * - reads KV and checks the value blob was the same as previously written.
00031  * - closes KV.
00032  * - finds a KV (there is only 1 to find).
00033  * - for the KV returned, get the key name.
00034  * - for the KV returned, get the value length.
00035  * - for the KV returned, delete the KV.
00036  * - find another KV (which fails as there are no more keys to find).
00037  * - flushes the updated state to flash to store the removal of the deleted KV.
00038  * - uninitialises
00039  * - stops
00040  *
00041  * This test is coded so as to work in the following modes:
00042  * - flash sync mode i.e. with caps.asynchronous_ops == false
00043  * - flash async mode i.e. with caps.asynchronous_ops == true
00044  *
00045  * The dual async/sync mode support with the same code is more complicated
00046  * than if the implementation just supported sync mode for example. However,
00047  * it has the benefit of being more versatile.
00048  *
00049  * The test leaves the flash in the same state as at the beginning of the test so
00050  * it can be run a second time on the device without flashing, and the test should
00051  * still work.
00052  *
00053  * \par How to Build Example1 as a Stand-alone Application
00054  *
00055  * This example can be build as a stand-alone application as follows:
00056  * - Create a new mbed application using the `mbed new .` command.
00057  * - Copy this file example1.cpp from the to the top level application directory and rename the file to main.cpp.
00058  * - 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`.
00059  */
00060 #if defined __MBED__ && ! defined TOOLCHAIN_GCC_ARM
00061 
00062 #include "mbed.h"
00063 #include "cfstore_config.h"
00064 #include "Driver_Common.h"
00065 #include "cfstore_debug.h"
00066 #include "cfstore_test.h"
00067 #include "configuration_store.h"
00068 #include "utest/utest.h"
00069 #include "unity/unity.h"
00070 #include "greentea-client/test_env.h"
00071 
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <string.h>
00075 #include <inttypes.h>
00076 
00077 using namespace utest::v1;
00078 
00079 static control_t cfstore_example1_test_00(const size_t call_count)
00080 {
00081     (void) call_count;
00082     printf("Not implemented for ARM toolchain\n");
00083     return CaseNext;
00084 }
00085 
00086 
00087 utest::v1::status_t greentea_setup(const size_t number_of_cases)
00088 {
00089     GREENTEA_SETUP(100, "default_auto");
00090     return greentea_test_setup_handler(number_of_cases);
00091 }
00092 
00093 Case cases[] = {
00094            /*          1         2         3         4         5         6        7  */
00095            /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
00096         Case("EXAMPLE1_test_00", cfstore_example1_test_00),
00097 };
00098 
00099 
00100 /* Declare your test specification with a custom setup handler */
00101 Specification specification(greentea_setup, cases);
00102 
00103 int main()
00104 {
00105     return !Harness::run(specification);
00106 }
00107 
00108 
00109 #else
00110 
00111 
00112 #include "mbed.h"
00113 
00114 #ifndef CFSTORE_EXAMPLE1_APP
00115 /* when built as Configuration-Store example, include greentea support otherwise omit */
00116 #include "utest/utest.h"
00117 #include "unity/unity.h"
00118 #include "greentea-client/test_env.h"
00119 
00120 #else   // CFSTORE_EXAMPLE1_APP
00121 // map utest types for building as stand alone example
00122 #define control_t   void
00123 #define CaseNext
00124 #endif  // CFSTORE_EXAMPLE1_APP
00125 
00126 #include "cfstore_config.h"
00127 #include "configuration_store.h"
00128 
00129 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00130 #include "flash_journal_strategy_sequential.h"
00131 #include "flash_journal.h"
00132 #include "Driver_Common.h"
00133 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00134 
00135 #include <stdio.h>
00136 #include <stdlib.h>
00137 #include <string.h>
00138 
00139 /// @cond CFSTORE_DOXYGEN_DISABLE
00140 #ifndef CFSTORE_EXAMPLE1_APP
00141 using namespace utest::v1;
00142 #endif
00143 
00144 
00145 #define CFSTORE_EX1_TEST_ASSERT(Expr)                       if (!(Expr)) { printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00146 #define CFSTORE_EX1_TEST_ASSERT_EQUAL(expected, actual)     if ((expected) != (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00147 #define CFSTORE_EX1_TEST_ASSERT_NOT_EQUAL(expected, actual) if ((expected) == (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00148 
00149 #define CFSTORE_EX1_TEST_ASSERT_MSG(Expr, _fmt, ...)      \
00150     do                                                    \
00151     {                                                     \
00152         if (!(Expr))                                      \
00153         {                                                 \
00154             printf(_fmt, __VA_ARGS__);                    \
00155             while (1) ;                                   \
00156         }                                                 \
00157     }while(0);
00158 
00159 #define CFSTORE_EX1_LOG(_fmt, ...)                        \
00160   do                                                      \
00161   {                                                       \
00162         printf(_fmt, __VA_ARGS__);                        \
00163   }while(0);
00164 
00165 
00166 const char* cfstore_ex_opcode_str[] =
00167 {
00168     "UNDEFINED",
00169     "CFSTORE_OPCODE_CLOSE",
00170     "CFSTORE_OPCODE_CREATE",
00171     "CFSTORE_OPCODE_DELETE",
00172     "CFSTORE_OPCODE_FIND",
00173     "CFSTORE_OPCODE_FLUSH",
00174     "CFSTORE_OPCODE_GET_KEY_NAME",
00175     "CFSTORE_OPCODE_GET_STATUS",
00176     "CFSTORE_OPCODE_GET_VALUE_LEN",
00177     "CFSTORE_OPCODE_INITIALIZE",
00178     "CFSTORE_OPCODE_OPEN",
00179     "CFSTORE_OPCODE_POWER_CONTROL",
00180     "CFSTORE_OPCODE_READ",
00181     "CFSTORE_OPCODE_RSEEK",
00182     "CFSTORE_OPCODE_UNINITIALIZE",
00183     "CFSTORE_OPCODE_WRITE",
00184     "CFSTORE_OPCODE_MAX"
00185 };
00186 
00187 bool cfstore_example1_done = false;
00188 const char* cfstore_ex_kv_name = "basement.medicine.pavement.government.trenchcoat.off.cough.off.kid.did.when.again.alleyway.friend.cap.pen.dollarbills.ten.foot.soot.put.but.anyway.say.May.DA.kid.did.toes.bows.those.hose.nose.clothes.man.blows.well.well";
00189 const char* cfstore_ex_kv_value = "TheRollingStone";
00190 #define CFSTORE_EX1_RSEEK_OFFSET    10   /* offset to S of Stone */
00191 
00192 typedef enum cfstore_ex_state_t {
00193     CFSTORE_EX_STATE_INITIALIZING = 1,
00194     CFSTORE_EX_STATE_INIT_DONE,
00195     CFSTORE_EX_STATE_CREATING,
00196     CFSTORE_EX_STATE_CREATE_DONE,
00197     CFSTORE_EX_STATE_WRITING,
00198     CFSTORE_EX_STATE_WRITE_DONE,
00199     CFSTORE_EX_STATE_CLOSING1,
00200     CFSTORE_EX_STATE_CLOSE_DONE1,
00201     CFSTORE_EX_STATE_FLUSHING1,
00202     CFSTORE_EX_STATE_FLUSH_DONE1,
00203     CFSTORE_EX_STATE_OPENING,
00204     CFSTORE_EX_STATE_OPEN_DONE,
00205     CFSTORE_EX_STATE_READING1,
00206     CFSTORE_EX_STATE_READ_DONE1,
00207     CFSTORE_EX_STATE_RSEEKING,
00208     CFSTORE_EX_STATE_RSEEK_DONE,
00209     CFSTORE_EX_STATE_READING2,
00210     CFSTORE_EX_STATE_READ_DONE2,
00211     CFSTORE_EX_STATE_CLOSING2,
00212     CFSTORE_EX_STATE_CLOSE_DONE2,
00213     CFSTORE_EX_STATE_FINDING1,
00214     CFSTORE_EX_STATE_FIND_DONE1,
00215     CFSTORE_EX_STATE_GETTING_KEY_NAME,
00216     CFSTORE_EX_STATE_GET_KEY_NAME_DONE,
00217     CFSTORE_EX_STATE_GETTING_VALUE_LEN,
00218     CFSTORE_EX_STATE_GET_VALUE_LEN_DONE,
00219     CFSTORE_EX_STATE_DELETING,
00220     CFSTORE_EX_STATE_DELETE_DONE,
00221     CFSTORE_EX_STATE_FINDING2,
00222     CFSTORE_EX_STATE_FIND_DONE2,
00223     CFSTORE_EX_STATE_FLUSHING2,
00224     CFSTORE_EX_STATE_FLUSH_DONE2,
00225     CFSTORE_EX_STATE_UNINITIALIZING,
00226     CFSTORE_EX_STATE_UNINIT_DONE
00227 } cfstore_ex_state_t;
00228 
00229 typedef struct cfstore_example1_ctx_t
00230 {
00231     ARM_CFSTORE_CAPABILITIES caps;
00232     uint8_t hkey[CFSTORE_HANDLE_BUFSIZE];
00233     uint8_t hkey_next_buf[CFSTORE_HANDLE_BUFSIZE];
00234     uint8_t hkey_prev_buf[CFSTORE_HANDLE_BUFSIZE];
00235     ARM_CFSTORE_HANDLE  hkey_next;
00236     ARM_CFSTORE_HANDLE  hkey_prev;
00237     cfstore_ex_state_t state;
00238     ARM_CFSTORE_SIZE len;
00239     ARM_CFSTORE_KEYDESC kdesc;
00240     ARM_CFSTORE_FMODE flags;
00241     char value[CFSTORE_KEY_NAME_MAX_LENGTH+1];
00242     /* callback attributes*/
00243     int32_t callback_status;
00244     ARM_CFSTORE_HANDLE  callback_handle;
00245 } cfstore_example1_ctx_t;
00246 
00247 static cfstore_example1_ctx_t cfstore_example1_ctx_g;
00248 
00249 extern ARM_CFSTORE_DRIVER cfstore_driver;
00250 ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver;
00251 
00252 /* forward declarations */
00253 static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx);
00254 /// @endcond
00255 
00256 
00257 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00258 
00259 #define CFSTORE_FLASH_START_FORMAT (FLASH_JOURNAL_OPCODE_RESET + 0x00010000)
00260 
00261 typedef enum cfstore_ex_flash_state_t {
00262     CFSTORE_EX_FLASH_STATE_STARTING = 1,
00263     CFSTORE_EX_FLASH_STATE_FORMATTING,
00264     CFSTORE_EX_FLASH_STATE_INITIALIZING,
00265     CFSTORE_EX_FLASH_STATE_RESETTING,
00266     CFSTORE_EX_FLASH_STATE_READY,
00267 } cfstore_ex_flash_state_t;
00268 
00269 typedef struct cfstore_example1_flash_ctx_t
00270 {
00271     volatile cfstore_ex_flash_state_t state;
00272 } cfstore_example1_flash_ctx_t;
00273 
00274 static cfstore_example1_flash_ctx_t cfstore_example1_flash_ctx_g;
00275 
00276 
00277 static void cfstore_ex_flash_journal_callback(int32_t status, FlashJournal_OpCode_t cmd_code)
00278 {
00279     static FlashJournal_t jrnl;
00280     extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
00281     const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F;
00282 
00283 
00284     if(cmd_code == (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT) {
00285         CFSTORE_EX1_LOG("FORMATTING%s", "\n");
00286         status = flashJournalStrategySequential_format(drv, 4, cfstore_ex_flash_journal_callback);
00287         CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status);
00288         if(status == 0) {
00289             /* async completion pending */
00290             return;
00291         }
00292         /* status > 0 implies  operation completed synchronously
00293          * intentional fall through */
00294     }
00295 
00296     switch(cmd_code)
00297     {
00298     case FLASH_JOURNAL_OPCODE_FORMAT:
00299         /* format done */
00300         CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status);
00301         cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_INITIALIZING;
00302 
00303         CFSTORE_EX1_LOG("FLASH INITIALIZING%s", "\n");
00304         status = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL);
00305         CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status);
00306         if(status == 0) {
00307             /* async completion pending */
00308             break;
00309         }
00310         /* status > 0 implies  operation completed synchronously
00311          * intentional fall through */
00312     case FLASH_JOURNAL_OPCODE_INITIALIZE:
00313         /* initialize done */
00314         CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status);
00315         cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_RESETTING;
00316 
00317         CFSTORE_EX1_LOG("FLASH RESETTING%s", "\n");
00318         status = FlashJournal_reset(&jrnl);
00319         CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (status=%d)\r\n", __func__, (int) status);
00320         /* intentional fall through */
00321     case FLASH_JOURNAL_OPCODE_RESET:
00322         /* reset done */
00323         CFSTORE_EX1_LOG("FLASH RESET DONE%s", "\n");
00324         cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_READY;
00325         break;
00326 
00327     default:
00328         CFSTORE_EX1_LOG("%s:Error: notification of unsupported cmd_code event (status=%d, cmd_code=%d)\n", __func__, (int) status, (int) cmd_code);
00329         return;
00330     }
00331     return;
00332 }
00333 #endif  /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00334 
00335 
00336 
00337 /* @brief   test startup code to reset flash for testing purposes.
00338  */
00339 static int32_t cfstore_test_startup(void)
00340 {
00341     ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities();
00342     CFSTORE_EX1_LOG("INITIALIZING: caps.asynchronous_ops=%d\n", (int) caps.asynchronous_ops);
00343 
00344 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00345 
00346     memset(&cfstore_example1_flash_ctx_g, 0, sizeof(cfstore_example1_flash_ctx_g));
00347     cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_STARTING;
00348     cfstore_ex_flash_journal_callback(JOURNAL_STATUS_OK, (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT);
00349     while(cfstore_example1_flash_ctx_g.state != CFSTORE_EX_FLASH_STATE_READY) {
00350         /* spin */
00351     }
00352 
00353 #endif /*  CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00354 
00355     return ARM_DRIVER_OK;
00356 }
00357 
00358 
00359 static void cfstore_ex_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE  handle)
00360 {
00361     (void) handle;
00362 
00363     cfstore_example1_ctx_t* ctx = (cfstore_example1_ctx_t*) client_context;
00364 
00365     /* CFSTORE_EX1_LOG("%s:entered: status=%d, cmd_code=%d (%s) handle=%p\r\n", __func__, (int) status, (int) cmd_code, cfstore_ex_opcode_str[cmd_code], handle); */
00366     switch(cmd_code)
00367     {
00368     case CFSTORE_OPCODE_INITIALIZE:
00369         ctx->state = CFSTORE_EX_STATE_INIT_DONE;
00370         break;
00371     case CFSTORE_OPCODE_CREATE:
00372         ctx->state = CFSTORE_EX_STATE_CREATE_DONE;
00373         break;
00374     case CFSTORE_OPCODE_WRITE:
00375         ctx->state = CFSTORE_EX_STATE_WRITE_DONE;
00376         break;
00377     case CFSTORE_OPCODE_CLOSE:
00378         switch(ctx->state)
00379         {
00380         case(CFSTORE_EX_STATE_CLOSING1):
00381             ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1;
00382             break;
00383         case(CFSTORE_EX_STATE_CLOSING2):
00384             ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2;
00385             break;
00386         default:
00387             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Close() error (line=%u)\r\n", __func__, __LINE__);
00388             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00389              * and hence is commented out. Re-instate if previous assert is removed.
00390              * break; */
00391         }
00392         break;
00393     case CFSTORE_OPCODE_FLUSH:
00394         switch(ctx->state)
00395         {
00396             case(CFSTORE_EX_STATE_FLUSHING1):
00397                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1;
00398                 break;
00399             case(CFSTORE_EX_STATE_FLUSHING2):
00400                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2;
00401                 break;
00402             default:
00403                 CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__);
00404                 /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00405                  * and hence is commented out. Re-instate if previous assert is removed.
00406                  * break; */
00407         }
00408         break;
00409     case CFSTORE_OPCODE_OPEN:
00410         ctx->state = CFSTORE_EX_STATE_OPEN_DONE;
00411         break;
00412     case CFSTORE_OPCODE_FIND:
00413         switch(ctx->state)
00414         {
00415         case(CFSTORE_EX_STATE_FINDING1):
00416             ctx->state = CFSTORE_EX_STATE_FIND_DONE1;
00417             break;
00418         case(CFSTORE_EX_STATE_FINDING2):
00419             ctx->state = CFSTORE_EX_STATE_FIND_DONE2;
00420             break;
00421         default:
00422             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__);
00423             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00424              * and hence is commented out. Re-instate if previous assert is removed.
00425              * break; */
00426         }
00427         break;
00428     case CFSTORE_OPCODE_GET_KEY_NAME:
00429         ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE;
00430         break;
00431     case CFSTORE_OPCODE_GET_VALUE_LEN:
00432         ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE;
00433         break;
00434     case CFSTORE_OPCODE_READ:
00435         switch(ctx->state)
00436         {
00437         case(CFSTORE_EX_STATE_READING1):
00438             ctx->state = CFSTORE_EX_STATE_READ_DONE1;
00439             break;
00440         case(CFSTORE_EX_STATE_READING2):
00441             ctx->state = CFSTORE_EX_STATE_READ_DONE2;
00442             break;
00443         default:
00444             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Read() error (line=%u)\r\n", __func__, __LINE__);
00445             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00446              * and hence is commented out. Re-instate if previous assert is removed.
00447              * break; */
00448         }
00449         break;
00450     case CFSTORE_OPCODE_RSEEK:
00451         ctx->state = CFSTORE_EX_STATE_RSEEK_DONE;
00452         break;
00453     case CFSTORE_OPCODE_DELETE:
00454         ctx->state = CFSTORE_EX_STATE_DELETE_DONE;
00455         break;
00456     case CFSTORE_OPCODE_UNINITIALIZE:
00457         ctx->state = CFSTORE_EX_STATE_UNINIT_DONE;
00458         break;
00459     case CFSTORE_OPCODE_GET_STATUS:
00460     case CFSTORE_OPCODE_POWER_CONTROL:
00461     default:
00462         CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: received asynchronous notification for opcode=%d (%s)\r\b", __func__, cmd_code, cmd_code < CFSTORE_OPCODE_MAX ? cfstore_ex_opcode_str[cmd_code] : "unknown");
00463         /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00464          * and hence is commented out. Re-instate if previous assert is removed.
00465          * break; */
00466     }
00467     ctx->callback_status = status;
00468     ctx->callback_handle = handle;
00469     cfstore_ex_fms_update(ctx);
00470     return;
00471 }
00472 
00473 static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx)
00474 {
00475     int32_t ret;
00476 
00477     switch (ctx->state)
00478     {
00479         case CFSTORE_EX_STATE_INITIALIZING:
00480             CFSTORE_EX1_LOG("INITIALIZING%s", "\r\n");
00481             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_INITIALIZE can be invoked before Initialize() has returned
00482             ret = cfstore_drv->Initialize(cfstore_ex_callback, ctx);
00483             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret);
00484             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00485                 ctx->state = CFSTORE_EX_STATE_INIT_DONE;
00486                 break;
00487             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00488                 // await pending notification of completion.
00489                 break;
00490             }
00491             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00492             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00493              * and hence is commented out. Re-instate if previous assert is removed.
00494              * break; */
00495 
00496         case CFSTORE_EX_STATE_INIT_DONE:
00497             CFSTORE_EX1_LOG("INIT_DONE%s", "\r\n");
00498             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Initialize() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00499             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_INITIALIZE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00500             ctx->state = CFSTORE_EX_STATE_CREATING;
00501             // intentional fall-through
00502 
00503         case CFSTORE_EX_STATE_CREATING:
00504             CFSTORE_EX1_LOG("CREATING%s", "\r\n");
00505             memset(&ctx->kdesc, 0, sizeof(ARM_CFSTORE_KEYDESC));
00506             ctx->kdesc.drl = ARM_RETENTION_NVM;
00507             ctx->len = strlen(cfstore_ex_kv_value);
00508             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CREATE can be invoked before Create() has returned
00509             ret = cfstore_drv->Create(cfstore_ex_kv_name, ctx->len, &ctx->kdesc, ctx->hkey);
00510             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Create() failed (ret=%ld)\r\n", __func__, ret);
00511             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00512                 ctx->state = CFSTORE_EX_STATE_CREATE_DONE;
00513                 break;
00514             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00515                 // await pending notification of completion.
00516                 break;
00517             }
00518             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00519             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00520              * and hence is commented out. Re-instate if previous assert is removed.
00521              * break; */
00522 
00523         case CFSTORE_EX_STATE_CREATE_DONE:
00524             CFSTORE_EX1_LOG("CREATE_DONE%s", "\r\n");
00525             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Create() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00526             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CREATE) received handle (%p) is not the hkey supplied to Create()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00527             ctx->state = CFSTORE_EX_STATE_WRITING;
00528             // intentional fall-through
00529 
00530         case CFSTORE_EX_STATE_WRITING:
00531             CFSTORE_EX1_LOG("WRITING%s", "\r\n");
00532             ctx->len = strlen(cfstore_ex_kv_value);
00533             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_WRITE can be invoked before Write() has returned
00534             ret = cfstore_drv->Write(ctx->hkey, cfstore_ex_kv_value, &ctx->len);
00535             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Write() failed (ret=%ld)\r\n", __func__, ret);
00536             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00537                 ctx->state = CFSTORE_EX_STATE_WRITE_DONE;
00538                 break;
00539             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00540                 // await pending notification of completion.
00541                 break;
00542             }
00543             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00544             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00545              * and hence is commented out. Re-instate if previous assert is removed.
00546              * break; */
00547 
00548         case CFSTORE_EX_STATE_WRITE_DONE:
00549             CFSTORE_EX1_LOG("WRITE_DONE%s", "\r\n");
00550             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Write() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00551             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(cfstore_ex_kv_value));
00552             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len);
00553             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_WRITE) received handle (%p) is not the hkey supplied to Write()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00554             ctx->state = CFSTORE_EX_STATE_CLOSING1;
00555             // intentional fall-through
00556 
00557         case CFSTORE_EX_STATE_CLOSING1:
00558             CFSTORE_EX1_LOG("CLOSING1%s", "\r\n");
00559             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned
00560             ret = cfstore_drv->Close(ctx->hkey);
00561             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00562             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00563                 ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1;
00564                 break;
00565             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00566                 // await pending notification of completion.
00567                 break;
00568             }
00569             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00570             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00571              * and hence is commented out. Re-instate if previous assert is removed.
00572              * break; */
00573 
00574         case CFSTORE_EX_STATE_CLOSE_DONE1:
00575             CFSTORE_EX1_LOG("CLOSE_DONE1%s", "\r\n");
00576             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00577             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CLOSE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00578             ctx->state = CFSTORE_EX_STATE_FLUSHING1;
00579             // intentional fall-through
00580 
00581         case CFSTORE_EX_STATE_FLUSHING1:
00582             CFSTORE_EX1_LOG("FLUSHING1%s", "\r\n");
00583             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned
00584             ret = cfstore_drv->Flush();
00585             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret);
00586             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00587                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1;
00588                 break;
00589             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00590                 // await pending notification of completion.
00591                 break;
00592             }
00593             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00594             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00595              * and hence is commented out. Re-instate if previous assert is removed.
00596              * break; */
00597 
00598         case CFSTORE_EX_STATE_FLUSH_DONE1:
00599             CFSTORE_EX1_LOG("FLUSH_DONE1%s", "\r\n");
00600             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00601             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FLUSH) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00602             ctx->state = CFSTORE_EX_STATE_OPENING;
00603             // intentional fall-through
00604 
00605         case CFSTORE_EX_STATE_OPENING:
00606             CFSTORE_EX1_LOG("OPENING%s", "\r\n");
00607             memset(&ctx->flags, 0, sizeof(ctx->flags));
00608             memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE);
00609             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_OPEN can be invoked before Open() has returned
00610             ret = cfstore_drv->Open(cfstore_ex_kv_name, ctx->flags, ctx->hkey);
00611             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Open() failed (ret=%ld)\r\n", __func__, ret);
00612             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00613                 ctx->state = CFSTORE_EX_STATE_OPEN_DONE;
00614                 break;
00615             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00616                 // await pending notification of completion.
00617                 break;
00618             }
00619             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00620             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00621              * and hence is commented out. Re-instate if previous assert is removed.
00622              * break; */
00623 
00624         case CFSTORE_EX_STATE_OPEN_DONE:
00625             CFSTORE_EX1_LOG("OPEN_DONE%s", "\r\n");
00626             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Open() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00627             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_OPEN) received handle (%p) is not the hkey supplied to Open()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00628             ctx->state = CFSTORE_EX_STATE_READING1;
00629             // intentional fall-through
00630 
00631         case CFSTORE_EX_STATE_READING1:
00632             CFSTORE_EX1_LOG("READING1%s", "\r\n");
00633             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00634             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00635             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00636             ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len);
00637             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret);
00638             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00639                 ctx->state = CFSTORE_EX_STATE_READ_DONE1;
00640                 break;
00641             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00642                 // await pending notification of completion.
00643                 break;
00644             }
00645             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00646             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00647              * and hence is commented out. Re-instate if previous assert is removed.
00648              * break; */
00649 
00650         case CFSTORE_EX_STATE_READ_DONE1:
00651             CFSTORE_EX1_LOG("READ_DONE1%s", "\r\n");
00652             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00653             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(cfstore_ex_kv_value));
00654             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len);
00655             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_READ) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00656             CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex_kv_value, strlen(cfstore_ex_kv_value)) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex_kv_value);
00657             ctx->state = CFSTORE_EX_STATE_RSEEKING;
00658             // intentional fall-through
00659 
00660         case CFSTORE_EX_STATE_RSEEKING:
00661             CFSTORE_EX1_LOG("RSEEKING%s", "\r\n");
00662             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00663             ret = cfstore_drv->Rseek(ctx->hkey, CFSTORE_EX1_RSEEK_OFFSET);
00664             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Rseek() failed (ret=%ld)\r\n", __func__, ret);
00665             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00666                 ctx->state = CFSTORE_EX_STATE_RSEEK_DONE;
00667                 break;
00668             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00669                 // await pending notification of completion.
00670                 break;
00671             }
00672             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00673             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00674              * and hence is commented out. Re-instate if previous assert is removed.
00675              * break; */
00676 
00677         case CFSTORE_EX_STATE_RSEEK_DONE:
00678             CFSTORE_EX1_LOG("RSEEK_DONE%s", "\r\n");
00679             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00680             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_RSEEK) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00681             ctx->state = CFSTORE_EX_STATE_READING2;
00682             // intentional fall-through
00683 
00684         case CFSTORE_EX_STATE_READING2:
00685             CFSTORE_EX1_LOG("READING2%s", "\r\n");
00686             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00687             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00688             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00689             ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len);
00690             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret);
00691             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00692                 ctx->state = CFSTORE_EX_STATE_READ_DONE2;
00693                 break;
00694             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00695                 // await pending notification of completion.
00696                 break;
00697             }
00698             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00699             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00700              * and hence is commented out. Re-instate if previous assert is removed.
00701              * break; */
00702 
00703         case CFSTORE_EX_STATE_READ_DONE2:
00704             CFSTORE_EX1_LOG("READ_DONE2%s", "\r\n");
00705             CFSTORE_EX1_LOG("%s: value=%s\r\n", __func__, ctx->value);
00706             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00707             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET]), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET]));
00708             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len);
00709             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_READ) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey);
00710             CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, &cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET], strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET])) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, &cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET]);
00711             ctx->state = CFSTORE_EX_STATE_CLOSING2;
00712             // intentional fall-through
00713 
00714         case CFSTORE_EX_STATE_CLOSING2:
00715             CFSTORE_EX1_LOG("CLOSING2%s", "\r\n");
00716             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned
00717             ret = cfstore_drv->Close(ctx->hkey);
00718             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00719             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00720                 ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2;
00721                 break;
00722             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00723                 // await pending notification of completion.
00724                 break;
00725             }
00726             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00727             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00728              * and hence is commented out. Re-instate if previous assert is removed.
00729              * break; */
00730 
00731         case CFSTORE_EX_STATE_CLOSE_DONE2:
00732             CFSTORE_EX1_LOG("CLOSE_DONE2%s", "\r\n");
00733             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00734             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CLOSE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00735             ctx->state = CFSTORE_EX_STATE_FINDING1;
00736             // intentional fall-through
00737 
00738         case CFSTORE_EX_STATE_FINDING1:
00739             CFSTORE_EX1_LOG("FINDING1%s", "\r\n");
00740             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned
00741             ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev);
00742             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Find() failed (ret=%ld)\r\n", __func__, ret);
00743             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00744                 ctx->state = CFSTORE_EX_STATE_FIND_DONE1;
00745                 break;
00746             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00747                 // await pending notification of completion.
00748                 break;
00749             }
00750             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00751             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00752              * and hence is commented out. Re-instate if previous assert is removed.
00753              * break; */
00754 
00755         case CFSTORE_EX_STATE_FIND_DONE1:
00756             CFSTORE_EX1_LOG("FIND_DONE1%s", "\r\n");
00757             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == ARM_DRIVER_OK, "%s:Error: Find() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00758             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FIND) received handle (%p) is not the hkey supplied to Find()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev);
00759             ctx->state = CFSTORE_EX_STATE_GETTING_KEY_NAME;
00760             // intentional fall-through
00761 
00762         case CFSTORE_EX_STATE_GETTING_KEY_NAME:
00763             CFSTORE_EX1_LOG("GETTING_KEY_NAME%s", "\r\n");
00764             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00765             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00766             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_KEY_NAME can be invoked before GetKeyName() has returned
00767             ret = cfstore_drv->GetKeyName(ctx->hkey_prev, ctx->value, (uint8_t*) &ctx->len);
00768             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetKeyName() failed (ret=%ld)\r\n", __func__, ret);
00769             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00770                 ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE;
00771                 break;
00772             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00773                 // await pending notification of completion.
00774                 break;
00775             }
00776             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00777             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00778              * and hence is commented out. Re-instate if previous assert is removed.
00779              * break; */
00780 
00781         case CFSTORE_EX_STATE_GET_KEY_NAME_DONE:
00782             CFSTORE_EX1_LOG("GET_KEY_NAME_DONE%s", "\r\n");
00783             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetKeyName() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00784             CFSTORE_EX1_TEST_ASSERT_MSG( ((int32_t) ctx->len == ((int32_t) strlen(cfstore_ex_kv_name)+1)), "%s:Error: GetKeyName() updated value of len parameter (%ld) != strlen(cfstore_ex_kv_name) (%ld) (\r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex_kv_name));
00785             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_GET_KEY_NAME) received handle (%p) is not the hkey supplied to GetKeyName()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev);
00786             CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex_kv_name, strlen(cfstore_ex_kv_name)) == 0, "%s:Error: the key name (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex_kv_name);
00787             ctx->state = CFSTORE_EX_STATE_GETTING_VALUE_LEN;
00788             // intentional fall-through
00789 
00790         case CFSTORE_EX_STATE_GETTING_VALUE_LEN:
00791             CFSTORE_EX1_LOG("GETTING_VALUE_LEN%s", "\r\n");
00792             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00793             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_VALUE_LEN can be invoked before GetValueLen() has returned
00794             ret = cfstore_drv->GetValueLen(ctx->hkey_prev, &ctx->len);
00795             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetValueLen() failed (ret=%ld)\r\n", __func__, ret);
00796             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00797                 ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE;
00798                 break;
00799             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00800                 // await pending notification of completion.
00801                 break;
00802             }
00803             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00804             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00805              * and hence is commented out. Re-instate if previous assert is removed.
00806              * break; */
00807 
00808         case CFSTORE_EX_STATE_GET_VALUE_LEN_DONE:
00809             CFSTORE_EX1_LOG("GET_VALUE_LEN_DONE%s", "\r\n");
00810             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetValueLen() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00811             CFSTORE_EX1_TEST_ASSERT_MSG((int32_t) ctx->len == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: GetValueLen() updated value of len parameter (%ld) != strlen(cfstore_ex_kv_value)(%ld) \r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex_kv_value));
00812             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_GET_VALUE_LEN) received handle (%p) is not the hkey supplied to GetValueLen()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev);
00813             ctx->state = CFSTORE_EX_STATE_DELETING;
00814             // intentional fall-through
00815 
00816         case CFSTORE_EX_STATE_DELETING:
00817             CFSTORE_EX1_LOG("DELETING%s", "\r\n");
00818             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_DELETE can be invoked before Delete() has returned
00819             ret = cfstore_drv->Delete(ctx->callback_handle);
00820             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00821             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00822                 ctx->state = CFSTORE_EX_STATE_DELETE_DONE;
00823                 break;
00824             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00825                 // await pending notification of completion.
00826                 break;
00827             }
00828             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00829             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00830              * and hence is commented out. Re-instate if previous assert is removed.
00831              * break; */
00832 
00833         case CFSTORE_EX_STATE_DELETE_DONE:
00834             CFSTORE_EX1_LOG("DELETE_DONE%s", "\r\n");
00835             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Delete() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00836             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_DELETE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00837             CFSTORE_HANDLE_SWAP(ctx->hkey_prev, ctx->hkey_next);
00838             ctx->state = CFSTORE_EX_STATE_FINDING2;
00839             // intentional fall-through
00840 
00841         case CFSTORE_EX_STATE_FINDING2:
00842             CFSTORE_EX1_LOG("FINDING2%s", "\r\n");
00843             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned
00844             ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev);
00845             CFSTORE_EX1_TEST_ASSERT_MSG(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() failed to return expected value of ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (ret=%ld)\r\n", __func__, ret);
00846             if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == false) {
00847                 ctx->state = CFSTORE_EX_STATE_FIND_DONE2;
00848                 break;
00849             } else if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == true) {
00850                 // await pending notification of completion.
00851                 break;
00852             }
00853             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00854             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00855              * and hence is commented out. Re-instate if previous assert is removed.
00856              * break; */
00857 
00858         case CFSTORE_EX_STATE_FIND_DONE2:
00859             CFSTORE_EX1_LOG("FIND_DONE2%s", "\r\n");
00860             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() completion should have been ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (status=%ld)\r\n", __func__, ctx->callback_status);
00861             ctx->state = CFSTORE_EX_STATE_FLUSHING2;
00862             // intentional fall-through
00863 
00864         case CFSTORE_EX_STATE_FLUSHING2:
00865             CFSTORE_EX1_LOG("FLUSHING2%s", "\r\n");
00866             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned
00867             ret = cfstore_drv->Flush();
00868             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error:2: Flush() failed (ret=%ld)\r\n", __func__, ret);
00869             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00870                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2;
00871                 break;
00872             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00873                 // await pending notification of completion.
00874                 break;
00875             }
00876             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00877             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00878              * and hence is commented out. Re-instate if previous assert is removed.
00879              * break; */
00880 
00881         case CFSTORE_EX_STATE_FLUSH_DONE2:
00882             CFSTORE_EX1_LOG("FLUSH_DONE2%s", "\r\n");
00883             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00884             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FLUSH) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00885             ctx->state = CFSTORE_EX_STATE_UNINITIALIZING;
00886             // intentional fall-through
00887 
00888         case CFSTORE_EX_STATE_UNINITIALIZING:
00889             CFSTORE_EX1_LOG("UNINITIALIZING%s", "\r\n");
00890             ret = cfstore_drv->Uninitialize();
00891             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Uninitialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret);
00892             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00893                 ctx->state = CFSTORE_EX_STATE_UNINIT_DONE;
00894                 break;
00895             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00896                 // await pending notification of completion.
00897                 break;
00898             }
00899             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00900             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00901              * and hence is commented out. Re-instate if previous assert is removed.
00902              * break; */
00903 
00904         case CFSTORE_EX_STATE_UNINIT_DONE:
00905             CFSTORE_EX1_LOG("UNINIT_DONE%s", "\r\n");
00906             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_UNINITIALIZE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle);
00907             cfstore_example1_done = true;
00908             CFSTORE_EX1_LOG("***************%s", "\r\n");
00909             CFSTORE_EX1_LOG("*** SUCCESS ***%s", "\r\n");
00910             CFSTORE_EX1_LOG("***************%s", "\r\n");
00911             break;
00912     }
00913 }
00914 
00915 static control_t cfstore_example1_app_start(const size_t call_count)
00916 {
00917     cfstore_example1_ctx_t* ctx = &cfstore_example1_ctx_g;
00918 
00919     (void) call_count;
00920 
00921     /* initialise the context */
00922     memset(ctx, 0, sizeof(cfstore_example1_ctx_t));
00923     cfstore_example1_done = false;
00924     ctx->hkey_next = ctx->hkey_next_buf;
00925     ctx->hkey_prev = ctx->hkey_prev_buf;
00926     ctx->callback_status = ARM_DRIVER_ERROR;
00927     ctx->state = CFSTORE_EX_STATE_INITIALIZING;
00928     ctx->caps = cfstore_drv->GetCapabilities();
00929     cfstore_ex_fms_update(ctx);
00930 
00931     /* main application worker loop */
00932     while (!cfstore_example1_done)
00933     {
00934         // do some work
00935         CFSTORE_EX1_LOG("%s: going to sleep!\r\n", __func__);
00936 
00937 #if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 3
00938         __WFE();
00939 #endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 3 */
00940 
00941 #if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 4
00942         /* mbedosV3++
00943          * todo: port __WFE()
00944          */
00945 #endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 4 */
00946         CFSTORE_EX1_LOG("%s: woke up!\r\n", __func__);
00947     }
00948     return CaseNext;
00949 }
00950 
00951 #ifndef CFSTORE_EXAMPLE1_APP
00952 /* when built as Configuration-Store example, include greentea support otherwise omit */
00953 
00954 /* report whether built/configured for flash sync or async mode */
00955 static control_t cfstore_example1_test_00(const size_t call_count)
00956 {
00957     int32_t ret = ARM_DRIVER_ERROR;
00958     (void) call_count;
00959 
00960     ret = cfstore_test_startup();
00961     CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret);
00962     return CaseNext;
00963 }
00964 
00965 /// @cond CFSTORE_DOXYGEN_DISABLE
00966 utest::v1::status_t greentea_setup(const size_t number_of_cases)
00967 {
00968     GREENTEA_SETUP(25, "default_auto");
00969     return greentea_test_setup_handler(number_of_cases);
00970 }
00971 
00972 Case cases[] = {
00973            /*          1         2         3         4         5         6        7  */
00974            /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
00975         Case("EXAMPLE1_test_00", cfstore_example1_test_00),
00976         Case("EXAMPLE1_test_01_start", cfstore_example1_app_start),
00977 };
00978 
00979 
00980 /* Declare your test specification with a custom setup handler */
00981 Specification specification(greentea_setup, cases);
00982 
00983 int main()
00984 {
00985     return !Harness::run(specification);
00986 }
00987 /// @endcond
00988 
00989 
00990 #else   // CFSTORE_EXAMPLE1_APP
00991 
00992 // stand alone Configuration-Store-Example
00993 void app_start(int argc __unused, char** argv __unused)
00994 {
00995     cfstore_example1_app_start(0);
00996 }
00997 
00998 
00999 
01000 #endif // CFSTORE_EXAMPLE1_APP
01001 
01002 
01003 #endif // __MBED__ && ! defined TOOLCHAIN_GCC_ARM