Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
at24mac.cpp
00001 /* 00002 * Copyright (c) 2016-2016 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "at24mac.h" 00017 00018 #if DEVICE_I2C 00019 00020 /* Device addressing */ 00021 #define AT24MAC_EEPROM_ADDRESS (0x0A<<4) 00022 #define AT24MAC_RW_PROTECT_ADDRESS (0x06<<4) 00023 #define AT24MAC_SERIAL_ADDRESS (0x0B<<4) 00024 00025 /* Known memory blocks */ 00026 #define AT24MAC_SERIAL_OFFSET (0x80) 00027 #define AT24MAC_EUI64_OFFSET (0x98) 00028 #define AT24MAC_EUI48_OFFSET (0x9A) 00029 00030 #define SERIAL_LEN 16 00031 #define EUI64_LEN 8 00032 #define EUI48_LEN 6 00033 00034 using namespace mbed; 00035 00036 AT24Mac::AT24Mac(PinName sda, PinName scl) : _i2c(sda , scl) 00037 { 00038 // Do nothing 00039 } 00040 00041 int AT24Mac::read_serial(void *buf) 00042 { 00043 char offset = AT24MAC_SERIAL_OFFSET; 00044 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) 00045 return -1; //No ACK 00046 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, SERIAL_LEN); 00047 } 00048 00049 int AT24Mac::read_eui64(void *buf) 00050 { 00051 char offset = AT24MAC_EUI64_OFFSET; 00052 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) 00053 return -1; //No ACK 00054 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI64_LEN); 00055 } 00056 00057 int AT24Mac::read_eui48(void *buf) 00058 { 00059 char offset = AT24MAC_EUI48_OFFSET; 00060 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) 00061 return -1; //No ACK 00062 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI48_LEN); 00063 } 00064 00065 #endif /* DEVICE_I2C */
Generated on Tue Aug 9 2022 00:37:02 by
1.7.2