mirror of https://github.com/ARMmbed/mbed-os.git
remove ethernet driver as it is not compatible
parent
f35ba494ca
commit
304b584040
|
@ -1,451 +0,0 @@
|
|||
/* MPS2 Peripheral Library
|
||||
*
|
||||
* Copyright (c) 2006-2018 ARM Limited
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder 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 HOLDER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code implementation file for the LAN Ethernet interface.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mbed_wait_api.h"
|
||||
#include "ETH_MPS2.h"
|
||||
|
||||
// SMSC9220 low-level operations
|
||||
unsigned int smsc9220_mac_regread(unsigned char regoffset, unsigned int *data)
|
||||
{
|
||||
unsigned int val, maccmd;
|
||||
int timedout;
|
||||
int error;
|
||||
|
||||
error = 0;
|
||||
val = SMSC9220->MAC_CSR_CMD;
|
||||
if (!(val & ((unsigned int)1 << 31))) { // Make sure there's no pending operation
|
||||
maccmd = 0;
|
||||
maccmd |= regoffset;
|
||||
maccmd |= ((unsigned int)1 << 30); // Indicates read
|
||||
maccmd |= ((unsigned int)1 << 31); // Start bit
|
||||
SMSC9220->MAC_CSR_CMD = maccmd; // Start operation
|
||||
|
||||
timedout = 50;
|
||||
do {
|
||||
val = SMSC9220->BYTE_TEST; // A no-op read.
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
} while (timedout && (SMSC9220->MAC_CSR_CMD & ((unsigned int)1 << 31)));
|
||||
|
||||
if (!timedout) {
|
||||
error = 1;
|
||||
} else {
|
||||
*data = SMSC9220->MAC_CSR_DATA;
|
||||
}
|
||||
} else {
|
||||
*data = 0;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
unsigned int smsc9220_mac_regwrite(unsigned char regoffset, unsigned int data)
|
||||
{
|
||||
unsigned int read, maccmd;
|
||||
int timedout;
|
||||
int error;
|
||||
|
||||
error = 0;
|
||||
read = SMSC9220->MAC_CSR_CMD;
|
||||
if (!(read & ((unsigned int)1 << 31))) { // Make sure there's no pending operation
|
||||
SMSC9220->MAC_CSR_DATA = data; // Store data.
|
||||
maccmd = 0;
|
||||
maccmd |= regoffset;
|
||||
maccmd &= ~((unsigned int)1 << 30); // Clear indicates write
|
||||
maccmd |= ((unsigned int)1 << 31); // Indicate start of operation
|
||||
SMSC9220->MAC_CSR_CMD = maccmd;
|
||||
|
||||
timedout = 50;
|
||||
do {
|
||||
read = SMSC9220->BYTE_TEST; // A no-op read.
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
} while (timedout && (SMSC9220->MAC_CSR_CMD & ((unsigned int)1 << 31)));
|
||||
|
||||
if (!timedout) {
|
||||
error = 1;
|
||||
}
|
||||
} else {
|
||||
printf("Warning: SMSC9220 MAC CSR is busy. No data written.\n");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
unsigned int smsc9220_phy_regread(unsigned char regoffset, unsigned short *data)
|
||||
{
|
||||
unsigned int val, phycmd;
|
||||
int error;
|
||||
int timedout;
|
||||
|
||||
error = 0;
|
||||
|
||||
smsc9220_mac_regread(SMSC9220_MAC_MII_ACC, &val);
|
||||
|
||||
if (!(val & 1)) { // Not busy
|
||||
phycmd = 0;
|
||||
phycmd |= (1 << 11); // 1 to [15:11]
|
||||
phycmd |= ((regoffset & 0x1F) << 6); // Put regoffset to [10:6]
|
||||
phycmd &= ~(1 << 1); // Clear [1] indicates read.
|
||||
phycmd |= (1 << 0); // Set [0] indicates operation start
|
||||
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_MII_ACC, phycmd);
|
||||
|
||||
val = 0;
|
||||
timedout = 50;
|
||||
do {
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
smsc9220_mac_regread(SMSC9220_MAC_MII_ACC, &val);
|
||||
} while (timedout && (val & ((unsigned int)1 << 0)));
|
||||
|
||||
if (!timedout) {
|
||||
error = 1;
|
||||
} else {
|
||||
smsc9220_mac_regread(SMSC9220_MAC_MII_DATA, (unsigned int *)data);
|
||||
}
|
||||
|
||||
} else {
|
||||
*data = 0;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
unsigned int smsc9220_phy_regwrite(unsigned char regoffset, unsigned short data)
|
||||
{
|
||||
unsigned int val, phycmd;
|
||||
int error;
|
||||
int timedout;
|
||||
|
||||
error = 0;
|
||||
|
||||
smsc9220_mac_regread(SMSC9220_MAC_MII_ACC, &val);
|
||||
|
||||
if (!(val & 1)) { // Not busy
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_MII_DATA, (data & 0xFFFF)); // Load the data
|
||||
phycmd = 0;
|
||||
phycmd |= (1 << 11); // 1 to [15:11]
|
||||
phycmd |= ((regoffset & 0x1F) << 6); // Put regoffset to [10:6]
|
||||
phycmd |= (1 << 1); // Set [1] indicates write.
|
||||
phycmd |= (1 << 0); // Set [0] indicates operation start
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_MII_ACC, phycmd); // Start operation
|
||||
|
||||
phycmd = 0;
|
||||
timedout = 50;
|
||||
|
||||
do {
|
||||
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
smsc9220_mac_regread(SMSC9220_MAC_MII_ACC, &phycmd);
|
||||
} while (timedout && (phycmd & (1 << 0)));
|
||||
|
||||
if (!timedout) {
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("Warning: SMSC9220 MAC MII is busy. No data written.\n");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
// Returns smsc9220 id.
|
||||
unsigned int smsc9220_read_id(void)
|
||||
{
|
||||
return SMSC9220->ID_REV;
|
||||
}
|
||||
|
||||
// Initiates a soft reset, returns 0 on success, or 1 on failure.
|
||||
unsigned int smsc9220_soft_reset(void)
|
||||
{
|
||||
int timedout;
|
||||
|
||||
timedout = 10;
|
||||
// Soft reset
|
||||
SMSC9220->HW_CFG |= 1;
|
||||
|
||||
do {
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
} while (timedout && (SMSC9220->HW_CFG & 1));
|
||||
|
||||
if (!timedout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void smsc9220_set_txfifo(unsigned int val)
|
||||
{
|
||||
// 2kb minimum, 14kb maximum
|
||||
if (val < 2 || val > 14) {
|
||||
return;
|
||||
}
|
||||
|
||||
SMSC9220->HW_CFG = val << 16;
|
||||
}
|
||||
|
||||
|
||||
unsigned int smsc9220_wait_eeprom(void)
|
||||
{
|
||||
int timedout;
|
||||
|
||||
timedout = 50;
|
||||
|
||||
do {
|
||||
wait_ms(1);
|
||||
timedout--;
|
||||
|
||||
} while (timedout && (SMSC9220->E2P_CMD & ((unsigned int) 1 << 31)));
|
||||
|
||||
if (!timedout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* initialise irqs */
|
||||
void smsc9220_init_irqs(void)
|
||||
{
|
||||
SMSC9220->INT_EN = 0x0;
|
||||
SMSC9220->INT_STS = 0xFFFFFFFF; // clear all interrupts
|
||||
SMSC9220->IRQ_CFG = 0x22000100; // irq deassertion at 220 usecs and master IRQ enable.
|
||||
}
|
||||
|
||||
unsigned int smsc9220_check_phy(void)
|
||||
{
|
||||
unsigned short phyid1, phyid2;
|
||||
|
||||
smsc9220_phy_regread(SMSC9220_PHY_ID1, &phyid1);
|
||||
smsc9220_phy_regread(SMSC9220_PHY_ID2, &phyid2);
|
||||
return ((phyid1 == 0xFFFF && phyid2 == 0xFFFF) ||
|
||||
(phyid1 == 0x0 && phyid2 == 0x0));
|
||||
}
|
||||
|
||||
unsigned int smsc9220_reset_phy(void)
|
||||
{
|
||||
unsigned short read;
|
||||
|
||||
if (smsc9220_phy_regread(SMSC9220_PHY_BCONTROL, &read)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
read |= (1 << 15);
|
||||
if (smsc9220_phy_regwrite(SMSC9220_PHY_BCONTROL, read)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Advertise all speeds and pause capabilities */
|
||||
void smsc9220_advertise_cap(void)
|
||||
{
|
||||
unsigned short aneg_adv;
|
||||
aneg_adv = 0;
|
||||
|
||||
|
||||
smsc9220_phy_regread(SMSC9220_PHY_ANEG_ADV, &aneg_adv);
|
||||
aneg_adv |= 0xDE0;
|
||||
|
||||
smsc9220_phy_regwrite(SMSC9220_PHY_ANEG_ADV, aneg_adv);
|
||||
smsc9220_phy_regread(SMSC9220_PHY_ANEG_ADV, &aneg_adv);
|
||||
return;
|
||||
}
|
||||
|
||||
void smsc9220_establish_link(void)
|
||||
{
|
||||
unsigned short bcr;
|
||||
|
||||
smsc9220_phy_regread(SMSC9220_PHY_BCONTROL, &bcr);
|
||||
bcr |= (1 << 12) | (1 << 9);
|
||||
smsc9220_phy_regwrite(SMSC9220_PHY_BCONTROL, bcr);
|
||||
smsc9220_phy_regread(SMSC9220_PHY_BCONTROL, &bcr);
|
||||
|
||||
{
|
||||
unsigned int hw_cfg;
|
||||
|
||||
hw_cfg = 0;
|
||||
hw_cfg = SMSC9220->HW_CFG;
|
||||
|
||||
hw_cfg &= 0xF0000;
|
||||
hw_cfg |= (1 << 20);
|
||||
SMSC9220->HW_CFG = hw_cfg;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void smsc9220_enable_xmit(void)
|
||||
{
|
||||
SMSC9220->TX_CFG = 0x2; // Enable trasmission
|
||||
return;
|
||||
}
|
||||
|
||||
void smsc9220_enable_mac_xmit(void)
|
||||
{
|
||||
unsigned int mac_cr;
|
||||
|
||||
mac_cr = 0;
|
||||
smsc9220_mac_regread(SMSC9220_MAC_CR, &mac_cr);
|
||||
|
||||
mac_cr |= (1 << 3); // xmit enable
|
||||
mac_cr |= (1 << 28); // Heartbeat disable
|
||||
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_CR, mac_cr);
|
||||
return;
|
||||
}
|
||||
|
||||
void smsc9220_enable_mac_recv(void)
|
||||
{
|
||||
unsigned int mac_cr;
|
||||
|
||||
mac_cr = 0;
|
||||
smsc9220_mac_regread(SMSC9220_MAC_CR, &mac_cr);
|
||||
mac_cr |= (1 << 2); // Recv enable
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_CR, mac_cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
unsigned int smsc9220_check_ready(void)
|
||||
{
|
||||
return !(SMSC9220->PMT_CTRL & 1);
|
||||
}
|
||||
|
||||
/* Generate a soft irq */
|
||||
void smsc9220_set_soft_int(void)
|
||||
{
|
||||
SMSC9220->INT_EN |= 0x80000000;
|
||||
}
|
||||
|
||||
/* clear soft irq */
|
||||
void smsc9220_clear_soft_int(void)
|
||||
{
|
||||
SMSC9220->INT_STS |= 0x80000000;
|
||||
}
|
||||
|
||||
|
||||
unsigned int smsc9220_recv_packet(unsigned int *recvbuf, unsigned int *index)
|
||||
{
|
||||
unsigned int rxfifo_inf; // Tells us the status of rx payload and status fifos.
|
||||
unsigned int rxfifo_stat;
|
||||
|
||||
unsigned int pktsize;
|
||||
unsigned int dwords_to_read;
|
||||
|
||||
rxfifo_inf = SMSC9220->RX_FIFO_INF;
|
||||
|
||||
if (rxfifo_inf & 0xFFFF) { // If there's data
|
||||
rxfifo_stat = SMSC9220->RX_STAT_PORT;
|
||||
if (rxfifo_stat != 0) { // Fetch status of this packet
|
||||
pktsize = ((rxfifo_stat >> 16) & 0x3FFF);
|
||||
if (rxfifo_stat & (1 << 15)) {
|
||||
printf("Error occured during receiving of packets on the bus.\n");
|
||||
return 1;
|
||||
} else {
|
||||
/* Below formula (recommended by SMSC9220 code)
|
||||
* gives 1 more than required. This is perhaps because
|
||||
* a last word is needed for not word aligned packets.
|
||||
*/
|
||||
dwords_to_read = (pktsize + 3) >> 2;
|
||||
// PIO copy of data received:
|
||||
while (dwords_to_read > 0) {
|
||||
recvbuf[*index] = SMSC9220->RX_DATA_PORT;
|
||||
(*index)++;
|
||||
dwords_to_read--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
rxfifo_stat = SMSC9220->RX_STAT_PORT;
|
||||
rxfifo_inf = SMSC9220->RX_FIFO_INF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Does the actual transfer of data to FIFO, note it does no
|
||||
// fifo availability checking. This should be done by caller.
|
||||
// Assumes the whole frame is transferred at once as a single segment
|
||||
void smsc9220_xmit_packet(unsigned char *pkt, unsigned int length)
|
||||
{
|
||||
unsigned int txcmd_a, txcmd_b;
|
||||
unsigned int dwords_to_write;
|
||||
volatile unsigned int dwritten;
|
||||
unsigned int *pktptr;
|
||||
volatile unsigned int xmit_stat, xmit_stat2, xmit_inf;
|
||||
int i;
|
||||
|
||||
pktptr = (unsigned int *) pkt;
|
||||
txcmd_a = 0;
|
||||
txcmd_b = 0;
|
||||
|
||||
txcmd_a |= (1 << 12) | (1 << 13); // First and last segments
|
||||
txcmd_a |= length & 0x7FF; // [10:0] contains length
|
||||
|
||||
txcmd_b |= ((length & 0xFFFF) << 16); // [31:16] contains length
|
||||
txcmd_b |= length & 0x7FF; // [10:0] also contains length
|
||||
|
||||
|
||||
SMSC9220->TX_DATA_PORT = txcmd_a;
|
||||
SMSC9220->TX_DATA_PORT = txcmd_b;
|
||||
dwritten = dwords_to_write = (length + 3) >> 2;
|
||||
|
||||
// PIO Copy to FIFO. Could replace this with DMA.
|
||||
while (dwords_to_write > 0) {
|
||||
SMSC9220->TX_DATA_PORT = *pktptr;
|
||||
pktptr++;
|
||||
dwords_to_write--;
|
||||
}
|
||||
|
||||
xmit_stat = SMSC9220->TX_STAT_PORT;
|
||||
xmit_stat2 = SMSC9220->TX_STAT_PORT;
|
||||
xmit_inf = SMSC9220->TX_FIFO_INF;
|
||||
|
||||
if (xmit_stat2 != 0) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
xmit_stat2 = SMSC9220->TX_STAT_PORT;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/* MPS2 Peripheral Library
|
||||
*
|
||||
* Copyright (c) 2006-2018 ARM Limited
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder 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 HOLDER 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.
|
||||
*/
|
||||
|
||||
#ifndef _ETH_MPS2_H_
|
||||
#define _ETH_MPS2_H_
|
||||
|
||||
#include "SMM_MPS2.h"
|
||||
|
||||
// Function declarations
|
||||
|
||||
unsigned int smsc9220_mac_regread(unsigned char regoffset, unsigned int *data);
|
||||
unsigned int smsc9220_mac_regwrite(unsigned char regoffset, unsigned int data);
|
||||
unsigned int smsc9220_phy_regread(unsigned char regoffset, unsigned short *data);
|
||||
unsigned int smsc9220_phy_regwrite(unsigned char regoffset, unsigned short data);
|
||||
|
||||
unsigned int smsc9220_read_id(void);
|
||||
unsigned int smsc9220_soft_reset(void);
|
||||
void smsc9220_set_txfifo(unsigned int val);
|
||||
unsigned int smsc9220_wait_eeprom(void);
|
||||
void smsc9220_init_irqs(void);
|
||||
unsigned int smsc9220_check_phy(void);
|
||||
unsigned int smsc9220_reset_phy(void);
|
||||
|
||||
void smsc9220_advertise_cap(void);
|
||||
void smsc9220_establish_link(void);
|
||||
void smsc9220_enable_xmit(void);
|
||||
void smsc9220_enable_mac_xmit(void);
|
||||
void smsc9220_enable_mac_recv(void);
|
||||
unsigned int smsc9220_check_ready(void);
|
||||
void smsc9220_set_soft_int(void);
|
||||
void smsc9220_clear_soft_int(void);
|
||||
|
||||
unsigned int smsc9220_recv_packet(unsigned int *recvbuf, unsigned int *index);
|
||||
void smsc9220_xmit_packet(unsigned char *pkt, unsigned int length);
|
||||
|
||||
#endif
|
|
@ -1,162 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2018 ARM Limited
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "mps2_ethernet_api.h"
|
||||
#include "cmsis.h"
|
||||
#include "mbed_interface.h"
|
||||
#include "mbed_toolchain.h"
|
||||
#include "mbed_error.h"
|
||||
#include "ETH_MPS2.h"
|
||||
#include "mbed_wait_api.h"
|
||||
|
||||
#define TX_PKT_SIZE 256
|
||||
#define RX_PKT_SIZE 300
|
||||
|
||||
// Types
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
|
||||
int smsc9220_check_id(void)
|
||||
{
|
||||
int error;
|
||||
unsigned int id;
|
||||
error = 0;
|
||||
|
||||
id = smsc9220_read_id();
|
||||
|
||||
// If bottom and top halves of the word are the same
|
||||
if (((id >> 16) & 0xFFFF) == (id & 0xFFFF)) {
|
||||
error = 1;
|
||||
return error;
|
||||
}
|
||||
switch (((id >> 16) & 0xFFFF)) {
|
||||
case 0x9220:
|
||||
break;
|
||||
|
||||
default:
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int smsc9220_check_macaddress(void)
|
||||
{
|
||||
const unsigned int mac_valid_high = 0xC00A;
|
||||
const unsigned int mac_valid_low = 0x00F70200;
|
||||
unsigned int mac_low;
|
||||
unsigned int mac_high;
|
||||
|
||||
// Read current mac address.
|
||||
smsc9220_mac_regread(SMSC9220_MAC_ADDRH, &mac_high);
|
||||
smsc9220_mac_regread(SMSC9220_MAC_ADDRL, &mac_low);
|
||||
|
||||
// Writing temporary address:
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_ADDRH, mac_valid_high);
|
||||
smsc9220_mac_regwrite(SMSC9220_MAC_ADDRL, mac_valid_low);
|
||||
|
||||
// Verify write was correct:
|
||||
smsc9220_mac_regread(SMSC9220_MAC_ADDRH, &mac_high);
|
||||
smsc9220_mac_regread(SMSC9220_MAC_ADDRL, &mac_low);
|
||||
|
||||
|
||||
if (mac_high != mac_valid_high || mac_low != mac_valid_low) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void smsc9220_print_mac_registers()
|
||||
{
|
||||
unsigned int read;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
read = 0;
|
||||
|
||||
for (i = 1; i <= 0xC; i++) {
|
||||
smsc9220_mac_regread(i, &read);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void smsc9220_print_phy_registers()
|
||||
{
|
||||
unsigned short read;
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
read = 0;
|
||||
for (i = 0; i <= 6; i++) {
|
||||
smsc9220_phy_regread(i, &read);
|
||||
}
|
||||
smsc9220_phy_regread(i = 17, &read);
|
||||
|
||||
smsc9220_phy_regread(i = 18, &read);
|
||||
|
||||
smsc9220_phy_regread(i = 27, &read);
|
||||
|
||||
smsc9220_phy_regread(i = 29, &read);
|
||||
|
||||
smsc9220_phy_regread(i = 30, &read);
|
||||
|
||||
smsc9220_phy_regread(i = 31, &read);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Ethernet Device initialize
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
int ethernet_transmission(unsigned char *pkt, unsigned int length)
|
||||
{
|
||||
smsc9220_xmit_packet(pkt, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ethernet_reception(unsigned int *recvbuf, unsigned int *index)
|
||||
{
|
||||
return smsc9220_recv_packet((unsigned int *)recvbuf, index);
|
||||
}
|
||||
|
||||
int ethernet_mac_address(char *mac)
|
||||
{
|
||||
return smsc9220_check_macaddress();
|
||||
}
|
||||
|
||||
unsigned int ethernet_check_ready(void)
|
||||
{
|
||||
return smsc9220_check_ready();
|
||||
}
|
||||
|
||||
unsigned int ethernet_intf()
|
||||
{
|
||||
unsigned int txfifo_inf;
|
||||
|
||||
txfifo_inf = SMSC9220->TX_FIFO_INF;
|
||||
|
||||
return txfifo_inf;
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2018 ARM Limited
|
||||
*
|
||||
* 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 MPS2_ETHERNET_API_H
|
||||
#define MPS2_ETHERNET_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_ETHERNET
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Connection constants
|
||||
|
||||
// send ethernet write buffer, returning the packet size sent
|
||||
int ethernet_transmission(unsigned char *pkt, unsigned int length);
|
||||
|
||||
// recieve from ethernet buffer, returning packet size, or 0 if no packet
|
||||
int ethernet_reception(unsigned int *recvbuf, unsigned int *index);
|
||||
|
||||
// get the ethernet address
|
||||
int ethernet_mac_address(char *mac);
|
||||
|
||||
unsigned int ethernet_check_ready(void);
|
||||
|
||||
unsigned int ethernet_intf(void);
|
||||
|
||||
int smsc9220_check_id(void);
|
||||
|
||||
int smsc9220_check_macaddress(void);
|
||||
|
||||
void smsc9220_print_mac_registers(void);
|
||||
void smsc9220_print_phy_registers(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2018 ARM Limited
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "ethernet_api.h"
|
||||
#include "mps2_ethernet_api.h"
|
||||
#include "cmsis.h"
|
||||
#include "mbed_interface.h"
|
||||
#include "mbed_toolchain.h"
|
||||
#include "mbed_error.h"
|
||||
#include "ETH_MPS2.h"
|
||||
#include "mbed_wait_api.h"
|
||||
|
||||
#define TX_PKT_SIZE 256
|
||||
#define RX_PKT_SIZE 300
|
||||
|
||||
// Types
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Ethernet Device initialize
|
||||
*----------------------------------------------------------------------------*/
|
||||
int ethernet_init()
|
||||
{
|
||||
int error;
|
||||
error = 0;
|
||||
|
||||
if (smsc9220_check_id()) {
|
||||
error = TRUE;
|
||||
}
|
||||
|
||||
if (smsc9220_soft_reset()) {
|
||||
error = TRUE;
|
||||
}
|
||||
|
||||
smsc9220_set_txfifo(5);
|
||||
|
||||
// Sets automatic flow control thresholds, and backpressure
|
||||
// threshold to defaults specified.
|
||||
SMSC9220->AFC_CFG = 0x006E3740;
|
||||
|
||||
if (smsc9220_wait_eeprom()) {
|
||||
error = TRUE;
|
||||
}
|
||||
|
||||
// Configure GPIOs as LED outputs.
|
||||
SMSC9220->GPIO_CFG = 0x70070000;
|
||||
|
||||
smsc9220_init_irqs();
|
||||
|
||||
/* Configure MAC addresses here if needed. */
|
||||
|
||||
if (smsc9220_check_phy()) {
|
||||
error = TRUE;
|
||||
}
|
||||
|
||||
if (smsc9220_reset_phy()) {
|
||||
error = TRUE;
|
||||
return error;
|
||||
}
|
||||
|
||||
wait_ms(100);
|
||||
// Checking whether phy reset completed successfully.
|
||||
{
|
||||
unsigned short phyreset;
|
||||
phyreset = 0;
|
||||
smsc9220_phy_regread(SMSC9220_PHY_BCONTROL, &phyreset);
|
||||
if (phyreset & (1 << 15)) {
|
||||
error = TRUE;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Advertise capabilities */
|
||||
smsc9220_advertise_cap();
|
||||
|
||||
|
||||
/* Begin to establish link */
|
||||
smsc9220_establish_link(); // bit [12] of BCONTROL seems self-clearing.
|
||||
// Although it's not so in the manual.
|
||||
|
||||
/* Interrupt threshold */
|
||||
SMSC9220->FIFO_INT = 0xFF000000;
|
||||
|
||||
smsc9220_enable_mac_xmit();
|
||||
|
||||
smsc9220_enable_xmit();
|
||||
|
||||
SMSC9220->RX_CFG = 0;
|
||||
|
||||
smsc9220_enable_mac_recv();
|
||||
|
||||
// Rx status FIFO level irq threshold
|
||||
SMSC9220->FIFO_INT &= ~(0xFF); // Clear 2 bottom nibbles
|
||||
|
||||
// This sleep is compulsory otherwise txmit/receive will fail.
|
||||
wait_ms(2000);
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Ethernet Device Uninitialize
|
||||
*----------------------------------------------------------------------------*/
|
||||
void ethernet_free()
|
||||
{
|
||||
}
|
||||
|
||||
int ethernet_write(const char *data, int size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ethernet_send()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ethernet_receive()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read from an recevied ethernet packet.
|
||||
// After receive returnd a number bigger than 0 it is
|
||||
// possible to read bytes from this packet.
|
||||
// Read will write up to size bytes into data.
|
||||
// It is possible to use read multible times.
|
||||
// Each time read will start reading after the last read byte before.
|
||||
|
||||
int ethernet_read(char *data, int dlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ethernet_address(char *mac)
|
||||
{
|
||||
mbed_mac_address(mac);
|
||||
}
|
||||
|
||||
int ethernet_link(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ethernet_set_link(int speed, int duplex)
|
||||
{
|
||||
smsc9220_establish_link();
|
||||
}
|
||||
|
Loading…
Reference in New Issue