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.
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 <stdlib.h> 00018 #include "eventOS_scheduler.h" 00019 #include "eventOS_event.h" 00020 #include "net_interface.h" 00021 #include "nsdynmemLIB.h" 00022 #include "randLIB.h" 00023 #include "platform/arm_hal_timer.h" 00024 #include "ns_hal_init.h" 00025 #include "include/mesh_system.h" 00026 #include "mbed_assert.h" 00027 #include "mbed_error.h" 00028 // For tracing we need to define flag, have include and define group 00029 #define HAVE_DEBUG 1 00030 #include "ns_trace.h" 00031 #define TRACE_GROUP "m6-mesh-system" 00032 00033 /* Heap for NanoStack */ 00034 #if !MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP 00035 static uint8_t app_stack_heap[MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1]; 00036 #else 00037 static uint8_t *app_stack_heap; 00038 #endif 00039 static bool mesh_initialized = false; 00040 #ifdef MBED_CONF_MBED_MESH_API_HEAP_STAT_INFO_DEFINITION 00041 MBED_CONF_MBED_MESH_API_HEAP_STAT_INFO_DEFINITION; 00042 #endif 00043 00044 /* 00045 * Heap error handler, called when heap problem is detected. 00046 * Function is for-ever loop. 00047 */ 00048 static void mesh_system_heap_error_handler(heap_fail_t event) 00049 { 00050 MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_OUT_OF_MEMORY), "Heap error, mesh_system_heap_error_handler()", event); 00051 } 00052 00053 void mesh_system_init(void) 00054 { 00055 if (mesh_initialized == false) { 00056 #if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP 00057 app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1); 00058 MBED_ASSERT(app_stack_heap); 00059 #endif 00060 ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE, 00061 mesh_system_heap_error_handler, MBED_CONF_MBED_MESH_API_HEAP_STAT_INFO); 00062 eventOS_scheduler_mutex_wait(); 00063 net_init_core(); 00064 eventOS_scheduler_mutex_release(); 00065 mesh_initialized = true; 00066 } 00067 } 00068 00069 void mesh_system_send_connect_event(uint8_t receiver) 00070 { 00071 arm_event_s event = { 00072 .sender = receiver, 00073 .event_id = APPL_EVENT_CONNECT, 00074 .receiver = receiver, 00075 .event_type = APPLICATION_EVENT, 00076 .priority = ARM_LIB_LOW_PRIORITY_EVENT, 00077 }; 00078 eventOS_event_send(&event); 00079 }
Generated on Tue Aug 9 2022 00:37:15 by
1.7.2