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