]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/RX/ether_callback.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / RX / ether_callback.c
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 * File Name    : ether_callback.c
21 * Version      : ----
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 ***********************************************************************************************************************/
28
29 /***********************************************************************************************************************
30 Includes   <System Includes> , "Project Includes"
31 ***********************************************************************************************************************/
32 #include "r_ether_rx_if.h"
33
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);
42
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];
46
47 void EINT_Trig_isr(void *);
48
49 /*
50  * When that Link Status changes, the following function will be called:
51  */
52 void prvLinkStatusChange( BaseType_t xStatus );
53
54 /***********************************************************************************************************************
55 * Function Name: callback_ether
56 * Description  : Regist of callback function
57 * Arguments    : -
58 * Return Value : 0: success, -1:failed
59 ***********************************************************************************************************************/
60 int32_t callback_ether_regist(void)
61 {
62     ether_param_t   param;
63     ether_cb_t      cb_func;
64
65     int32_t         ret;
66
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)
72     {
73         return -1;
74     }
75
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)
81     {
82         return -1;
83     }
84     return 0;
85 } /* End of function callback_ether_regist() */
86
87 /***********************************************************************************************************************
88 * Function Name: callback_ether
89 * Description  : Sample of the callback function
90 * Arguments    : pparam -
91 *
92 * Return Value : none
93 ***********************************************************************************************************************/
94 void callback_ether(void * pparam)
95 {
96     ether_cb_arg_t    * pdecode;
97     uint32_t            channel;
98
99     pdecode = (ether_cb_arg_t *)pparam;
100     channel = pdecode->channel;                             /* Get Ethernet channel number */
101
102     switch (pdecode->event_id)
103     {
104         /* Callback function that notifies user to have detected magic packet. */
105         case ETHER_CB_EVENT_ID_WAKEON_LAN:
106             callback_wakeon_lan(channel);
107             break;
108
109         /* Callback function that notifies user to have become Link up. */
110         case ETHER_CB_EVENT_ID_LINK_ON:
111             callback_link_on(channel);
112             break;
113
114         /* Callback function that notifies user to have become Link down. */
115         case ETHER_CB_EVENT_ID_LINK_OFF:
116             callback_link_off(channel);
117             break;
118
119         default:
120             break;
121     }
122 } /* End of function callback_ether() */
123
124 /***********************************************************************************************************************
125 * Function Name: callback_wakeon_lan
126 * Description  :
127 * Arguments    : channel -
128 *                    Ethernet channel number
129 * Return Value : none
130 ***********************************************************************************************************************/
131 static void callback_wakeon_lan(uint32_t channel)
132 {
133     if (ETHER_CHANNEL_MAX > channel)
134     {
135         magic_packet_detect[channel] = 1;
136
137         /* Please add necessary processing when magic packet is detected.  */
138     }
139 } /* End of function callback_wakeon_lan() */
140
141 /***********************************************************************************************************************
142 * Function Name: callback_link_on
143 * Description  :
144 * Arguments    : channel -
145 *                    Ethernet channel number
146 * Return Value : none
147 ***********************************************************************************************************************/
148 static void callback_link_on(uint32_t channel)
149 {
150     if (ETHER_CHANNEL_MAX > channel)
151     {
152         link_detect[channel] = ETHER_FLAG_ON_LINK_ON;
153
154         /* Please add necessary processing when becoming Link up. */
155                 prvLinkStatusChange( 1 );
156     }
157 } /* End of function callback_link_on() */
158
159 /***********************************************************************************************************************
160 * Function Name: callback_link_off
161 * Description  :
162 * Arguments    : channel -
163 *                    Ethernet channel number
164 * Return Value : none
165 ***********************************************************************************************************************/
166 static void callback_link_off(uint32_t channel)
167 {
168     if (ETHER_CHANNEL_MAX > channel)
169     {
170         link_detect[channel] = ETHER_FLAG_ON_LINK_OFF;
171
172         /* Please add necessary processing when becoming Link down. */
173                 prvLinkStatusChange( 0 );
174     }
175 } /* End of function ether_cb_link_off() */
176
177 /* End of File */