Version of easy-connect with the u-blox cellular platforms C027 and C030 added.
atmel-rf-driver/source/at24mac.cpp@6:304d3ba87a01, 2017-11-03 (annotated)
- Committer:
- RobMeades
- Date:
- Fri Nov 03 13:01:23 2017 +0000
- Revision:
- 6:304d3ba87a01
- Parent:
- 0:19aa55d66228
Add comment concerning N2XX baud rate.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-ublox | 0:19aa55d66228 | 1 | /* |
group-ublox | 0:19aa55d66228 | 2 | * Copyright (c) 2016-2016 ARM Limited. All rights reserved. |
group-ublox | 0:19aa55d66228 | 3 | * SPDX-License-Identifier: Apache-2.0 |
group-ublox | 0:19aa55d66228 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
group-ublox | 0:19aa55d66228 | 5 | * not use this file except in compliance with the License. |
group-ublox | 0:19aa55d66228 | 6 | * You may obtain a copy of the License at |
group-ublox | 0:19aa55d66228 | 7 | * |
group-ublox | 0:19aa55d66228 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
group-ublox | 0:19aa55d66228 | 9 | * |
group-ublox | 0:19aa55d66228 | 10 | * Unless required by applicable law or agreed to in writing, software |
group-ublox | 0:19aa55d66228 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
group-ublox | 0:19aa55d66228 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
group-ublox | 0:19aa55d66228 | 13 | * See the License for the specific language governing permissions and |
group-ublox | 0:19aa55d66228 | 14 | * limitations under the License. |
group-ublox | 0:19aa55d66228 | 15 | */ |
group-ublox | 0:19aa55d66228 | 16 | #include "at24mac.h" |
group-ublox | 0:19aa55d66228 | 17 | |
group-ublox | 0:19aa55d66228 | 18 | /* Device addressing */ |
group-ublox | 0:19aa55d66228 | 19 | #define AT24MAC_EEPROM_ADDRESS (0x0A<<4) |
group-ublox | 0:19aa55d66228 | 20 | #define AT24MAC_RW_PROTECT_ADDRESS (0x06<<4) |
group-ublox | 0:19aa55d66228 | 21 | #define AT24MAC_SERIAL_ADDRESS (0x0B<<4) |
group-ublox | 0:19aa55d66228 | 22 | |
group-ublox | 0:19aa55d66228 | 23 | /* Known memory blocks */ |
group-ublox | 0:19aa55d66228 | 24 | #define AT24MAC_SERIAL_OFFSET (0x80) |
group-ublox | 0:19aa55d66228 | 25 | #define AT24MAC_EUI64_OFFSET (0x98) |
group-ublox | 0:19aa55d66228 | 26 | #define AT24MAC_EUI48_OFFSET (0x9A) |
group-ublox | 0:19aa55d66228 | 27 | |
group-ublox | 0:19aa55d66228 | 28 | #define SERIAL_LEN 16 |
group-ublox | 0:19aa55d66228 | 29 | #define EUI64_LEN 8 |
group-ublox | 0:19aa55d66228 | 30 | #define EUI48_LEN 6 |
group-ublox | 0:19aa55d66228 | 31 | |
group-ublox | 0:19aa55d66228 | 32 | AT24Mac::I2CReset::I2CReset(PinName sda, PinName scl) |
group-ublox | 0:19aa55d66228 | 33 | { |
group-ublox | 0:19aa55d66228 | 34 | mbed::DigitalInOut SDA(sda, PIN_OUTPUT, PullUp, 1); |
group-ublox | 0:19aa55d66228 | 35 | mbed::DigitalInOut SCL(scl, PIN_OUTPUT, PullUp, 0); |
group-ublox | 0:19aa55d66228 | 36 | //generate 9 clocks for worst-case scenario |
group-ublox | 0:19aa55d66228 | 37 | for (int i = 0; i < 10; ++i) { |
group-ublox | 0:19aa55d66228 | 38 | SCL = 1; |
group-ublox | 0:19aa55d66228 | 39 | wait_us(5); |
group-ublox | 0:19aa55d66228 | 40 | SCL = 0; |
group-ublox | 0:19aa55d66228 | 41 | wait_us(5); |
group-ublox | 0:19aa55d66228 | 42 | } |
group-ublox | 0:19aa55d66228 | 43 | //generate a STOP condition |
group-ublox | 0:19aa55d66228 | 44 | SDA = 0; |
group-ublox | 0:19aa55d66228 | 45 | wait_us(5); |
group-ublox | 0:19aa55d66228 | 46 | SCL = 1; |
group-ublox | 0:19aa55d66228 | 47 | wait_us(5); |
group-ublox | 0:19aa55d66228 | 48 | SDA = 1; |
group-ublox | 0:19aa55d66228 | 49 | wait_us(5); |
group-ublox | 0:19aa55d66228 | 50 | } |
group-ublox | 0:19aa55d66228 | 51 | |
group-ublox | 0:19aa55d66228 | 52 | /*I2C needs to be reset before constructing the I2C object (in case I2C is stuck) |
group-ublox | 0:19aa55d66228 | 53 | because they use the same pins, therefore i2c_reset has to be before _i2c |
group-ublox | 0:19aa55d66228 | 54 | in the initializer list*/ |
group-ublox | 0:19aa55d66228 | 55 | AT24Mac::AT24Mac(PinName sda, PinName scl) : i2c_reset(sda, scl), _i2c(sda, scl) |
group-ublox | 0:19aa55d66228 | 56 | { |
group-ublox | 0:19aa55d66228 | 57 | // Do nothing |
group-ublox | 0:19aa55d66228 | 58 | } |
group-ublox | 0:19aa55d66228 | 59 | |
group-ublox | 0:19aa55d66228 | 60 | int AT24Mac::read_serial(void *buf) |
group-ublox | 0:19aa55d66228 | 61 | { |
group-ublox | 0:19aa55d66228 | 62 | char offset = AT24MAC_SERIAL_OFFSET; |
group-ublox | 0:19aa55d66228 | 63 | if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) |
group-ublox | 0:19aa55d66228 | 64 | return -1; //No ACK |
group-ublox | 0:19aa55d66228 | 65 | return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, SERIAL_LEN); |
group-ublox | 0:19aa55d66228 | 66 | } |
group-ublox | 0:19aa55d66228 | 67 | |
group-ublox | 0:19aa55d66228 | 68 | int AT24Mac::read_eui64(void *buf) |
group-ublox | 0:19aa55d66228 | 69 | { |
group-ublox | 0:19aa55d66228 | 70 | char offset = AT24MAC_EUI64_OFFSET; |
group-ublox | 0:19aa55d66228 | 71 | if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) |
group-ublox | 0:19aa55d66228 | 72 | return -1; //No ACK |
group-ublox | 0:19aa55d66228 | 73 | return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI64_LEN); |
group-ublox | 0:19aa55d66228 | 74 | } |
group-ublox | 0:19aa55d66228 | 75 | |
group-ublox | 0:19aa55d66228 | 76 | int AT24Mac::read_eui48(void *buf) |
group-ublox | 0:19aa55d66228 | 77 | { |
group-ublox | 0:19aa55d66228 | 78 | char offset = AT24MAC_EUI48_OFFSET; |
group-ublox | 0:19aa55d66228 | 79 | if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true)) |
group-ublox | 0:19aa55d66228 | 80 | return -1; //No ACK |
group-ublox | 0:19aa55d66228 | 81 | return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI48_LEN); |
group-ublox | 0:19aa55d66228 | 82 | } |