1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Protocol (IP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_ip.h"
29 #include "tx_timer.h"
30
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _nx_ip_fast_periodic_timer_entry PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Yuxin Zhou, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function handles waking up the IP helper thread on a periodic */
46 /* basis for higher-frequency IPv6/TCP events. This timer is enabled */
47 /* when IPv6 or TCP is enabled. */
48 /* */
49 /* INPUT */
50 /* */
51 /* ip_address IP address in a ULONG */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* None */
56 /* */
57 /* CALLS */
58 /* */
59 /* tx_event_flags_set Set event flags to wakeup */
60 /* IP helper thread */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* ThreadX system timer thread */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nx_ip_fast_periodic_timer_entry(ULONG ip_address)75 static VOID _nx_ip_fast_periodic_timer_entry(ULONG ip_address)
76 {
77
78 NX_IP *ip_ptr;
79
80
81 /* Setup IP pointer. */
82 NX_TIMER_EXTENSION_PTR_GET(ip_ptr, NX_IP, ip_address)
83
84 /* Wakeup this IP's helper thread. */
85 tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_FAST_EVENT, TX_OR);
86 }
87
88
89 /**************************************************************************/
90 /* */
91 /* FUNCTION RELEASE */
92 /* */
93 /* _nx_ip_fast_periodic_timer_create PORTABLE C */
94 /* 6.1 */
95 /* AUTHOR */
96 /* */
97 /* Yuxin Zhou, Microsoft Corporation */
98 /* */
99 /* DESCRIPTION */
100 /* */
101 /* This function creates a high resolution timer for driving IPv6 and */
102 /* TCP time-keeping events. */
103 /* */
104 /* INPUT */
105 /* */
106 /* ip_ptr Pointer into IP instance. */
107 /* */
108 /* OUTPUT */
109 /* */
110 /* None */
111 /* */
112 /* CALLS */
113 /* */
114 /* tx_timer_create Set event flags to wakeup */
115 /* IP helper thread */
116 /* */
117 /* CALLED BY */
118 /* */
119 /* nx_ipv6_enable */
120 /* nx_tcp_enable */
121 /* */
122 /* RELEASE HISTORY */
123 /* */
124 /* DATE NAME DESCRIPTION */
125 /* */
126 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
127 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
128 /* resulting in version 6.1 */
129 /* */
130 /**************************************************************************/
_nx_ip_fast_periodic_timer_create(NX_IP * ip_ptr)131 VOID _nx_ip_fast_periodic_timer_create(NX_IP *ip_ptr)
132 {
133
134 ULONG _nx_ip_fast_timer_rate;
135
136 if (ip_ptr -> nx_ip_fast_periodic_timer_created)
137 {
138 return;
139 }
140
141 _nx_ip_fast_timer_rate = (NX_IP_PERIODIC_RATE + (NX_IP_FAST_TIMER_RATE - 1)) / NX_IP_FAST_TIMER_RATE;
142
143 /* Create the fast TCP timer. */
144 /*lint -e{923} suppress cast of pointer to ULONG. */
145 tx_timer_create(&(ip_ptr -> nx_ip_fast_periodic_timer), ip_ptr -> nx_ip_name,
146 _nx_ip_fast_periodic_timer_entry, (ULONG)(ALIGN_TYPE)ip_ptr,
147 _nx_ip_fast_timer_rate, _nx_ip_fast_timer_rate, TX_AUTO_ACTIVATE);
148
149 NX_TIMER_EXTENSION_PTR_SET(&(ip_ptr -> nx_ip_fast_periodic_timer), ip_ptr)
150
151 /* Set the flag to indicate that the fast timer has been created. */
152 ip_ptr -> nx_ip_fast_periodic_timer_created = 1;
153 }
154
155