Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /*
switches 0:5c4d7b2438d3 2 * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
switches 0:5c4d7b2438d3 3 * SPDX-License-Identifier: Apache-2.0
switches 0:5c4d7b2438d3 4 *
switches 0:5c4d7b2438d3 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
switches 0:5c4d7b2438d3 6 * not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 7 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 8 *
switches 0:5c4d7b2438d3 9 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
switches 0:5c4d7b2438d3 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 14 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 15 * limitations under the License.
switches 0:5c4d7b2438d3 16 */
switches 0:5c4d7b2438d3 17 #include <stdio.h>
switches 0:5c4d7b2438d3 18 #include <string.h>
switches 0:5c4d7b2438d3 19 #include <utility> // std::pair
switches 0:5c4d7b2438d3 20 #include "mbed.h"
switches 0:5c4d7b2438d3 21 #include "greentea-client/test_env.h"
switches 0:5c4d7b2438d3 22 #include "unity/unity.h"
switches 0:5c4d7b2438d3 23 #include "utest/utest.h"
switches 0:5c4d7b2438d3 24
switches 0:5c4d7b2438d3 25 using namespace utest::v1;
switches 0:5c4d7b2438d3 26
switches 0:5c4d7b2438d3 27 #define PATTERN_CHECK_VALUE 0xF0F0ADAD
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 class CppTestCaseHelperClass {
switches 0:5c4d7b2438d3 30 private:
switches 0:5c4d7b2438d3 31 const char* name;
switches 0:5c4d7b2438d3 32 const unsigned pattern;
switches 0:5c4d7b2438d3 33
switches 0:5c4d7b2438d3 34 public:
switches 0:5c4d7b2438d3 35 CppTestCaseHelperClass(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
switches 0:5c4d7b2438d3 36 print("init");
switches 0:5c4d7b2438d3 37 }
switches 0:5c4d7b2438d3 38
switches 0:5c4d7b2438d3 39 void print(const char *message) {
switches 0:5c4d7b2438d3 40 printf("%s::%s\n", name, message);
switches 0:5c4d7b2438d3 41 }
switches 0:5c4d7b2438d3 42
switches 0:5c4d7b2438d3 43 bool check_init(void) {
switches 0:5c4d7b2438d3 44 bool result = (pattern == PATTERN_CHECK_VALUE);
switches 0:5c4d7b2438d3 45 print(result ? "check_init: OK" : "check_init: ERROR");
switches 0:5c4d7b2438d3 46 return result;
switches 0:5c4d7b2438d3 47 }
switches 0:5c4d7b2438d3 48
switches 0:5c4d7b2438d3 49 void stack_test(void) {
switches 0:5c4d7b2438d3 50 print("stack_test");
switches 0:5c4d7b2438d3 51 CppTestCaseHelperClass t("Stack");
switches 0:5c4d7b2438d3 52 t.hello();
switches 0:5c4d7b2438d3 53 }
switches 0:5c4d7b2438d3 54
switches 0:5c4d7b2438d3 55 void hello(void) {
switches 0:5c4d7b2438d3 56 print("hello");
switches 0:5c4d7b2438d3 57 }
switches 0:5c4d7b2438d3 58
switches 0:5c4d7b2438d3 59 ~CppTestCaseHelperClass() {
switches 0:5c4d7b2438d3 60 print("destroy");
switches 0:5c4d7b2438d3 61 }
switches 0:5c4d7b2438d3 62 };
switches 0:5c4d7b2438d3 63
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 void test_case_basic() {
switches 0:5c4d7b2438d3 66 TEST_ASSERT_TRUE(true);
switches 0:5c4d7b2438d3 67 TEST_ASSERT_FALSE(false);
switches 0:5c4d7b2438d3 68 TEST_ASSERT_EQUAL_STRING("The quick brown fox jumps over the lazy dog",
switches 0:5c4d7b2438d3 69 "The quick brown fox jumps over the lazy dog");
switches 0:5c4d7b2438d3 70 }
switches 0:5c4d7b2438d3 71
switches 0:5c4d7b2438d3 72 void test_case_blinky() {
switches 0:5c4d7b2438d3 73 static DigitalOut myled(LED1);
switches 0:5c4d7b2438d3 74 const int cnt_max = 1024;
switches 0:5c4d7b2438d3 75 for (int cnt = 0; cnt < cnt_max; ++cnt) {
switches 0:5c4d7b2438d3 76 myled = !myled;
switches 0:5c4d7b2438d3 77 }
switches 0:5c4d7b2438d3 78 }
switches 0:5c4d7b2438d3 79
switches 0:5c4d7b2438d3 80 void test_case_cpp_stack() {
switches 0:5c4d7b2438d3 81 // Check C++ start-up initialisation
switches 0:5c4d7b2438d3 82 CppTestCaseHelperClass s("Static");
switches 0:5c4d7b2438d3 83
switches 0:5c4d7b2438d3 84 // Global stack object simple test
switches 0:5c4d7b2438d3 85 s.stack_test();
switches 0:5c4d7b2438d3 86 TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed");
switches 0:5c4d7b2438d3 87 }
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 void test_case_cpp_heap() {
switches 0:5c4d7b2438d3 90 // Heap test object simple test
switches 0:5c4d7b2438d3 91 CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap");
switches 0:5c4d7b2438d3 92 m->hello();
switches 0:5c4d7b2438d3 93 TEST_ASSERT_TRUE_MESSAGE(m->check_init(), "m->check_init() failed");
switches 0:5c4d7b2438d3 94 delete m;
switches 0:5c4d7b2438d3 95 }
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
switches 0:5c4d7b2438d3 98 greentea_case_failure_abort_handler(source, reason);
switches 0:5c4d7b2438d3 99 return STATUS_CONTINUE;
switches 0:5c4d7b2438d3 100 }
switches 0:5c4d7b2438d3 101
switches 0:5c4d7b2438d3 102 // Generic test cases
switches 0:5c4d7b2438d3 103 Case cases[] = {
switches 0:5c4d7b2438d3 104 Case("Basic", test_case_basic, greentea_failure_handler),
switches 0:5c4d7b2438d3 105 Case("Blinky", test_case_blinky, greentea_failure_handler),
switches 0:5c4d7b2438d3 106 Case("C++ stack", test_case_cpp_stack, greentea_failure_handler),
switches 0:5c4d7b2438d3 107 Case("C++ heap", test_case_cpp_heap, greentea_failure_handler)
switches 0:5c4d7b2438d3 108 };
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
switches 0:5c4d7b2438d3 111 GREENTEA_SETUP(20, "default_auto");
switches 0:5c4d7b2438d3 112 return greentea_test_setup_handler(number_of_cases);
switches 0:5c4d7b2438d3 113 }
switches 0:5c4d7b2438d3 114
switches 0:5c4d7b2438d3 115 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
switches 0:5c4d7b2438d3 116
switches 0:5c4d7b2438d3 117 int main() {
switches 0:5c4d7b2438d3 118 Harness::run(specification);
switches 0:5c4d7b2438d3 119 }