joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

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 #ifdef YOTTA_CFG_CFSTORE_UVISOR
00072 #include "uvisor-lib/uvisor-lib.h"
00073 #include "cfstore_uvisor.h"
00074 #endif /* YOTTA_CFG_CFSTORE_UVISOR */
00075 
00076 #include <stdio.h>
00077 #include <stdlib.h>
00078 #include <string.h>
00079 #include <inttypes.h>
00080 
00081 using namespace utest::v1;
00082 
00083 static control_t cfstore_example1_test_00(const size_t call_count)
00084 {
00085     (void) call_count;
00086     printf("Not implemented for ARM toolchain\n");
00087     return CaseNext;
00088 }
00089 
00090 
00091 utest::v1::status_t greentea_setup(const size_t number_of_cases)
00092 {
00093     GREENTEA_SETUP(100, "default_auto");
00094     return greentea_test_setup_handler(number_of_cases);
00095 }
00096 
00097 Case cases[] = {
00098            /*          1         2         3         4         5         6        7  */
00099            /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
00100         Case("EXAMPLE1_test_00", cfstore_example1_test_00),
00101 };
00102 
00103 
00104 /* Declare your test specification with a custom setup handler */
00105 Specification specification(greentea_setup, cases);
00106 
00107 int main()
00108 {
00109     return !Harness::run(specification);
00110 }
00111 
00112 
00113 #else
00114 
00115 
00116 #include "mbed.h"
00117 
00118 #ifndef CFSTORE_EXAMPLE1_APP
00119 /* when built as Configuration-Store example, include greentea support otherwise omit */
00120 #include "utest/utest.h"
00121 #include "unity/unity.h"
00122 #include "greentea-client/test_env.h"
00123 
00124 #else   // CFSTORE_EXAMPLE1_APP
00125 // map utest types for building as stand alone example
00126 #define control_t   void
00127 #define CaseNext
00128 #endif  // CFSTORE_EXAMPLE1_APP
00129 
00130 #include "cfstore_config.h"
00131 #include "configuration_store.h"
00132 
00133 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00134 #include "flash_journal_strategy_sequential.h"
00135 #include "flash_journal.h"
00136 #include "Driver_Common.h"
00137 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00138 
00139 #ifdef YOTTA_CFG_CONFIG_UVISOR
00140 #include "uvisor-lib/uvisor-lib.h"
00141 #endif /* YOTTA_CFG_CONFIG_UVISOR */
00142 
00143 #include <stdio.h>
00144 #include <stdlib.h>
00145 #include <string.h>
00146 
00147 /// @cond CFSTORE_DOXYGEN_DISABLE
00148 #ifndef CFSTORE_EXAMPLE1_APP
00149 using namespace utest::v1;
00150 #endif
00151 
00152 
00153 #define CFSTORE_EX1_TEST_ASSERT(Expr)                       if (!(Expr)) { printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00154 #define CFSTORE_EX1_TEST_ASSERT_EQUAL(expected, actual)     if ((expected) != (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00155 #define CFSTORE_EX1_TEST_ASSERT_NOT_EQUAL(expected, actual) if ((expected) == (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;}
00156 
00157 #define CFSTORE_EX1_TEST_ASSERT_MSG(Expr, _fmt, ...)      \
00158     do                                                    \
00159     {                                                     \
00160         if (!(Expr))                                      \
00161         {                                                 \
00162             printf(_fmt, __VA_ARGS__);                    \
00163             while (1) ;                                   \
00164         }                                                 \
00165     }while(0);
00166 
00167 #define CFSTORE_EX1_LOG(_fmt, ...)                        \
00168   do                                                      \
00169   {                                                       \
00170         printf(_fmt, __VA_ARGS__);                        \
00171   }while(0);
00172 
00173 
00174 const char* cfstore_ex_opcode_str[] =
00175 {
00176     "UNDEFINED",
00177     "CFSTORE_OPCODE_CLOSE",
00178     "CFSTORE_OPCODE_CREATE",
00179     "CFSTORE_OPCODE_DELETE",
00180     "CFSTORE_OPCODE_FIND",
00181     "CFSTORE_OPCODE_FLUSH",
00182     "CFSTORE_OPCODE_GET_KEY_NAME",
00183     "CFSTORE_OPCODE_GET_STATUS",
00184     "CFSTORE_OPCODE_GET_VALUE_LEN",
00185     "CFSTORE_OPCODE_INITIALIZE",
00186     "CFSTORE_OPCODE_OPEN",
00187     "CFSTORE_OPCODE_POWER_CONTROL",
00188     "CFSTORE_OPCODE_READ",
00189     "CFSTORE_OPCODE_RSEEK",
00190     "CFSTORE_OPCODE_UNINITIALIZE",
00191     "CFSTORE_OPCODE_WRITE",
00192     "CFSTORE_OPCODE_MAX"
00193 };
00194 
00195 bool cfstore_example1_done = false;
00196 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";
00197 const char* cfstore_ex_kv_value = "TheRollingStone";
00198 #define CFSTORE_EX1_RSEEK_OFFSET    10   /* offset to S of Stone */
00199 
00200 typedef enum cfstore_ex_state_t {
00201     CFSTORE_EX_STATE_INITIALIZING = 1,
00202     CFSTORE_EX_STATE_INIT_DONE,
00203     CFSTORE_EX_STATE_CREATING,
00204     CFSTORE_EX_STATE_CREATE_DONE,
00205     CFSTORE_EX_STATE_WRITING,
00206     CFSTORE_EX_STATE_WRITE_DONE,
00207     CFSTORE_EX_STATE_CLOSING1,
00208     CFSTORE_EX_STATE_CLOSE_DONE1,
00209     CFSTORE_EX_STATE_FLUSHING1,
00210     CFSTORE_EX_STATE_FLUSH_DONE1,
00211     CFSTORE_EX_STATE_OPENING,
00212     CFSTORE_EX_STATE_OPEN_DONE,
00213     CFSTORE_EX_STATE_READING1,
00214     CFSTORE_EX_STATE_READ_DONE1,
00215     CFSTORE_EX_STATE_RSEEKING,
00216     CFSTORE_EX_STATE_RSEEK_DONE,
00217     CFSTORE_EX_STATE_READING2,
00218     CFSTORE_EX_STATE_READ_DONE2,
00219     CFSTORE_EX_STATE_CLOSING2,
00220     CFSTORE_EX_STATE_CLOSE_DONE2,
00221     CFSTORE_EX_STATE_FINDING1,
00222     CFSTORE_EX_STATE_FIND_DONE1,
00223     CFSTORE_EX_STATE_GETTING_KEY_NAME,
00224     CFSTORE_EX_STATE_GET_KEY_NAME_DONE,
00225     CFSTORE_EX_STATE_GETTING_VALUE_LEN,
00226     CFSTORE_EX_STATE_GET_VALUE_LEN_DONE,
00227     CFSTORE_EX_STATE_DELETING,
00228     CFSTORE_EX_STATE_DELETE_DONE,
00229     CFSTORE_EX_STATE_FINDING2,
00230     CFSTORE_EX_STATE_FIND_DONE2,
00231     CFSTORE_EX_STATE_FLUSHING2,
00232     CFSTORE_EX_STATE_FLUSH_DONE2,
00233     CFSTORE_EX_STATE_UNINITIALIZING,
00234     CFSTORE_EX_STATE_UNINIT_DONE
00235 } cfstore_ex_state_t;
00236 
00237 
00238 typedef struct cfstore_example1_ctx_t
00239 {
00240     ARM_CFSTORE_CAPABILITIES caps;
00241     uint8_t hkey[CFSTORE_HANDLE_BUFSIZE];
00242     uint8_t hkey_next_buf[CFSTORE_HANDLE_BUFSIZE];
00243     uint8_t hkey_prev_buf[CFSTORE_HANDLE_BUFSIZE];
00244     ARM_CFSTORE_HANDLE  hkey_next;
00245     ARM_CFSTORE_HANDLE  hkey_prev;
00246     cfstore_ex_state_t state;
00247     ARM_CFSTORE_SIZE len;
00248     ARM_CFSTORE_KEYDESC kdesc;
00249     ARM_CFSTORE_FMODE flags;
00250     char value[CFSTORE_KEY_NAME_MAX_LENGTH+1];
00251     /* callback attributes*/
00252     int32_t callback_status;
00253     ARM_CFSTORE_HANDLE  callback_handle;
00254 } cfstore_example1_ctx_t;
00255 
00256 static cfstore_example1_ctx_t cfstore_example1_ctx_g;
00257 
00258 extern ARM_CFSTORE_DRIVER cfstore_driver;
00259 ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver;
00260 
00261 /* forward declarations */
00262 static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx);
00263 /// @endcond
00264 
00265 
00266 /* @brief   test startup code to reset flash
00267  */
00268 static int32_t cfstore_test_startup(void)
00269 {
00270     ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities();
00271     CFSTORE_EX1_LOG("INITIALIZING: caps.asynchronous_ops=%d\n", (int) caps.asynchronous_ops);
00272 
00273 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00274 
00275     int32_t ret = ARM_DRIVER_ERROR;
00276     static FlashJournal_t jrnl;
00277     extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0);
00278     const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0);
00279 
00280     ret = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL);
00281     CFSTORE_EX1_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (ret=%d)\r\n", __func__, (int) ret);
00282 
00283     ret = FlashJournal_reset(&jrnl);
00284     CFSTORE_EX1_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (ret=%d)\r\n", __func__, (int) ret);
00285 #endif /*  CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00286 
00287     return ARM_DRIVER_OK;
00288 }
00289 
00290 
00291 static void cfstore_ex_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE  handle)
00292 {
00293     (void) handle;
00294 
00295     cfstore_example1_ctx_t* ctx = (cfstore_example1_ctx_t*) client_context;
00296 
00297     /* 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); */
00298     switch(cmd_code)
00299     {
00300     case CFSTORE_OPCODE_INITIALIZE:
00301         ctx->state = CFSTORE_EX_STATE_INIT_DONE;
00302         break;
00303     case CFSTORE_OPCODE_CREATE:
00304         ctx->state = CFSTORE_EX_STATE_CREATE_DONE;
00305         break;
00306     case CFSTORE_OPCODE_WRITE:
00307         ctx->state = CFSTORE_EX_STATE_WRITE_DONE;
00308         break;
00309     case CFSTORE_OPCODE_CLOSE:
00310         switch(ctx->state)
00311         {
00312         case(CFSTORE_EX_STATE_CLOSING1):
00313             ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1;
00314             break;
00315         case(CFSTORE_EX_STATE_CLOSING2):
00316             ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2;
00317             break;
00318         default:
00319             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Close() error (line=%u)\r\n", __func__, __LINE__);
00320             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00321              * and hence is commented out. Re-instate if previous assert is removed.
00322              * break; */
00323         }
00324         break;
00325     case CFSTORE_OPCODE_FLUSH:
00326         switch(ctx->state)
00327         {
00328             case(CFSTORE_EX_STATE_FLUSHING1):
00329                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1;
00330                 break;
00331             case(CFSTORE_EX_STATE_FLUSHING2):
00332                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2;
00333                 break;
00334             default:
00335                 CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__);
00336                 /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00337                  * and hence is commented out. Re-instate if previous assert is removed.
00338                  * break; */
00339         }
00340         break;
00341     case CFSTORE_OPCODE_OPEN:
00342         ctx->state = CFSTORE_EX_STATE_OPEN_DONE;
00343         break;
00344     case CFSTORE_OPCODE_FIND:
00345         switch(ctx->state)
00346         {
00347         case(CFSTORE_EX_STATE_FINDING1):
00348             ctx->state = CFSTORE_EX_STATE_FIND_DONE1;
00349             break;
00350         case(CFSTORE_EX_STATE_FINDING2):
00351             ctx->state = CFSTORE_EX_STATE_FIND_DONE2;
00352             break;
00353         default:
00354             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__);
00355             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00356              * and hence is commented out. Re-instate if previous assert is removed.
00357              * break; */
00358         }
00359         break;
00360     case CFSTORE_OPCODE_GET_KEY_NAME:
00361         ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE;
00362         break;
00363     case CFSTORE_OPCODE_GET_VALUE_LEN:
00364         ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE;
00365         break;
00366     case CFSTORE_OPCODE_READ:
00367         switch(ctx->state)
00368         {
00369         case(CFSTORE_EX_STATE_READING1):
00370             ctx->state = CFSTORE_EX_STATE_READ_DONE1;
00371             break;
00372         case(CFSTORE_EX_STATE_READING2):
00373             ctx->state = CFSTORE_EX_STATE_READ_DONE2;
00374             break;
00375         default:
00376             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Read() error (line=%u)\r\n", __func__, __LINE__);
00377             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00378              * and hence is commented out. Re-instate if previous assert is removed.
00379              * break; */
00380         }
00381         break;
00382     case CFSTORE_OPCODE_RSEEK:
00383         ctx->state = CFSTORE_EX_STATE_RSEEK_DONE;
00384         break;
00385     case CFSTORE_OPCODE_DELETE:
00386         ctx->state = CFSTORE_EX_STATE_DELETE_DONE;
00387         break;
00388     case CFSTORE_OPCODE_UNINITIALIZE:
00389         ctx->state = CFSTORE_EX_STATE_UNINIT_DONE;
00390         break;
00391     case CFSTORE_OPCODE_GET_STATUS:
00392     case CFSTORE_OPCODE_POWER_CONTROL:
00393     default:
00394         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");
00395         /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00396          * and hence is commented out. Re-instate if previous assert is removed.
00397          * break; */
00398     }
00399     ctx->callback_status = status;
00400     ctx->callback_handle = handle;
00401     cfstore_ex_fms_update(ctx);
00402     return;
00403 }
00404 
00405 static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx)
00406 {
00407     int32_t ret;
00408 
00409     switch (ctx->state)
00410     {
00411         case CFSTORE_EX_STATE_INITIALIZING:
00412             CFSTORE_EX1_LOG("INITIALIZING%s", "\r\n");
00413             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_INITIALIZE can be invoked before Initialize() has returned
00414             ret = cfstore_drv->Initialize(cfstore_ex_callback, ctx);
00415             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);
00416             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00417                 ctx->state = CFSTORE_EX_STATE_INIT_DONE;
00418                 break;
00419             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00420                 // await pending notification of completion.
00421                 break;
00422             }
00423             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00424             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00425              * and hence is commented out. Re-instate if previous assert is removed.
00426              * break; */
00427 
00428         case CFSTORE_EX_STATE_INIT_DONE:
00429             CFSTORE_EX1_LOG("INIT_DONE%s", "\r\n");
00430             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Initialize() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00431             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);
00432             ctx->state = CFSTORE_EX_STATE_CREATING;
00433             // intentional fall-through
00434 
00435         case CFSTORE_EX_STATE_CREATING:
00436             CFSTORE_EX1_LOG("CREATING%s", "\r\n");
00437             memset(&ctx->kdesc, 0, sizeof(ARM_CFSTORE_KEYDESC));
00438             ctx->kdesc.drl = ARM_RETENTION_NVM;
00439             ctx->len = strlen(cfstore_ex_kv_value);
00440             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CREATE can be invoked before Create() has returned
00441             ret = cfstore_drv->Create(cfstore_ex_kv_name, ctx->len, &ctx->kdesc, ctx->hkey);
00442             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Create() failed (ret=%ld)\r\n", __func__, ret);
00443             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00444                 ctx->state = CFSTORE_EX_STATE_CREATE_DONE;
00445                 break;
00446             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00447                 // await pending notification of completion.
00448                 break;
00449             }
00450             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00451             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00452              * and hence is commented out. Re-instate if previous assert is removed.
00453              * break; */
00454 
00455         case CFSTORE_EX_STATE_CREATE_DONE:
00456             CFSTORE_EX1_LOG("CREATE_DONE%s", "\r\n");
00457             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Create() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00458             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);
00459             ctx->state = CFSTORE_EX_STATE_WRITING;
00460             // intentional fall-through
00461 
00462         case CFSTORE_EX_STATE_WRITING:
00463             CFSTORE_EX1_LOG("WRITING%s", "\r\n");
00464             ctx->len = strlen(cfstore_ex_kv_value);
00465             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_WRITE can be invoked before Write() has returned
00466             ret = cfstore_drv->Write(ctx->hkey, cfstore_ex_kv_value, &ctx->len);
00467             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Write() failed (ret=%ld)\r\n", __func__, ret);
00468             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00469                 ctx->state = CFSTORE_EX_STATE_WRITE_DONE;
00470                 break;
00471             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00472                 // await pending notification of completion.
00473                 break;
00474             }
00475             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00476             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00477              * and hence is commented out. Re-instate if previous assert is removed.
00478              * break; */
00479 
00480         case CFSTORE_EX_STATE_WRITE_DONE:
00481             CFSTORE_EX1_LOG("WRITE_DONE%s", "\r\n");
00482             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Write() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00483             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));
00484             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);
00485             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);
00486             ctx->state = CFSTORE_EX_STATE_CLOSING1;
00487             // intentional fall-through
00488 
00489         case CFSTORE_EX_STATE_CLOSING1:
00490             CFSTORE_EX1_LOG("CLOSING1%s", "\r\n");
00491             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned
00492             ret = cfstore_drv->Close(ctx->hkey);
00493             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00494             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00495                 ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1;
00496                 break;
00497             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00498                 // await pending notification of completion.
00499                 break;
00500             }
00501             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00502             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00503              * and hence is commented out. Re-instate if previous assert is removed.
00504              * break; */
00505 
00506         case CFSTORE_EX_STATE_CLOSE_DONE1:
00507             CFSTORE_EX1_LOG("CLOSE_DONE1%s", "\r\n");
00508             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00509             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);
00510             ctx->state = CFSTORE_EX_STATE_FLUSHING1;
00511             // intentional fall-through
00512 
00513         case CFSTORE_EX_STATE_FLUSHING1:
00514             CFSTORE_EX1_LOG("FLUSHING1%s", "\r\n");
00515             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned
00516             ret = cfstore_drv->Flush();
00517             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret);
00518             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00519                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1;
00520                 break;
00521             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00522                 // await pending notification of completion.
00523                 break;
00524             }
00525             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00526             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00527              * and hence is commented out. Re-instate if previous assert is removed.
00528              * break; */
00529 
00530         case CFSTORE_EX_STATE_FLUSH_DONE1:
00531             CFSTORE_EX1_LOG("FLUSH_DONE1%s", "\r\n");
00532             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00533             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);
00534             ctx->state = CFSTORE_EX_STATE_OPENING;
00535             // intentional fall-through
00536 
00537         case CFSTORE_EX_STATE_OPENING:
00538             CFSTORE_EX1_LOG("OPENING%s", "\r\n");
00539             memset(&ctx->flags, 0, sizeof(ctx->flags));
00540             memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE);
00541             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_OPEN can be invoked before Open() has returned
00542             ret = cfstore_drv->Open(cfstore_ex_kv_name, ctx->flags, ctx->hkey);
00543             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Open() failed (ret=%ld)\r\n", __func__, ret);
00544             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00545                 ctx->state = CFSTORE_EX_STATE_OPEN_DONE;
00546                 break;
00547             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00548                 // await pending notification of completion.
00549                 break;
00550             }
00551             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00552             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00553              * and hence is commented out. Re-instate if previous assert is removed.
00554              * break; */
00555 
00556         case CFSTORE_EX_STATE_OPEN_DONE:
00557             CFSTORE_EX1_LOG("OPEN_DONE%s", "\r\n");
00558             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Open() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00559             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);
00560             ctx->state = CFSTORE_EX_STATE_READING1;
00561             // intentional fall-through
00562 
00563         case CFSTORE_EX_STATE_READING1:
00564             CFSTORE_EX1_LOG("READING1%s", "\r\n");
00565             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00566             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00567             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00568             ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len);
00569             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret);
00570             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00571                 ctx->state = CFSTORE_EX_STATE_READ_DONE1;
00572                 break;
00573             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00574                 // await pending notification of completion.
00575                 break;
00576             }
00577             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00578             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00579              * and hence is commented out. Re-instate if previous assert is removed.
00580              * break; */
00581 
00582         case CFSTORE_EX_STATE_READ_DONE1:
00583             CFSTORE_EX1_LOG("READ_DONE1%s", "\r\n");
00584             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00585             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));
00586             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);
00587             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);
00588             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);
00589             ctx->state = CFSTORE_EX_STATE_RSEEKING;
00590             // intentional fall-through
00591 
00592         case CFSTORE_EX_STATE_RSEEKING:
00593             CFSTORE_EX1_LOG("RSEEKING%s", "\r\n");
00594             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00595             ret = cfstore_drv->Rseek(ctx->hkey, CFSTORE_EX1_RSEEK_OFFSET);
00596             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Rseek() failed (ret=%ld)\r\n", __func__, ret);
00597             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00598                 ctx->state = CFSTORE_EX_STATE_RSEEK_DONE;
00599                 break;
00600             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00601                 // await pending notification of completion.
00602                 break;
00603             }
00604             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00605             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00606              * and hence is commented out. Re-instate if previous assert is removed.
00607              * break; */
00608 
00609         case CFSTORE_EX_STATE_RSEEK_DONE:
00610             CFSTORE_EX1_LOG("RSEEK_DONE%s", "\r\n");
00611             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00612             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);
00613             ctx->state = CFSTORE_EX_STATE_READING2;
00614             // intentional fall-through
00615 
00616         case CFSTORE_EX_STATE_READING2:
00617             CFSTORE_EX1_LOG("READING2%s", "\r\n");
00618             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00619             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00620             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned
00621             ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len);
00622             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret);
00623             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00624                 ctx->state = CFSTORE_EX_STATE_READ_DONE2;
00625                 break;
00626             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00627                 // await pending notification of completion.
00628                 break;
00629             }
00630             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00631             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00632              * and hence is commented out. Re-instate if previous assert is removed.
00633              * break; */
00634 
00635         case CFSTORE_EX_STATE_READ_DONE2:
00636             CFSTORE_EX1_LOG("READ_DONE2%s", "\r\n");
00637             CFSTORE_EX1_LOG("%s: value=%s\r\n", __func__, ctx->value);
00638             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00639             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]));
00640             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);
00641             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);
00642             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]);
00643             ctx->state = CFSTORE_EX_STATE_CLOSING2;
00644             // intentional fall-through
00645 
00646         case CFSTORE_EX_STATE_CLOSING2:
00647             CFSTORE_EX1_LOG("CLOSING2%s", "\r\n");
00648             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned
00649             ret = cfstore_drv->Close(ctx->hkey);
00650             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00651             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00652                 ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2;
00653                 break;
00654             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00655                 // await pending notification of completion.
00656                 break;
00657             }
00658             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00659             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00660              * and hence is commented out. Re-instate if previous assert is removed.
00661              * break; */
00662 
00663         case CFSTORE_EX_STATE_CLOSE_DONE2:
00664             CFSTORE_EX1_LOG("CLOSE_DONE2%s", "\r\n");
00665             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00666             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);
00667             ctx->state = CFSTORE_EX_STATE_FINDING1;
00668             // intentional fall-through
00669 
00670         case CFSTORE_EX_STATE_FINDING1:
00671             CFSTORE_EX1_LOG("FINDING1%s", "\r\n");
00672             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned
00673             ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev);
00674             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Find() failed (ret=%ld)\r\n", __func__, ret);
00675             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00676                 ctx->state = CFSTORE_EX_STATE_FIND_DONE1;
00677                 break;
00678             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00679                 // await pending notification of completion.
00680                 break;
00681             }
00682             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00683             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00684              * and hence is commented out. Re-instate if previous assert is removed.
00685              * break; */
00686 
00687         case CFSTORE_EX_STATE_FIND_DONE1:
00688             CFSTORE_EX1_LOG("FIND_DONE1%s", "\r\n");
00689             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == ARM_DRIVER_OK, "%s:Error: Find() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00690             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);
00691             ctx->state = CFSTORE_EX_STATE_GETTING_KEY_NAME;
00692             // intentional fall-through
00693 
00694         case CFSTORE_EX_STATE_GETTING_KEY_NAME:
00695             CFSTORE_EX1_LOG("GETTING_KEY_NAME%s", "\r\n");
00696             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00697             memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
00698             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_KEY_NAME can be invoked before GetKeyName() has returned
00699             ret = cfstore_drv->GetKeyName(ctx->hkey_prev, ctx->value, (uint8_t*) &ctx->len);
00700             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetKeyName() failed (ret=%ld)\r\n", __func__, ret);
00701             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00702                 ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE;
00703                 break;
00704             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00705                 // await pending notification of completion.
00706                 break;
00707             }
00708             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00709             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00710              * and hence is commented out. Re-instate if previous assert is removed.
00711              * break; */
00712 
00713         case CFSTORE_EX_STATE_GET_KEY_NAME_DONE:
00714             CFSTORE_EX1_LOG("GET_KEY_NAME_DONE%s", "\r\n");
00715             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetKeyName() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00716             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));
00717             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);
00718             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);
00719             ctx->state = CFSTORE_EX_STATE_GETTING_VALUE_LEN;
00720             // intentional fall-through
00721 
00722         case CFSTORE_EX_STATE_GETTING_VALUE_LEN:
00723             CFSTORE_EX1_LOG("GETTING_VALUE_LEN%s", "\r\n");
00724             ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH;
00725             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_VALUE_LEN can be invoked before GetValueLen() has returned
00726             ret = cfstore_drv->GetValueLen(ctx->hkey_prev, &ctx->len);
00727             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetValueLen() failed (ret=%ld)\r\n", __func__, ret);
00728             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00729                 ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE;
00730                 break;
00731             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00732                 // await pending notification of completion.
00733                 break;
00734             }
00735             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00736             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00737              * and hence is commented out. Re-instate if previous assert is removed.
00738              * break; */
00739 
00740         case CFSTORE_EX_STATE_GET_VALUE_LEN_DONE:
00741             CFSTORE_EX1_LOG("GET_VALUE_LEN_DONE%s", "\r\n");
00742             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetValueLen() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00743             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));
00744             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);
00745             ctx->state = CFSTORE_EX_STATE_DELETING;
00746             // intentional fall-through
00747 
00748         case CFSTORE_EX_STATE_DELETING:
00749             CFSTORE_EX1_LOG("DELETING%s", "\r\n");
00750             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_DELETE can be invoked before Delete() has returned
00751             ret = cfstore_drv->Delete(ctx->callback_handle);
00752             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret);
00753             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00754                 ctx->state = CFSTORE_EX_STATE_DELETE_DONE;
00755                 break;
00756             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00757                 // await pending notification of completion.
00758                 break;
00759             }
00760             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00761             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00762              * and hence is commented out. Re-instate if previous assert is removed.
00763              * break; */
00764 
00765         case CFSTORE_EX_STATE_DELETE_DONE:
00766             CFSTORE_EX1_LOG("DELETE_DONE%s", "\r\n");
00767             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Delete() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00768             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);
00769             CFSTORE_HANDLE_SWAP(ctx->hkey_prev, ctx->hkey_next);
00770             ctx->state = CFSTORE_EX_STATE_FINDING2;
00771             // intentional fall-through
00772 
00773         case CFSTORE_EX_STATE_FINDING2:
00774             CFSTORE_EX1_LOG("FINDING2%s", "\r\n");
00775             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned
00776             ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev);
00777             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);
00778             if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == false) {
00779                 ctx->state = CFSTORE_EX_STATE_FIND_DONE2;
00780                 break;
00781             } else if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == true) {
00782                 // await pending notification of completion.
00783                 break;
00784             }
00785             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00786             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00787              * and hence is commented out. Re-instate if previous assert is removed.
00788              * break; */
00789 
00790         case CFSTORE_EX_STATE_FIND_DONE2:
00791             CFSTORE_EX1_LOG("FIND_DONE2%s", "\r\n");
00792             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);
00793             ctx->state = CFSTORE_EX_STATE_FLUSHING2;
00794             // intentional fall-through
00795 
00796         case CFSTORE_EX_STATE_FLUSHING2:
00797             CFSTORE_EX1_LOG("FLUSHING2%s", "\r\n");
00798             // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned
00799             ret = cfstore_drv->Flush();
00800             CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error:2: Flush() failed (ret=%ld)\r\n", __func__, ret);
00801             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00802                 ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2;
00803                 break;
00804             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00805                 // await pending notification of completion.
00806                 break;
00807             }
00808             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00809             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00810              * and hence is commented out. Re-instate if previous assert is removed.
00811              * break; */
00812 
00813         case CFSTORE_EX_STATE_FLUSH_DONE2:
00814             CFSTORE_EX1_LOG("FLUSH_DONE2%s", "\r\n");
00815             CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status);
00816             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);
00817             ctx->state = CFSTORE_EX_STATE_UNINITIALIZING;
00818             // intentional fall-through
00819 
00820         case CFSTORE_EX_STATE_UNINITIALIZING:
00821             CFSTORE_EX1_LOG("UNINITIALIZING%s", "\r\n");
00822             ret = cfstore_drv->Uninitialize();
00823             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);
00824             if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) {
00825                 ctx->state = CFSTORE_EX_STATE_UNINIT_DONE;
00826                 break;
00827             } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) {
00828                 // await pending notification of completion.
00829                 break;
00830             }
00831             CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__);
00832             /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning
00833              * and hence is commented out. Re-instate if previous assert is removed.
00834              * break; */
00835 
00836         case CFSTORE_EX_STATE_UNINIT_DONE:
00837             CFSTORE_EX1_LOG("UNINIT_DONE%s", "\r\n");
00838             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);
00839             cfstore_example1_done = true;
00840             CFSTORE_EX1_LOG("***************%s", "\r\n");
00841             CFSTORE_EX1_LOG("*** SUCCESS ***%s", "\r\n");
00842             CFSTORE_EX1_LOG("***************%s", "\r\n");
00843             break;
00844     }
00845 }
00846 
00847 static control_t cfstore_example1_app_start(const size_t call_count)
00848 {
00849     cfstore_example1_ctx_t* ctx = &cfstore_example1_ctx_g;
00850 
00851     (void) call_count;
00852 
00853     /* initialise the context */
00854     memset(ctx, 0, sizeof(cfstore_example1_ctx_t));
00855     cfstore_example1_done = false;
00856     ctx->hkey_next = ctx->hkey_next_buf;
00857     ctx->hkey_prev = ctx->hkey_prev_buf;
00858     ctx->callback_status = ARM_DRIVER_ERROR;
00859     ctx->state = CFSTORE_EX_STATE_INITIALIZING;
00860     ctx->caps = cfstore_drv->GetCapabilities();
00861     cfstore_ex_fms_update(ctx);
00862 
00863     /* main application worker loop */
00864     while (!cfstore_example1_done)
00865     {
00866         // do some work
00867         CFSTORE_EX1_LOG("%s: going to sleep!\r\n", __func__);
00868 
00869 #if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 3
00870         __WFE();
00871 #endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 3 */
00872 
00873 #if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 4
00874         /* mbedosV3++
00875          * todo: port __WFE()
00876          */
00877 #endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 4 */
00878         CFSTORE_EX1_LOG("%s: woke up!\r\n", __func__);
00879     }
00880     return CaseNext;
00881 }
00882 
00883 #ifndef CFSTORE_EXAMPLE1_APP
00884 /* when built as Configuration-Store example, include greentea support otherwise omit */
00885 
00886 /* report whether built/configured for flash sync or async mode */
00887 static control_t cfstore_example1_test_00(const size_t call_count)
00888 {
00889     int32_t ret = ARM_DRIVER_ERROR;
00890     (void) call_count;
00891 
00892     ret = cfstore_test_startup();
00893     CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret);
00894     return CaseNext;
00895 }
00896 
00897 /// @cond CFSTORE_DOXYGEN_DISABLE
00898 utest::v1::status_t greentea_setup(const size_t number_of_cases)
00899 {
00900     GREENTEA_SETUP(25, "default_auto");
00901     return greentea_test_setup_handler(number_of_cases);
00902 }
00903 
00904 Case cases[] = {
00905            /*          1         2         3         4         5         6        7  */
00906            /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
00907         Case("EXAMPLE1_test_00", cfstore_example1_test_00),
00908         Case("EXAMPLE1_test_01_start", cfstore_example1_app_start),
00909 };
00910 
00911 
00912 /* Declare your test specification with a custom setup handler */
00913 Specification specification(greentea_setup, cases);
00914 
00915 int main()
00916 {
00917     return !Harness::run(specification);
00918 }
00919 /// @endcond
00920 
00921 
00922 #else   // CFSTORE_EXAMPLE1_APP
00923 
00924 // stand alone Configuration-Store-Example
00925 void app_start(int argc __unused, char** argv __unused)
00926 {
00927     cfstore_example1_app_start(0);
00928 }
00929 
00930 
00931 
00932 #endif // CFSTORE_EXAMPLE1_APP
00933 
00934 
00935 #endif // __MBED__ && ! defined TOOLCHAIN_GCC_ARM