takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/mbedmicro-mbed/cpp/main.cpp@0:8fdf9a60065b, 2018-10-10 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | #include "greentea-client/test_env.h" |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | #define PATTERN_CHECK_VALUE 0xF0F0ADAD |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | class Test { |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | private: |
kadonotakashi | 0:8fdf9a60065b | 23 | const char *name; |
kadonotakashi | 0:8fdf9a60065b | 24 | const int pattern; |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | public: |
kadonotakashi | 0:8fdf9a60065b | 27 | Test(const char *_name, bool print_message = true) : name(_name), pattern(PATTERN_CHECK_VALUE) |
kadonotakashi | 0:8fdf9a60065b | 28 | { |
kadonotakashi | 0:8fdf9a60065b | 29 | if (print_message) { |
kadonotakashi | 0:8fdf9a60065b | 30 | print("init"); |
kadonotakashi | 0:8fdf9a60065b | 31 | } |
kadonotakashi | 0:8fdf9a60065b | 32 | } |
kadonotakashi | 0:8fdf9a60065b | 33 | |
kadonotakashi | 0:8fdf9a60065b | 34 | void print(const char *message) |
kadonotakashi | 0:8fdf9a60065b | 35 | { |
kadonotakashi | 0:8fdf9a60065b | 36 | printf("%s::%s\n", name, message); |
kadonotakashi | 0:8fdf9a60065b | 37 | } |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | bool check_init(void) |
kadonotakashi | 0:8fdf9a60065b | 40 | { |
kadonotakashi | 0:8fdf9a60065b | 41 | bool result = (pattern == PATTERN_CHECK_VALUE); |
kadonotakashi | 0:8fdf9a60065b | 42 | print(result ? "check_init: OK" : "check_init: ERROR"); |
kadonotakashi | 0:8fdf9a60065b | 43 | return result; |
kadonotakashi | 0:8fdf9a60065b | 44 | } |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | void stack_test(void) |
kadonotakashi | 0:8fdf9a60065b | 47 | { |
kadonotakashi | 0:8fdf9a60065b | 48 | print("stack_test"); |
kadonotakashi | 0:8fdf9a60065b | 49 | Test t("Stack"); |
kadonotakashi | 0:8fdf9a60065b | 50 | t.hello(); |
kadonotakashi | 0:8fdf9a60065b | 51 | } |
kadonotakashi | 0:8fdf9a60065b | 52 | |
kadonotakashi | 0:8fdf9a60065b | 53 | void hello(void) |
kadonotakashi | 0:8fdf9a60065b | 54 | { |
kadonotakashi | 0:8fdf9a60065b | 55 | print("hello"); |
kadonotakashi | 0:8fdf9a60065b | 56 | } |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | ~Test() |
kadonotakashi | 0:8fdf9a60065b | 59 | { |
kadonotakashi | 0:8fdf9a60065b | 60 | print("destroy"); |
kadonotakashi | 0:8fdf9a60065b | 61 | } |
kadonotakashi | 0:8fdf9a60065b | 62 | }; |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | /* Check C++ startup initialisation */ |
kadonotakashi | 0:8fdf9a60065b | 65 | Test s("Static", false); |
kadonotakashi | 0:8fdf9a60065b | 66 | |
kadonotakashi | 0:8fdf9a60065b | 67 | /* EXPECTED OUTPUT: |
kadonotakashi | 0:8fdf9a60065b | 68 | ******************* |
kadonotakashi | 0:8fdf9a60065b | 69 | Static::init |
kadonotakashi | 0:8fdf9a60065b | 70 | Static::stack_test |
kadonotakashi | 0:8fdf9a60065b | 71 | Stack::init |
kadonotakashi | 0:8fdf9a60065b | 72 | Stack::hello |
kadonotakashi | 0:8fdf9a60065b | 73 | Stack::destroy |
kadonotakashi | 0:8fdf9a60065b | 74 | Static::check_init: OK |
kadonotakashi | 0:8fdf9a60065b | 75 | Heap::init |
kadonotakashi | 0:8fdf9a60065b | 76 | Heap::hello |
kadonotakashi | 0:8fdf9a60065b | 77 | Heap::destroy |
kadonotakashi | 0:8fdf9a60065b | 78 | *******************/ |
kadonotakashi | 0:8fdf9a60065b | 79 | int main(void) |
kadonotakashi | 0:8fdf9a60065b | 80 | { |
kadonotakashi | 0:8fdf9a60065b | 81 | GREENTEA_SETUP(10, "default_auto"); |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | bool result = true; |
kadonotakashi | 0:8fdf9a60065b | 84 | for (;;) { |
kadonotakashi | 0:8fdf9a60065b | 85 | s.print("init"); |
kadonotakashi | 0:8fdf9a60065b | 86 | // Global stack object simple test |
kadonotakashi | 0:8fdf9a60065b | 87 | s.stack_test(); |
kadonotakashi | 0:8fdf9a60065b | 88 | if (s.check_init() == false) { |
kadonotakashi | 0:8fdf9a60065b | 89 | result = false; |
kadonotakashi | 0:8fdf9a60065b | 90 | break; |
kadonotakashi | 0:8fdf9a60065b | 91 | } |
kadonotakashi | 0:8fdf9a60065b | 92 | |
kadonotakashi | 0:8fdf9a60065b | 93 | // Heap test object simple test |
kadonotakashi | 0:8fdf9a60065b | 94 | Test *m = new Test("Heap"); |
kadonotakashi | 0:8fdf9a60065b | 95 | m->hello(); |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | if (m->check_init() == false) { |
kadonotakashi | 0:8fdf9a60065b | 98 | result = false; |
kadonotakashi | 0:8fdf9a60065b | 99 | } |
kadonotakashi | 0:8fdf9a60065b | 100 | delete m; |
kadonotakashi | 0:8fdf9a60065b | 101 | break; |
kadonotakashi | 0:8fdf9a60065b | 102 | } |
kadonotakashi | 0:8fdf9a60065b | 103 | |
kadonotakashi | 0:8fdf9a60065b | 104 | GREENTEA_TESTSUITE_RESULT(result); |
kadonotakashi | 0:8fdf9a60065b | 105 | } |