3131#include "peripheral/eth/plib_eth.h"
3232
3333static uint8_t kUIDArray [UID_LENGTH ];
34+ static const uint32_t MICROCHIP_OID1 = 0x00001ec0 ;
35+ static const uint32_t MICROCHIP_OID2 = 0x00d88039 ;
3436
3537inline uint8_t ShiftRight (uint8_t b ) {
3638 return (b >> 4 ) & 0x0f ;
@@ -42,23 +44,49 @@ inline uint8_t ShiftLeft(uint8_t b) {
4244
4345void UIDStore_Init () {
4446 // The UID is derived from the RDM manufacturer ID & the MAC address.
45- // The first 3 bytes of the MAC address is the Microchip OID 00:1e:c0 which
46- // is constant. The bottom 3 bytes contain the unique serial number.
47+ // The first 3 bytes of the MAC address is the Microchip OIDs, which are one
48+ // of 00:1E:C0, 00:04:A3 or D8:80:39. The bottom 3 bytes contain the unique
49+ // serial number.
4750 //
4851 // To support more than one responder per device, we set the lower 4 bits of
4952 // the UID to 0 so we have 16 responders per device. These means the complete
5053 // UID takes the form:
51- // MMMM:1AAAAAA0
52- // Where M is the PLASA manufacturer ID and A are the values from the MAC
53- // address.
54- kUIDArray [0 ] = CFG_MANUFACTURER_ID >> 8 ;
55- kUIDArray [1 ] = CFG_MANUFACTURER_ID & 0xff ;
56- kUIDArray [2 ] = 0x10 + ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 4 ));
57- kUIDArray [3 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 4 )) +
58- ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 5 ));
59- kUIDArray [4 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 5 )) +
60- ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 6 ));
61- kUIDArray [5 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 6 ));
54+ // MMMM:XAAAAAA0
55+ // Where M is the PLASA manufacturer ID, X is derived from the OID and A is
56+ // the values from the MAC address. X is derived from the OID as follows:
57+ //
58+ // 00:1E:C0 -> 1
59+ // D8:80:39 -> 2
60+ uint32_t oid = (PLIB_ETH_StationAddressGet (ETH_ID_0 , 1 ) << 16 ) +
61+ (PLIB_ETH_StationAddressGet (ETH_ID_0 , 2 ) << 8 ) +
62+ PLIB_ETH_StationAddressGet (ETH_ID_0 , 3 );
63+ uint8_t upper_id = 0 ;
64+ if (oid == MICROCHIP_OID1 ) {
65+ upper_id = 0x10 ;
66+ } else if (oid == MICROCHIP_OID2 ) {
67+ upper_id = 0x20 ;
68+ }
69+
70+ if (upper_id ) {
71+ kUIDArray [0 ] = CFG_MANUFACTURER_ID >> 8 ;
72+ kUIDArray [1 ] = CFG_MANUFACTURER_ID & 0xff ;
73+ kUIDArray [2 ] = upper_id +
74+ ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 4 ));
75+ kUIDArray [3 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 4 )) +
76+ ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 5 ));
77+ kUIDArray [4 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 5 )) +
78+ ShiftRight (PLIB_ETH_StationAddressGet (ETH_ID_0 , 6 ));
79+ kUIDArray [5 ] = ShiftLeft (PLIB_ETH_StationAddressGet (ETH_ID_0 , 6 ));
80+ } else {
81+ // If we didn't match the OID, default to the NULL UID to make it obvious
82+ // what happened
83+ kUIDArray [0 ] = 0 ;
84+ kUIDArray [1 ] = 0 ;
85+ kUIDArray [2 ] = 0 ;
86+ kUIDArray [3 ] = 0 ;
87+ kUIDArray [4 ] = 0 ;
88+ kUIDArray [5 ] = 0 ;
89+ }
6290}
6391
6492const uint8_t * const kUID = & kUIDArray [0 ];
0 commit comments