123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "TeensyMAC.h"
- #include <Arduino.h>
- #define MY_SYSREGISTERFILE ((uint8_t *)0x40041000)
- static uint32_t _getserialhw(void) {
- uint32_t num;
- __disable_irq();
- #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
- FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
- FTFL_FCCOB0 = 0x41;
- FTFL_FCCOB1 = 15;
- FTFL_FSTAT = FTFL_FSTAT_CCIF;
- while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ;
- num = *(uint32_t *)&FTFL_FCCOB7;
- #elif defined(HAS_KINETIS_FLASH_FTFE)
-
- FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
- *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
- FTFL_FSTAT = FTFL_FSTAT_CCIF;
- while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ;
- num = *(uint32_t *)&FTFL_FCCOBB;
- #endif
- __enable_irq();
- return num;
- }
- #if defined(HAS_KINETIS_FLASH_FTFE) && (F_CPU > 120000000)
- extern "C" void startup_early_hook(void) {
- #if defined(KINETISK)
- WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
- #elif defined(KINETISL)
- SIM_COPC = 0;
- #endif
- *(uint32_t*)(MY_SYSREGISTERFILE) = _getserialhw();
- }
- uint32_t teensySerial(void) {
- uint32_t num;
- num = *(uint32_t*)(MY_SYSREGISTERFILE);
-
-
- if (num < 10000000) num = num * 10;
- return num;
- }
- uint64_t teensyMAC(void) {
- return 0x04E9E5000000ULL | (*(uint32_t*)(MY_SYSREGISTERFILE));
- }
- #else
- uint32_t teensySerial(void) {
- uint32_t num;
- num = _getserialhw();
-
-
- if (num < 10000000) num = num * 10;
- return num;
- }
- uint64_t teensyMAC(void) {
- return 0x04E9E5000000ULL | _getserialhw();
- }
- #endif
- void teensyMAC(uint8_t *macArray) {
- uint64_t mac = teensyMAC();
- macArray[0] = (uint8_t)((mac >> 40) & 0xFF);
- macArray[1] = (uint8_t)((mac >> 32) & 0xFF);
- macArray[2] = (uint8_t)((mac >> 24) & 0XFF);
- macArray[3] = (uint8_t)((mac >> 16) & 0XFF);
- macArray[4] = (uint8_t)((mac >> 8) & 0XFF);
- macArray[5] = (uint8_t)(mac & 0XFF);
- }
|