Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers at24mac.cpp Source File

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     }
00047     return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, SERIAL_LEN);
00048 }
00049 
00050 int AT24Mac::read_eui64(void *buf)
00051 {
00052     char offset = AT24MAC_EUI64_OFFSET;
00053     if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) {
00054         return -1;    //No ACK
00055     }
00056     return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, EUI64_LEN);
00057 }
00058 
00059 int AT24Mac::read_eui48(void *buf)
00060 {
00061     char offset = AT24MAC_EUI48_OFFSET;
00062     if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) {
00063         return -1;    //No ACK
00064     }
00065     return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char *)buf, EUI48_LEN);
00066 }
00067 
00068 #endif /* DEVICE_I2C */