diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c index a72faea7be..94ffcdf195 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | |||
@@ -120,9 +120,10 @@ static bool input_interrupt_pending; | |||
120 | #define MONOTIME_OFFSET_FILE ROCKBOX_DIR "/monotime_offset.dat" | 120 | #define MONOTIME_OFFSET_FILE ROCKBOX_DIR "/monotime_offset.dat" |
121 | static uint32_t monotime_offset; | 121 | static uint32_t monotime_offset; |
122 | /* Buffer last read monotime value. Reading monotime takes | 122 | /* Buffer last read monotime value. Reading monotime takes |
123 | * atleast 700 us so the tick counter is used together with | 123 | * atleast 1400 us so the tick counter is used together with |
124 | * last read monotime value to return current time. | 124 | * last read monotime value to return current time. |
125 | */ | 125 | */ |
126 | static bool monotime_available; | ||
126 | static uint32_t monotime_value; | 127 | static uint32_t monotime_value; |
127 | static unsigned long monotime_value_tick; | 128 | static unsigned long monotime_value_tick; |
128 | 129 | ||
@@ -521,16 +522,6 @@ bool charging_state(void) | |||
521 | return (avr_battery_status & BATTERY_STATUS_CHARGING) != 0; | 522 | return (avr_battery_status & BATTERY_STATUS_CHARGING) != 0; |
522 | } | 523 | } |
523 | 524 | ||
524 | static uint32_t avr_hid_get_monotime(void) | ||
525 | { | ||
526 | uint8_t tmp[4]; | ||
527 | if (avr_execute_command(CMD_MONOTIME, tmp, sizeof(tmp))) | ||
528 | { | ||
529 | return (tmp[0]) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); | ||
530 | } | ||
531 | return 0; | ||
532 | } | ||
533 | |||
534 | static void avr_hid_enable_wheel(void) | 525 | static void avr_hid_enable_wheel(void) |
535 | { | 526 | { |
536 | uint8_t enable = 0x01; | 527 | uint8_t enable = 0x01; |
@@ -651,22 +642,48 @@ static bool write_monotime_offset(void) | |||
651 | 642 | ||
652 | static void read_monotime(void) | 643 | static void read_monotime(void) |
653 | { | 644 | { |
654 | uint32_t value = avr_hid_get_monotime(); | 645 | uint8_t tmp[4]; |
655 | int flags = disable_irq_save(); | 646 | uint32_t t1, t2; |
656 | monotime_value = value; | 647 | |
657 | monotime_value_tick = current_tick; | 648 | if (!avr_execute_command(CMD_MONOTIME, tmp, sizeof(tmp))) |
658 | restore_irq(flags); | 649 | { |
650 | return; | ||
651 | } | ||
652 | t1 = (tmp[0]) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); | ||
653 | |||
654 | if (!avr_execute_command(CMD_MONOTIME, tmp, sizeof(tmp))) | ||
655 | { | ||
656 | return; | ||
657 | } | ||
658 | t2 = (tmp[0]) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); | ||
659 | |||
660 | if ((t1 == t2) || (t1 + 1 == t2)) | ||
661 | { | ||
662 | int flags = disable_irq_save(); | ||
663 | monotime_value = t1; | ||
664 | monotime_value_tick = current_tick; | ||
665 | restore_irq(flags); | ||
666 | monotime_available = true; | ||
667 | } | ||
659 | } | 668 | } |
660 | 669 | ||
661 | static time_t get_timestamp(void) | 670 | static time_t get_timestamp(void) |
662 | { | 671 | { |
663 | time_t timestamp; | 672 | time_t timestamp; |
664 | int flags = disable_irq_save(); | 673 | if (!monotime_available) |
665 | timestamp = monotime_value; | 674 | { |
666 | timestamp += monotime_offset; | 675 | read_monotime(); |
667 | timestamp += ((current_tick - monotime_value_tick) / HZ); | 676 | } |
668 | restore_irq(flags); | 677 | if (monotime_available) |
669 | return timestamp; | 678 | { |
679 | int flags = disable_irq_save(); | ||
680 | timestamp = monotime_value; | ||
681 | timestamp += monotime_offset; | ||
682 | timestamp += ((current_tick - monotime_value_tick) / HZ); | ||
683 | restore_irq(flags); | ||
684 | return timestamp; | ||
685 | } | ||
686 | return 0; | ||
670 | } | 687 | } |
671 | 688 | ||
672 | void rtc_init(void) | 689 | void rtc_init(void) |