A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 /*
ram54288 0:a7a43371b306 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:a7a43371b306 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:a7a43371b306 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:a7a43371b306 5 * not use this file except in compliance with the License.
ram54288 0:a7a43371b306 6 * You may obtain a copy of the License at
ram54288 0:a7a43371b306 7 *
ram54288 0:a7a43371b306 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:a7a43371b306 9 *
ram54288 0:a7a43371b306 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:a7a43371b306 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:a7a43371b306 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:a7a43371b306 13 * See the License for the specific language governing permissions and
ram54288 0:a7a43371b306 14 * limitations under the License.
ram54288 0:a7a43371b306 15 */
ram54288 0:a7a43371b306 16 #include <string.h>
ram54288 0:a7a43371b306 17 #include <stdio.h>
ram54288 0:a7a43371b306 18 #include <stdarg.h>
ram54288 0:a7a43371b306 19
ram54288 0:a7a43371b306 20 //stack
ram54288 0:a7a43371b306 21 #include "eventOS_event.h"
ram54288 0:a7a43371b306 22 #include "eventOS_scheduler.h"
ram54288 0:a7a43371b306 23
ram54288 0:a7a43371b306 24 //mbed-client-libservice
ram54288 0:a7a43371b306 25 #include "randLIB.h"
ram54288 0:a7a43371b306 26 #include "nsdynmemLIB.h"
ram54288 0:a7a43371b306 27 #include "mbed-trace/mbed_trace.h"
ram54288 0:a7a43371b306 28 #include "ns_cmdline.h"
ram54288 0:a7a43371b306 29
ram54288 0:a7a43371b306 30
ram54288 0:a7a43371b306 31 //application
ram54288 0:a7a43371b306 32 #include "cmd_commands.h"
ram54288 0:a7a43371b306 33
ram54288 0:a7a43371b306 34 #define APP_DEV_HEAP_SIZE 30000
ram54288 0:a7a43371b306 35
ram54288 0:a7a43371b306 36 void eventOS_scheduler_idle(void)
ram54288 0:a7a43371b306 37 {
ram54288 0:a7a43371b306 38 eventOS_scheduler_wait();
ram54288 0:a7a43371b306 39 }
ram54288 0:a7a43371b306 40
ram54288 0:a7a43371b306 41 /*Global variables*/
ram54288 0:a7a43371b306 42
ram54288 0:a7a43371b306 43 uint8_t app_defined_stack_heap[APP_DEV_HEAP_SIZE];
ram54288 0:a7a43371b306 44
ram54288 0:a7a43371b306 45 void app_heap_error_handler(heap_fail_t event)
ram54288 0:a7a43371b306 46 {
ram54288 0:a7a43371b306 47 switch (event)
ram54288 0:a7a43371b306 48 {
ram54288 0:a7a43371b306 49 case NS_DYN_MEM_NULL_FREE:
ram54288 0:a7a43371b306 50 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:NULL_FREE");
ram54288 0:a7a43371b306 51 break;
ram54288 0:a7a43371b306 52 case NS_DYN_MEM_DOUBLE_FREE:
ram54288 0:a7a43371b306 53 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:DOUBLE_FREE");
ram54288 0:a7a43371b306 54 break;
ram54288 0:a7a43371b306 55
ram54288 0:a7a43371b306 56 case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID:
ram54288 0:a7a43371b306 57 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SIZE_NOT_VALID");
ram54288 0:a7a43371b306 58 break;
ram54288 0:a7a43371b306 59 case NS_DYN_MEM_POINTER_NOT_VALID:
ram54288 0:a7a43371b306 60 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:POINTER_NOT_VALID");
ram54288 0:a7a43371b306 61 break;
ram54288 0:a7a43371b306 62
ram54288 0:a7a43371b306 63 case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED:
ram54288 0:a7a43371b306 64 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SECTOR_CORRUPTED");
ram54288 0:a7a43371b306 65 break;
ram54288 0:a7a43371b306 66
ram54288 0:a7a43371b306 67 case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED:
ram54288 0:a7a43371b306 68 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SECTOR_UNITIALIZED");
ram54288 0:a7a43371b306 69 break;
ram54288 0:a7a43371b306 70 default:
ram54288 0:a7a43371b306 71 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:UNKNOWN!");
ram54288 0:a7a43371b306 72 break;
ram54288 0:a7a43371b306 73 }
ram54288 0:a7a43371b306 74 while(1);
ram54288 0:a7a43371b306 75 }
ram54288 0:a7a43371b306 76
ram54288 0:a7a43371b306 77 int app_time_i=0;
ram54288 0:a7a43371b306 78 char* time_now(size_t size)
ram54288 0:a7a43371b306 79 {
ram54288 0:a7a43371b306 80 static char str[10] = {0};
ram54288 0:a7a43371b306 81 sprintf(str, "[%04d]", app_time_i++);
ram54288 0:a7a43371b306 82 return str;
ram54288 0:a7a43371b306 83 }
ram54288 0:a7a43371b306 84
ram54288 0:a7a43371b306 85 void trace_printer(const char* str)
ram54288 0:a7a43371b306 86 {
ram54288 0:a7a43371b306 87 printf("%s\r\n", str);
ram54288 0:a7a43371b306 88 cmd_output();
ram54288 0:a7a43371b306 89 fflush(stdout);
ram54288 0:a7a43371b306 90 }
ram54288 0:a7a43371b306 91 void cmd_printer(const char *str)
ram54288 0:a7a43371b306 92 {
ram54288 0:a7a43371b306 93 cmd_printf("%s", str);
ram54288 0:a7a43371b306 94 fflush(stdout);
ram54288 0:a7a43371b306 95 }
ram54288 0:a7a43371b306 96
ram54288 0:a7a43371b306 97 void custom_cmd_response_out(const char* fmt, va_list ap)
ram54288 0:a7a43371b306 98 {
ram54288 0:a7a43371b306 99 vprintf(fmt, ap);
ram54288 0:a7a43371b306 100 fflush(stdout);
ram54288 0:a7a43371b306 101 }
ram54288 0:a7a43371b306 102
ram54288 0:a7a43371b306 103 mem_stat_t memory_heap_stat;
ram54288 0:a7a43371b306 104 /**
ram54288 0:a7a43371b306 105 * \brief Application infinite loop.
ram54288 0:a7a43371b306 106 */
ram54288 0:a7a43371b306 107 int main(void)
ram54288 0:a7a43371b306 108 {
ram54288 0:a7a43371b306 109 ns_dyn_mem_init(app_defined_stack_heap, APP_DEV_HEAP_SIZE, app_heap_error_handler, &memory_heap_stat);
ram54288 0:a7a43371b306 110 eventOS_scheduler_init();
ram54288 0:a7a43371b306 111 mbed_trace_init();
ram54288 0:a7a43371b306 112 mbed_trace_print_function_set( trace_printer );
ram54288 0:a7a43371b306 113 mbed_trace_cmdprint_function_set( cmd_printer );
ram54288 0:a7a43371b306 114 mbed_trace_prefix_function_set( time_now );
ram54288 0:a7a43371b306 115 mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN);
ram54288 0:a7a43371b306 116 cmd_init( &custom_cmd_response_out );
ram54288 0:a7a43371b306 117
ram54288 0:a7a43371b306 118 initialize_app_commands(0);
ram54288 0:a7a43371b306 119
ram54288 0:a7a43371b306 120 eventOS_scheduler_run();
ram54288 0:a7a43371b306 121 return 0;
ram54288 0:a7a43371b306 122 }