Skip to content

Commit b1b816f

Browse files
committed
works, added check functions to the test example
1 parent 612a82c commit b1b816f

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

test/pinmode/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ OBJECTS=$(BASENAME).rel
2020
SDOBJECTS=main.rel wiring.rel wiring_digital.rel SPI.rel \
2121
HardwareSerial.rel Print.rel
2222

23-
.PHONY: all clean flash
23+
.PHONY: all clean flash statistics
2424

2525
#all: $(OBJECTS)
2626

@@ -41,6 +41,13 @@ readopt:
4141
stm8flash -c stlinkv2 -p stm8s103?3 -s opt -r opt.bin
4242

4343

44+
# lists the length of functions and constants defined in the primary source
45+
# file
46+
statistics: $(EXECUTABLE)
47+
grep "[0-9] _" $(BASENAME).rst |\
48+
awk 'BEGIN {print "length\tfunction\n------\t----------";}{ a=strtonum("0x"$$1);if (name) print a-s "\t" name; s=a; name=$$3}'
49+
50+
4451
clean:
4552
rm -f *.lib *.rst *.rel *.lst *.ihx *.sym *.asm *.lk *.map \
4653
*.cdb *.adb *~ *.bak

test/pinmode/pinmode.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,17 @@ void pinMode1(uint8_t pin, uint8_t mode)
8484
}
8585
#endif
8686

87-
#if 0
87+
//
88+
void pinMode_asm(uint8_t pin, uint8_t mode)
89+
{
90+
(void) pin; // empty code to avoid warning
91+
(void) mode;
92+
__asm
93+
sub sp, #16
94+
#if 1
8895
; pinmode.c: 10: uint8_t bit = digitalPinToBitMask(pin);
8996
clrw x
97+
9098
ld a,(0x03, sp)
9199
ld xl,a
92100
addw x, #_digital_pin_to_bit_mask_PGM+0
@@ -96,24 +104,17 @@ void pinMode1(uint8_t pin, uint8_t mode)
96104
ld yh,a ; yh = ~bit
97105

98106
; pinmode.c: 11: uint8_t port = digitalPinToPort(pin);
99-
addw x, #_digital_pin_to_bit_mask_PGM - _digital_pin_to_bit_mask_PGM
107+
;;hier addw x, #_digital_pin_to_bit_mask_PGM - _digital_pin_to_bit_mask_PGM
100108
ld a, (x) ; port
101109
jreq 00018$
102110

103-
sll
104-
clrw
111+
sll a
112+
clrw x
105113
ld xl,a
106114
addw x, #_port_to_output_PGM+0 ; x = gpio
107115

108116
ld a,(0x04,sp) ; a = mode, flags are set
109-
#endif
110-
//
111-
void pinMode_asm(uint8_t pin, uint8_t mode)
112-
{
113-
(void) pin; // empty code to avoid warning
114-
(void) mode;
115-
__asm
116-
sub sp, #16
117+
#else
117118
; pinmode.c: 10: uint8_t bit = digitalPinToBitMask(pin);
118119
ldw x, #_digital_pin_to_bit_mask_PGM+0
119120
ld a, xl
@@ -154,6 +155,7 @@ __asm
154155
cpl a
155156
ld yh,a ; yh = ~bit
156157
ld a, (0x14, sp) ; a=mode, flags are set
158+
#endif
157159

158160
; gpio->DDR: (2,x) (war an c,SP)
159161
; gpio->CR1: (3,x) (war an 8,SP)
@@ -252,25 +254,43 @@ __endasm;
252254
//
253255

254256

257+
uint8_t checkresult(uint8_t *adr, uint8_t *data)
258+
{
259+
uint8_t i,ok;
260+
261+
ok = 1;
262+
for (i=0; i<3; ++i) {
263+
if (adr[2+i] != data[i]) ok=0;
264+
}
265+
return ok;
266+
}
267+
268+
255269
void setup(void)
256270
{
257271
// expected result: xx xx 00 00 00
258272
pinMode_asm(PA1,INPUT);
273+
checkresult(GPIOA_BaseAddress, "\x00\x00\x00");
259274

260275
// expected result: xx xx 20 20 00
261276
pinMode_asm(PB5,OUTPUT);
277+
checkresult(GPIOB_BaseAddress, "\x20\x20\x00");
262278

263279
// expected result: xx xx 00 10 00
264280
pinMode_asm(PC4,INPUT_PULLUP);
281+
checkresult(GPIOC_BaseAddress, "\x00\x10\x00");
265282

266283
// expected result: xx xx 20 10 00
267284
pinMode_asm(PC5,OUTPUT_OD);
285+
checkresult(GPIOC_BaseAddress, "\x20\x10\x00");
268286

269287
// expected result: xx xx 02 02 02
270288
pinMode_asm(PD1,OUTPUT_FAST);
289+
checkresult(GPIOD_BaseAddress, "\x02\x02\x02");
271290

272291
// expected result: xx xx 42 02 42
273292
pinMode_asm(PD6,OUTPUT_OD_FAST);
293+
checkresult(GPIOD_BaseAddress, "\x42\x02\x42");
274294
}
275295

276296

0 commit comments

Comments
 (0)