|
1 | | -/* |
2 | | - * test spi functions |
| 1 | +/** |
| 2 | + * Test the optimized Versions of pinMode |
| 3 | + * |
| 4 | + * After each test the content of the GPIO registers is checked against |
| 5 | + * the expected values. The table results[] contains the number of mismatched |
| 6 | + * bytes after each test. |
| 7 | + * |
| 8 | + * Expected result: all bytes in results[] == 0x00 |
3 | 9 | */ |
4 | 10 |
|
5 | 11 | #define ARDUINO_MAIN |
|
9 | 15 | void pinMode_c(uint8_t pin, uint8_t mode); |
10 | 16 | void pinMode_asm(uint8_t pin, uint8_t mode); |
11 | 17 |
|
| 18 | +// select which function should be used for the test |
| 19 | +#define pinMode_test pinMode_asm |
| 20 | + |
| 21 | +uint8_t results[6]; |
12 | 22 |
|
| 23 | +/** |
| 24 | + * checks a memory area for an expected content |
| 25 | + * |
| 26 | + * @returns: number of mismatched bytes (0=ok) |
| 27 | + */ |
13 | 28 | uint8_t checkresult(uint16_t adr, uint8_t *data) |
14 | 29 | { |
15 | | - uint8_t i,ok; |
| 30 | + uint8_t i,err; |
16 | 31 |
|
17 | | - ok = 1; |
| 32 | + err = 0; |
18 | 33 | for (i=0; i<3; ++i) { |
19 | | - if (((uint8_t*)adr)[2+i] != data[i]) ok=0; |
| 34 | + if (((uint8_t*)adr)[2+i] != data[i]) err++; |
20 | 35 | } |
21 | | - return ok; |
| 36 | + return err; |
22 | 37 | } |
23 | 38 |
|
| 39 | +/** |
| 40 | + * fills a memory area with zeros |
| 41 | + * |
| 42 | + * The simulator does not clear the memory and does not properly |
| 43 | + * initialize the IO registers after reset. Use this instead. |
| 44 | + */ |
| 45 | +void _memset(unsigned char *adr, unsigned int cnt) |
| 46 | +{ |
| 47 | + while (cnt--) *adr++=0; |
| 48 | +} |
24 | 49 |
|
25 | 50 | void main(void) |
26 | 51 | { |
| 52 | + unsigned char *r = results; |
| 53 | + |
| 54 | + _memset((unsigned char *)GPIOA_BaseAddress, 20); |
| 55 | + |
27 | 56 | // expected result: xx xx 00 00 00 |
28 | | - pinMode_asm(PA1,INPUT); |
29 | | - checkresult(GPIOA_BaseAddress, "\x00\x00\x00"); |
| 57 | + pinMode_test(PA1,INPUT); |
| 58 | + *r++ = checkresult(GPIOA_BaseAddress, "\x00\x00\x00"); |
30 | 59 |
|
31 | 60 | // expected result: xx xx 20 20 00 |
32 | | - pinMode_asm(PB5,OUTPUT); |
33 | | - checkresult(GPIOB_BaseAddress, "\x20\x20\x00"); |
| 61 | + pinMode_test(PB5,OUTPUT); |
| 62 | + *r++ = checkresult(GPIOB_BaseAddress, "\x20\x20\x00"); |
34 | 63 |
|
35 | 64 | // expected result: xx xx 00 10 00 |
36 | | - pinMode_asm(PC4,INPUT_PULLUP); |
37 | | - checkresult(GPIOC_BaseAddress, "\x00\x10\x00"); |
| 65 | + pinMode_test(PC4,INPUT_PULLUP); |
| 66 | + *r++ = checkresult(GPIOC_BaseAddress, "\x00\x10\x00"); |
38 | 67 |
|
39 | 68 | // expected result: xx xx 20 10 00 |
40 | | - pinMode_asm(PC5,OUTPUT_OD); |
41 | | - checkresult(GPIOC_BaseAddress, "\x20\x10\x00"); |
| 69 | + pinMode_test(PC5,OUTPUT_OD); |
| 70 | + *r++ = checkresult(GPIOC_BaseAddress, "\x20\x10\x00"); |
42 | 71 |
|
43 | 72 | // expected result: xx xx 02 02 02 |
44 | | - pinMode_asm(PD1,OUTPUT_FAST); |
45 | | - checkresult(GPIOD_BaseAddress, "\x02\x02\x02"); |
| 73 | + pinMode_test(PD1,OUTPUT_FAST); |
| 74 | + *r++ = checkresult(GPIOD_BaseAddress, "\x02\x02\x02"); |
46 | 75 |
|
47 | 76 | // expected result: xx xx 42 02 42 |
48 | | - pinMode_asm(PD6,OUTPUT_OD_FAST); |
49 | | - checkresult(GPIOD_BaseAddress, "\x42\x02\x42"); |
| 77 | + pinMode_test(PD6,OUTPUT_OD_FAST); |
| 78 | + *r++ = checkresult(GPIOD_BaseAddress, "\x42\x02\x42"); |
| 79 | + |
| 80 | + for(;;); // endless loop |
50 | 81 | } |
51 | 82 |
|
52 | 83 | /* |
|
0 commit comments