Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
mesh_system.c
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "eventOS_scheduler.h" 00018 #include "eventOS_event.h" 00019 #include "net_interface.h" 00020 #include "nsdynmemLIB.h" 00021 #include "randLIB.h" 00022 #include "platform/arm_hal_timer.h" 00023 #ifdef YOTTA_CFG 00024 #include "sal-iface-6lowpan/ns_sal.h" 00025 #else 00026 #include "ns_hal_init.h" 00027 #endif 00028 #include "include/static_config.h" 00029 #include "include/mesh_system.h" 00030 // For tracing we need to define flag, have include and define group 00031 #define HAVE_DEBUG 1 00032 #include "ns_trace.h" 00033 #define TRACE_GROUP "m6-mesh-system" 00034 00035 /* Heap for NanoStack */ 00036 static uint8_t app_stack_heap[MBED_MESH_API_HEAP_SIZE + 1]; 00037 static bool mesh_initialized = false; 00038 00039 /* 00040 * Heap error handler, called when heap problem is detected. 00041 * Function is for-ever loop. 00042 */ 00043 static void mesh_system_heap_error_handler(heap_fail_t event) 00044 { 00045 tr_error("Heap error, mesh_system_heap_error_handler() %d", event); 00046 switch (event) { 00047 case NS_DYN_MEM_NULL_FREE: 00048 case NS_DYN_MEM_DOUBLE_FREE: 00049 case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID: 00050 case NS_DYN_MEM_POINTER_NOT_VALID: 00051 case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED: 00052 case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED: 00053 break; 00054 default: 00055 break; 00056 } 00057 while (1); 00058 } 00059 00060 void mesh_system_init(void) 00061 { 00062 if (mesh_initialized == false) { 00063 #ifndef YOTTA_CFG 00064 ns_hal_init(app_stack_heap, MBED_MESH_API_HEAP_SIZE, 00065 mesh_system_heap_error_handler, NULL); 00066 eventOS_scheduler_mutex_wait(); 00067 net_init_core(); 00068 eventOS_scheduler_mutex_release(); 00069 #else 00070 ns_dyn_mem_init(app_stack_heap, MBED_MESH_API_HEAP_SIZE, 00071 mesh_system_heap_error_handler, NULL); 00072 randLIB_seed_random(); 00073 platform_timer_enable(); 00074 eventOS_scheduler_init(); 00075 trace_init(); // trace system needs to be initialized right after eventOS_scheduler_init 00076 net_init_core(); 00077 /* initialize 6LoWPAN socket adaptation layer */ 00078 ns_sal_init_stack(); 00079 #endif 00080 mesh_initialized = true; 00081 } 00082 } 00083 00084 void mesh_system_send_connect_event(uint8_t receiver) 00085 { 00086 arm_event_s event = { 00087 .sender = receiver, 00088 .event_id = APPL_EVENT_CONNECT, 00089 .receiver = receiver, 00090 .event_type = APPLICATION_EVENT, 00091 .priority = ARM_LIB_LOW_PRIORITY_EVENT, 00092 }; 00093 eventOS_event_send(&event); 00094 }
Generated on Tue Jul 12 2022 12:28:43 by
