From fa97e9366d79e23bd5d7d4a1deff61bd05ca291f Mon Sep 17 00:00:00 2001 From: "romolo.manfredini@gmail.com" Date: Wed, 3 Oct 2012 21:05:56 +0000 Subject: [PATCH] Better coprocessor temperature support --- src/board_sky9x.cpp | 2 ++ src/drivers.cpp | 7 +++++++ src/sky9x/sound_driver.cpp | 24 ++++++++++++++++-------- src/sky9x/sound_driver.h | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/board_sky9x.cpp b/src/board_sky9x.cpp index b087b6a4b..6cb914388 100644 --- a/src/board_sky9x.cpp +++ b/src/board_sky9x.cpp @@ -1035,6 +1035,8 @@ void read_9_adc() #endif temperature = (((int32_t)temperature * 7) + ((((int32_t)ADC->ADC_CDR15 - 838) * 621) >> 11)) >> 3; // Filter it + if (get_tmr10ms()<100) + return; if (temperature < 200 && temperature > maxTemperature) { maxTemperature = temperature; } diff --git a/src/drivers.cpp b/src/drivers.cpp index 4e928df18..96a398c5e 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -165,6 +165,13 @@ void per10ms() /* Update global Date/Time every 100 per10ms cycles */ if (++g_ms100 == 100) { g_rtcTime++; // inc global unix timestamp one second +#if defined (PCBSKY9X) + if (g_rtcTime < 120) { + rtc_init(); + } else { + read_coprocessor(true); + } +#endif g_ms100 = 0; } #endif diff --git a/src/sky9x/sound_driver.cpp b/src/sky9x/sound_driver.cpp index da91d630d..0eceeeb31 100644 --- a/src/sky9x/sound_driver.cpp +++ b/src/sky9x/sound_driver.cpp @@ -236,6 +236,7 @@ uint8_t Volume_read ; uint8_t Coproc_read ; int8_t Coproc_temp ; int8_t Coproc_valid ; +bool get_onlytemp; static uint8_t *Twi_read_address ; static uint8_t TwiOperation ; @@ -357,8 +358,13 @@ void read_volume() __enable_irq() ; } -void read_coprocessor() +void read_coprocessor(bool onlytemp) { + if (onlytemp) { + get_onlytemp=true; + } else { + get_onlytemp=false; + } CoProc_read_pending = 1 ; __disable_irq() ; i2c_check_for_request() ; @@ -422,14 +428,16 @@ extern "C" void TWI0_IRQHandler() // Got data from tiny app // Set the date and time struct gtm utm; - utm.tm_sec = Co_proc_status[1] ; - utm.tm_min = Co_proc_status[2] ; - utm.tm_hour = Co_proc_status[3] ; - utm.tm_mday = Co_proc_status[4] ; - utm.tm_mon = Co_proc_status[5] - 1; - utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - 1900; + if (!get_onlytemp) { + utm.tm_sec = Co_proc_status[1] ; + utm.tm_min = Co_proc_status[2] ; + utm.tm_hour = Co_proc_status[3] ; + utm.tm_mday = Co_proc_status[4] ; + utm.tm_mon = Co_proc_status[5] - 1; + utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - 1900; + g_rtcTime = gmktime(&utm); + } Coproc_temp = Co_proc_status[8]; - g_rtcTime = gmktime(&utm); } TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers if ( TWI0->TWI_SR & TWI_SR_RXRDY ) { diff --git a/src/sky9x/sound_driver.h b/src/sky9x/sound_driver.h index 5c069fdf2..850cb73ec 100644 --- a/src/sky9x/sound_driver.h +++ b/src/sky9x/sound_driver.h @@ -46,7 +46,7 @@ extern void start_timer1( void ) ; extern void initDac( void ) ; extern void end_sound( void ) ; extern void write_coprocessor( uint8_t *ptr, uint32_t count ) ; -extern void read_coprocessor( void ) ; +extern void read_coprocessor( bool onlytemp=false ) ; extern uint8_t Coproc_read ; extern int8_t Coproc_valid ; extern int8_t Coproc_temp ;