FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:35:07 2017 +0000
Revision:
0:a2cb7295a1f7
Initial commit

Who changed what in which revision?

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