我的应用是读取 SPI 上的传感器数据并对其进行广播。 广播后、它应该在设定的时间段内进入睡眠(待机模式)、但只要发生外部硬件中断、它就应该被唤醒。 但我的应用无法退出待机模式。 正如你在代码中看到的,我使用了"sleep()" API,并将其发送到 sleep10秒,但当我尝试把它唤醒早,它不会唤醒。 我还尝试了 "Power_sleep (PowerCC26XX_STANDBY)"但它甚至没有进入睡眠状态。
PIN_Config wakeup_pin[] =
{
IOID_18 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE | PIN_HYSTERESIS,
PIN_TERMINATE /* Terminate list */
};void spi_createTask(void)
{
Display_init();
GPIO_init();
SPI_init();
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = appTaskStack;
taskParams.stackSize = SPI_TASK_STACK_SIZE;
taskParams.priority = SPI_TASK_PRIORITY;
Task_construct(&SPI_task, SPI_taskFunction, &taskParams, NULL);
}void vfnSpiPerformXfers (SPI_Handle masterSpi)
{
uint8_t u8xfer_nb_bytes;
static uint8_t u8Temperature = 0;
static float fPressure = 0;
static float fAccZ = 0;
static float fAccX = 0;
char bleStr[30] = {0};
char tempStr[10] = {0};
Int key;
/* Prepare the Tx buffer for SPI transfers */
u8xfer_nb_bytes = u8SpiFillTxBuffer();
key = HwiP_disable();
/* Launch the SPI transfers - this is a blocking operation */
vfnSpiTriggerXfers(masterSpi, u8xfer_nb_bytes);
HwiP_restore(key);
// key = Hwi_disable();
/* Store sensor data in the application buffer.
Note that the returned status is discarded here, but in a final application it should
be used to check the validity of the data received and do a re-try in case transfers
were not successfully */
if(u8SpiStoreData())
{ key = HwiP_disable();
#if 0
u8Temperature = getTemperatureValue(gSendData.array_data[13]);
fPressure = getPressureValue(gSendData.array_data[6], gSendData.array_data[7]);
fAccZ = getAccelerometerValue(gSendData.array_data[8], gSendData.array_data[9]);
fAccX = getAccelerometerValue(gSendData.array_data[10], gSendData.array_data[11]);
#else
// sleep(30);
u8Temperature = getTemperatureValue(gSendData.array_data[13]);
fPressure = getPressureValue(gSendData.array_data[7], gSendData.array_data[6]);
fAccZ = getAccelerometerValue(gSendData.array_data[9], gSendData.array_data[8]);
fAccX = getAccelerometerValue(gSendData.array_data[11], gSendData.array_data[10]);
#endif
if(u8Temperature >= HIGH_TEMPERATURE_THRESHOLD){
notifyTemperature(NOTIFY_HIGH_TEMPERATURE);
}
else if(u8Temperature <= LOW_TEMPERATURE_THRESHOLD){
notifyTemperature(NOTIFY_LOW_TEMPERATURE);
}
else{
notifyTemperature(NOTIFY_NONE);
}
if(fPressure >= HIGH_PRESSURE_THRESHOLD){
notifyPressure(NOTIFY_HIGH_PRESSURE);
}
else if(fPressure <= LOW_PRESSURE_THRESHOLD){
notifyPressure(NOTIFY_LOW_PRESSURE);
}
else{
notifyPressure(NOTIFY_NONE);
}
memset(tempStr, 0, sizeof(tempStr));
memset(bleStr, 0, sizeof(bleStr));
itoa(u8Temperature, tempStr);
strcat(bleStr, tempStr);
strcat(bleStr, ",");
memset(tempStr, 0, sizeof(tempStr));
ftoa(fPressure, tempStr, 2 );
strcat(bleStr, tempStr);
strcat(bleStr, ",");
memset(tempStr, 0, sizeof(tempStr));
ftoa(fAccX, tempStr, 2 );
strcat(bleStr, tempStr);
strcat(bleStr, ",");
memset(tempStr, 0, sizeof(tempStr));
ftoa(fAccZ, tempStr, 2 );
strcat(bleStr, tempStr);
// PRCMPeripheralSleepEnable(PRCM_PERIPH_GPIO);
// PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_GPIO);
// PRCMLoadSet();
// PINCC26XX_setWakeup(wakeup_pin);
// DataService_SetParameter(DS_STRING_ID, sizeof(bleStr), bleStr);
HwiP_restore(key);
sleep(10);
//Power_sleep( PowerCC26XX_STANDBY);
DataService_SetParameter(DS_STRING_ID, sizeof(bleStr), bleStr);
// PRCMSleep();
}
// Hwi_restore(key);
}void SPI_taskFunction(UArg arg0, UArg arg1)
{
/* Local variables. Variables here go onto task stack!! */
/* Run one-time code when task starts */
SPI_Handle masterSpi;
SPI_Params spiParams;
uint32_t i;
Semaphore_Handle semHandle;
Clock_Handle clockHandle;
int32_t wakeuppincurrent = 0;
int32_t wakeuppinprevious = 0;
semHandle = setupTimer(&clockHandle, 1000); // 1 Second delay
if (semHandle == NULL) {
while (1);
}
hPin_wakeup = PIN_open(&pinState_wakeup, wakeup_pin);
// Register ISR
PIN_registerIntCb(hPin_wakeup, buttonHwiFxn);
// Configure interrupt
PIN_setConfig(hPin_wakeup, PIN_BM_IRQ, IOID_18 | PIN_IRQ_NEGEDGE);
// Enable wakeup
PIN_setConfig(hPin_wakeup, PINCC26XX_BM_WAKEUP, IOID_18|PINCC26XX_WAKEUP_NEGEDGE);
while(1)
{
hPin_wakeup = PIN_open(&pinState_wakeup, wakeup_pin);
//KBI high
hPin_kbi = PIN_open(&pinState_kbi, kbi_pin_table);
PIN_setOutputValue(hPin_kbi, IOID_9, 1);
while(1)
{
wakeuppincurrent = PIN_getInputValue(IOID_18);
if(wakeuppincurrent != wakeuppinprevious)
{
// status change of wake up pin changes
wakeuppinprevious = wakeuppincurrent;
if(wakeuppincurrent == 1)
{
int i = 0;
for( i = 0; i<100; i++)
{
PIN_setOutputValue(hPin_kbi, IOID_9, 1);
PIN_setOutputValue(hPin_kbi, IOID_9, 0);
}
//wait for KBI acknowledge(slave will drive wake up pin to low)
while(PIN_getInputValue(IOID_18) == 1)
{
}
break;
}
}
}
PIN_remove(hPin_kbi, IOID_9);
/* Open SPI as master (default) */
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.bitRate = 1000000 ;
spiParams.dataSize = 16;
spiParams.mode = SPI_MASTER;
masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
if (masterSpi == NULL) {
Display_printf(display, 0, 0, "Error initializing master SPI\n");
while (1);
}
else {
Display_printf(display, 0, 0, "Master SPI initialized\n");
}
for (i=0; i < SPI_MSG_LENGTH; i++)
memmove((void *)masterTxBuffer+i, (const void *)masterTxBuffer1+i, 1);
if (1) {
vfnSpiPerformXfers(masterSpi);
}
SPI_close(masterSpi);
Display_printf(display, 0, 0, "\nDone");
/*
* Block until the timer posts the semaphore.
* Since it is waiting forever, no need to check the return code.
*/
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
}
}