Skip to content

NXP: Enable MBED_TICKLESS on various NXP platforms #10796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 22, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_power_mgmt.h"
#include "common_functions.h"
#include "platform/arm_hal_interrupt.h"
#include "platform/arm_hal_phy.h"
Expand Down Expand Up @@ -87,8 +88,9 @@ static uint8_t MAC64_addr[8];

static xcvrState_t mPhySeqState;
static uint8_t rf_mac_handle;
volatile uint8_t rf_ed_value = 0;
static bool rf_ack_pending_state = false;
static volatile uint8_t rf_ed_value = 0;
static volatile bool rf_ack_pending_state = false;
static volatile bool sleep_blocked = false;

static NanostackRfPhyKw41z *rf = NULL;

Expand Down Expand Up @@ -155,6 +157,11 @@ static int8_t rf_device_register(void)
static void rf_device_unregister(void)
{
arm_net_phy_unregister(rf_radio_driver_id);

if (sleep_blocked) {
sleep_manager_unlock_deep_sleep();
sleep_blocked = false;
}
}

/*
Expand Down Expand Up @@ -209,23 +216,41 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
/*Reset PHY driver and set to idle*/
case PHY_INTERFACE_RESET:
rf_abort();
if (sleep_blocked) {
sleep_manager_unlock_deep_sleep();
sleep_blocked = false;
}
break;
/*Disable PHY Interface driver*/
case PHY_INTERFACE_DOWN:
rf_abort();
if (sleep_blocked) {
sleep_manager_unlock_deep_sleep();
sleep_blocked = false;
}
break;
/*Enable PHY Interface driver*/
case PHY_INTERFACE_UP:
if (PhyPlmeSetCurrentChannelRequest(rf_channel, 0)) {
return 1;
}
if (!sleep_blocked) {
/* Disable enter to deep sleep when transfer active */
sleep_manager_lock_deep_sleep();
sleep_blocked = true;
}
rf_receive();
break;
/*Enable wireless interface ED scan mode*/
case PHY_INTERFACE_RX_ENERGY_STATE:
if (PhyPlmeSetCurrentChannelRequest(rf_channel, 0)) {
return 1;
}
if (!sleep_blocked) {
/* Disable enter to deep sleep when transfer active */
sleep_manager_lock_deep_sleep();
sleep_blocked = true;
}
rf_abort();
rf_mac_ed_state_enable();
break;
Expand All @@ -234,6 +259,11 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
if (PhyPlmeSetCurrentChannelRequest(rf_channel, 0)) {
return 1;
}
if (!sleep_blocked) {
/* Disable enter to deep sleep when transfer active */
sleep_manager_lock_deep_sleep();
sleep_blocked = true;
}
rf_receive();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "kinetis_emac_config.h"
#include "kinetis_emac.h"
#include "mbed_power_mgmt.h"

enet_handle_t g_handle;
// TX Buffer descriptors
Expand Down Expand Up @@ -496,6 +497,9 @@ bool Kinetis_EMAC::power_up()
return false;
}

// Can't enter deep sleep as long as Ethernet is active
sleep_manager_lock_deep_sleep();

/* Worker thread */
thread = create_new_thread("Kinetis_EMAC_thread", &Kinetis_EMAC::thread_function, this, THREAD_STACKSIZE, THREAD_PRIORITY, &thread_cb);

Expand Down Expand Up @@ -580,7 +584,8 @@ void Kinetis_EMAC::set_all_multicast(bool all)

void Kinetis_EMAC::power_down()
{
/* No-op at this stage */
// Ethernet went down, can enter deep sleep
sleep_manager_unlock_deep_sleep();
}

void Kinetis_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "imx_emac_config.h"
#include "imx_emac.h"
#include "mbed_power_mgmt.h"

enet_handle_t g_handle;
// RX packet buffer pointers
Expand Down Expand Up @@ -500,6 +501,9 @@ bool Kinetis_EMAC::power_up()
return false;
}

// Can't enter deep sleep as long as Ethernet is active
sleep_manager_lock_deep_sleep();

/* Worker thread */
thread = create_new_thread("Kinetis_EMAC_thread", &Kinetis_EMAC::thread_function, this, THREAD_STACKSIZE, THREAD_PRIORITY, &thread_cb);

Expand Down Expand Up @@ -584,7 +588,8 @@ void Kinetis_EMAC::set_all_multicast(bool all)

void Kinetis_EMAC::power_down()
{
/* No-op at this stage */
// Ethernet went down, can enter deep sleep
sleep_manager_unlock_deep_sleep();
}

void Kinetis_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
Expand Down
Loading