|
43 | 43 | // |
44 | 44 | // This parameter thus only specifies how quickly the modem can go to sleep, |
45 | 45 | // which we want to be as low as possible. |
46 | | -#define PSM_DEFAULT_AWAKE_PARAMETER "00000001" |
47 | | -#define PSM_DEFAULT_AWAKE_TIME 2 |
| 46 | +// |
| 47 | +// This is 10 seconds |
| 48 | +#define PSM_DEFAULT_AWAKE_PARAMETER "00000101" |
48 | 49 |
|
49 | 50 | #define PSM_REMAINING_SLEEP_TIME_THRESHOLD 5 |
50 | 51 |
|
@@ -79,6 +80,7 @@ static volatile bool pit_triggered = false; |
79 | 80 | static SleepMode sleep_mode; |
80 | 81 | static bool retrieved_sleep_time = false; |
81 | 82 | static uint32_t sleep_time = 0; |
| 83 | +static uint32_t sleep_time_requested = 0; |
82 | 84 |
|
83 | 85 | static uint8_t cell_led_state = 0; |
84 | 86 | static uint8_t con_led_state = 0; |
@@ -333,12 +335,24 @@ static WakeUpReason regularSleep(void) { |
333 | 335 | sleep_time = retrieveOperatorSleepTime(); |
334 | 336 |
|
335 | 337 | if (sleep_time == 0) { |
336 | | - Log.debugf("Got invalid sleep time: %d\r\n", sleep_time); |
| 338 | + Log.debugf("Got invalid sleep time from operator: %d\r\n", |
| 339 | + sleep_time); |
337 | 340 | return WakeUpReason::INVALID_SLEEP_TIME; |
338 | 341 | } else { |
339 | | - Log.debugf("Sleep time set to: %d seconds\r\n", sleep_time); |
| 342 | + if (sleep_time_requested != sleep_time) { |
| 343 | + Log.warnf("Operator was not able to match the requested sleep " |
| 344 | + "time of %d seconds. ", |
| 345 | + sleep_time_requested); |
| 346 | + Log.rawf("Operator sat the sleep time to %d seconds.\r\n", |
| 347 | + sleep_time); |
| 348 | + } |
| 349 | + |
340 | 350 | retrieved_sleep_time = true; |
341 | 351 | } |
| 352 | + |
| 353 | + // Retrieving the operator sleep time will call CEREG, which will |
| 354 | + // trigger led ctrl, so we just disable it again. |
| 355 | + LedCtrl.off(Led::CELL, true); |
342 | 356 | } |
343 | 357 |
|
344 | 358 | // The timeout here is arbitrary as we attempt to put the modem in sleep in |
@@ -370,28 +384,38 @@ static WakeUpReason regularSleep(void) { |
370 | 384 |
|
371 | 385 | sleep_cpu(); |
372 | 386 |
|
373 | | - // Woken up by some external interrupt |
374 | | - if (!pit_triggered && modem_is_in_power_save) { |
375 | | - wakeup_reason = WakeUpReason::EXTERNAL_INTERRUPT; |
376 | | - break; |
377 | | - } |
378 | | - |
379 | 387 | // Got woken up by the PIT interrupt |
380 | 388 | if (pit_triggered) { |
381 | 389 | remaining_time_seconds -= 1; |
382 | | - pit_triggered = false; |
383 | 390 | } |
384 | 391 |
|
385 | | - // Modem caused the CPU to be awoken |
386 | | - if (!modem_is_in_power_save) { |
| 392 | + // If we are within the threshold, we assume that the awake was from the |
| 393 | + // modem |
| 394 | + if (remaining_time_seconds < PSM_REMAINING_SLEEP_TIME_THRESHOLD) { |
| 395 | + wakeup_reason = WakeUpReason::OK; |
| 396 | + break; |
387 | 397 |
|
388 | | - if (remaining_time_seconds < PSM_REMAINING_SLEEP_TIME_THRESHOLD) { |
389 | | - wakeup_reason = WakeUpReason::OK; |
390 | | - break; |
391 | | - } else { |
392 | | - wakeup_reason = WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY; |
393 | | - break; |
394 | | - } |
| 398 | + } |
| 399 | + // If modem is already awake and the remaining time was not within |
| 400 | + // the threshold, the modem has woken the CPU up prematurely to do |
| 401 | + // some work |
| 402 | + else if (!pit_triggered && !modem_is_in_power_save) { |
| 403 | + wakeup_reason = WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY; |
| 404 | + break; |
| 405 | + } |
| 406 | + // If we are not within the remaining sleep time threshold, the modem |
| 407 | + // did not wake the CPU up, neither the PIT, the reason for wake up is |
| 408 | + // bound to be by some external interrupt. |
| 409 | + else if (!pit_triggered) { |
| 410 | + wakeup_reason = WakeUpReason::EXTERNAL_INTERRUPT; |
| 411 | + break; |
| 412 | + } |
| 413 | + |
| 414 | + // We clear the flag here as we want the information whether the PIT was |
| 415 | + // triggered or not as well as the remaining time for the other cases |
| 416 | + // above |
| 417 | + if (pit_triggered) { |
| 418 | + pit_triggered = false; |
395 | 419 | } |
396 | 420 | } |
397 | 421 |
|
@@ -499,8 +523,15 @@ bool LowPowerClass::begin(const SleepMultiplier sleep_multiplier, |
499 | 523 | sleep_parameter_str, |
500 | 524 | PSM_DEFAULT_AWAKE_PARAMETER); |
501 | 525 |
|
502 | | - sleep_time = decodeSleepMultiplier(sleep_multiplier) * |
503 | | - min(sleep_value, PSM_VALUE_MAX); |
| 526 | + sleep_time_requested = decodeSleepMultiplier(sleep_multiplier) * |
| 527 | + min(sleep_value, PSM_VALUE_MAX); |
| 528 | + |
| 529 | + // If we choose deep sleep, the modem will be completely off and we don't |
| 530 | + // have to negotiate the sleep time with the operator, thus the requested |
| 531 | + // sleep time and the actual sleep time will be equal |
| 532 | + if (mode == SleepMode::DEEP) { |
| 533 | + sleep_time = sleep_time_requested; |
| 534 | + } |
504 | 535 |
|
505 | 536 | return SequansController.retryCommand(command); |
506 | 537 | } |
|
0 commit comments