xref: /FreeRTOS-Plus-TCP-v4.0.0/source/portable/NetworkInterface/RX/ether_callback.c (revision a4124602cc584fa0658448c229f48a459a84fbb1)
1 /***********************************************************************************************************************
2 * DISCLAIMER
3 * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
4 * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
5 * applicable laws, including copyright laws.
6 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
7 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
8 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
9 * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
10 * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS
11 * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
12 * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
13 * this software. By using this software, you agree to the additional terms and conditions found by accessing the
14 * following link:
15 * http://www.renesas.com/disclaimer
16 *
17 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
18 ***********************************************************************************************************************/
19 
20 /***********************************************************************************************************************
21 * File Name    : ether_callback.c
22 * Version      : ----
23 * Description  : This module solves all the world's problems
24 ***********************************************************************************************************************/
25 
26 /**********************************************************************************************************************
27  * History : DD.MM.YYYY Version  Description
28  *         : 05.01.2015 ----     Clean up source code.
29  ***********************************************************************************************************************/
30 
31 /***********************************************************************************************************************
32 *  Includes   <System Includes> , "Project Includes"
33 ***********************************************************************************************************************/
34 #include "r_ether_rx_if.h"
35 
36 /***********************************************************************************************************************
37 *  Private global variables and functions
38 ***********************************************************************************************************************/
39 int32_t callback_ether_regist( void );
40 void callback_ether( void * pparam );
41 static void callback_wakeon_lan( uint32_t channel );
42 static void callback_link_on( uint32_t channel );
43 static void callback_link_off( uint32_t channel );
44 
45 volatile uint8_t pause_enable = ETHER_FLAG_OFF;
46 volatile uint8_t magic_packet_detect[ ETHER_CHANNEL_MAX ];
47 volatile uint8_t link_detect[ ETHER_CHANNEL_MAX ];
48 
49 void EINT_Trig_isr( void * );
50 
51 /*
52  * When that Link Status changes, the following function will be called:
53  */
54 void prvLinkStatusChange( BaseType_t xStatus );
55 
56 /***********************************************************************************************************************
57 * Function Name: callback_ether
58 * Description  : Regist of callback function
59 * Arguments    : -
60 * Return Value : 0: success, -1:failed
61 ***********************************************************************************************************************/
callback_ether_regist(void)62 int32_t callback_ether_regist( void )
63 {
64     ether_param_t param;
65     ether_cb_t cb_func;
66 
67     int32_t ret;
68 
69     /* Set the callback function (LAN cable connect/disconnect event) */
70     cb_func.pcb_func = &callback_ether;
71     param.ether_callback = cb_func;
72     ret = R_ETHER_Control( CONTROL_SET_CALLBACK, param );
73 
74     if( ETHER_SUCCESS != ret )
75     {
76         return -1;
77     }
78 
79     /* Set the callback function (Ether interrupt event) */
80     cb_func.pcb_int_hnd = &EINT_Trig_isr;
81     param.ether_callback = cb_func;
82     ret = R_ETHER_Control( CONTROL_SET_INT_HANDLER, param );
83 
84     if( ETHER_SUCCESS != ret )
85     {
86         return -1;
87     }
88 
89     return 0;
90 } /* End of function callback_ether_regist() */
91 
92 /***********************************************************************************************************************
93 * Function Name: callback_ether
94 * Description  : Sample of the callback function
95 * Arguments    : pparam -
96 *
97 * Return Value : none
98 ***********************************************************************************************************************/
callback_ether(void * pparam)99 void callback_ether( void * pparam )
100 {
101     ether_cb_arg_t * pdecode;
102     uint32_t channel;
103 
104     pdecode = ( ether_cb_arg_t * ) pparam;
105     channel = pdecode->channel; /* Get Ethernet channel number */
106 
107     switch( pdecode->event_id )
108     {
109         /* Callback function that notifies user to have detected magic packet. */
110         case ETHER_CB_EVENT_ID_WAKEON_LAN:
111             callback_wakeon_lan( channel );
112             break;
113 
114         /* Callback function that notifies user to have become Link up. */
115         case ETHER_CB_EVENT_ID_LINK_ON:
116             callback_link_on( channel );
117             break;
118 
119         /* Callback function that notifies user to have become Link down. */
120         case ETHER_CB_EVENT_ID_LINK_OFF:
121             callback_link_off( channel );
122             break;
123 
124         default:
125             break;
126     }
127 } /* End of function callback_ether() */
128 
129 /***********************************************************************************************************************
130 * Function Name: callback_wakeon_lan
131 * Description  :
132 * Arguments    : channel -
133 *                    Ethernet channel number
134 * Return Value : none
135 ***********************************************************************************************************************/
callback_wakeon_lan(uint32_t channel)136 static void callback_wakeon_lan( uint32_t channel )
137 {
138     if( ETHER_CHANNEL_MAX > channel )
139     {
140         magic_packet_detect[ channel ] = 1;
141 
142         /* Please add necessary processing when magic packet is detected.  */
143     }
144 } /* End of function callback_wakeon_lan() */
145 
146 /***********************************************************************************************************************
147 * Function Name: callback_link_on
148 * Description  :
149 * Arguments    : channel -
150 *                    Ethernet channel number
151 * Return Value : none
152 ***********************************************************************************************************************/
callback_link_on(uint32_t channel)153 static void callback_link_on( uint32_t channel )
154 {
155     if( ETHER_CHANNEL_MAX > channel )
156     {
157         link_detect[ channel ] = ETHER_FLAG_ON_LINK_ON;
158 
159         /* Please add necessary processing when becoming Link up. */
160         prvLinkStatusChange( 1 );
161     }
162 } /* End of function callback_link_on() */
163 
164 /***********************************************************************************************************************
165 * Function Name: callback_link_off
166 * Description  :
167 * Arguments    : channel -
168 *                    Ethernet channel number
169 * Return Value : none
170 ***********************************************************************************************************************/
callback_link_off(uint32_t channel)171 static void callback_link_off( uint32_t channel )
172 {
173     if( ETHER_CHANNEL_MAX > channel )
174     {
175         link_detect[ channel ] = ETHER_FLAG_ON_LINK_OFF;
176 
177         /* Please add necessary processing when becoming Link down. */
178         prvLinkStatusChange( 0 );
179     }
180 } /* End of function ether_cb_link_off() */
181 
182 /* End of File */
183