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 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_packet_deferred_receive                      PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function receives a packet from the link driver (usually the   */
45 /*    link driver's input ISR) and places it in the deferred receive      */
46 /*    packet queue.  This moves the minimal receive packet processing     */
47 /*    from the ISR to the IP helper thread.                               */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    ip_ptr                                Pointer to IP control block   */
52 /*    packet_ptr                            Pointer to packet to send     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_event_flags_set                    Set events for IP thread      */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application I/O Driver                                              */
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_packet_deferred_receive(NX_IP * ip_ptr,NX_PACKET * packet_ptr)75 VOID  _nx_ip_packet_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
76 {
77 
78 TX_INTERRUPT_SAVE_AREA
79 
80 
81     /* Disable interrupts.  */
82     TX_DISABLE
83 
84     /* Add debug information. */
85     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
86 
87     /* Check to see if the deferred processing queue is empty.  */
88     if (ip_ptr -> nx_ip_deferred_received_packet_head)
89     {
90 
91         /* Not empty, just place the packet at the end of the queue.  */
92         (ip_ptr -> nx_ip_deferred_received_packet_tail) -> nx_packet_queue_next =  packet_ptr;
93         packet_ptr -> nx_packet_queue_next =  NX_NULL;
94         ip_ptr -> nx_ip_deferred_received_packet_tail =  packet_ptr;
95 
96         /* Restore interrupts.  */
97         TX_RESTORE
98     }
99     else
100     {
101 
102         /* Empty deferred receive processing queue.  Just setup the head pointers and
103            set the event flags to ensure the IP helper thread looks at the deferred processing
104            queue.  */
105         ip_ptr -> nx_ip_deferred_received_packet_head =  packet_ptr;
106         ip_ptr -> nx_ip_deferred_received_packet_tail =  packet_ptr;
107         packet_ptr -> nx_packet_queue_next =             NX_NULL;
108 
109         /* Restore interrupts.  */
110         TX_RESTORE
111 
112         /* Wakeup IP helper thread to process the IP deferred receive.  */
113         tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_RECEIVE_EVENT, TX_OR);
114     }
115 }
116 
117