added facility to debug the stack pointer on P3_4 (LCD LED cathode)
roughly 139 bytes functions were chosen by manually traversing pow_decn to the bottom
This commit is contained in:
parent
7593260487
commit
4316f928f8
7
Makefile
7
Makefile
@ -4,8 +4,9 @@ SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --idata-loc 0x80
|
|||||||
#SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --stack-auto --model-large
|
#SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --stack-auto --model-large
|
||||||
FLASHFILE ?= main.hex
|
FLASHFILE ?= main.hex
|
||||||
LARGE_LDFLAGS += -L/usr/share/sdcc/lib/large/
|
LARGE_LDFLAGS += -L/usr/share/sdcc/lib/large/
|
||||||
|
# CFLAGS += -DSTACK_DEBUG # write the stack pointer to P3_4
|
||||||
|
|
||||||
SRC = src/lcd.c src/key.c src/utils.c src/decn/decn.c src/calc.c
|
SRC = src/lcd.c src/key.c src/utils.c src/decn/decn.c src/calc.c src/stack_debug.c
|
||||||
|
|
||||||
OBJ=$(patsubst src%.c,build%.rel, $(SRC))
|
OBJ=$(patsubst src%.c,build%.rel, $(SRC))
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ all: main
|
|||||||
|
|
||||||
build/%.rel: src/%.c src/%.h
|
build/%.rel: src/%.c src/%.h
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(SDCC) $(SDCCOPTS) -o $@ -c $<
|
$(SDCC) $(SDCCOPTS) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
main: $(OBJ)
|
main: $(OBJ)
|
||||||
$(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(CFLAGS) $^
|
$(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(CFLAGS) $^
|
||||||
@ -21,7 +22,7 @@ main: $(OBJ)
|
|||||||
@ tail -n 5 build/main.mem | head -n 2
|
@ tail -n 5 build/main.mem | head -n 2
|
||||||
@ tail -n 1 build/main.mem
|
@ tail -n 1 build/main.mem
|
||||||
cp build/$@.ihx $@.hex
|
cp build/$@.ihx $@.hex
|
||||||
|
|
||||||
eeprom:
|
eeprom:
|
||||||
sed -ne '/:..1/ { s/1/0/2; p }' main.hex > eeprom.hex
|
sed -ne '/:..1/ { s/1/0/2; p }' main.hex > eeprom.hex
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
|
#include "stack_debug.h"
|
||||||
|
|
||||||
__xdata dec80 StoredDecn;
|
__xdata dec80 StoredDecn;
|
||||||
__xdata dec80 LastX;
|
__xdata dec80 LastX;
|
||||||
|
@ -12,7 +12,7 @@ target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
|
|||||||
target_link_libraries(coverage_config INTERFACE --coverage)
|
target_link_libraries(coverage_config INTERFACE --coverage)
|
||||||
|
|
||||||
# decn library
|
# decn library
|
||||||
add_library(decn decn.c)
|
add_library(decn decn.c ../utils.c)
|
||||||
|
|
||||||
# decn library with coverage
|
# decn library with coverage
|
||||||
add_library(decn_cover decn.c)
|
add_library(decn_cover decn.c)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
#include "../stack_debug.h"
|
||||||
|
|
||||||
#include "decn.h"
|
#include "decn.h"
|
||||||
|
|
||||||
@ -86,6 +87,8 @@ const dec80 DECN_LN_10 = {
|
|||||||
|
|
||||||
void copy_decn(dec80* const dest, const dec80* const src){
|
void copy_decn(dec80* const dest, const dec80* const src){
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
stack_debug(0x01);
|
||||||
dest->exponent = src->exponent;
|
dest->exponent = src->exponent;
|
||||||
|
|
||||||
//copy nibbles
|
//copy nibbles
|
||||||
@ -163,6 +166,7 @@ static void remove_leading_zeros(dec80* x){
|
|||||||
uint8_t is_negative = (x->exponent < 0);
|
uint8_t is_negative = (x->exponent < 0);
|
||||||
exp_t exponent = get_exponent(x);
|
exp_t exponent = get_exponent(x);
|
||||||
|
|
||||||
|
stack_debug(0x02);
|
||||||
//find first non-zero digit100
|
//find first non-zero digit100
|
||||||
for (digit100 = 0; digit100 < DEC80_NUM_LSU; digit100++){
|
for (digit100 = 0; digit100 < DEC80_NUM_LSU; digit100++){
|
||||||
if (x->lsu[digit100] != 0){
|
if (x->lsu[digit100] != 0){
|
||||||
|
@ -155,9 +155,15 @@ void LCD_Open(void) {
|
|||||||
//P2 entire port
|
//P2 entire port
|
||||||
P2M1 = 0;
|
P2M1 = 0;
|
||||||
P2M0 = 0xff;
|
P2M0 = 0xff;
|
||||||
|
#ifdef STACK_DEBUG
|
||||||
|
// P3_4 is special
|
||||||
|
P3M1 &= ~(0xe0);
|
||||||
|
P3M0 |= (0xe0);
|
||||||
|
#else
|
||||||
//P3 pins 7:4
|
//P3 pins 7:4
|
||||||
P3M1 &= ~(0xf0);
|
P3M1 &= ~(0xf0);
|
||||||
P3M0 |= (0xf0);
|
P3M0 |= (0xf0);
|
||||||
|
#endif
|
||||||
|
|
||||||
_delay_ms(30); // to allow LCD powerup
|
_delay_ms(30); // to allow LCD powerup
|
||||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#else
|
#else
|
||||||
#include "stc15.h"
|
#include "stc15.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "stack_debug.h"
|
||||||
|
|
||||||
#define FOSC 11583000
|
#define FOSC 11583000
|
||||||
|
|
||||||
@ -225,7 +226,9 @@ int main()
|
|||||||
LCD_Open();
|
LCD_Open();
|
||||||
KeyInit();
|
KeyInit();
|
||||||
Timer0Init(); //for reading keyboard
|
Timer0Init(); //for reading keyboard
|
||||||
BACKLIGHT_ON(); //turn on led backlight
|
backlight_on(); //turn on led backlight
|
||||||
|
stack_debug_init();
|
||||||
|
stack_debug(0xfe);
|
||||||
|
|
||||||
ExpBuf[0] = 0;
|
ExpBuf[0] = 0;
|
||||||
ExpBuf[1] = 0;
|
ExpBuf[1] = 0;
|
||||||
@ -529,7 +532,7 @@ int main()
|
|||||||
LcdAvailable.release();
|
LcdAvailable.release();
|
||||||
#endif
|
#endif
|
||||||
//turn backlight back on
|
//turn backlight back on
|
||||||
BACKLIGHT_ON();
|
backlight_on();
|
||||||
} //while (1)
|
} //while (1)
|
||||||
}
|
}
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
92
src/stack_debug.c
Normal file
92
src/stack_debug.c
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "stack_debug.h"
|
||||||
|
|
||||||
|
#if defined(STACK_DEBUG)
|
||||||
|
extern uint16_t _SP;
|
||||||
|
|
||||||
|
inline static void HIGH() {
|
||||||
|
P3_4 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void LOW() {
|
||||||
|
P3_4 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stack_debug_init() {
|
||||||
|
P3M1 &= ~(0x10);
|
||||||
|
P3M0 |= 0x10;
|
||||||
|
LOW();
|
||||||
|
stack_debug_write(0x55);
|
||||||
|
stack_debug_write(0xAA);
|
||||||
|
stack_debug_write(0x55);
|
||||||
|
stack_debug_write(0xAA);
|
||||||
|
stack_debug_write(0x80);
|
||||||
|
stack_debug_write(0x10);
|
||||||
|
stack_debug_write(0x08);
|
||||||
|
stack_debug_write(0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for frequency of 12.000 MHz (12.005 adjusted) this gives a rate of 1'190'000 Baud
|
||||||
|
negative polarity, MSB
|
||||||
|
*/
|
||||||
|
|
||||||
|
void stack_debug_write(uint8_t value) __naked {
|
||||||
|
value;
|
||||||
|
__asm
|
||||||
|
.macro HIGH
|
||||||
|
setb _P3_4
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro LOW
|
||||||
|
clr _P3_4
|
||||||
|
.endm
|
||||||
|
|
||||||
|
mov dph,r0
|
||||||
|
mov a,dpl
|
||||||
|
mov r0,#8
|
||||||
|
; START
|
||||||
|
HIGH ; 1
|
||||||
|
nop ; 1
|
||||||
|
nop ; 1
|
||||||
|
nop ; 1
|
||||||
|
stack_debug_1$:
|
||||||
|
rlc a ; 1
|
||||||
|
jc stack_debug_2$ ; 3
|
||||||
|
HIGH ; 1
|
||||||
|
djnz r0,stack_debug_1$ ; 4
|
||||||
|
sjmp stack_debug_3$ ; 3
|
||||||
|
stack_debug_2$:
|
||||||
|
LOW ; 1
|
||||||
|
djnz r0,stack_debug_1$ ; 4
|
||||||
|
sjmp stack_debug_3$ ; 3
|
||||||
|
stack_debug_3$:
|
||||||
|
nop ; 1
|
||||||
|
; STOP
|
||||||
|
LOW ; 1
|
||||||
|
nop ; 1
|
||||||
|
nop ; 1
|
||||||
|
|
||||||
|
mov r0,dph ; 3
|
||||||
|
ret ; 4
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stack_debug(uint8_t marker) {
|
||||||
|
stack_debug_write(marker);
|
||||||
|
stack_debug_write(SP);
|
||||||
|
}
|
||||||
|
#endif // !defined(DESKTOP)
|
54
src/stack_debug.h
Normal file
54
src/stack_debug.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#ifndef SRC_STACK_DEBUG_H_
|
||||||
|
#define SRC_STACK_DEBUG_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if !defined(DESKTOP)
|
||||||
|
#include "stc15.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// P3_4 is connected to the cathode and the only pin that is not toggled normally
|
||||||
|
// unfortunately, the hardware uart cannot be mapped to TX = P3_4
|
||||||
|
|
||||||
|
#if defined(STACK_DEBUG)
|
||||||
|
void stack_debug_init(void);
|
||||||
|
void stack_debug(uint8_t marker);
|
||||||
|
void stack_debug_write(uint8_t value) __naked;
|
||||||
|
#else
|
||||||
|
#define stack_debug_init()
|
||||||
|
#define stack_debug(marker)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(DESKTOP) || defined(STACK_DEBUG)
|
||||||
|
#define backlight_on()
|
||||||
|
#define backlight_off()
|
||||||
|
#else
|
||||||
|
inline void backlight_on(void) {
|
||||||
|
P3_4 = 0;
|
||||||
|
}
|
||||||
|
inline void backlight_off(void) {
|
||||||
|
P3_4 = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -29,7 +29,6 @@ void _delay_us(uint8_t us)
|
|||||||
(void) us;
|
(void) us;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void backlight_off(void){ }
|
|
||||||
#else //!DESKTOP
|
#else //!DESKTOP
|
||||||
void _delay_ms(uint8_t ms)
|
void _delay_ms(uint8_t ms)
|
||||||
{
|
{
|
||||||
@ -69,10 +68,6 @@ void _delay_us(uint8_t us)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void backlight_off(void){
|
|
||||||
P3_4 = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //ifdef desktop
|
#endif //ifdef desktop
|
||||||
|
|
||||||
#ifdef DESKTOP
|
#ifdef DESKTOP
|
||||||
|
@ -35,9 +35,6 @@ void _delay_us(uint8_t us);
|
|||||||
#define _delay_us(x) _delay_ms(1)
|
#define _delay_us(x) _delay_ms(1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void backlight_off(void);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define DESKTOP
|
#define DESKTOP
|
||||||
@ -58,11 +55,9 @@ char* u32str(uint32_t x, char* buf, uint8_t base);
|
|||||||
#define __at uint8_t*
|
#define __at uint8_t*
|
||||||
#define SDCC_ISR(isr, reg)
|
#define SDCC_ISR(isr, reg)
|
||||||
#define __using(x)
|
#define __using(x)
|
||||||
#define BACKLIGHT_ON()
|
|
||||||
#define TURN_OFF()
|
#define TURN_OFF()
|
||||||
#else
|
#else
|
||||||
#define SDCC_ISR(isr, reg) __interrupt (isr) __using (reg)
|
#define SDCC_ISR(isr, reg) __interrupt (isr) __using (reg)
|
||||||
#define BACKLIGHT_ON() P3_4 = 0
|
|
||||||
#define TURN_OFF() P3_2 = 0
|
#define TURN_OFF() P3_2 = 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user