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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
at24mac_s2lp.cpp
00001 /* 00002 * Copyright (c) 2019-2019 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 "NanostackRfPhys2lp.h" 00017 #include "at24mac_s2lp.h" 00018 00019 00020 #if DEVICE_I2C 00021 #ifdef AT24MAC 00022 00023 /* Device addressing */ 00024 #define AT24MAC_EEPROM_ADDRESS (0x0A<<4) 00025 #define AT24MAC_RW_PROTECT_ADDRESS (0x06<<4) 00026 #define AT24MAC_SERIAL_ADDRESS (0x0B<<4) 00027 00028 /* Known memory blocks */ 00029 #define AT24MAC_SERIAL_OFFSET (0x80) 00030 #define AT24MAC_EUI64_OFFSET (0x98) 00031 #define AT24MAC_EUI48_OFFSET (0x9A) 00032 00033 #define SERIAL_LEN 16 00034 #define EUI64_LEN 8 00035 #define EUI48_LEN 6 00036 00037 using namespace mbed; 00038 00039 AT24Mac_s2lp::AT24Mac_s2lp(PinName sda, PinName scl) : _i2c(sda, scl) 00040 { 00041 // Do nothing 00042 } 00043 00044 int AT24Mac_s2lp::read_serial(void *buf) 00045 { 00046 char offset = AT24MAC_SERIAL_OFFSET; 00047 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) { 00048 return -1; //No ACK 00049 } 00050 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, SERIAL_LEN); 00051 } 00052 00053 int AT24Mac_s2lp::read_eui64(void *buf) 00054 { 00055 char offset = AT24MAC_EUI64_OFFSET; 00056 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) { 00057 return -1; //No ACK 00058 } 00059 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, EUI64_LEN); 00060 } 00061 00062 int AT24Mac_s2lp::read_eui48(void *buf) 00063 { 00064 char offset = AT24MAC_EUI48_OFFSET; 00065 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) { 00066 return -1; //No ACK 00067 } 00068 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, EUI48_LEN); 00069 } 00070 00071 #endif /* AT24MAC */ 00072 #endif /* DEVICE_I2C */
Generated on Tue Jul 12 2022 13:54:01 by
