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