Update licence

pull/8725/head
chao_king 2018-11-13 17:33:12 +08:00 committed by c_jin
parent 700f3a2c69
commit 9131b3f9ec
3 changed files with 754 additions and 754 deletions

View File

@ -1,77 +1,77 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2018 Gigadevice * Copyright (c) 2018 Gigadevice
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "gd32f30x.h" #include "gd32f30x.h"
/** /**
* Initializes the HW pin for enet * Initializes the HW pin for enet
* *
*/ */
void enet_bsp_init(void) void enet_bsp_init(void)
{ {
/* Enable GPIOs clocks */ /* Enable GPIOs clocks */
rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_GPIOC); rcu_periph_clock_enable(RCU_GPIOC);
rcu_periph_clock_enable(RCU_AF); rcu_periph_clock_enable(RCU_AF);
gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_8); gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_8);
rcu_pll2_config(RCU_PLL2_MUL10); rcu_pll2_config(RCU_PLL2_MUL10);
rcu_osci_on(RCU_PLL2_CK); rcu_osci_on(RCU_PLL2_CK);
rcu_osci_stab_wait(RCU_PLL2_CK); rcu_osci_stab_wait(RCU_PLL2_CK);
rcu_ckout0_config(RCU_CKOUT0SRC_CKPLL2); rcu_ckout0_config(RCU_CKOUT0SRC_CKPLL2);
gpio_ethernet_phy_select(GPIO_ENET_PHY_RMII); gpio_ethernet_phy_select(GPIO_ENET_PHY_RMII);
/** ETH GPIO Configuration /** ETH GPIO Configuration
RMII_REF_CLK ----------------------> PA1 RMII_REF_CLK ----------------------> PA1
RMII_MDIO -------------------------> PA2 RMII_MDIO -------------------------> PA2
RMII_MDC --------------------------> PC1 RMII_MDC --------------------------> PC1
RMII_MII_CRS_DV -------------------> PA7 RMII_MII_CRS_DV -------------------> PA7
RMII_MII_RXD0 ---------------------> PC4 RMII_MII_RXD0 ---------------------> PC4
RMII_MII_RXD1 ---------------------> PC5 RMII_MII_RXD1 ---------------------> PC5
RMII_MII_TX_EN --------------------> PB11 RMII_MII_TX_EN --------------------> PB11
RMII_MII_TXD0 ---------------------> PB12 RMII_MII_TXD0 ---------------------> PB12
RMII_MII_TXD1 ---------------------> PB13 RMII_MII_TXD1 ---------------------> PB13
*/ */
/* PA1: ETH_RMII_REF_CLK */ /* PA1: ETH_RMII_REF_CLK */
gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_1); gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_1);
/* PA2: ETH_MDIO */ /* PA2: ETH_MDIO */
gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_2); gpio_para_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_2);
/* PA7: ETH_RMII_CRS_DV */ /* PA7: ETH_RMII_CRS_DV */
gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_7); gpio_para_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_7);
/* PB11: ETH_RMII_TX_EN */ /* PB11: ETH_RMII_TX_EN */
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_11); gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_11);
/* PB12: ETH_RMII_TXD0 */ /* PB12: ETH_RMII_TXD0 */
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_12); gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_12);
/* PB13: ETH_RMII_TXD1 */ /* PB13: ETH_RMII_TXD1 */
gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_13); gpio_para_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_13);
/* PC1: ETH_MDC */ /* PC1: ETH_MDC */
gpio_para_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_1); gpio_para_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_MAX, GPIO_PIN_1);
/* PC4: ETH_RMII_RXD0 */ /* PC4: ETH_RMII_RXD0 */
gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_4); gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_4);
/* PC5: ETH_RMII_RXD1 */ /* PC5: ETH_RMII_RXD1 */
gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_5); gpio_para_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_MAX, GPIO_PIN_5);
/* Enable the Ethernet global Interrupt */ /* Enable the Ethernet global Interrupt */
nvic_irq_enable(ENET_IRQn, 0x7, 0); nvic_irq_enable(ENET_IRQn, 0x7, 0);
/* Enable ETHERNET clock */ /* Enable ETHERNET clock */
rcu_periph_clock_enable(RCU_ENET); rcu_periph_clock_enable(RCU_ENET);
rcu_periph_clock_enable(RCU_ENETTX); rcu_periph_clock_enable(RCU_ENETTX);
rcu_periph_clock_enable(RCU_ENETRX); rcu_periph_clock_enable(RCU_ENETRX);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,174 +1,174 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2018 Gigadevice * Copyright (c) 2018 Gigadevice
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef GD32_EMAC_H_ #ifndef GD32_EMAC_H_
#define GD32_EMAC_H_ #define GD32_EMAC_H_
#include "EMAC.h" #include "EMAC.h"
#include "rtos/Semaphore.h" #include "rtos/Semaphore.h"
#include "rtos/Mutex.h" #include "rtos/Mutex.h"
class GD32_EMAC : public EMAC { class GD32_EMAC : public EMAC {
public: public:
GD32_EMAC(); GD32_EMAC();
static GD32_EMAC &get_instance(); static GD32_EMAC &get_instance();
/** /**
* Return maximum transmission unit * Return maximum transmission unit
* *
* @return MTU in bytes * @return MTU in bytes
*/ */
virtual uint32_t get_mtu_size() const; virtual uint32_t get_mtu_size() const;
/** /**
* Gets memory buffer alignment preference * Gets memory buffer alignment preference
* *
* Gets preferred memory buffer alignment of the Emac device. IP stack may or may not * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not
* align link out memory buffer chains using the alignment. * align link out memory buffer chains using the alignment.
* *
* @return Memory alignment requirement in bytes * @return Memory alignment requirement in bytes
*/ */
virtual uint32_t get_align_preference() const; virtual uint32_t get_align_preference() const;
/** /**
* Return interface name * Return interface name
* *
* @param name Pointer to where the name should be written * @param name Pointer to where the name should be written
* @param size Maximum number of character to copy * @param size Maximum number of character to copy
*/ */
virtual void get_ifname(char *name, uint8_t size) const; virtual void get_ifname(char *name, uint8_t size) const;
/** /**
* Returns size of the underlying interface HW address size. * Returns size of the underlying interface HW address size.
* *
* @return HW address size in bytes * @return HW address size in bytes
*/ */
virtual uint8_t get_hwaddr_size() const; virtual uint8_t get_hwaddr_size() const;
/** /**
* Return interface-supplied HW address * Return interface-supplied HW address
* *
* Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size
* *
* HW address need not be provided if this interface does not have its own HW * HW address need not be provided if this interface does not have its own HW
* address configuration; stack will choose address from central system * address configuration; stack will choose address from central system
* configuration if the function returns false and does not write to addr. * configuration if the function returns false and does not write to addr.
* *
* @param addr HW address for underlying interface * @param addr HW address for underlying interface
* @return true if HW address is available * @return true if HW address is available
*/ */
virtual bool get_hwaddr(uint8_t *addr) const; virtual bool get_hwaddr(uint8_t *addr) const;
/** /**
* Set HW address for interface * Set HW address for interface
* *
* Provided address has to be of correct size, see @a get_hwaddr_size * Provided address has to be of correct size, see @a get_hwaddr_size
* *
* Called to set the MAC address to actually use - if @a get_hwaddr is provided * Called to set the MAC address to actually use - if @a get_hwaddr is provided
* the stack would normally use that, but it could be overridden, eg for test * the stack would normally use that, but it could be overridden, eg for test
* purposes. * purposes.
* *
* @param addr Address to be set * @param addr Address to be set
*/ */
virtual void set_hwaddr(const uint8_t *addr); virtual void set_hwaddr(const uint8_t *addr);
/** /**
* Sends the packet over the link * Sends the packet over the link
* *
* That can not be called from an interrupt context. * That can not be called from an interrupt context.
* *
* @param buf Packet to be send * @param buf Packet to be send
* @return True if the packet was send successfully, False otherwise * @return True if the packet was send successfully, False otherwise
*/ */
virtual bool link_out(emac_mem_buf_t *buf); virtual bool link_out(emac_mem_buf_t *buf);
/** /**
* Initializes the HW * Initializes the HW
* *
* @return True on success, False in case of an error. * @return True on success, False in case of an error.
*/ */
virtual bool power_up(); virtual bool power_up();
/** /**
* Deinitializes the HW * Deinitializes the HW
* *
*/ */
virtual void power_down(); virtual void power_down();
/** /**
* Sets a callback that needs to be called for packets received for that interface * Sets a callback that needs to be called for packets received for that interface
* *
* @param input_cb Function to be register as a callback * @param input_cb Function to be register as a callback
*/ */
virtual void set_link_input_cb(emac_link_input_cb_t input_cb); virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
/** /**
* Sets a callback that needs to be called on link status changes for given interface * Sets a callback that needs to be called on link status changes for given interface
* *
* @param state_cb Function to be register as a callback * @param state_cb Function to be register as a callback
*/ */
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb); virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
/** Add device to a multicast group /** Add device to a multicast group
* *
* @param address A multicast group hardware address * @param address A multicast group hardware address
*/ */
virtual void add_multicast_group(const uint8_t *address); virtual void add_multicast_group(const uint8_t *address);
/** Remove device from a multicast group /** Remove device from a multicast group
* *
* @param address A multicast group hardware address * @param address A multicast group hardware address
*/ */
virtual void remove_multicast_group(const uint8_t *address); virtual void remove_multicast_group(const uint8_t *address);
/** Request reception of all multicast packets /** Request reception of all multicast packets
* *
* @param all True to receive all multicasts * @param all True to receive all multicasts
* False to receive only multicasts addressed to specified groups * False to receive only multicasts addressed to specified groups
*/ */
virtual void set_all_multicast(bool all); virtual void set_all_multicast(bool all);
/** Sets memory manager that is used to handle memory buffers /** Sets memory manager that is used to handle memory buffers
* *
* @param mem_mngr Pointer to memory manager * @param mem_mngr Pointer to memory manager
*/ */
virtual void set_memory_manager(EMACMemoryManager &mem_mngr); virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
/* Called from driver functions */ /* Called from driver functions */
osThreadId_t rx_thread; /**< Processing rx thread */ osThreadId_t rx_thread; /**< Processing rx thread */
private: private:
bool low_level_init(); bool low_level_init();
void packet_rx(); void packet_rx();
emac_mem_buf_t *low_level_input(void); emac_mem_buf_t *low_level_input(void);
static void thread_function(void *pvParameters); static void thread_function(void *pvParameters);
void phy_task(); void phy_task();
void eth_arch_enable_interrupts(); void eth_arch_enable_interrupts();
void eth_arch_disable_interrupts(); void eth_arch_disable_interrupts();
mbed_rtos_storage_thread_t rx_thread_cb; mbed_rtos_storage_thread_t rx_thread_cb;
rtos::Mutex TXLockMutex;/**< TX critical section mutex */ rtos::Mutex TXLockMutex;/**< TX critical section mutex */
emac_link_input_cb_t emac_link_input_cb; /**< Callback for incoming data */ emac_link_input_cb_t emac_link_input_cb; /**< Callback for incoming data */
emac_link_state_change_cb_t emac_link_state_cb; /**< Link state change callback */ emac_link_state_change_cb_t emac_link_state_cb; /**< Link state change callback */
EMACMemoryManager *memory_manager; /**< Memory manager */ EMACMemoryManager *memory_manager; /**< Memory manager */
uint32_t phy_status; uint32_t phy_status;
int phy_task_handle; /**< Handle for phy task event */ int phy_task_handle; /**< Handle for phy task event */
}; };
#endif /* GD32_EMAC_H_ */ #endif /* GD32_EMAC_H_ */