diff src/sleepmode.asm @ 634:4050675965ea

3.10 stable release
author heinrichsweikamp
date Tue, 28 Apr 2020 17:34:31 +0200
parents 185ba2f91f59
children 8c1f1f334275
line wrap: on
line diff
--- a/src/sleepmode.asm	Thu Mar 05 15:06:14 2020 +0100
+++ b/src/sleepmode.asm	Tue Apr 28 17:34:31 2020 +0200
@@ -1,6 +1,6 @@
 ;=============================================================================
 ;
-;   File sleepmode.asm                        combined next generation V3.08.8
+;   File sleepmode.asm                      * combined next generation V3.09.4n
 ;
 ;   Sleep Mode
 ;
@@ -56,10 +56,14 @@
 ;							sm_flags,7	; unused
 
 
+;=============================================================================
 slmode	CODE
-
 ;==============================================================================
 
+
+;-----------------------------------------------------------------------------
+; Entry Point for Sleep Mode
+;
 	global	sleeploop
 sleeploop:
 	clrf	STKPTR							; clear return addresses stack
@@ -75,7 +79,7 @@
 	bsf		sleepmode						; flag being in sleep mode
 	bsf		block_sensor_interrupt			; suspend ISR from executing sensor interrupts
 
-	call	disable_ir_s8					; power-down IR/S8 interrupts
+	call	disable_ir_s8_analog			; power-down IR/S8/analog interface
 	call	mcp_sleep						; power-down RX power supply
 
 	clrf	ADCON0							; power-down ADC module
@@ -85,9 +89,8 @@
 	call	eeprom_deco_data_write			; update deco data     in EEPROM
 	call	eeprom_battery_gauge_write		; update battery gauge in EEPROM
 
-	btfsc	options_changed					; do the options need to be stored to EEPROM ?
+	btfsc	option_changed					; do the options need to be stored to EEPROM ?
 	call	option_check_and_store_all		; YES - check and store all option values in EEPROM
-	bcf		options_changed					; clear flag
 
 	call	ext_flash_enable_protection		; enable write protection on external flash
 
@@ -106,18 +109,18 @@
 	btfss	sleepmode						; shall terminate sleep mode?
 	bra		sleeploop_exit					; YES
 
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 
 	btfss	deep_sleep						; shall enter deep sleep?
 	bra		sleeploop_loop					; NO  - remain in normal sleep loop
 	;bra	deepsleep_pre					; YES - enter     deep   sleep loop
 
 deepsleep_pre:
-	bcf		PIE1,0							; disable timer 1 interrupt
-	bcf		PIE2,1							; disable timer 2 interrupt
-	bcf		PIE5,3							; disable timer 7 interrupt
-	bcf		INTCON,4						; disable INT0    interrupt
-	bcf		INTCON3,3						; disable INT1    interrupt
+	bcf		PIE1,TMR1IE						; disable timer 1 interrupt
+	bcf		PIE2,TMR3IE						; disable timer 2 interrupt
+	bcf		PIE5,TMR7IE						; disable timer 7 interrupt
+	bcf		INTCON, INT0IE					; disable INT0    interrupt
+	bcf		INTCON3,INT1IE					; disable INT1    interrupt
 
 	bcf		power_sw1						; power-down switch 1
 	bcf		power_sw2						; power-down switch 2
@@ -135,7 +138,7 @@
 	btfsc	trigger_full_second				; one second in deep sleep?
 	rcall	one_sec_sleep					; YES - check switches, check pressure sensor, etc.
 
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 
 	btfss	sleepmode						; shall leave sleep mode?
 	bcf		deep_sleep						; YES - leave deep sleep mode then, too
@@ -149,15 +152,14 @@
 	call	power_up_switches				; turn on    the analog switches
 	rcall	init_avg_switches				; initialize the averaging system
 
-	bsf		PIE1,0							; enable timer 1 interrupt
-	bsf		PIE2,1							; enable timer 2 interrupt
-	bsf		PIE5,3							; enable timer 7 interrupt
-	bsf		INTCON,4						; enable INT0    interrupt
-	bsf		INTCON3,3						; enable INT1    interrupt
+	bsf		PIE1,TMR1IE						; enable timer 1 interrupt
+	bsf		PIE2,TMR3IE						; enable timer 2 interrupt
+	bsf		PIE5,TMR7IE						; enable timer 7 interrupt
+	bsf		INTCON, INT0IE					; enable INT0    interrupt
+	bsf		INTCON3,INT1IE					; enable INT1    interrupt
 
 	bra		sleeploop_loop					; enter normal sleep loop
 
-
 sleeploop_exit:
 	bcf		switch_left						; eventually clear left  button event
 	bcf		switch_right					; eventually clear right button event
@@ -168,8 +170,10 @@
 	goto	restart							; restart
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Tasks every Second in Sleep Mode
+;
 one_sec_sleep:
-	; tasks every second in sleep mode
 	bcf		trigger_full_second				; clear trigger flag
 
 	btfsc	switch_left						; left switch pressed?
@@ -195,14 +199,14 @@
 	btfsc	charge_in_sleep					; YES - already showing charge screen?
 	bra		one_sec_sleep_1b				;       YES - only update data
 
-	bsf	charge_in_sleep
-	bcf	deep_sleep						; wake-up from deepsleep
+	bsf		charge_in_sleep
+	bcf		deep_sleep						; wake-up from deepsleep
 	call	TFT_boot						; initialize TFT (includes clear screen)
 	movlw	.32
 	movff	WREG,max_CCPR1L					; bank safe
 	call	TFT_Display_FadeIn				; dim up the display
 one_sec_sleep_1b:
-	call	TFT_batt_surfmode				; show battery type, voltage and color-coded percentage
+	call	TFT_surfmode_batt				; show battery type, voltage and color-coded percentage
 	bra		one_sec_sleep_2					; continue
 
 one_sec_sleep_1a:
@@ -230,6 +234,9 @@
 	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Tasks every 10 Seconds in Sleep Mode
+;
 ten_sec_sleep:
 	; tasks every 10 seconds in sleep mode
 	clrf	sm_timer_10sec					; clear timer
@@ -242,6 +249,9 @@
 	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Tasks every Minute in Sleep Mode
+;
 one_min_sleep:
 	; tasks every minute in sleep mode
 	bcf		trigger_full_minute				; clear flag
@@ -261,6 +271,9 @@
 	return									;     - done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Tasks every 10 Minutes in Sleep Mode
+;
 ten_min_sleep:
 	; tasks every 10 minutes in sleep mode
 	clrf	sm_timer_10min					; reset timer to 0
@@ -296,6 +309,9 @@
 	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Tasks every Hour in Sleep Mode
+;
 one_hour_sleep:
 	; tasks every hour in sleep mode mode
 	bcf		trigger_full_hour				; clear one hour flag
@@ -304,13 +320,16 @@
 	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Initialization of the Button Event Averaging System
+;
 init_avg_switches:
 	; pause 4 seconds using CPU sleep mode to conserve on battery
 	movlw	.4								; time to pause
 	movwf	loop_counter					; initialize loop counter
 	bcf		trigger_full_second				; clear 'one second elapsed' flag
 activate_switches_1:
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 	btfss	trigger_full_second				; did 1 second elapsed meanwhile?
 	bra		activate_switches_1				; NO  - loop
 	bcf		trigger_full_second				; YES - clear flag
@@ -327,17 +346,19 @@
 
 	; clear all button events that may have intermediately occurred
 	bcf		PIR1,TMR1IF						; clear button-hold-down timer
-	bcf		INTCON,INT0IF					; clear right button activity
+	bcf		INTCON, INT0IF					; clear right button activity
 	bcf		INTCON3,INT1IF					; clear left  button activity
 	bcf		analog_sw1_pressed				; clear analog switch 1 activity
 	bcf		analog_sw2_pressed				; clear analog switch 2 activity
 	bcf		switch_right					; clear right button event
 	bcf		switch_left						; clear left  button event
 
-	; done
-	return
+	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - Check for Change in Accelerometer Z-Axis
+;
 check_accelerometer:
 	rcall	deepsleep_get_accel				; read accelerometer into WREG
 	subwf	accel_reference,W				; reference value - accel_DZ+0 -> WREG
@@ -350,9 +371,12 @@
 	return									; done
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - read Accelerometer Z-Axis
+;
 deepsleep_get_accel:
 	call	I2C_init_compass				; start compass
-	rcall	sleepmode_sleep					; wait a little bit
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 	call	I2C_RX_accelerometer			; read accelerometer
 	call	I2C_RX_accelerometer			; read accelerometer
 	call	I2C_sleep_compass				; shut down compass
@@ -360,7 +384,12 @@
 	return									; done
 
 
-pressuretest_sleep_fast:					; get pressure without averaging (faster to save some power in sleep mode)
+;-----------------------------------------------------------------------------
+; Helper Function - read Pressure without Averaging
+;
+; faster method to save some power in sleep mode
+;
+pressuretest_sleep_fast:
 	banksel	isr_backup						; select bank ISR data
 
 	CLRI	pressure_abs_avg				; clear pressure    average register
@@ -368,14 +397,14 @@
 
 	call	get_temperature_start			; start temperature integration (73.5 us)
 
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 
 	call	get_temperature_value			; state 1: get temperature
 	call	get_pressure_start				; start pressure integration
 
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
-	rcall	sleepmode_sleep					; wait at least 35 ms (every 62.5 ms timer7 wakeup)
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
+	rcall	sleepmode_sleep					; sleep for 62.5...125 ms
 
 	call	get_pressure_value				; state2: get pressure (51 us)
 	call	calculate_compensation			; calculate temperature compensated pressure (27 us)
@@ -386,29 +415,24 @@
 	return
 
 
+;-----------------------------------------------------------------------------
+; Helper Function - sleep for 62.5...125 ms
+;
 sleepmode_sleep:
-	movff	BSR,BSR_backup					; backup BSR
-
-	banksel	common
+	movff	BSR,BSR_backup					; backup current bank selection
+	banksel	common							; switch to bank common
 	btfsc	charge_in_sleep					; already showing charge screen?
-	bra		sleepmode_sleepwalk				; YES - skip the actual sleep (But wait)
-
-;	banksel	T7GCON							; switch bank, T7* is outside access RAM
-;	clrf	T7GCON							; reset timer7 gate control register
-;	movlw	b'10001101'						; 1:1 prescaler -> 2 seconds @ 32768 Hz, not synced
-;	movwf	T7CON
-	sleep
-	sleep
-;	clrf	T7GCON							; reset timer7 gate control register
-;	movlw	b'10001001'						; 1:1 prescaler ->  2 seconds @ 32768 Hz, synced
-;	movwf	T7CON
+	bra		sleepmode_sleepwalk				; YES - skip the actual sleep (but wait)
+	sleep									; NO  - put CPU into sleep (wakes up by timer 7 IRQ)
+	sleep									;     - put CPU into sleep again
 sleepmode_sleep_1:
-	movff	BSR_backup,BSR					; restore BSR
-	return
-
+	movff	BSR_backup,BSR					; restore bank selection
+	return									; done
 
 sleepmode_sleepwalk:
-	WAITMS	d'65'
-	bra		sleepmode_sleep_1
+	WAITMS	d'65'							; wait 65 ms
+	bra		sleepmode_sleep_1				; continue with common part
 
- END
\ No newline at end of file
+;-----------------------------------------------------------------------------
+
+ END