//*****************************************************************************
//
// emac.c - Driver for the Integrated Ethernet Controller
//
// Copyright (c) 2013-2017 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup emac_api
//! @{
//
//*****************************************************************************
#include <msp432e411y.h>
#include "types.h"
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_emac.h"
#include "debug.h"
#include "emac.h"
#include "sysctl.h"
#include "interrupt.h"
#include "sw_crc.h"
//*****************************************************************************
//
// Combined defines used in parameter validity checks.
//
//*****************************************************************************
//*****************************************************************************
//
// Combined valid configuration flags.
//
//*****************************************************************************
#define VALID_CONFIG_FLAGS (EMAC_CONFIG_USE_MACADDR1 | \
EMAC_CONFIG_SA_INSERT | \
EMAC_CONFIG_SA_REPLACE | \
EMAC_CONFIG_2K_PACKETS | \
EMAC_CONFIG_STRIP_CRC | \
EMAC_CONFIG_JABBER_DISABLE | \
EMAC_CONFIG_JUMBO_ENABLE | \
EMAC_CONFIG_IF_GAP_MASK | \
EMAC_CONFIG_CS_DISABLE | \
EMAC_CONFIG_100MBPS | \
EMAC_CONFIG_RX_OWN_DISABLE | \
EMAC_CONFIG_LOOPBACK | \
EMAC_CONFIG_FULL_DUPLEX | \
EMAC_CONFIG_CHECKSUM_OFFLOAD | \
EMAC_CONFIG_RETRY_DISABLE | \
EMAC_CONFIG_AUTO_CRC_STRIPPING | \
EMAC_CONFIG_BO_MASK | \
EMAC_CONFIG_DEFERRAL_CHK_ENABLE | \
EMAC_CONFIG_PREAMBLE_MASK)
//*****************************************************************************
//
// Combined valid frame filter flags.
//
//*****************************************************************************
#define VALID_FRMFILTER_FLAGS (EMAC_FRMFILTER_RX_ALL | \
EMAC_FRMFILTER_VLAN | \
EMAC_FRMFILTER_HASH_AND_PERFECT | \
EMAC_FRMFILTER_SADDR | \
EMAC_FRMFILTER_INV_SADDR | \
EMAC_FRMFILTER_PASS_NO_PAUSE | \
EMAC_FRMFILTER_PASS_ALL_CTRL | \
EMAC_FRMFILTER_PASS_ADDR_CTRL | \
EMAC_FRMFILTER_BROADCAST | \
EMAC_FRMFILTER_PASS_MULTICAST | \
EMAC_FRMFILTER_INV_DADDR | \
EMAC_FRMFILTER_HASH_MULTICAST | \
EMAC_FRMFILTER_HASH_UNICAST | \
EMAC_FRMFILTER_PROMISCUOUS)
//*****************************************************************************
//
// Combined valid maskable interrupts.
//
//*****************************************************************************
#define EMAC_MASKABLE_INTS (EMAC_INT_EARLY_RECEIVE | \
EMAC_INT_BUS_ERROR | \
EMAC_INT_EARLY_TRANSMIT | \
EMAC_INT_RX_WATCHDOG | \
EMAC_INT_RX_STOPPED | \
EMAC_INT_RX_NO_BUFFER | \
EMAC_INT_RECEIVE | \
EMAC_INT_TX_UNDERFLOW | \
EMAC_INT_RX_OVERFLOW | \
EMAC_INT_TX_JABBER | \
EMAC_INT_TX_NO_BUFFER | \
EMAC_INT_TX_STOPPED | \
EMAC_INT_TRANSMIT | \
EMAC_INT_NORMAL_INT | \
EMAC_INT_ABNORMAL_INT | \
EMAC_INT_PHY)
//*****************************************************************************
//
// Combined valid normal interrupts.
//
//*****************************************************************************
#define EMAC_NORMAL_INTS (EMAC_INT_TRANSMIT | \
EMAC_INT_RECEIVE | \
EMAC_INT_EARLY_RECEIVE | \
EMAC_INT_TX_NO_BUFFER)
//*****************************************************************************
//
// Combined valid abnormal interrupts.
//
//*****************************************************************************
#define EMAC_ABNORMAL_INTS (EMAC_INT_TX_STOPPED | \
EMAC_INT_TX_JABBER | \