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