EVE 1.0
ksz8851.h
Go to the documentation of this file.
1 #ifndef KSZ8851_H_INCLUDED
2 #define KSZ8851_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2014-2016, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief Driver for KSZ8851 Ethernet chip.
36  *
37  * @author DT, Jetro AS
38  */ /******************************************************************/
39 
40 #include <sys/process.h>
41 #include <core/mwork.h>
42 #include <net/uip-fw.h>
43 #include <net/uip.h>
44 #include <net/common/ep.h>
45 #include <dev/spi.h>
46 
47 /**
48  * \defgroup ksz8851 KSZ8851 ethernet chip driver
49  * \ingroup extdrv
50  * \{
51  *
52  */
53 
54 struct ksz8851_t;
55 
56 enum ksz8851_opstate_t {
57  KSZ8851_OFF,
58  KSZ8851_INIT,
59  KSZ8851_DISCONNECTED,
60  KSZ8851_ON,
61 };
62 
63 enum ksz8851_leds_mode_t {
64  KSZ8851_LEDS_MODE_LINK_ACT_100BT,
65  KSZ8851_LEDS_MODE_LINK_ACT,
66  KSZ8851_LEDS_MODE_OFF,
67 };
68 
69 enum ksz8851_leds_test_t {
70  KSZ8851_LEDS_NO_TEST,
71  KSZ8851_LEDS_TEST_OFF,
72  KSZ8851_LEDS_TEST_GREEN,
73  KSZ8851_LEDS_TEST_BOTH,
74 };
75 
76 struct ksz8851_xfer_t {
77  void *Data;
78  int ByteCount;
79  ep_if_xfer_cb_t Callback;
80 };
81 
82 struct ksz8851_events_t {
83  struct process *MonitorProcess;
84  process_event_t EventMedia;
85 };
86 
87 struct ksz8851_state_t {
88  struct mwork_t Work;
89  struct process Process;
90  struct uip_fw_netif Netif;
91  uip_lladdr_t MacAddr;
92  const struct ksz8851_t *Module;
93  const struct ksz8851_events_t *Events;
94  enum ksz8851_opstate_t Opstate;
95  struct ksz8851_xfer_t RxXfer;
96  struct ksz8851_xfer_t TxXfer;
97  uint16_t RxFrameCount;
98  uint16_t Ier;
99  bool PowerSave;
100 };
101 
102 struct ksz8851_t {
103  struct ksz8851_state_t *State;
104  const struct spi_t *Spi;
105  struct spi_cs_t SpiCs;
106  uint32_t SpiBaudrate;
107  uint8_t IrqPin;
108  uint8_t ResetPin;
109  bool ResetActiveHigh;
110  bool PowerSaveDefault;
111 };
112 
113 void EthInit(const struct ksz8851_t *Module, const struct ksz8851_events_t *Events);
114 void EthPowerSave(const struct ksz8851_t *Module, bool IsOn);
115 void EthSetLedsMode(const struct ksz8851_t *Module, enum ksz8851_leds_mode_t Mode);
116 void EthDoLedsTest(const struct ksz8851_t *Module, enum ksz8851_leds_test_t Test);
117 void EthRead(struct process *Process, void *Data, int ByteCount, ep_if_xfer_cb_t Callback);
118 void EthWrite(struct process *Process, void *Data, int ByteCount, ep_if_xfer_cb_t Callback);
119 void EthAbortTransfer(struct process *Process);
120 void EthInterruptCb(const struct ksz8851_t *Module);
121 
122 static inline bool EthCableConnected(const struct ksz8851_t *Module)
123 {
124  return (Module->State->Opstate == KSZ8851_ON);
125 }
126 
127 /** \} */
128 
129 #endif /* KSZ8851_H_INCLUDED */
Header file for the EVE millisecond-scale work scheduling.
Definition: mwork.h:182
802.3 address
Definition: uip.h:134
Definition: spi.h:113
Driver for the MCU&#39;s SPI blocks.
ep_xfer_status_t(* ep_if_xfer_cb_t)(ep_xfer_status_t status, uint32_t xferred, uint32_t remaining)
Definition: ep.h:66
uint32_t Mode
Definition: spi.h:117
USB endpoint primitive.
Definition: spi.h:166