Skip to content

Commit

Permalink
Added mbed_mac_address
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas.larsson committed Sep 16, 2016
1 parent 0e5a0d6 commit eacccdd
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
#include <string.h>
#include "stm32f4xx_hal.h"

#define C029_OTP_START_ADDRESS (0x1FFF7800U)
#define C029_OTP_END_ADDRESS (C029_OTP_START_ADDRESS + (16*32))
#define C029_MAC_ETHERNET_ID (3)

typedef struct C029_OTP_Header {
uint8_t id;
uint8_t len;
uint8_t data[];
} __attribute__((__packed__)) C029_OTP_Header;

static int _macRetrieved = 0;
static char _macAddr[6] = { 0x02, 0x02, 0xF7, 0xF0, 0x00, 0x00 };

static C029_OTP_Header *increment(C029_OTP_Header *pTemp)
{
uint8_t len = 0;
uint8_t id = 0;
uint8_t *p = (uint8_t*)pTemp;

memcpy((void*)&id, (void*)pTemp, 1);

if (id == 0xFF){
p++;
}
else {
p++;
memcpy((void*)&len, (void*)p++, 1);
p += len;
}
return (C029_OTP_Header*)p;
}

/**
* Override HAL Eth Init function
*/
Expand Down Expand Up @@ -83,4 +116,27 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
/* Disable the Ethernet global Interrupt */
NVIC_DisableIRQ(ETH_IRQn);
}
}

void mbed_mac_address(char *mac)
{
C029_OTP_Header *pFound = NULL;
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
C029_OTP_Header temp;

if (_macRetrieved == 0) {
while ((pTemp >= (C029_OTP_Header*)C029_OTP_START_ADDRESS) && (pTemp < (C029_OTP_Header*)C029_OTP_END_ADDRESS)){
memcpy((void*)&temp, (void*)pTemp, sizeof(temp));
if (temp.id == C029_MAC_ETHERNET_ID){
pFound = pTemp;
break;
}
pTemp = increment(pTemp);
}
if (pFound != NULL) {
memcpy(_macAddr, pFound->data, 6);
_macRetrieved = 1;
}
}
memcpy(mac, _macAddr, 6);
}

0 comments on commit eacccdd

Please sign in to comment.