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.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2018-10-15 12:35:05 +00:00
|
|
|
|
2019-03-14 09:29:32 +00:00
|
|
|
#include "esp32/rom/ets_sys.h"
|
|
|
|
#include "esp32/rom/gpio.h"
|
2016-11-08 09:45:17 +00:00
|
|
|
|
|
|
|
#include "soc/dport_reg.h"
|
2019-05-13 10:02:45 +00:00
|
|
|
#include "soc/rtc_periph.h"
|
|
|
|
#include "soc/gpio_periph.h"
|
2016-11-08 09:45:17 +00:00
|
|
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "driver/gpio.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#include "emac_common.h"
|
|
|
|
|
2017-01-06 05:49:42 +00:00
|
|
|
void emac_enable_flowctrl(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_GMACFC_REG, EMAC_TFCE);
|
|
|
|
REG_SET_BIT(EMAC_GMACFC_REG, EMAC_RFCE);
|
|
|
|
REG_CLR_BIT(EMAC_GMACFC_REG, EMAC_DZPQ);
|
|
|
|
REG_SET_FIELD(EMAC_GMACFC_REG, EMAC_PAUSE_TIME, 0x1648);
|
|
|
|
REG_SET_FIELD(EMAC_GMACFC_REG, EMAC_PLT, 0x1);
|
2017-01-06 05:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_disable_flowctrl(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_CLR_BIT(EMAC_GMACFC_REG, EMAC_TFCE);
|
|
|
|
REG_CLR_BIT(EMAC_GMACFC_REG, EMAC_RFCE);
|
|
|
|
REG_CLR_BIT(EMAC_GMACFC_REG, EMAC_DZPQ);
|
|
|
|
REG_SET_FIELD(EMAC_GMACFC_REG, EMAC_PAUSE_TIME, 0);
|
|
|
|
REG_SET_FIELD(EMAC_GMACFC_REG, EMAC_PLT, 0);
|
2017-01-06 05:49:42 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
void emac_enable_dma_tx(void)
|
|
|
|
{
|
|
|
|
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_TRANSMISSION_COMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
void emac_enable_dma_rx(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_RX);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_disable_dma_tx(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_CLR_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_TRANSMISSION_COMMAND);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_disable_dma_rx(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_CLR_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_RX);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_enable_clk(bool enable)
|
|
|
|
{
|
|
|
|
if (enable == true) {
|
2017-05-10 07:45:04 +00:00
|
|
|
DPORT_REG_SET_BIT(EMAC_CLK_EN_REG, EMAC_CLK_EN);
|
2016-11-08 09:45:17 +00:00
|
|
|
} else {
|
2017-05-10 07:45:04 +00:00
|
|
|
DPORT_REG_CLR_BIT(EMAC_CLK_EN_REG, EMAC_CLK_EN);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void emac_dma_init(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_FWD_UNDER_GF);
|
|
|
|
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_OPT_SECOND_FRAME);
|
2016-11-08 09:45:17 +00:00
|
|
|
REG_SET_FIELD(EMAC_DMABUSMODE_REG, EMAC_PROG_BURST_LEN, 4);
|
2017-01-06 05:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_mac_enable_txrx(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACRX);
|
|
|
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACTX);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void emac_mac_init(void)
|
|
|
|
{
|
2018-03-14 08:18:07 +00:00
|
|
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX);
|
|
|
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII);
|
|
|
|
REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED);
|
2018-10-15 12:35:05 +00:00
|
|
|
REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PAM);
|
2016-11-08 09:45:17 +00:00
|
|
|
}
|
2019-05-07 10:30:10 +00:00
|
|
|
|
|
|
|
void emac_enable_promiscuous(void)
|
|
|
|
{
|
|
|
|
REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PMODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void emac_disable_promiscuous(void)
|
|
|
|
{
|
|
|
|
REG_CLR_BIT(EMAC_GMACFF_REG, EMAC_PMODE);
|
|
|
|
}
|