1 /***********************************************************************************************************************
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
15 * http://www.renesas.com/disclaimer
17 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
18 ***********************************************************************************************************************/
19 /***********************************************************************************************************************
20 * File Name : ether_callback.c
22 * Description : This module solves all the world's problems
23 ***********************************************************************************************************************/
24 /**********************************************************************************************************************
25 * History : DD.MM.YYYY Version Description
26 * : 05.01.2015 ---- Clean up source code.
27 ***********************************************************************************************************************/
29 /***********************************************************************************************************************
30 Includes <System Includes> , "Project Includes"
31 ***********************************************************************************************************************/
32 #include "r_ether_rx_if.h"
34 /***********************************************************************************************************************
35 Private global variables and functions
36 ***********************************************************************************************************************/
37 int32_t callback_ether_regist(void);
38 void callback_ether(void * pparam);
39 static void callback_wakeon_lan(uint32_t channel);
40 static void callback_link_on(uint32_t channel);
41 static void callback_link_off(uint32_t channel);
43 volatile uint8_t pause_enable = ETHER_FLAG_OFF;
44 volatile uint8_t magic_packet_detect[ETHER_CHANNEL_MAX];
45 volatile uint8_t link_detect[ETHER_CHANNEL_MAX];
47 void EINT_Trig_isr(void *);
50 * When that Link Status changes, the following function will be called:
52 void prvLinkStatusChange( BaseType_t xStatus );
54 /***********************************************************************************************************************
55 * Function Name: callback_ether
56 * Description : Regist of callback function
58 * Return Value : 0: success, -1:failed
59 ***********************************************************************************************************************/
60 int32_t callback_ether_regist(void)
67 /* Set the callback function (LAN cable connect/disconnect event) */
68 cb_func.pcb_func = &callback_ether;
69 param.ether_callback = cb_func;
70 ret = R_ETHER_Control(CONTROL_SET_CALLBACK, param);
71 if (ETHER_SUCCESS != ret)
76 /* Set the callback function (Ether interrupt event) */
77 cb_func.pcb_int_hnd = &EINT_Trig_isr;
78 param.ether_callback = cb_func;
79 ret = R_ETHER_Control(CONTROL_SET_INT_HANDLER, param);
80 if (ETHER_SUCCESS != ret)
85 } /* End of function callback_ether_regist() */
87 /***********************************************************************************************************************
88 * Function Name: callback_ether
89 * Description : Sample of the callback function
90 * Arguments : pparam -
93 ***********************************************************************************************************************/
94 void callback_ether(void * pparam)
96 ether_cb_arg_t * pdecode;
99 pdecode = (ether_cb_arg_t *)pparam;
100 channel = pdecode->channel; /* Get Ethernet channel number */
102 switch (pdecode->event_id)
104 /* Callback function that notifies user to have detected magic packet. */
105 case ETHER_CB_EVENT_ID_WAKEON_LAN:
106 callback_wakeon_lan(channel);
109 /* Callback function that notifies user to have become Link up. */
110 case ETHER_CB_EVENT_ID_LINK_ON:
111 callback_link_on(channel);
114 /* Callback function that notifies user to have become Link down. */
115 case ETHER_CB_EVENT_ID_LINK_OFF:
116 callback_link_off(channel);
122 } /* End of function callback_ether() */
124 /***********************************************************************************************************************
125 * Function Name: callback_wakeon_lan
127 * Arguments : channel -
128 * Ethernet channel number
129 * Return Value : none
130 ***********************************************************************************************************************/
131 static void callback_wakeon_lan(uint32_t channel)
133 if (ETHER_CHANNEL_MAX > channel)
135 magic_packet_detect[channel] = 1;
137 /* Please add necessary processing when magic packet is detected. */
139 } /* End of function callback_wakeon_lan() */
141 /***********************************************************************************************************************
142 * Function Name: callback_link_on
144 * Arguments : channel -
145 * Ethernet channel number
146 * Return Value : none
147 ***********************************************************************************************************************/
148 static void callback_link_on(uint32_t channel)
150 if (ETHER_CHANNEL_MAX > channel)
152 link_detect[channel] = ETHER_FLAG_ON_LINK_ON;
154 /* Please add necessary processing when becoming Link up. */
155 prvLinkStatusChange( 1 );
157 } /* End of function callback_link_on() */
159 /***********************************************************************************************************************
160 * Function Name: callback_link_off
162 * Arguments : channel -
163 * Ethernet channel number
164 * Return Value : none
165 ***********************************************************************************************************************/
166 static void callback_link_off(uint32_t channel)
168 if (ETHER_CHANNEL_MAX > channel)
170 link_detect[channel] = ETHER_FLAG_ON_LINK_OFF;
172 /* Please add necessary processing when becoming Link down. */
173 prvLinkStatusChange( 0 );
175 } /* End of function ether_cb_link_off() */