Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/edbg_eui: add driver to get MAC address from Atmel EDBG #14134

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ ifneq (,$(filter dynamixel,$(USEMODULE)))
USEMODULE += uart_half_duplex
endif

ifneq (,$(filter edbg_eui,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif

ifneq (,$(filter enc28j60,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_gpio_irq
Expand Down
1 change: 1 addition & 0 deletions drivers/edbg_eui/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
53 changes: 53 additions & 0 deletions drivers/edbg_eui/edbg_eui.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 Benjamin Valentin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_edbg_eui
*
* @{
* @file
* @brief Driver for getting a unique ID from the Atmel Embedded Debugger.
*
* @author Benjamin Valentin <[email protected]>
*
* @}
*/

#include "edbg_eui.h"
#include "periph/i2c.h"
#include "net/l2util.h"

#ifndef EDBG_I2C_DEV
#define EDBG_I2C_DEV I2C_DEV(0)
#endif

#define EDBG_ADDR (0x28)
#define TOKEN_EUI64 (0xD2)
#define TOKEN_EXT (0xE1)

int edbg_get_eui64(eui64_t *addr)
{
int res = 0;
i2c_acquire(EDBG_I2C_DEV);

/* dummy read for another token - following edbg user manual, section 4.3.1
* only returns the EUI-64 once, this work-around works reliable though.
*/
if ((res = i2c_read_regs(EDBG_I2C_DEV, EDBG_ADDR, TOKEN_EXT, addr, 2, 0))) {
goto out;
}

/* EDBG provides an EUI-64 for the internal radio */
if ((res = i2c_read_regs(EDBG_I2C_DEV, EDBG_ADDR, TOKEN_EUI64, addr, sizeof(*addr), 0))) {
goto out;
}

out:
i2c_release(EDBG_I2C_DEV);
return res;
}
44 changes: 44 additions & 0 deletions drivers/include/edbg_eui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2020 Benjamin Valentin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup drivers_edbg_eui Driver for getting MAC address out of Atmel EDBG
* @ingroup drivers_misc
* @brief Device driver interface for the AT24MAC I2C chip
* @{
*
* @file
*
* @author Benjamin Valentin <[email protected]>
*/

#ifndef EDBG_EUI_H
#define EDBG_EUI_H

#include <stdint.h>
#include "net/eui64.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Get the unique EUI64 address from a Atmel EDBG debugger
*
* @param[out] addr memory location to copy the address into.
*
* @return 0 on success, error otherwise.
*/
int edbg_get_eui64(eui64_t *addr);

#ifdef __cplusplus
}
#endif

#endif /* EDBG_EUI_H */
/** @} */
8 changes: 8 additions & 0 deletions tests/driver_edbg_eui/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BOARD ?= samr21-xpro
BOARD_WHITELIST = samr21-xpro

include ../Makefile.tests_common

USEMODULE += edbg_eui

include $(RIOTBASE)/Makefile.include
50 changes: 50 additions & 0 deletions tests/driver_edbg_eui/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 Benjamin Valentin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the EDBG EUI driver
*
* @author Benjamin Valentin <[email protected]>
*
* @}
*/

#include <stdio.h>
#include "edbg_eui.h"

static int test_get_eui64(void)
{
eui64_t e64;
if (edbg_get_eui64(&e64) != 0) {
puts("[FAILED]");
return 1;
}

printf("EUI-64:");
for (unsigned i = 0; i < sizeof(e64.uint8); ++i) {
printf(" %02x", e64.uint8[i]);
}
puts("");

return 0;
}

int main(void)
{
if (test_get_eui64()) {
return -1;
}

puts("[SUCCESS]");

return 0;
}