mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
580:3c14cb9b87c5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/hal/TARGET_ARM_SSG/TARGET_MPS2/SDK/mps2_ethernet_api.c	Thu Jul 02 16:15:09 2015 +0100
@@ -0,0 +1,127 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 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 "toolchain.h"
+#include "mbed_error.h"
+#include "ETH_MPS2.h"
+#include "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)
+{
+    int error;
+    const unsigned int mac_valid_high = 0xC00A;
+    const unsigned int mac_valid_low = 0x00F70200;
+    unsigned int mac_low;
+    unsigned int mac_high;
+
+    error = 0;
+
+    // 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) {
+        error = TRUE;
+        return error;
+    }
+
+    return error;
+}
+
+
+/*----------------------------------------------------------------------------
+  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;
+
+}
+