Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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