Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 /*
kadonotakashi 0:8fdf9a60065b 2 * Copyright (c) 2017, ARM Limited, All Rights Reserved
kadonotakashi 0:8fdf9a60065b 3 * SPDX-License-Identifier: Apache-2.0
kadonotakashi 0:8fdf9a60065b 4 *
kadonotakashi 0:8fdf9a60065b 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
kadonotakashi 0:8fdf9a60065b 6 * not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 * You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8 *
kadonotakashi 0:8fdf9a60065b 9 * http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10 *
kadonotakashi 0:8fdf9a60065b 11 * Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
kadonotakashi 0:8fdf9a60065b 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 * See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 * limitations under the License.
kadonotakashi 0:8fdf9a60065b 16 */
kadonotakashi 0:8fdf9a60065b 17
kadonotakashi 0:8fdf9a60065b 18 #include "mbed.h"
kadonotakashi 0:8fdf9a60065b 19 #include "greentea-client/test_env.h"
kadonotakashi 0:8fdf9a60065b 20 #include "unity.h"
kadonotakashi 0:8fdf9a60065b 21 #include "utest.h"
kadonotakashi 0:8fdf9a60065b 22
kadonotakashi 0:8fdf9a60065b 23 #include <events/mbed_events.h>
kadonotakashi 0:8fdf9a60065b 24 #include "NFCEEPROMDriver.h"
kadonotakashi 0:8fdf9a60065b 25
kadonotakashi 0:8fdf9a60065b 26 #if !MBED_CONF_NFCEEPROM
kadonotakashi 0:8fdf9a60065b 27 #error [NOT_SUPPORTED] NFC EEPROM not supported for this target
kadonotakashi 0:8fdf9a60065b 28 #endif
kadonotakashi 0:8fdf9a60065b 29
kadonotakashi 0:8fdf9a60065b 30 using namespace utest::v1;
kadonotakashi 0:8fdf9a60065b 31 using namespace mbed::nfc;
kadonotakashi 0:8fdf9a60065b 32
kadonotakashi 0:8fdf9a60065b 33 /* individual steps that map to specific operations that include parameters */
kadonotakashi 0:8fdf9a60065b 34 typedef enum {
kadonotakashi 0:8fdf9a60065b 35 START_SESSION = 0x0000,
kadonotakashi 0:8fdf9a60065b 36
kadonotakashi 0:8fdf9a60065b 37 END_SESSION = 0x0100,
kadonotakashi 0:8fdf9a60065b 38
kadonotakashi 0:8fdf9a60065b 39 READ_BYTES = 0x0200,
kadonotakashi 0:8fdf9a60065b 40 READ_2_BYTES = 0x0201,
kadonotakashi 0:8fdf9a60065b 41 READ_2_BYTES_OFFSET_FAIL = 0x0202,
kadonotakashi 0:8fdf9a60065b 42 READ_4_BYTES = 0x0203,
kadonotakashi 0:8fdf9a60065b 43 READ_4_BYTES_MIXED = 0x0204,
kadonotakashi 0:8fdf9a60065b 44 READ_4_BYTES_OFFSET = 0x0205,
kadonotakashi 0:8fdf9a60065b 45 READ_4_BYTES_ERASED = 0x0206,
kadonotakashi 0:8fdf9a60065b 46 READ_4_BYTES_FAIL = 0x0207,
kadonotakashi 0:8fdf9a60065b 47
kadonotakashi 0:8fdf9a60065b 48 WRITE_BYTES = 0x0300,
kadonotakashi 0:8fdf9a60065b 49 WRITE_2_BYTES = 0x0301,
kadonotakashi 0:8fdf9a60065b 50 WRITE_2_BYTES_OFFSET = 0x0302,
kadonotakashi 0:8fdf9a60065b 51 WRITE_2_BYTES_OFFSET_FAIL = 0x0303,
kadonotakashi 0:8fdf9a60065b 52 WRITE_4_BYTES = 0x0304,
kadonotakashi 0:8fdf9a60065b 53 WRITE_4_BYTES_FAIL = 0x0305,
kadonotakashi 0:8fdf9a60065b 54
kadonotakashi 0:8fdf9a60065b 55 ERASE_BYTES = 0x0400,
kadonotakashi 0:8fdf9a60065b 56 ERASE_4_BYTES = 0x0401,
kadonotakashi 0:8fdf9a60065b 57
kadonotakashi 0:8fdf9a60065b 58 READ_SIZE = 0x0500,
kadonotakashi 0:8fdf9a60065b 59 READ_SIZE_2 = 0x0501,
kadonotakashi 0:8fdf9a60065b 60 READ_SIZE_4 = 0x0502,
kadonotakashi 0:8fdf9a60065b 61
kadonotakashi 0:8fdf9a60065b 62 WRITE_SIZE = 0x0600,
kadonotakashi 0:8fdf9a60065b 63 WRITE_SIZE_2 = 0x0601,
kadonotakashi 0:8fdf9a60065b 64 WRITE_SIZE_4 = 0x0602,
kadonotakashi 0:8fdf9a60065b 65
kadonotakashi 0:8fdf9a60065b 66 TERMINATE = 0xFF00
kadonotakashi 0:8fdf9a60065b 67 } TestCommand_t;
kadonotakashi 0:8fdf9a60065b 68
kadonotakashi 0:8fdf9a60065b 69 /* We group the command based on their fist byte to simplify step checking.
kadonotakashi 0:8fdf9a60065b 70 * Individual conditions of a step are checked in the event so this doesn't
kadonotakashi 0:8fdf9a60065b 71 * sacrifice any correctness checking */
kadonotakashi 0:8fdf9a60065b 72 const size_t TEST_COMMAND_GROUP_MASK = 0xFF00;
kadonotakashi 0:8fdf9a60065b 73
kadonotakashi 0:8fdf9a60065b 74 /* test case sequences that index into the array of commands which comprise them */
kadonotakashi 0:8fdf9a60065b 75 typedef enum {
kadonotakashi 0:8fdf9a60065b 76 SESSION_TEST,
kadonotakashi 0:8fdf9a60065b 77 WRITE_READ_TEST,
kadonotakashi 0:8fdf9a60065b 78 ERASE_TEST,
kadonotakashi 0:8fdf9a60065b 79 WRITE_READ_SIZE_TEST,
kadonotakashi 0:8fdf9a60065b 80 TRUNCATE_TEST,
kadonotakashi 0:8fdf9a60065b 81 WRITE_TRUNCATE_TEST,
kadonotakashi 0:8fdf9a60065b 82 WRITE_WITH_OFFSET_TEST,
kadonotakashi 0:8fdf9a60065b 83 WRITE_BEYOND_SIZE_TEST,
kadonotakashi 0:8fdf9a60065b 84 SEQUENCE_MAX
kadonotakashi 0:8fdf9a60065b 85 } TestSequence_t;
kadonotakashi 0:8fdf9a60065b 86
kadonotakashi 0:8fdf9a60065b 87 static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE);
kadonotakashi 0:8fdf9a60065b 88
kadonotakashi 0:8fdf9a60065b 89 static const size_t MAX_STEP = 10;
kadonotakashi 0:8fdf9a60065b 90 static const size_t BUFFER_MAX = 10;
kadonotakashi 0:8fdf9a60065b 91
kadonotakashi 0:8fdf9a60065b 92 /* defines the "script" the test follows, each step is checked and all
kadonotakashi 0:8fdf9a60065b 93 * have to execute to completion for a successful run */
kadonotakashi 0:8fdf9a60065b 94 static const TestCommand_t SEQUENCES[SEQUENCE_MAX][MAX_STEP] = {
kadonotakashi 0:8fdf9a60065b 95 /* SESSION_TEST */
kadonotakashi 0:8fdf9a60065b 96 { START_SESSION, END_SESSION, TERMINATE },
kadonotakashi 0:8fdf9a60065b 97
kadonotakashi 0:8fdf9a60065b 98 /* WRITE_READ_TEST */
kadonotakashi 0:8fdf9a60065b 99 {
kadonotakashi 0:8fdf9a60065b 100 START_SESSION, WRITE_SIZE_4, READ_SIZE_4, WRITE_4_BYTES, READ_4_BYTES,
kadonotakashi 0:8fdf9a60065b 101 WRITE_2_BYTES, READ_4_BYTES_MIXED, END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 102 },
kadonotakashi 0:8fdf9a60065b 103
kadonotakashi 0:8fdf9a60065b 104 /* ERASE_TEST */
kadonotakashi 0:8fdf9a60065b 105 {
kadonotakashi 0:8fdf9a60065b 106 START_SESSION, WRITE_SIZE_4, READ_SIZE_4, WRITE_4_BYTES, READ_4_BYTES,
kadonotakashi 0:8fdf9a60065b 107 ERASE_4_BYTES, READ_4_BYTES_ERASED, END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 108 },
kadonotakashi 0:8fdf9a60065b 109
kadonotakashi 0:8fdf9a60065b 110 /* WRITE_READ_SIZE_TEST */
kadonotakashi 0:8fdf9a60065b 111 {
kadonotakashi 0:8fdf9a60065b 112 START_SESSION, WRITE_SIZE_2, READ_SIZE_2, WRITE_SIZE_4, READ_SIZE_4,
kadonotakashi 0:8fdf9a60065b 113 END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 114 },
kadonotakashi 0:8fdf9a60065b 115
kadonotakashi 0:8fdf9a60065b 116 /* TRUNCATE_TEST */
kadonotakashi 0:8fdf9a60065b 117 {
kadonotakashi 0:8fdf9a60065b 118 START_SESSION, WRITE_SIZE_4, READ_SIZE_4, WRITE_4_BYTES, READ_4_BYTES,
kadonotakashi 0:8fdf9a60065b 119 WRITE_SIZE_2, READ_SIZE_2, READ_4_BYTES_FAIL, END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 120 },
kadonotakashi 0:8fdf9a60065b 121
kadonotakashi 0:8fdf9a60065b 122 /* WRITE_TRUNCATE_TEST */
kadonotakashi 0:8fdf9a60065b 123 {
kadonotakashi 0:8fdf9a60065b 124 START_SESSION, WRITE_SIZE_2, READ_SIZE_2, WRITE_4_BYTES_FAIL, READ_4_BYTES_FAIL,
kadonotakashi 0:8fdf9a60065b 125 END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 126 },
kadonotakashi 0:8fdf9a60065b 127
kadonotakashi 0:8fdf9a60065b 128 /* WRITE_WITH_OFFSET_TEST */
kadonotakashi 0:8fdf9a60065b 129 {
kadonotakashi 0:8fdf9a60065b 130 START_SESSION, WRITE_SIZE_4, READ_SIZE_4, WRITE_4_BYTES, READ_4_BYTES,
kadonotakashi 0:8fdf9a60065b 131 WRITE_2_BYTES_OFFSET, READ_4_BYTES_OFFSET, END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 132 },
kadonotakashi 0:8fdf9a60065b 133
kadonotakashi 0:8fdf9a60065b 134 /* WRITE_BEYOND_SIZE_TEST */
kadonotakashi 0:8fdf9a60065b 135 {
kadonotakashi 0:8fdf9a60065b 136 START_SESSION, WRITE_SIZE_2, READ_SIZE_2, WRITE_2_BYTES_OFFSET_FAIL, READ_2_BYTES_OFFSET_FAIL,
kadonotakashi 0:8fdf9a60065b 137 WRITE_2_BYTES, READ_2_BYTES, END_SESSION, TERMINATE
kadonotakashi 0:8fdf9a60065b 138 }
kadonotakashi 0:8fdf9a60065b 139 };
kadonotakashi 0:8fdf9a60065b 140
kadonotakashi 0:8fdf9a60065b 141 static const uint8_t DATA_4_BYTES[] = { 0x01, 0x02, 0x03, 0x04 };
kadonotakashi 0:8fdf9a60065b 142 static const uint8_t DATA_2_BYTES[] = { 0x05, 0x06 };
kadonotakashi 0:8fdf9a60065b 143 static const uint8_t DATA_4_BYTES_MIXED[] = { 0x05, 0x06, 0x03, 0x04 };
kadonotakashi 0:8fdf9a60065b 144 static const uint8_t DATA_4_BYTES_OFFSET[] = { 0x01, 0x02, 0x05, 0x06 };
kadonotakashi 0:8fdf9a60065b 145 static const uint8_t DATA_4_BYTES_ERASED[] = { 0x00, 0x00, 0x00, 0x00 };
kadonotakashi 0:8fdf9a60065b 146
kadonotakashi 0:8fdf9a60065b 147 class DriverTest : public NFCEEPROMDriver::Delegate {
kadonotakashi 0:8fdf9a60065b 148 public:
kadonotakashi 0:8fdf9a60065b 149 DriverTest(NFCEEPROMDriver *_driver)
kadonotakashi 0:8fdf9a60065b 150 : _operation_data(NULL),
kadonotakashi 0:8fdf9a60065b 151 _driver(_driver),
kadonotakashi 0:8fdf9a60065b 152 _sequence(SEQUENCE_MAX),
kadonotakashi 0:8fdf9a60065b 153 _step(0),
kadonotakashi 0:8fdf9a60065b 154 _result_size(0),
kadonotakashi 0:8fdf9a60065b 155 _address(0),
kadonotakashi 0:8fdf9a60065b 156 _success(true) { };
kadonotakashi 0:8fdf9a60065b 157
kadonotakashi 0:8fdf9a60065b 158 virtual ~DriverTest() { };
kadonotakashi 0:8fdf9a60065b 159
kadonotakashi 0:8fdf9a60065b 160 /* Delegate events */
kadonotakashi 0:8fdf9a60065b 161
kadonotakashi 0:8fdf9a60065b 162 virtual void on_session_started(bool success)
kadonotakashi 0:8fdf9a60065b 163 {
kadonotakashi 0:8fdf9a60065b 164 if (success != _success) {
kadonotakashi 0:8fdf9a60065b 165 TEST_FAIL_MESSAGE("failed to start session");
kadonotakashi 0:8fdf9a60065b 166 }
kadonotakashi 0:8fdf9a60065b 167
kadonotakashi 0:8fdf9a60065b 168 evaluate_step(START_SESSION);
kadonotakashi 0:8fdf9a60065b 169 };
kadonotakashi 0:8fdf9a60065b 170
kadonotakashi 0:8fdf9a60065b 171 virtual void on_session_ended(bool success)
kadonotakashi 0:8fdf9a60065b 172 {
kadonotakashi 0:8fdf9a60065b 173 if (success != _success) {
kadonotakashi 0:8fdf9a60065b 174 TEST_FAIL_MESSAGE("failed to end session");
kadonotakashi 0:8fdf9a60065b 175 }
kadonotakashi 0:8fdf9a60065b 176
kadonotakashi 0:8fdf9a60065b 177 evaluate_step(END_SESSION);
kadonotakashi 0:8fdf9a60065b 178 };
kadonotakashi 0:8fdf9a60065b 179
kadonotakashi 0:8fdf9a60065b 180 virtual void on_bytes_read(size_t count)
kadonotakashi 0:8fdf9a60065b 181 {
kadonotakashi 0:8fdf9a60065b 182 if (count != _result_size) {
kadonotakashi 0:8fdf9a60065b 183 TEST_FAIL_MESSAGE("failed to read bytes");
kadonotakashi 0:8fdf9a60065b 184 }
kadonotakashi 0:8fdf9a60065b 185 if (memcmp(_buffer, _operation_data, count) != 0) {
kadonotakashi 0:8fdf9a60065b 186 TEST_FAIL_MESSAGE("read bytes are different than expected");
kadonotakashi 0:8fdf9a60065b 187 }
kadonotakashi 0:8fdf9a60065b 188
kadonotakashi 0:8fdf9a60065b 189 evaluate_step(READ_BYTES);
kadonotakashi 0:8fdf9a60065b 190 };
kadonotakashi 0:8fdf9a60065b 191
kadonotakashi 0:8fdf9a60065b 192 virtual void on_bytes_written(size_t count)
kadonotakashi 0:8fdf9a60065b 193 {
kadonotakashi 0:8fdf9a60065b 194 if (count != _result_size) {
kadonotakashi 0:8fdf9a60065b 195 TEST_FAIL_MESSAGE("failed to write bytes");
kadonotakashi 0:8fdf9a60065b 196 }
kadonotakashi 0:8fdf9a60065b 197
kadonotakashi 0:8fdf9a60065b 198 evaluate_step(WRITE_BYTES);
kadonotakashi 0:8fdf9a60065b 199 };
kadonotakashi 0:8fdf9a60065b 200
kadonotakashi 0:8fdf9a60065b 201 virtual void on_size_written(bool success)
kadonotakashi 0:8fdf9a60065b 202 {
kadonotakashi 0:8fdf9a60065b 203 if (success != _success) {
kadonotakashi 0:8fdf9a60065b 204 TEST_FAIL_MESSAGE("failed to write size");
kadonotakashi 0:8fdf9a60065b 205 }
kadonotakashi 0:8fdf9a60065b 206
kadonotakashi 0:8fdf9a60065b 207 evaluate_step(WRITE_SIZE);
kadonotakashi 0:8fdf9a60065b 208 };
kadonotakashi 0:8fdf9a60065b 209
kadonotakashi 0:8fdf9a60065b 210 virtual void on_size_read(bool success, size_t size)
kadonotakashi 0:8fdf9a60065b 211 {
kadonotakashi 0:8fdf9a60065b 212 if (success != _success || size != _result_size) {
kadonotakashi 0:8fdf9a60065b 213 TEST_FAIL_MESSAGE("failed to read size");
kadonotakashi 0:8fdf9a60065b 214 }
kadonotakashi 0:8fdf9a60065b 215
kadonotakashi 0:8fdf9a60065b 216 evaluate_step(READ_SIZE);
kadonotakashi 0:8fdf9a60065b 217 };
kadonotakashi 0:8fdf9a60065b 218
kadonotakashi 0:8fdf9a60065b 219 virtual void on_bytes_erased(size_t count)
kadonotakashi 0:8fdf9a60065b 220 {
kadonotakashi 0:8fdf9a60065b 221 if (count != _result_size) {
kadonotakashi 0:8fdf9a60065b 222 TEST_FAIL_MESSAGE("failed to erase bytes");
kadonotakashi 0:8fdf9a60065b 223 }
kadonotakashi 0:8fdf9a60065b 224
kadonotakashi 0:8fdf9a60065b 225 evaluate_step(ERASE_BYTES);
kadonotakashi 0:8fdf9a60065b 226 }
kadonotakashi 0:8fdf9a60065b 227
kadonotakashi 0:8fdf9a60065b 228 /* Sequence running code */
kadonotakashi 0:8fdf9a60065b 229
kadonotakashi 0:8fdf9a60065b 230 void run_sequence(TestSequence_t sequence)
kadonotakashi 0:8fdf9a60065b 231 {
kadonotakashi 0:8fdf9a60065b 232 _sequence = sequence;
kadonotakashi 0:8fdf9a60065b 233
kadonotakashi 0:8fdf9a60065b 234 if (_sequence >= SEQUENCE_MAX) {
kadonotakashi 0:8fdf9a60065b 235 TEST_FAIL_MESSAGE("internal test failure - invalid command");
kadonotakashi 0:8fdf9a60065b 236 }
kadonotakashi 0:8fdf9a60065b 237
kadonotakashi 0:8fdf9a60065b 238 execute_next_step();
kadonotakashi 0:8fdf9a60065b 239
kadonotakashi 0:8fdf9a60065b 240 event_queue.dispatch_forever();
kadonotakashi 0:8fdf9a60065b 241
kadonotakashi 0:8fdf9a60065b 242 TEST_ASSERT_EQUAL(TERMINATE, SEQUENCES[_sequence][_step]);
kadonotakashi 0:8fdf9a60065b 243 }
kadonotakashi 0:8fdf9a60065b 244
kadonotakashi 0:8fdf9a60065b 245 void execute_next_step()
kadonotakashi 0:8fdf9a60065b 246 {
kadonotakashi 0:8fdf9a60065b 247 TestCommand_t command = SEQUENCES[_sequence][_step];
kadonotakashi 0:8fdf9a60065b 248
kadonotakashi 0:8fdf9a60065b 249 /* setup data buffer */
kadonotakashi 0:8fdf9a60065b 250 switch (command) {
kadonotakashi 0:8fdf9a60065b 251 case READ_2_BYTES:
kadonotakashi 0:8fdf9a60065b 252 case READ_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 253 case WRITE_2_BYTES:
kadonotakashi 0:8fdf9a60065b 254 case WRITE_2_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 255 case WRITE_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 256 _operation_data = DATA_2_BYTES;
kadonotakashi 0:8fdf9a60065b 257 break;
kadonotakashi 0:8fdf9a60065b 258 case READ_4_BYTES:
kadonotakashi 0:8fdf9a60065b 259 case READ_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 260 case WRITE_4_BYTES:
kadonotakashi 0:8fdf9a60065b 261 case WRITE_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 262 _operation_data = DATA_4_BYTES;
kadonotakashi 0:8fdf9a60065b 263 break;
kadonotakashi 0:8fdf9a60065b 264 case READ_4_BYTES_ERASED:
kadonotakashi 0:8fdf9a60065b 265 _operation_data = DATA_4_BYTES_ERASED;
kadonotakashi 0:8fdf9a60065b 266 break;
kadonotakashi 0:8fdf9a60065b 267 case READ_4_BYTES_MIXED:
kadonotakashi 0:8fdf9a60065b 268 _operation_data = DATA_4_BYTES_MIXED;
kadonotakashi 0:8fdf9a60065b 269 break;
kadonotakashi 0:8fdf9a60065b 270 case READ_4_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 271 _operation_data = DATA_4_BYTES_OFFSET;
kadonotakashi 0:8fdf9a60065b 272 break;
kadonotakashi 0:8fdf9a60065b 273 default:
kadonotakashi 0:8fdf9a60065b 274 _operation_data = NULL;
kadonotakashi 0:8fdf9a60065b 275 }
kadonotakashi 0:8fdf9a60065b 276
kadonotakashi 0:8fdf9a60065b 277 /* setup result size */
kadonotakashi 0:8fdf9a60065b 278 switch (command) {
kadonotakashi 0:8fdf9a60065b 279 case READ_2_BYTES:
kadonotakashi 0:8fdf9a60065b 280 case READ_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 281 case WRITE_2_BYTES:
kadonotakashi 0:8fdf9a60065b 282 case WRITE_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 283 case WRITE_2_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 284 case READ_SIZE_2:
kadonotakashi 0:8fdf9a60065b 285 _result_size = 2;
kadonotakashi 0:8fdf9a60065b 286 break;
kadonotakashi 0:8fdf9a60065b 287 case READ_4_BYTES:
kadonotakashi 0:8fdf9a60065b 288 case READ_4_BYTES_ERASED:
kadonotakashi 0:8fdf9a60065b 289 case READ_4_BYTES_MIXED:
kadonotakashi 0:8fdf9a60065b 290 case READ_4_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 291 case WRITE_4_BYTES:
kadonotakashi 0:8fdf9a60065b 292 case ERASE_4_BYTES:
kadonotakashi 0:8fdf9a60065b 293 case READ_SIZE_4:
kadonotakashi 0:8fdf9a60065b 294 _result_size = 4;
kadonotakashi 0:8fdf9a60065b 295 break;
kadonotakashi 0:8fdf9a60065b 296 default:
kadonotakashi 0:8fdf9a60065b 297 _result_size = 0;
kadonotakashi 0:8fdf9a60065b 298 }
kadonotakashi 0:8fdf9a60065b 299
kadonotakashi 0:8fdf9a60065b 300 /* setup operation size */
kadonotakashi 0:8fdf9a60065b 301 switch (command) {
kadonotakashi 0:8fdf9a60065b 302 case READ_2_BYTES:
kadonotakashi 0:8fdf9a60065b 303 case READ_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 304 case WRITE_2_BYTES:
kadonotakashi 0:8fdf9a60065b 305 case WRITE_2_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 306 case WRITE_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 307 case WRITE_SIZE_2:
kadonotakashi 0:8fdf9a60065b 308 _operation_size = 2;
kadonotakashi 0:8fdf9a60065b 309 break;
kadonotakashi 0:8fdf9a60065b 310 case READ_4_BYTES:
kadonotakashi 0:8fdf9a60065b 311 case READ_4_BYTES_ERASED:
kadonotakashi 0:8fdf9a60065b 312 case READ_4_BYTES_MIXED:
kadonotakashi 0:8fdf9a60065b 313 case READ_4_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 314 case READ_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 315 case WRITE_4_BYTES:
kadonotakashi 0:8fdf9a60065b 316 case WRITE_4_BYTES_FAIL:
kadonotakashi 0:8fdf9a60065b 317 case ERASE_4_BYTES:
kadonotakashi 0:8fdf9a60065b 318 case READ_SIZE_4:
kadonotakashi 0:8fdf9a60065b 319 case WRITE_SIZE_4:
kadonotakashi 0:8fdf9a60065b 320 _operation_size = 4;
kadonotakashi 0:8fdf9a60065b 321 break;
kadonotakashi 0:8fdf9a60065b 322 default:
kadonotakashi 0:8fdf9a60065b 323 _operation_size = 0;
kadonotakashi 0:8fdf9a60065b 324 }
kadonotakashi 0:8fdf9a60065b 325
kadonotakashi 0:8fdf9a60065b 326 /* setup offset */
kadonotakashi 0:8fdf9a60065b 327 switch (command) {
kadonotakashi 0:8fdf9a60065b 328 case READ_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 329 case WRITE_2_BYTES_OFFSET:
kadonotakashi 0:8fdf9a60065b 330 case WRITE_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 331 _address = 2;
kadonotakashi 0:8fdf9a60065b 332 break;
kadonotakashi 0:8fdf9a60065b 333 default:
kadonotakashi 0:8fdf9a60065b 334 _address = 0;
kadonotakashi 0:8fdf9a60065b 335 }
kadonotakashi 0:8fdf9a60065b 336
kadonotakashi 0:8fdf9a60065b 337 /* setup command success */
kadonotakashi 0:8fdf9a60065b 338 switch (command) {
kadonotakashi 0:8fdf9a60065b 339 case READ_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 340 case WRITE_2_BYTES_OFFSET_FAIL:
kadonotakashi 0:8fdf9a60065b 341 _success = false;
kadonotakashi 0:8fdf9a60065b 342 break;
kadonotakashi 0:8fdf9a60065b 343 default:
kadonotakashi 0:8fdf9a60065b 344 _success = true;
kadonotakashi 0:8fdf9a60065b 345 }
kadonotakashi 0:8fdf9a60065b 346
kadonotakashi 0:8fdf9a60065b 347 /* call next command */
kadonotakashi 0:8fdf9a60065b 348 switch (command & TEST_COMMAND_GROUP_MASK) {
kadonotakashi 0:8fdf9a60065b 349 case START_SESSION:
kadonotakashi 0:8fdf9a60065b 350 _driver->start_session(true);
kadonotakashi 0:8fdf9a60065b 351 break;
kadonotakashi 0:8fdf9a60065b 352 case END_SESSION:
kadonotakashi 0:8fdf9a60065b 353 _driver->end_session();
kadonotakashi 0:8fdf9a60065b 354 break;
kadonotakashi 0:8fdf9a60065b 355 case READ_BYTES:
kadonotakashi 0:8fdf9a60065b 356 _driver->read_bytes(_address, _buffer, _operation_size);
kadonotakashi 0:8fdf9a60065b 357 break;
kadonotakashi 0:8fdf9a60065b 358 case WRITE_BYTES:
kadonotakashi 0:8fdf9a60065b 359 _driver->write_bytes(_address, _operation_data, _operation_size);
kadonotakashi 0:8fdf9a60065b 360 break;
kadonotakashi 0:8fdf9a60065b 361 case ERASE_BYTES:
kadonotakashi 0:8fdf9a60065b 362 _driver->erase_bytes(_address, 4);
kadonotakashi 0:8fdf9a60065b 363 break;
kadonotakashi 0:8fdf9a60065b 364 case READ_SIZE:
kadonotakashi 0:8fdf9a60065b 365 _driver->read_size();
kadonotakashi 0:8fdf9a60065b 366 break;
kadonotakashi 0:8fdf9a60065b 367 case WRITE_SIZE:
kadonotakashi 0:8fdf9a60065b 368 _driver->write_size(_operation_size);
kadonotakashi 0:8fdf9a60065b 369 break;
kadonotakashi 0:8fdf9a60065b 370 case TERMINATE:
kadonotakashi 0:8fdf9a60065b 371 event_queue.break_dispatch();
kadonotakashi 0:8fdf9a60065b 372 break;
kadonotakashi 0:8fdf9a60065b 373 default:
kadonotakashi 0:8fdf9a60065b 374 TEST_FAIL_MESSAGE("internal test failure - invalid command");
kadonotakashi 0:8fdf9a60065b 375 }
kadonotakashi 0:8fdf9a60065b 376 }
kadonotakashi 0:8fdf9a60065b 377
kadonotakashi 0:8fdf9a60065b 378 void evaluate_step(TestCommand_t command_completed)
kadonotakashi 0:8fdf9a60065b 379 {
kadonotakashi 0:8fdf9a60065b 380 /* check last command succeeded */
kadonotakashi 0:8fdf9a60065b 381 TEST_ASSERT_EQUAL(command_completed, SEQUENCES[_sequence][_step]&TEST_COMMAND_GROUP_MASK);
kadonotakashi 0:8fdf9a60065b 382
kadonotakashi 0:8fdf9a60065b 383 _step++;
kadonotakashi 0:8fdf9a60065b 384
kadonotakashi 0:8fdf9a60065b 385 if (_step == MAX_STEP) {
kadonotakashi 0:8fdf9a60065b 386 TEST_FAIL_MESSAGE("internal test failure - too many steps");
kadonotakashi 0:8fdf9a60065b 387 }
kadonotakashi 0:8fdf9a60065b 388
kadonotakashi 0:8fdf9a60065b 389 execute_next_step();
kadonotakashi 0:8fdf9a60065b 390 }
kadonotakashi 0:8fdf9a60065b 391
kadonotakashi 0:8fdf9a60065b 392 private:
kadonotakashi 0:8fdf9a60065b 393 uint8_t _buffer[BUFFER_MAX];
kadonotakashi 0:8fdf9a60065b 394 const uint8_t *_operation_data;
kadonotakashi 0:8fdf9a60065b 395
kadonotakashi 0:8fdf9a60065b 396 NFCEEPROMDriver *_driver;
kadonotakashi 0:8fdf9a60065b 397
kadonotakashi 0:8fdf9a60065b 398 TestSequence_t _sequence;
kadonotakashi 0:8fdf9a60065b 399 size_t _step;
kadonotakashi 0:8fdf9a60065b 400 size_t _result_size;
kadonotakashi 0:8fdf9a60065b 401 size_t _operation_size;
kadonotakashi 0:8fdf9a60065b 402 size_t _address;
kadonotakashi 0:8fdf9a60065b 403 bool _success;
kadonotakashi 0:8fdf9a60065b 404 };
kadonotakashi 0:8fdf9a60065b 405
kadonotakashi 0:8fdf9a60065b 406 /* test case running code */
kadonotakashi 0:8fdf9a60065b 407
kadonotakashi 0:8fdf9a60065b 408 static DriverTest *driver_test;
kadonotakashi 0:8fdf9a60065b 409 extern NFCEEPROMDriver *greentea_nfc_EEPROM_driver_get_instance();
kadonotakashi 0:8fdf9a60065b 410
kadonotakashi 0:8fdf9a60065b 411 utest::v1::status_t test_setup(const Case *const source, const size_t index_of_case)
kadonotakashi 0:8fdf9a60065b 412 {
kadonotakashi 0:8fdf9a60065b 413 NFCEEPROMDriver *driver = greentea_nfc_EEPROM_driver_get_instance();
kadonotakashi 0:8fdf9a60065b 414 driver_test = new DriverTest(driver);
kadonotakashi 0:8fdf9a60065b 415
kadonotakashi 0:8fdf9a60065b 416 driver->set_event_queue(&event_queue);
kadonotakashi 0:8fdf9a60065b 417 driver->set_delegate(driver_test);
kadonotakashi 0:8fdf9a60065b 418 driver->reset();
kadonotakashi 0:8fdf9a60065b 419
kadonotakashi 0:8fdf9a60065b 420 TEST_ASSERT_NOT_EQUAL(0, driver->read_max_size());
kadonotakashi 0:8fdf9a60065b 421
kadonotakashi 0:8fdf9a60065b 422 return greentea_case_setup_handler(source, index_of_case);
kadonotakashi 0:8fdf9a60065b 423 }
kadonotakashi 0:8fdf9a60065b 424
kadonotakashi 0:8fdf9a60065b 425 void session()
kadonotakashi 0:8fdf9a60065b 426 {
kadonotakashi 0:8fdf9a60065b 427 driver_test->run_sequence(SESSION_TEST);
kadonotakashi 0:8fdf9a60065b 428 }
kadonotakashi 0:8fdf9a60065b 429
kadonotakashi 0:8fdf9a60065b 430 void write_read()
kadonotakashi 0:8fdf9a60065b 431 {
kadonotakashi 0:8fdf9a60065b 432 driver_test->run_sequence(WRITE_READ_TEST);
kadonotakashi 0:8fdf9a60065b 433 }
kadonotakashi 0:8fdf9a60065b 434
kadonotakashi 0:8fdf9a60065b 435 void erase_bytes()
kadonotakashi 0:8fdf9a60065b 436 {
kadonotakashi 0:8fdf9a60065b 437 driver_test->run_sequence(ERASE_TEST);
kadonotakashi 0:8fdf9a60065b 438 }
kadonotakashi 0:8fdf9a60065b 439
kadonotakashi 0:8fdf9a60065b 440 void write_read_size()
kadonotakashi 0:8fdf9a60065b 441 {
kadonotakashi 0:8fdf9a60065b 442 driver_test->run_sequence(WRITE_READ_SIZE_TEST);
kadonotakashi 0:8fdf9a60065b 443 }
kadonotakashi 0:8fdf9a60065b 444
kadonotakashi 0:8fdf9a60065b 445 void truncate_size()
kadonotakashi 0:8fdf9a60065b 446 {
kadonotakashi 0:8fdf9a60065b 447 driver_test->run_sequence(TRUNCATE_TEST);
kadonotakashi 0:8fdf9a60065b 448 }
kadonotakashi 0:8fdf9a60065b 449
kadonotakashi 0:8fdf9a60065b 450 void write_bytes_truncated()
kadonotakashi 0:8fdf9a60065b 451 {
kadonotakashi 0:8fdf9a60065b 452 driver_test->run_sequence(WRITE_TRUNCATE_TEST);
kadonotakashi 0:8fdf9a60065b 453 }
kadonotakashi 0:8fdf9a60065b 454
kadonotakashi 0:8fdf9a60065b 455 void write_with_offset()
kadonotakashi 0:8fdf9a60065b 456 {
kadonotakashi 0:8fdf9a60065b 457 driver_test->run_sequence(WRITE_WITH_OFFSET_TEST);
kadonotakashi 0:8fdf9a60065b 458 }
kadonotakashi 0:8fdf9a60065b 459
kadonotakashi 0:8fdf9a60065b 460 void write_beyond_size()
kadonotakashi 0:8fdf9a60065b 461 {
kadonotakashi 0:8fdf9a60065b 462 driver_test->run_sequence(WRITE_BEYOND_SIZE_TEST);
kadonotakashi 0:8fdf9a60065b 463 }
kadonotakashi 0:8fdf9a60065b 464
kadonotakashi 0:8fdf9a60065b 465 utest::v1::status_t test_tear_down(const Case *const source, const size_t passed,
kadonotakashi 0:8fdf9a60065b 466 const size_t failed, const failure_t reason)
kadonotakashi 0:8fdf9a60065b 467 {
kadonotakashi 0:8fdf9a60065b 468 delete driver_test;
kadonotakashi 0:8fdf9a60065b 469
kadonotakashi 0:8fdf9a60065b 470 return greentea_case_teardown_handler(source, passed, failed, reason);
kadonotakashi 0:8fdf9a60065b 471 }
kadonotakashi 0:8fdf9a60065b 472
kadonotakashi 0:8fdf9a60065b 473 /* test setup */
kadonotakashi 0:8fdf9a60065b 474
kadonotakashi 0:8fdf9a60065b 475 utest::v1::status_t test_init(const size_t number_of_cases)
kadonotakashi 0:8fdf9a60065b 476 {
kadonotakashi 0:8fdf9a60065b 477 GREENTEA_SETUP(10, "default_auto");
kadonotakashi 0:8fdf9a60065b 478 return greentea_test_setup_handler(number_of_cases);
kadonotakashi 0:8fdf9a60065b 479 }
kadonotakashi 0:8fdf9a60065b 480
kadonotakashi 0:8fdf9a60065b 481 // Test cases
kadonotakashi 0:8fdf9a60065b 482 Case cases[] = {
kadonotakashi 0:8fdf9a60065b 483 Case("NFCEEPROM-SESSION", test_setup, session, test_tear_down),
kadonotakashi 0:8fdf9a60065b 484 Case("NFCEEPROM-WRITE-READ", test_setup, write_read, test_tear_down),
kadonotakashi 0:8fdf9a60065b 485 Case("NFCEEPROM-ERASE-BYTES", test_setup, erase_bytes, test_tear_down),
kadonotakashi 0:8fdf9a60065b 486 Case("NFCEEPROM-WRITE-READ-SIZE", test_setup, write_read_size, test_tear_down),
kadonotakashi 0:8fdf9a60065b 487 Case("NFCEEPROM-TRUNCATE-SIZE", test_setup, truncate_size, test_tear_down),
kadonotakashi 0:8fdf9a60065b 488 Case("NFCEEPROM-WRITE-BYTES-TRUNCATED", test_setup, write_bytes_truncated, test_tear_down),
kadonotakashi 0:8fdf9a60065b 489 Case("NFCEEPROM-WRITE-WITH-OFFSET", test_setup, write_with_offset, test_tear_down),
kadonotakashi 0:8fdf9a60065b 490 Case("NFCEEPROM-WRITE-BEYOND-SIZE", test_setup, write_beyond_size, test_tear_down)
kadonotakashi 0:8fdf9a60065b 491 };
kadonotakashi 0:8fdf9a60065b 492
kadonotakashi 0:8fdf9a60065b 493 Specification specification(test_init, cases);
kadonotakashi 0:8fdf9a60065b 494
kadonotakashi 0:8fdf9a60065b 495 // Entry point into the tests
kadonotakashi 0:8fdf9a60065b 496 int main()
kadonotakashi 0:8fdf9a60065b 497 {
kadonotakashi 0:8fdf9a60065b 498 return !Harness::run(specification);
kadonotakashi 0:8fdf9a60065b 499 }