123r

Dependencies:   WNC14A2AInterface

Committer:
JMF
Date:
Wed Apr 19 01:13:10 2017 +0000
Revision:
0:2563b0415d1f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:2563b0415d1f 1 /*
JMF 0:2563b0415d1f 2 * Copyright (c) 2016-2016 ARM Limited. All rights reserved.
JMF 0:2563b0415d1f 3 * SPDX-License-Identifier: Apache-2.0
JMF 0:2563b0415d1f 4 * Licensed under the Apache License, Version 2.0 (the License); you may
JMF 0:2563b0415d1f 5 * not use this file except in compliance with the License.
JMF 0:2563b0415d1f 6 * You may obtain a copy of the License at
JMF 0:2563b0415d1f 7 *
JMF 0:2563b0415d1f 8 * http://www.apache.org/licenses/LICENSE-2.0
JMF 0:2563b0415d1f 9 *
JMF 0:2563b0415d1f 10 * Unless required by applicable law or agreed to in writing, software
JMF 0:2563b0415d1f 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
JMF 0:2563b0415d1f 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 0:2563b0415d1f 13 * See the License for the specific language governing permissions and
JMF 0:2563b0415d1f 14 * limitations under the License.
JMF 0:2563b0415d1f 15 */
JMF 0:2563b0415d1f 16 #include "at24mac.h"
JMF 0:2563b0415d1f 17
JMF 0:2563b0415d1f 18 /* Device addressing */
JMF 0:2563b0415d1f 19 #define AT24MAC_EEPROM_ADDRESS (0x0A<<4)
JMF 0:2563b0415d1f 20 #define AT24MAC_RW_PROTECT_ADDRESS (0x06<<4)
JMF 0:2563b0415d1f 21 #define AT24MAC_SERIAL_ADDRESS (0x0B<<4)
JMF 0:2563b0415d1f 22
JMF 0:2563b0415d1f 23 /* Known memory blocks */
JMF 0:2563b0415d1f 24 #define AT24MAC_SERIAL_OFFSET (0x80)
JMF 0:2563b0415d1f 25 #define AT24MAC_EUI64_OFFSET (0x98)
JMF 0:2563b0415d1f 26 #define AT24MAC_EUI48_OFFSET (0x9A)
JMF 0:2563b0415d1f 27
JMF 0:2563b0415d1f 28 #define SERIAL_LEN 16
JMF 0:2563b0415d1f 29 #define EUI64_LEN 8
JMF 0:2563b0415d1f 30 #define EUI48_LEN 6
JMF 0:2563b0415d1f 31
JMF 0:2563b0415d1f 32 AT24Mac::AT24Mac(PinName sda, PinName scl) : _i2c(sda, scl)
JMF 0:2563b0415d1f 33 {
JMF 0:2563b0415d1f 34 // Do nothing
JMF 0:2563b0415d1f 35 }
JMF 0:2563b0415d1f 36
JMF 0:2563b0415d1f 37 int AT24Mac::read_serial(void *buf)
JMF 0:2563b0415d1f 38 {
JMF 0:2563b0415d1f 39 char offset = AT24MAC_SERIAL_OFFSET;
JMF 0:2563b0415d1f 40 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
JMF 0:2563b0415d1f 41 return -1; //No ACK
JMF 0:2563b0415d1f 42 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, SERIAL_LEN);
JMF 0:2563b0415d1f 43 }
JMF 0:2563b0415d1f 44
JMF 0:2563b0415d1f 45 int AT24Mac::read_eui64(void *buf)
JMF 0:2563b0415d1f 46 {
JMF 0:2563b0415d1f 47 char offset = AT24MAC_EUI64_OFFSET;
JMF 0:2563b0415d1f 48 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
JMF 0:2563b0415d1f 49 return -1; //No ACK
JMF 0:2563b0415d1f 50 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI64_LEN);
JMF 0:2563b0415d1f 51 }
JMF 0:2563b0415d1f 52
JMF 0:2563b0415d1f 53 int AT24Mac::read_eui48(void *buf)
JMF 0:2563b0415d1f 54 {
JMF 0:2563b0415d1f 55 char offset = AT24MAC_EUI48_OFFSET;
JMF 0:2563b0415d1f 56 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
JMF 0:2563b0415d1f 57 return -1; //No ACK
JMF 0:2563b0415d1f 58 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI48_LEN);
JMF 0:2563b0415d1f 59 }