diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c index 629e0bef3..c37f98d6c 100644 --- a/examples/platforms/cc2538/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -78,6 +78,8 @@ void enableReceiver(void) { if (!sIsReceiverEnabled) { + otLogInfoPlat("Enabling receiver", NULL); + // flush rxfifo HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; @@ -92,6 +94,8 @@ void disableReceiver(void) { if (sIsReceiverEnabled) { + otLogInfoPlat("Disabling receiver", NULL); + while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE); // flush rxfifo @@ -120,6 +124,8 @@ void setChannel(uint8_t channel) enabled = true; } + otLogInfoPlat("Channel=%d", channel); + HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5; sChannel = channel; @@ -145,6 +151,8 @@ void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid) { (void)aInstance; + otLogInfoPlat("PANID=%X", panid); + HWREG(RFCORE_FFSM_PAN_ID0) = panid & 0xFF; HWREG(RFCORE_FFSM_PAN_ID1) = panid >> 8; } @@ -153,6 +161,9 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address) { (void)aInstance; + otLogInfoPlat("ExtAddr=%X%X%X%X%X%X%X%X", + address[7], address[6], address[5], address[4], address[3], address[2], address[1], address[0]); + for (int i = 0; i < 8; i++) { ((volatile uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = address[i]; @@ -163,6 +174,8 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address) { (void)aInstance; + otLogInfoPlat("ShortAddr=%X", address); + HWREG(RFCORE_FFSM_SHORT_ADDR0) = address & 0xFF; HWREG(RFCORE_FFSM_SHORT_ADDR1) = address >> 8; } @@ -191,6 +204,8 @@ void cc2538RadioInit(void) // default: SRCMATCH.SRC_MATCH_EN(1), SRCMATCH.AUTOPEND(1), // SRCMATCH.PEND_DATAREQ_ONLY(1), RFCORE_XREG_FRMCTRL1_PENDING_OR(0) + + otLogInfoPlat("Initialized", NULL); } bool otPlatRadioIsEnabled(otInstance *aInstance) @@ -203,6 +218,7 @@ ThreadError otPlatRadioEnable(otInstance *aInstance) { if (!otPlatRadioIsEnabled(aInstance)) { + otLogDebgPlat("State=kStateSleep", NULL); sState = kStateSleep; } @@ -213,6 +229,7 @@ ThreadError otPlatRadioDisable(otInstance *aInstance) { if (otPlatRadioIsEnabled(aInstance)) { + otLogDebgPlat("State=kStateDisabled", NULL); sState = kStateDisabled; } @@ -226,6 +243,7 @@ ThreadError otPlatRadioSleep(otInstance *aInstance) if (sState == kStateSleep || sState == kStateReceive) { + otLogDebgPlat("State=kStateSleep", NULL); error = kThreadError_None; sState = kStateSleep; disableReceiver(); @@ -241,6 +259,8 @@ ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) if (sState != kStateDisabled) { + otLogDebgPlat("State=kStateReceive", NULL); + error = kThreadError_None; sState = kStateReceive; setChannel(aChannel); @@ -294,6 +314,8 @@ ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket) HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_TXON; while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE); + + otLogDebgPlat("Transmitted %d bytes", aPacket->mLength); } exit: @@ -328,6 +350,8 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) { (void)aInstance; + otLogInfoPlat("PromiscuousMode=%d", aEnable ? 1 : 0); + if (aEnable) { HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN; @@ -370,6 +394,8 @@ void readFrame(void) // resets rxfifo HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; + + otLogDebgPlat("Dropping %d received bytes (Invalid CRC)", length); } // check for rxfifo overflow @@ -405,7 +431,7 @@ void cc2538RadioProcess(otInstance *aInstance) if (((HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0) || (sReceiveFrame.mLength > IEEE802154_ACK_LENGTH)) { - + otLogDebgPlat("Received %d bytes", sReceiveFrame.mLength); otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError); } } @@ -415,6 +441,11 @@ void cc2538RadioProcess(otInstance *aInstance) { if (sTransmitError != kThreadError_None || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0) { + if (sTransmitError != kThreadError_None) + { + otLogDebgPlat("Transmit failed ErrorCode=%d", sTransmitError); + } + sState = kStateReceive; #if OPENTHREAD_ENABLE_DIAG @@ -573,8 +604,8 @@ int8_t findSrcMatchAvailEntry(bool aShort) uint32_t shortEnableStatus = getSrcMatchEntriesEnableStatus(true); uint32_t extEnableStatus = getSrcMatchEntriesEnableStatus(false); - otLogDebgMac("Short enable status: 0x%x\n", shortEnableStatus); - otLogDebgMac("Ext enable status: 0x%x\n", extEnableStatus); + otLogDebgPlat("Short enable status: 0x%x", shortEnableStatus); + otLogDebgPlat("Ext enable status: 0x%x", extEnableStatus); if (aShort) { @@ -622,6 +653,8 @@ void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) { (void)aInstance; + otLogInfoPlat("EnableSrcMatch=%d", aEnable ? 1 : 0); + if (aEnable) { // only set FramePending when ack for data poll if there are queued messages @@ -642,7 +675,7 @@ ThreadError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16 uint32_t *addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE; (void)aInstance; - otLogDebgMac("Available short address entry: %d\n", entry); + otLogDebgPlat("Add ShortAddr entry: %d", entry); VerifyOrExit(entry >= 0, error = kThreadError_NoBufs); @@ -666,7 +699,7 @@ ThreadError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t uint32_t *addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE; (void)aInstance; - otLogDebgMac("Available extended address entry: %d\n", entry); + otLogDebgPlat("Add ExtAddr entry: %d", entry); VerifyOrExit(entry >= 0, error = kThreadError_NoBufs); @@ -689,7 +722,7 @@ ThreadError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint int8_t entry = findSrcMatchShortEntry(aShortAddress); (void)aInstance; - otLogDebgMac("Found short address entry: %d\n", entry); + otLogDebgPlat("Clear ShortAddr entry: %d", entry); VerifyOrExit(entry >= 0, error = kThreadError_NoAddress); @@ -705,7 +738,7 @@ ThreadError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_ int8_t entry = findSrcMatchExtEntry(aExtAddress); (void)aInstance; - otLogDebgMac("Found ext address entry: %d\n", entry); + otLogDebgPlat("Clear ExtAddr entry: %d", entry); VerifyOrExit(entry >= 0, error = kThreadError_NoAddress); @@ -721,6 +754,8 @@ void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance) uint32_t *addrAutoPendEn = (uint32_t *)RFCORE_FFSM_SRCSHORTPENDEN0; (void)aInstance; + otLogDebgPlat("Clear ShortAddr entries", NULL); + for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE; i++) { HWREG(addrEn++) = 0; @@ -734,6 +769,8 @@ void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance) uint32_t *addrAutoPendEn = (uint32_t *)RFCORE_FFSM_SRCEXTPENDEN0; (void)aInstance; + otLogDebgPlat("Clear ExtAddr entries", NULL); + for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE; i++) { HWREG(addrEn++) = 0; diff --git a/examples/platforms/posix/logging.c b/examples/platforms/posix/logging.c index d8165804d..7d234fd47 100644 --- a/examples/platforms/posix/logging.c +++ b/examples/platforms/posix/logging.c @@ -129,6 +129,10 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat case kLogRegionNetDiag: LOG_PRINTF("NDG "); + break; + + case kLogRegionPlatform: + LOG_PRINTF("PLAT "); } va_start(args, aFormat); diff --git a/include/platform/logging.h b/include/platform/logging.h index dcb936467..90d90db96 100644 --- a/include/platform/logging.h +++ b/include/platform/logging.h @@ -88,6 +88,7 @@ typedef enum otLogRegion kLogRegionNcp = 9, ///< NCP kLogRegionMeshCoP = 10, ///< Mesh Commissioning Protocol kLogRegionNetDiag = 11, ///< Network Diagnostic + kLogRegionPlatform = 12, ///< Platform } otLogRegion; /** diff --git a/src/core/common/logging.cpp b/src/core/common/logging.cpp index b71d2c01c..4e01310be 100644 --- a/src/core/common/logging.cpp +++ b/src/core/common/logging.cpp @@ -199,6 +199,10 @@ const char *otLogRegionToString(otLogRegion aRegion) retval = "-DIAG----"; break; + case kLogRegionPlatform: + retval = "-PLAT----"; + break; + default: retval = "---------"; break; diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index 51a8ccbb9..5672407b2 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -278,7 +278,7 @@ extern "C" { #ifdef OPENTHREAD_CONFIG_LOG_MLE #define otLogCritMle(aFormat, ...) otLogCrit(kLogRegionMle, aFormat, ## __VA_ARGS__) #define otLogWarnMle(aFormat, ...) otLogWarn(kLogRegionMle, aFormat, ## __VA_ARGS__) -#define otLogWarnMleErr(aError, aFormat, ...) otLogWarn(kLogRegionMle, aFormat ", 0x%x\n", ## __VA_ARGS__) +#define otLogWarnMleErr(aError, aFormat, ...) otLogWarn(kLogRegionMle, aFormat ", 0x%x", ## __VA_ARGS__) #define otLogInfoMle(aFormat, ...) otLogInfo(kLogRegionMle, aFormat, ## __VA_ARGS__) #define otLogDebgMle(aFormat, ...) otLogDebg(kLogRegionMle, aFormat, ## __VA_ARGS__) #else @@ -537,7 +537,7 @@ extern "C" { #define otLogWarnMac(aFormat, ...) otLogWarn(kLogRegionMac, aFormat, ## __VA_ARGS__) #define otLogInfoMac(aFormat, ...) otLogInfo(kLogRegionMac, aFormat, ## __VA_ARGS__) #define otLogDebgMac(aFormat, ...) otLogDebg(kLogRegionMac, aFormat, ## __VA_ARGS__) -#define otLogDebgMacErr(aError, aFormat, ...) otLogWarn(kLogRegionMac, aFormat ", 0x%x\n", ## __VA_ARGS__) +#define otLogDebgMacErr(aError, aFormat, ...) otLogWarn(kLogRegionMac, aFormat ", 0x%x", ## __VA_ARGS__) #else #define otLogCritMac(aFormat, ...) #define otLogWarnMac(aFormat, ...) @@ -663,6 +663,57 @@ extern "C" { #define otLogCertMeshCoP(aFormat, ...) #endif +/** +* @def otLogCritPlat +* +* This method generates a log with level critical for the Platform region. +* +* @param[in] aFormat A pointer to the format string. +* @param[in] ... Arguments for the format specification. +* +*/ + +/** +* @def otLogWarnPlat +* +* This method generates a log with level warning for the Platform region. +* +* @param[in] aFormat A pointer to the format string. +* @param[in] ... Arguments for the format specification. +* +*/ + +/** +* @def otLogInfoPlat +* +* This method generates a log with level info for the Platform region. +* +* @param[in] aFormat A pointer to the format string. +* @param[in] ... Arguments for the format specification. +* +*/ + +/** +* @def otLogDebgPlat +* +* This method generates a log with level debug for the Platform region. +* +* @param[in] aFormat A pointer to the format string. +* @param[in] ... Arguments for the format specification. +* +*/ +#ifdef OPENTHREAD_CONFIG_LOG_PLATFORM +#define otLogCritPlat(aFormat, ...) otLogCrit(kLogRegionPlatform, aFormat, ## __VA_ARGS__) +#define otLogWarnPlat(aFormat, ...) otLogWarn(kLogRegionPlatform, aFormat, ## __VA_ARGS__) +#define otLogInfoPlat(aFormat, ...) otLogInfo(kLogRegionPlatform, aFormat, ## __VA_ARGS__) +#define otLogDebgPlat(aFormat, ...) otLogDebg(kLogRegionPlatform, aFormat, ## __VA_ARGS__) +#else +#define otLogCritPlat(aFormat, ...) +#define otLogWarnPlat(aFormat, ...) +#define otLogInfoPlat(aFormat, ...) +#define otLogDebgPlat(aFormat, ...) +#endif + #endif // WINDOWS_LOGGING /** diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index 272a7ad69..fdb250fef 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -381,6 +381,14 @@ */ #define OPENTHREAD_CONFIG_LOG_NETDIAG +/** +* @def OPENTHREAD_CONFIG_LOG_PLATFORM +* +* Define to enable platform region logging. +* +*/ +//#define OPENTHREAD_CONFIG_LOG_PLATFORM + /** * @def OPENTHREAD_CONFIG_LOG_PREPREND_REGION *