Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <debug.h>
#include "up_arch.h"
#include "chip.h"
#include "stm32.h"
#include <arch/board/board.h>
#define GPIO_ETH_PHY_INT (GPIO_INPUT|GPIO_PULLUP|GPIO_SPEED_50MHz|GPIO_PORTE|GPIO_PIN14)
static xcpt_t g_phy_handler;
static void *g_phy_arg;
void stm32_netinitialize(void)
{
_info("Enabling PHY power\n");
stm32_configgpio(GPIO_PWR_ETH);
stm32_gpiowrite(GPIO_PWR_ETH, 1);
up_mdelay(1);
_info("PHY reset...\n");
stm32_configgpio(GPIO_ETH_RST);
stm32_gpiowrite(GPIO_ETH_RST, 0);
up_mdelay(1);
_info("PHY reset done.\n");
stm32_gpiowrite(GPIO_ETH_RST, 1);
up_mdelay(1);
_info("Configuring PHY int\n");
stm32_configgpio(GPIO_ETH_PHY_INT);
g_phy_handler = NULL;
}
static void stm32_phy_enable(bool enable)
{
//_info("PHY IRQ enable :%d\n", enable);
if (enable)
{
stm32_gpiosetevent(GPIO_ETH_PHY_INT, /*rising*/ FALSE, /*falling*/ TRUE, TRUE,
g_phy_handler, /*arg*/ g_phy_arg);
}
else
{
stm32_gpiosetevent(GPIO_ETH_PHY_INT, /*rising*/ FALSE, /*falling*/ FALSE, FALSE,
NULL, /*arg*/ NULL);
}
}
/****************************************************************************
* Name: arch_phy_irq
*
* Description:
* This function may be called to register an interrupt handler that will
* be called when a PHY interrupt occurs. This function both attaches
* the interrupt handler and enables the interrupt if 'handler' is non-
* NULL. If handler is NULL, then the interrupt is detached and disabled
* instead.
*
* The PHY interrupt is always disabled upon return. The caller must
* call back through the enable function point to control the state of
* the interrupt.
*
* This interrupt may or may not be available on a given platform depending
* on how the network hardware architecture is implemented. In a typical
* case, the PHY interrupt is provided to board-level logic as a GPIO
* interrupt (in which case this is a board-specific interface and really
* should be called board_phy_irq()); In other cases, the PHY interrupt
* may be cause by the chip's MAC logic (in which case arch_phy_irq()) is
* an appropriate name. Other other boards, there may be no PHY interrupts
* available at all. If client attachable PHY interrupts are available
* from the board or from the chip, then CONFIG_ARCH_PHY_INTERRUPT should
* be defined to indicate that fact.
*
* Typical usage:
* a. OS service logic (not application logic*) attaches to the PHY
* PHY interrupt and enables the PHY interrupt.
* b. When the PHY interrupt occurs: (1) the interrupt should be
* disabled and () work should be scheduled on the worker thread (or
* perhaps a dedicated application thread).
* c. That worker thread should use the SIOCGMIIPHY, SIOCGMIIREG,
* and SIOCSMIIREG ioctl calls** to communicate with the PHY,
* determine what network event took place (Link Up/Down?), and
* take the appropriate actions.
* d. It should then interact the the PHY to clear any pending
* interrupts, then re-enable the PHY interrupt.
*
* * This is an OS internal interface and should not be used from
* application space. Rather applications should use the SIOCMIISIG
* ioctl to receive a signal when a PHY event occurs.
* ** This interrupt is really of no use if the Ethernet MAC driver
* does not support these ioctl calls.
*
* Input Parameters:
* intf - Identifies the network interface. For example "eth0". Only
* useful on platforms that support multiple Ethernet interfaces
* and, hence, multiple PHYs and PHY interrupts.
* handler - The client interrupt handler to be invoked when the PHY
* asserts an interrupt. Must reside in OS space, but can
* signal tasks in user space. A value of NULL can be passed
* in order to detach and disable the PHY interrupt.
* arg - The argument that will accompany the interrupt
* enable - A function pointer that be unsed to enable or disable the
* PHY interrupt.
*
* Returned Value:
* Zero (OK) returned on success; a negated errno value is returned on
* failure.
*
****************************************************************************/
int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, phy_enable_t *enable)
{
irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the
* following operations are atomic.
*/
flags = enter_critical_section();
/* Get the old interrupt handler and save the new one */
g_phy_handler = handler;
g_phy_arg = arg;
if (handler)
{
_info("Attach PHY IRQ\n");
*enable = stm32_phy_enable;
}
else
{
_info("Detach PHY IRQ\n");
*enable = NULL;
}
/* Return with the interrupt disabled in either case */
stm32_phy_enable(FALSE);
leave_critical_section(flags);
return 0;
}
int stm32_phy_boardinitialize(int intf)
{
_info("called (intf=%d)\n", intf);
_info("PHY reset...\n");
stm32_configgpio(GPIO_ETH_RST);
stm32_gpiowrite(GPIO_ETH_RST, 0);
up_mdelay(1);
_info("PHY reset done.\n");
stm32_gpiowrite(GPIO_ETH_RST, 1);
up_mdelay(1);
return 0;
}