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 /**   User Datagram Protocol (UDP)                                        */
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_udp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_udp_socket_receive_notify                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function sets the receive notify function pointer to the       */
45 /*    function specified by the application, which is called whenever     */
46 /*    a packet is received on the socket.  If a NULL pointer is supplied, */
47 /*    the receive notify function is disabled.                            */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    socket_ptr                            Pointer to UDP socket         */
52 /*    udp_receive_notify                    Routine to call when one or   */
53 /*                                            receive packets are         */
54 /*                                            available for the socket    */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    status                                Completion status             */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    None                                                                */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application Code                                                    */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nx_udp_socket_receive_notify(NX_UDP_SOCKET * socket_ptr,VOID (* udp_receive_notify)(NX_UDP_SOCKET * socket_ptr))77 UINT  _nx_udp_socket_receive_notify(NX_UDP_SOCKET *socket_ptr,
78                                     VOID (*udp_receive_notify)(NX_UDP_SOCKET *socket_ptr))
79 {
80 TX_INTERRUPT_SAVE_AREA
81 
82 
83     /* Disable interrupts.  */
84     TX_DISABLE
85 
86     /* Setup the receive notify function pointer.  */
87     socket_ptr -> nx_udp_receive_callback =  udp_receive_notify;
88 
89     /* Restore interrupts.  */
90     TX_RESTORE
91 
92     /* If trace is enabled, insert this event into the trace buffer.  */
93     NX_TRACE_IN_LINE_INSERT(NX_TRACE_UDP_SOCKET_RECEIVE_NOTIFY, socket_ptr -> nx_udp_socket_ip_ptr, socket_ptr, udp_receive_notify, 0, NX_TRACE_UDP_EVENTS, 0, 0);
94 
95     /* Return successful completion.  */
96     return(NX_SUCCESS);
97 }
98 
99