2016-11-08 09:45:17 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef _EMAC_DEV_H_
|
|
|
|
#define _EMAC_DEV_H_
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-01-28 12:29:58 +00:00
|
|
|
#include "esp_types.h"
|
|
|
|
#include "soc/emac_reg_v2.h"
|
|
|
|
|
2018-03-14 08:18:07 +00:00
|
|
|
#define EMAC_INTR_ENABLE_BIT (EMAC_DMAIN_TIE | EMAC_DMAIN_RIE | EMAC_DMAIN_RBUE | EMAC_DMAIN_NISE)
|
2016-11-08 09:45:17 +00:00
|
|
|
|
|
|
|
struct dma_desc {
|
|
|
|
uint32_t desc0;
|
|
|
|
uint32_t desc1;
|
|
|
|
uint32_t desc2;
|
|
|
|
uint32_t desc3;
|
|
|
|
};
|
|
|
|
|
2018-08-22 09:46:14 +00:00
|
|
|
typedef struct dma_extended_desc {
|
2016-11-08 09:45:17 +00:00
|
|
|
struct dma_desc basic;
|
|
|
|
uint32_t desc4;
|
|
|
|
uint32_t desc5;
|
|
|
|
uint32_t desc6;
|
|
|
|
uint32_t desc7;
|
2019-01-28 12:29:58 +00:00
|
|
|
} dma_extended_desc_t;
|
2016-11-08 09:45:17 +00:00
|
|
|
|
|
|
|
void emac_enable_clk(bool enable);
|
2018-09-19 02:45:53 +00:00
|
|
|
esp_err_t emac_reset(void);
|
2016-11-08 09:45:17 +00:00
|
|
|
void emac_set_gpio_pin_rmii(void);
|
|
|
|
void emac_set_gpio_pin_mii(void);
|
|
|
|
uint32_t emac_read_mac_version(void);
|
|
|
|
void emac_dma_init(void);
|
|
|
|
void emac_mac_init(void);
|
|
|
|
void emac_enable_dma_tx(void);
|
|
|
|
void emac_enable_dma_rx(void);
|
|
|
|
void emac_disable_dma_tx(void);
|
|
|
|
void emac_disable_dma_rx(void);
|
2017-01-06 05:49:42 +00:00
|
|
|
void emac_enable_flowctrl(void);
|
|
|
|
void emac_disable_flowctrl(void);
|
|
|
|
void emac_mac_enable_txrx(void);
|
2016-11-08 09:45:17 +00:00
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline uint32_t emac_read_tx_cur_reg(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
|
|
|
return REG_READ(EMAC_DMATXCURRDESC_REG);
|
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline uint32_t emac_read_rx_cur_reg(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
|
|
|
return REG_READ(EMAC_DMARXCURRDESC_REG);
|
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_poll_tx_cmd(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
|
|
|
//write any to wake up dma
|
|
|
|
REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
|
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_poll_rx_cmd(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
|
|
|
//write any to wake up dma
|
|
|
|
REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
|
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_disable_rx_intr(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE);
|
2016-12-18 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_enable_rx_intr(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE);
|
2016-12-18 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_disable_rx_unavail_intr(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE);
|
2016-12-18 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_enable_rx_unavail_intr(void)
|
2016-12-18 13:18:37 +00:00
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE);
|
2017-01-06 05:49:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void IRAM_ATTR emac_send_pause_frame_enable(void)
|
2017-01-06 05:49:42 +00:00
|
|
|
{
|
|
|
|
REG_SET_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
|
|
|
|
}
|
|
|
|
|
2018-08-29 03:26:44 +00:00
|
|
|
static inline void emac_send_pause_zero_frame_enable(void)
|
2017-01-06 05:49:42 +00:00
|
|
|
{
|
|
|
|
REG_CLR_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
|
2016-12-18 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|