Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12 from DimiL/b2g
Browse files Browse the repository at this point in the history
Bug 934835 - B2G NFC: NFC Daemon crash sometimes when enabled
  • Loading branch information
allstarschh committed Jan 13, 2014
2 parents 9eb872c + 4dcc4dc commit f995ccd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/broadcom/NfcManager.cpp
Expand Up @@ -175,11 +175,7 @@ bool NfcManager::initialize()

TheEnd:
if (sIsNfaEnabled) {
// TODO : remove this temporarily.
// It cause enable crash becase this will close NFC and if at the same time
// we get enable callback and do enable NFC accordingly. This may cause exception
// some times.
//PowerSwitch::getInstance().setLevel(PowerSwitch::LOW_POWER);
PowerSwitch::getInstance().setLevel(PowerSwitch::LOW_POWER);
}

return sIsNfaEnabled;
Expand Down
28 changes: 28 additions & 0 deletions src/broadcom/PowerSwitch.cpp
Expand Up @@ -13,6 +13,25 @@
#define LOG_TAG "BroadcomNfc"
#include <cutils/log.h>

// Bug 934835 : B2G NFC: NFC Daemon crash sometimes when enabled
// Set a delay between power off and power on,because libnfc-nci will crash if
// turn off then turn on immediatelly.
// 500 millis-seconds is experiment result.
#define PowerOnOffDelay 500 // milli-seconds.

static UINT32 TimeDiff(timespec start, timespec end)
{
timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) {
temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else {
temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
}
return (temp.tv_sec * 1000) + (temp.tv_nsec / 1000000);
}

void doStartupConfig();

PowerSwitch PowerSwitch::sPowerSwitch;
Expand All @@ -26,6 +45,7 @@ PowerSwitch::PowerSwitch()
, mDesiredScreenOffPowerState(0)
, mCurrActivity(0)
{
mLastPowerOffTime = (struct timespec){0, 0};
}

PowerSwitch::~PowerSwitch()
Expand Down Expand Up @@ -146,6 +166,7 @@ bool PowerSwitch::setPowerOffSleepState(bool sleep)
if (stat == NFA_STATUS_OK) {
mPowerStateEvent.wait();
mCurrLevel = LOW_POWER;
clock_gettime(CLOCK_REALTIME, &mLastPowerOffTime);
} else {
ALOGE("%s: API fail; stat=0x%X", __FUNCTION__, stat);
goto TheEnd;
Expand All @@ -162,6 +183,13 @@ bool PowerSwitch::setPowerOffSleepState(bool sleep)
SyncEventGuard guard(mPowerStateEvent);

ALOGD("%s: try full power", __FUNCTION__);

struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
int timediff = TimeDiff(mLastPowerOffTime, now);
if (timediff < PowerOnOffDelay) {
usleep((PowerOnOffDelay -timediff) * 1000);
}
stat = NFA_PowerOffSleepMode(FALSE);
if (stat == NFA_STATUS_OK) {
mPowerStateEvent.wait();
Expand Down
2 changes: 2 additions & 0 deletions src/broadcom/PowerSwitch.h
Expand Up @@ -5,6 +5,7 @@
#pragma once
#include "nfa_api.h"
#include "SyncEvent.h"
#include "sys/time.h"

/**
* Adjust the controller's power states.
Expand Down Expand Up @@ -181,4 +182,5 @@ class PowerSwitch
SyncEvent mPowerStateEvent;
PowerActivity mCurrActivity;
Mutex mMutex;
struct timespec mLastPowerOffTime;
};

0 comments on commit f995ccd

Please sign in to comment.