-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathonps_entry.c
95 lines (74 loc) · 2.13 KB
/
onps_entry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright 2022-2024 The Onps Project Author All Rights Reserved.
*
* Author:Neo-T
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* http://www.onps.org.cn/apache2.0.txt
*
*/
#define SYMBOL_GLOBALS
#include "onps.h"
#undef SYMBOL_GLOBALS
HMUTEX o_hMtxPrintf = INVALID_HMUTEX;
BOOL open_npstack_load(EN_ONPSERR *penErr)
{
//* lcp魔术字生成及tcp/udp端口号动态分配都需要随机数生成函数,所以协议栈启动时先设置个种子,确保栈每次启动时生成不同的随机数
srand(os_get_system_msecs());
do {
if (!buddy_init(penErr))
break;
if (!buf_list_init(penErr))
break;
#if SUPPORT_PRINTF && PRINTF_THREAD_MUTEX
o_hMtxPrintf = os_thread_mutex_init();
if (INVALID_HMUTEX == o_hMtxPrintf)
{
*penErr = ERRMUTEXINITFAILED;
break;
}
#endif
if (!one_shot_timer_init(penErr))
break;
if (!onps_input_init(penErr))
break;
if (!netif_init(penErr))
break;
if (!route_table_init(penErr))
break;
#if SUPPORT_PPP
if (!ppp_init(penErr))
break;
#endif
#if SUPPORT_ETHERNET
ethernet_init();
#endif
//* 启动协议栈
os_thread_onpstack_start(NULL);
return TRUE;
} while (FALSE);
netif_uninit();
onps_input_uninit();
if (INVALID_HMUTEX != o_hMtxPrintf)
os_thread_mutex_uninit(o_hMtxPrintf);
buf_list_uninit();
buddy_uninit();
one_shot_timer_uninit();
return FALSE;
}
void open_npstack_unload(void)
{
#if SUPPORT_PPP
ppp_uninit();
#endif
route_table_uninit();
netif_uninit();
one_shot_timer_uninit();
onps_input_uninit();
if (INVALID_HMUTEX != o_hMtxPrintf)
os_thread_mutex_uninit(o_hMtxPrintf);
buf_list_uninit();
buddy_uninit();
}