-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
72 lines (60 loc) · 1.34 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
static PROGMEM const unsigned crcs [] = {
#include "correct.h"
};
extern void instrs( void );
extern void instrs_end( void );
extern unsigned test_instr( unsigned );
#define UARTOUT_BAUD 57600
#include "uartout.h"
int main( void )
{
// Route stdout to UART
stdout = uartout_init();
cli();
printf( "// Starting\n" );
TESTDDR = 0;
// Be sure that port B acts like an 8-bit RAM location (used in test)
{
uint8_t b = 0;
do
{
TESTPORT = b;
if ( TESTPORT != b )
{
printf( "TESTPORT not acting like R/W bits\n" );
return 0;
}
}
while ( --b );
}
// without this linker strips table from asm code
static volatile char c = 123;
c = 0;
char failed = 0;
unsigned addr = (unsigned) &instrs;
const unsigned* p = crcs;
while ( addr < (unsigned) &instrs_end )
{
unsigned crc = test_instr( addr );
unsigned correct = pgm_read_word( p++ );
printf( "0x%04X,", crc );
if ( crc != correct )
{
printf( " // +0x%03x mismatch; table shows 0x%04X", addr*2, correct );
failed = 1;
}
printf( "\n" );
addr += 2;
if ( pgm_read_word( addr*2+2 ) == 0 )
// prev instr was a skip which uses four slots, so skip the last two
addr += 2;
}
if ( !failed )
printf( "// Passed\n" );
else
printf( "// Failed\n" );
return 0;
}