Created
December 5, 2014 04:04
-
-
Save ksksue/0f0c9d61e569941a9aa2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void pstorage_test_store_and_load(void) | |
{ | |
pstorage_handle_t handle; | |
pstorage_handle_t block_handle; | |
pstorage_module_param_t param; | |
uint8_t source_data[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; | |
uint8_t source_data_2[16] = {0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0}; | |
uint8_t dest_data[16] = {0}; | |
uint32_t err_code; | |
err_code = pstorage_init(); | |
APP_ERROR_CHECK(err_code); | |
param.block_size = 16; // ブロックサイズ 16 バイトに指定 | |
param.block_count = 10; // 10 ブロック確保。合計160バイト | |
param.cb = pstorage_cb_handler; // pstorageコールバックハンドラをセット | |
err_code = pstorage_register(¶m, &handle); | |
APP_ERROR_CHECK(err_code); | |
// ブロックIDを取得 | |
pstorage_block_identifier_get(&handle, 0, &block_handle); | |
// Flashの性質上、store処理の前にはclear処理が必須。またwait処理も必須。 | |
pstorage_wait_flag = 1; // ウェイトフラグをセットしておく。pstorage_cb_handler が呼ばれたら解除 | |
pstorage_wait_handle = block_handle.block_id; // どのIDのウェイト処理かを指定(複数ID使用時に必須) | |
pstorage_clear(&block_handle, 16); // 16 バイト分をクリア | |
while(pstorage_wait_flag) { power_manage(); } // クリア処理が完了するまでスリープ | |
// store処理、wait処理必須 | |
pstorage_wait_flag = 1; // ウェイトフラグをセットしておく。pstorage_cb_handler が呼ばれたら解除 | |
pstorage_wait_handle = block_handle.block_id; // どのIDのウェイト処理かを指定(複数ID使用時に必須) | |
pstorage_store(&block_handle, source_data, 16, 0); // 書き込み。各書き込みサイズは1ブロックサイズとする。 | |
while(pstorage_wait_flag) { power_manage(); } // 書き込み処理が完了するまでスリープ | |
// load処理、wait処理必要なし | |
pstorage_load(dest_data, &block_handle, 16, 0); // 読み込み。各読み込みサイズは1ブロックサイズとする。 | |
// clear処理なしで書き込みしたい場合はupdate処理。wait処理必須。 | |
pstorage_wait_flag = 1; // ウェイトフラグをセットしておく。pstorage_cb_handler が呼ばれたら解除 | |
pstorage_wait_handle = block_handle.block_id; // どのIDのウェイト処理かを指定(複数ID使用時に必須) | |
pstorage_update(&block_handle, source_data_2, 16, 0); // 書き込み。各書き込みサイズは1ブロックサイズとする。 | |
while(pstorage_wait_flag) { power_manage(); } // 書き込み処理が完了するまでスリープ | |
pstorage_load(dest_data, &block_handle, 16, 0); // 読み込み。各読み込みサイズは1ブロックサイズとする。 | |
pstorage_load(dest_data, &block_handle, 16, 0); // ブレークポイント用ダミー処理 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment