1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gnrc_lwmac: enable duty-cycle printing.

This commit is contained in:
shuguo 2018-04-13 09:34:00 +08:00 committed by shuguo
parent d3f8739a1e
commit 4a4e552cca
3 changed files with 13 additions and 20 deletions

View File

@ -90,14 +90,6 @@ extern "C" {
*/
#define GNRC_LWMAC_RADIO_IS_ON (0x04)
/**
* @brief Enable/disable duty-cycle record and print out.
* Set "1" to enable, set "0" to disable.
*/
#ifndef GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD
#define GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD (0U)
#endif
/**
* @brief The default largest number of parallel timeouts in LWMAC
*/
@ -204,7 +196,7 @@ typedef struct lwmac {
uint8_t lwmac_info; /**< LWMAC's internal informations (flags) */
gnrc_lwmac_timeout_t timeouts[GNRC_LWMAC_TIMEOUT_COUNT]; /**< Store timeouts used for protocol */
#if (GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD == 1)
#if (GNRC_MAC_ENABLE_DUTYCYCLE_RECORD == 1)
/* Parameters for recording duty-cycle */
uint32_t last_radio_on_time_ticks; /**< The last time in ticks when radio is on */
uint32_t radio_off_time_ticks; /**< The time in ticks when radio is off */

View File

@ -266,14 +266,6 @@ void lwmac_set_state(gnrc_netif_t *netif, gnrc_lwmac_state_t newstate)
case GNRC_LWMAC_TRANSMITTING: {
/* Enable duty cycling again */
rtt_handler(GNRC_LWMAC_EVENT_RTT_RESUME, netif);
#if (GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD == 1)
/* Output duty-cycle ratio */
uint64_t duty;
duty = (uint64_t) rtt_get_counter();
duty = ((uint64_t) netif->mac.prot.lwmac.awake_duration_sum_ticks) * 100 /
(duty - (uint64_t)netif->mac.prot.lwmac.system_start_time_ticks);
printf("[LWMAC]: achieved duty-cycle: %lu %% \n", (uint32_t)duty);
#endif
break;
}
case GNRC_LWMAC_SLEEPING: {
@ -880,7 +872,16 @@ static void _lwmac_msg_handler(gnrc_netif_t *netif, msg_t *msg)
lwmac_schedule_update(netif);
break;
}
#if (GNRC_MAC_ENABLE_DUTYCYCLE_RECORD == 1)
case GNRC_MAC_TYPE_GET_DUTYCYCLE: {
/* Output LWMAC's radio duty-cycle ratio */
uint64_t duty = (uint64_t) rtt_get_counter();
duty = ((uint64_t) netif->mac.prot.lwmac.awake_duration_sum_ticks) * 100 /
(duty - (uint64_t)netif->mac.prot.lwmac.system_start_time_ticks);
printf("[LWMAC]: achieved radio duty-cycle: %u %% \n", (unsigned) duty);
break;
}
#endif
default: {
#if ENABLE_DEBUG
DEBUG("[LWMAC]: unknown message type 0x%04x"
@ -933,7 +934,7 @@ static void _lwmac_init(gnrc_netif_t *netif)
/* Start duty cycling */
lwmac_set_state(netif, GNRC_LWMAC_START);
#if (GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD == 1)
#if (GNRC_MAC_ENABLE_DUTYCYCLE_RECORD == 1)
/* Start duty cycle recording */
netif->mac.prot.lwmac.system_start_time_ticks = rtt_get_counter();
netif->mac.prot.lwmac.last_radio_on_time_ticks = netif->mac.prot.lwmac.system_start_time_ticks;

View File

@ -191,7 +191,7 @@ void _gnrc_lwmac_set_netdev_state(gnrc_netif_t *netif, netopt_state_t devstate)
&devstate,
sizeof(devstate));
#if (GNRC_LWMAC_ENABLE_DUTYCYLE_RECORD == 1)
#if (GNRC_MAC_ENABLE_DUTYCYCLE_RECORD == 1)
if (devstate == NETOPT_STATE_IDLE) {
if (!(netif->mac.prot.lwmac.lwmac_info & GNRC_LWMAC_RADIO_IS_ON)) {
netif->mac.prot.lwmac.last_radio_on_time_ticks = rtt_get_counter();