Simple interface for Mbed Cloud Client

Dependents:  

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ns_hal_init.c Source File

ns_hal_init.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2016-2017 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 #include "ns_hal_init.h"
00020 
00021 #include "ns_types.h"
00022 #include <stdlib.h>
00023 #include <assert.h>
00024 
00025 #include "arm_hal_interrupt_private.h"
00026 #include "ns_event_loop.h"
00027 #include "eventOS_scheduler.h"
00028 #include "platform/arm_hal_timer.h"
00029 #include "ns_trace.h"
00030 
00031 
00032 void ns_hal_init(void *heap, size_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
00033 {
00034     static bool initted;
00035     if (initted) {
00036         return;
00037     }
00038     if (!heap) {
00039         heap = malloc(h_size);
00040         assert(heap);
00041         if (!heap) {
00042             return;
00043         }
00044     }
00045     platform_critical_init();
00046     ns_dyn_mem_init(heap, h_size, passed_fptr, info_ptr);
00047     eventOS_scheduler_init();
00048     // We do not initialise randlib, as it should be done after
00049     // RF driver has started, to get MAC address and RF noise as seed.
00050     // We do not initialise trace - left to application.
00051     ns_event_loop_thread_create();
00052     ns_event_loop_thread_start();
00053     initted = true;
00054 }