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
5
Makefile
5
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
|
||||
FLASHFILE ?= main.hex
|
||||
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))
|
||||
|
||||
@ -13,7 +14,7 @@ all: main
|
||||
|
||||
build/%.rel: src/%.c src/%.h
|
||||
mkdir -p $(dir $@)
|
||||
$(SDCC) $(SDCCOPTS) -o $@ -c $<
|
||||
$(SDCC) $(SDCCOPTS) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
main: $(OBJ)
|
||||
$(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(CFLAGS) $^
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "utils.h"
|
||||
|
||||
#include "calc.h"
|
||||
#include "stack_debug.h"
|
||||
|
||||
__xdata dec80 StoredDecn;
|
||||
__xdata dec80 LastX;
|
||||
|
@ -12,7 +12,7 @@ target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
|
||||
target_link_libraries(coverage_config INTERFACE --coverage)
|
||||
|
||||
# decn library
|
||||
add_library(decn decn.c)
|
||||
add_library(decn decn.c ../utils.c)
|
||||
|
||||
# decn library with coverage
|
||||
add_library(decn_cover decn.c)
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "../utils.h"
|
||||
#include "../stack_debug.h"
|
||||
|
||||
#include "decn.h"
|
||||
|
||||
@ -86,6 +87,8 @@ const dec80 DECN_LN_10 = {
|
||||
|
||||
void copy_decn(dec80* const dest, const dec80* const src){
|
||||
uint8_t i;
|
||||
|
||||
stack_debug(0x01);
|
||||
dest->exponent = src->exponent;
|
||||
|
||||
//copy nibbles
|
||||
@ -163,6 +166,7 @@ static void remove_leading_zeros(dec80* x){
|
||||
uint8_t is_negative = (x->exponent < 0);
|
||||
exp_t exponent = get_exponent(x);
|
||||
|
||||
stack_debug(0x02);
|
||||
//find first non-zero digit100
|
||||
for (digit100 = 0; digit100 < DEC80_NUM_LSU; digit100++){
|
||||
if (x->lsu[digit100] != 0){
|
||||
|
@ -155,9 +155,15 @@ void LCD_Open(void) {
|
||||
//P2 entire port
|
||||
P2M1 = 0;
|
||||
P2M0 = 0xff;
|
||||
#ifdef STACK_DEBUG
|
||||
// P3_4 is special
|
||||
P3M1 &= ~(0xe0);
|
||||
P3M0 |= (0xe0);
|
||||
#else
|
||||
//P3 pins 7:4
|
||||
P3M1 &= ~(0xf0);
|
||||
P3M0 |= (0xf0);
|
||||
#endif
|
||||
|
||||
_delay_ms(30); // to allow LCD powerup
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#else
|
||||
#include "stc15.h"
|
||||
#endif
|
||||
#include "stack_debug.h"
|
||||
|
||||
#define FOSC 11583000
|
||||
|
||||
@ -225,7 +226,9 @@ int main()
|
||||
LCD_Open();
|
||||
KeyInit();
|
||||
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[1] = 0;
|
||||
@ -529,7 +532,7 @@ int main()
|
||||
LcdAvailable.release();
|
||||
#endif
|
||||
//turn backlight back on
|
||||
BACKLIGHT_ON();
|
||||
backlight_on();
|
||||
} //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;
|
||||
}
|
||||
#endif
|
||||
void backlight_off(void){ }
|
||||
#else //!DESKTOP
|
||||
void _delay_ms(uint8_t ms)
|
||||
{
|
||||
@ -69,10 +68,6 @@ void _delay_us(uint8_t us)
|
||||
}
|
||||
#endif
|
||||
|
||||
void backlight_off(void){
|
||||
P3_4 = 1;
|
||||
}
|
||||
|
||||
#endif //ifdef desktop
|
||||
|
||||
#ifdef DESKTOP
|
||||
|
@ -35,9 +35,6 @@ void _delay_us(uint8_t us);
|
||||
#define _delay_us(x) _delay_ms(1)
|
||||
#endif
|
||||
|
||||
void backlight_off(void);
|
||||
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
#define DESKTOP
|
||||
@ -58,11 +55,9 @@ char* u32str(uint32_t x, char* buf, uint8_t base);
|
||||
#define __at uint8_t*
|
||||
#define SDCC_ISR(isr, reg)
|
||||
#define __using(x)
|
||||
#define BACKLIGHT_ON()
|
||||
#define TURN_OFF()
|
||||
#else
|
||||
#define SDCC_ISR(isr, reg) __interrupt (isr) __using (reg)
|
||||
#define BACKLIGHT_ON() P3_4 = 0
|
||||
#define TURN_OFF() P3_2 = 0
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user