Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ns_hal_init.c Source File

ns_hal_init.c

00001 /*
00002  * Copyright (c) 2016 ARM Limited, All Rights Reserved
00003  */
00004 
00005 #include "ns_types.h"
00006 #include <stdlib.h>
00007 #include <assert.h>
00008 
00009 #include "eventOS_scheduler.h"
00010 #include "ns_event_loop.h"
00011 #include "randLIB.h"
00012 #include "platform/arm_hal_timer.h"
00013 #include "ns_trace.h"
00014 
00015 #include "arm_hal_interrupt_private.h"
00016 #include "ns_hal_init.h"
00017 
00018 void ns_hal_init(void *heap, size_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
00019 {
00020     static bool initted;
00021     if (initted) {
00022         return;
00023     }
00024     if (!heap) {
00025         heap = malloc(h_size);
00026         assert(heap);
00027         if (!heap) {
00028             return;
00029         }
00030     }
00031     platform_critical_init();
00032     ns_dyn_mem_init(heap, h_size, passed_fptr, info_ptr);
00033     platform_timer_enable();
00034     eventOS_scheduler_init();
00035 
00036     // We do not initialise randlib, as it should be done after
00037     // RF driver has started, to get MAC address and RF noise as seed.
00038     // We do not initialise trace - left to application.
00039 
00040     // Prepare the event loop lock which is used even if the loop
00041     // is not ran in a separate thread.
00042     ns_event_loop_init();
00043 
00044 #if !MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
00045     ns_event_loop_thread_create();
00046     ns_event_loop_thread_start();
00047 #endif
00048 
00049     initted = true;
00050 }