; TASKING TriCore C compiler v1.5r1 Build 322 SN 00090364
; options: -e -A1 -g -O0 -Id:\ctri\include -s -N8 -zTC112_COR1 -zTC112_COR4
;          -zTC112_COR10 -zTC112_COR13 -zTC112_COR14 -zTC112_COR16 -zTC112_COR17
	.name	"ram_test"
	.symb	TOOL, "TASKING TriCore C compiler v1.5", 1
	.symb	TYPE, 256, "bit", 'g', 0, 1
	.symb	FILE, "ram_test.c"
; file "ram_test.c":
;    1 |#include "stdio.h"
	.symb	FILE, "d:\\ctri\\include\\stdio.h"
	.symb	FILE, "d:\\ctri\\include\\stdarg.h"
	.symb	ENDF
	.symb	TYPE, 258, 'P', #2
	.symb	TYPE, 259, "_iobuf", 'S', 24,\
		 "_ptr", #258, 0,\
		 "_base", #258, 4,\
		 "_cnt", #16, 8,\
		 "_bufsiz", #16, 12,\
		 "_flag", #5, 16,\
		 "_file", #2, 18,\
		 "_wcnt", #16, 20
	.symb	TYPE, 260, "FILE", 'T', #259
	.symb	TYPE, 261, "va_list", 'T', #258
	.symb	TYPE, 262, "size_t", 'T', #18
	.symb	TYPE, 263, "fpos_t", 'T', #7
	.symb	TYPE, 264, "off_t", 'T', #6
	.symb	ENDF
;    2 |// Überlegungen zum RAM-Test:
;    3 |// Der eigentliche Sinn diese Tests ist es NICHT, das RAM auf seine Funktion
;    4 |// zu testen, sondern den Zusatand der Adress- und Datenleitungen zu testen.
;    5 |// Folgende Fehlerquellen sind möglich:
;    6 |// Datenleitung Kurzschluss nach GND, VCC oder mit einer anderen Datenleitung
;    7 |//		oder floaten der Datenleitung
;    8 |// Adlessleitung das gleiche.
;    9 |// Um einen Adresstest durchführen zu können, müssen erst die Datenleitungen
;   10 |// überprüft werden. Zum Test der Datenleitungen ist es größtenteils egal, ob
;   11 |// die Adresen funktionieren. Das Testmuster für den Datentest würde sich bei 
;   12 |// fehlerhaften Adressen lediglich verteilt im Ram befinden und nicht der 
;   13 |// Reihe nach.
;   14 |// Für einen Adresstest sind funktionierende Datenleitungen unerläßlich. Der 
;   15 |// Adresstest schreibt ein sich änderndes Bitmuster in den Speicher, wobei
;   16 |// der komplette Speicher gefüllt werden muss, damit auch Kurzschlüsse nach VCC
;   17 |// erkannt werden.
;   18 |// Anschließend wird versucht, das Bitmuster wieder in der gleichen Reihenfolge
;   19 |// auszulesen. Is nun eine oder mehrere der Adressleitungen defekt, wurde
;   20 |// ein Teil des Bitmusters überschrieben und der Fehler kann angezeigt werden.
;   21 |// Das größte Problem stellen floatende Leitungen dar. Hier kann man nur mit 
;   22 |// wiederholten Tests den Fehler finden.
;   23 |
;   24 |//1MB SRAM an /CS1
;   25 |
;   26 |unsigned char RAM_TEST(void);
;   27 |
;   28 |
;   29 |unsigned char RAM_TEST(void)
;   30 |{
	.sdecl	"code.ram_test",CODE
	.sect	"code.ram_test"
	.align	4
	.symb	LINE, 30
	.symb	TYPE, 265, 'X', 8, #3, 26, 0
	.symb	GFUN, "RAM_TEST", RAM_TEST, #265, 0, 48, 0
	.symb	ALAB, RAM_TEST, #265
RAM_TEST:
	.symb	SOFF, 48
	.symb	IDEN, "uiHelp", -36, #18, 131, 0x5
	.symb	IDEN, "uiCnt", -32, #18, 131, 0x5
	.symb	TYPE, 267, 'P', #18
	.symb	IDEN, "puiDest", -28, #267, 131, 0x5
	.symb	IDEN, "uiStartAddressRAMbank1Test", -24, #18, 131, 0x5
	.symb	IDEN, "uiEndAddressRAMbank1Test", -20, #18, 131, 0x5
	.symb	IDEN, "uiStartAddressRAMbank2Test", -16, #18, 131, 0x5
	.symb	IDEN, "uiEndAddressRAMbank2Test", -12, #18, 131, 0x5
	.symb	IDEN, "ucErrorFlag", -8, #3, 131, 0x5
	nop
	sub16.a	sp,#48
;   31 |unsigned int uiHelp;
;   32 |unsigned int uiCnt;
;   33 |unsigned int *puiDest;
;   34 |unsigned int uiStartAddressRAMbank1Test;
;   35 |unsigned int uiEndAddressRAMbank1Test;
;   36 |unsigned int uiStartAddressRAMbank2Test;
;   37 |unsigned int uiEndAddressRAMbank2Test;
;   38 |unsigned char ucErrorFlag;
;   39 |
;   40 |uiHelp=0;
	.symb	LINE, 40
	mov16	d15,#0				; uiHelp
	st16.w	[sp]12,d15			; uiHelp
;   41 |uiStartAddressRAMbank1Test = 0xA0020000;
	.symb	LINE, 41
	movh	d15,#0xa002			; uiStartAddressRAMbank1Test
	st16.w	[sp]24,d15			; uiStartAddressRAMbank1Test
;   42 |uiEndAddressRAMbank1Test = 0xA00FFFFF;
	.symb	LINE, 42
	mov.u	d15,#0xffff			; uiEndAddressRAMbank1Test
	addih	d15,d15,#0xa00f			; uiEndAddressRAMbank1Test
	st16.w	[sp]28,d15			; uiEndAddressRAMbank1Test
;   43 |uiStartAddressRAMbank2Test = 0xA0100000;
	.symb	LINE, 43
	movh	d15,#0xa010			; uiStartAddressRAMbank2Test
	st16.w	[sp]32,d15			; uiStartAddressRAMbank2Test
;   44 |uiEndAddressRAMbank2Test = 0xA01FFFFF;
	.symb	LINE, 44
	mov.u	d15,#0xffff			; uiEndAddressRAMbank2Test
	addih	d15,d15,#0xa01f			; uiEndAddressRAMbank2Test
	st16.w	[sp]36,d15			; uiEndAddressRAMbank2Test
;   45 |ucErrorFlag = 0;
	.symb	LINE, 45
	mov16	d15,#0				; ucErrorFlag
	st.b	[sp]40,d15			; ucErrorFlag
;   46 |
;   47 |printf("Testing  1MB SRAM U16/U17 at /CS1...\n");
	.symb	LINE, 47
	movh.a	a4,#@his(_17)
	lea	a4,[a4]@los(_17)
	callg	printf
;   48 |// --------------------------- 	checking RAM-Bank 1 for error on data ---------------------
;   49 |    puiDest = (unsigned int *)(uiStartAddressRAMbank1Test);
	.symb	LINE, 49
	ld16.w	d15,[sp]24			; uiStartAddressRAMbank1Test
	mov16.a	a15,d15				; uiStartAddressRAMbank1Test
	st16.a	[sp]20,a15			; puiDest
;   50 |	// write test pattern
;   51 |	for (uiCnt = 0; uiCnt<32; uiCnt++)
	.symb	LINE, 51
	mov16	d15,#0				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
	j	_22
_21:
;   52 |	{
;   53 |		*puiDest++ = 0x1<<uiCnt;
	.symb	LINE, 53
	nop
	ld16.w	d15,[sp]16			; uiCnt
	mov16	d7,#1				; 1
	sha	d15,d7,d15
	ld.a	a7,[sp]20			; puiDest
	st16.w	[a7],d15			; puiDest
	ld.a	a7,[sp]20			; puiDest
	add16.a	a7,#4				; puiDest
	st.a	[sp]20,a7			; puiDest
	.symb	LINE, 51
	ld16.w	d15,[sp]16			; uiCnt
	add16	d15,#1				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
_22:
	nop
	ld16.w	d15,[sp]16			; uiCnt
	lt.u	d15,d15,#32
	jne	d15,#0,_21
;   54 |	}
;   55 |	// read test pattern
;   56 |	puiDest = (unsigned int *)(uiStartAddressRAMbank1Test);
	.symb	LINE, 56
	ld16.w	d15,[sp]24			; uiStartAddressRAMbank1Test
	mov16.a	a15,d15				; uiStartAddressRAMbank1Test
	st16.a	[sp]20,a15			; puiDest
;   57 |	for (uiCnt = 0; uiCnt<32; uiCnt++)
	.symb	LINE, 57
	mov16	d15,#0				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
	j	_25
_23:
;   58 |	{
;   59 |//    printf("DATA read=%08x at addr.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,(0x1<<uiCnt) );
;   60 |		if (*puiDest++ != 0x1<<uiCnt) 
	.symb	LINE, 60
	nop
	ld.a	a7,[sp]20			; puiDest
	ld.a	a6,[sp]20			; puiDest
	add16.a	a6,#4				; puiDest
	st.a	[sp]20,a6			; puiDest
	ld16.w	d15,[a7]
	ld.w	d7,[sp]16			; uiCnt
	mov16	d6,#1				; 1
	sha	d7,d6,d7
	jeq	d15,d7,_24
;   61 |		{
;   62 |			ucErrorFlag=1;
	.symb	LINE, 62
	mov16	d15,#1				; ucErrorFlag
	st.b	[sp]40,d15			; ucErrorFlag
;   63 |		    printf("	RAM-BANK1 ERROR: DATA read=%08x at addr.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,(0x1<<uiCnt) );
	.symb	LINE, 63
	movh.a	a4,#@his(_18)
	lea	a4,[a4]@los(_18)
	ld.a	a7,[sp]20			; puiDest
	ld16.w	d15,[a7]
	ld.a	a7,[sp]20			; puiDest
	ld.w	d7,[sp]16			; uiCnt
	mov16	d6,#1				; 1
	sha	d7,d6,d7
	st.w	[sp]8,d7
	st.a	[sp]4,a7			; puiDest
	st16.w	[sp],d15
	callg	printf
;   64 |		}
	.symb	LINE, 64
_24:
	.symb	LINE, 57
	nop
	ld16.w	d15,[sp]16			; uiCnt
	add16	d15,#1				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
_25:
	nop
	ld16.w	d15,[sp]16			; uiCnt
	lt.u	d15,d15,#32
	jne	d15,#0,_23
;   65 |	}
;   66 |// --------------------------- 	checking RAM-Bank 1 for error on address -------------------
;   67 |	// write test pattern
;   68 |	uiCnt=0;
	.symb	LINE, 68
	mov16	d15,#0				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
;   69 |	for (puiDest=(unsigned int *)(uiStartAddressRAMbank1Test); 
	.symb	LINE, 69
	ld16.w	d15,[sp]24			; uiStartAddressRAMbank1Test
	mov16.a	a15,d15				; uiStartAddressRAMbank1Test
	st16.a	[sp]20,a15			; puiDest
	j	_27
_26:
;   70 |				(puiDest <= (unsigned int *)uiEndAddressRAMbank1Test); puiDest++)
;   71 |	{
;   72 |		*puiDest = uiCnt++;
	.symb	LINE, 72
	nop
	ld16.w	d15,[sp]16			; uiCnt
	ld.w	d7,[sp]16			; uiCnt
	add16	d7,#1				; uiCnt
	st.w	[sp]16,d7			; uiCnt
	ld.a	a7,[sp]20			; puiDest
	st16.w	[a7],d15			; puiDest
	.symb	LINE, 70
	ld.a	a7,[sp]20			; puiDest
	add16.a	a7,#4				; puiDest
	st.a	[sp]20,a7			; puiDest
_27:
	nop
	ld.a	a7,[sp]20			; puiDest
	ld16.w	d15,[sp]28			; uiEndAddressRAMbank1Test
	mov16.a	a15,d15				; uiEndAddressRAMbank1Test
	ge.a	d15,a15,a7
	jne	d15,#0,_26
;   73 |	}
;   74 |
;   75 |    // read test pattern
;   76 |	uiCnt=0;
	.symb	LINE, 76
	mov16	d15,#0				; uiCnt
	st16.w	[sp]16,d15			; uiCnt
;   77 |	for (puiDest=(unsigned int *)(uiStartAddressRAMbank1Test); 
	.symb	LINE, 77
	ld16.w	d15,[sp]24			; uiStartAddressRAMbank1Test
	mov16.a	a15,d15				; uiStartAddressRAMbank1Test
	st16.a	[sp]20,a15			; puiDest
	j	_30
_28:
;   78 |				(puiDest <= (unsigned int *)uiEndAddressRAMbank1Test); puiDest++)
;   79 |	{
;   80 |//    printf("data read=%08x at ADDR.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,uiCnt);
;   81 |		if (*puiDest != uiCnt++) 
	.symb	LINE, 81
	nop
	ld.a	a7,[sp]20			; puiDest
	ld16.w	d15,[a7]
	ld.w	d7,[sp]16			; uiCnt
	ld.w	d6,[sp]16			; uiCnt
	add16	d6,#1				; uiCnt
	st.w	[sp]16,d6			; uiCnt
	jeq	d15,d7,_29
;   82 |		{
;   83 |			ucErrorFlag=1;
	.symb	LINE, 83
	mov16	d15,#1				; ucErrorFlag
	st.b	[sp]40,d15			; ucErrorFlag
;   84 |		    printf("	RAM-BANK1 ERROR: data read=%08x at ADDR.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,uiCnt);
	.symb	LINE, 84
	movh.a	a4,#@his(_19)
	lea	a4,[a4]@los(_19)
	ld.a	a7,[sp]20			; puiDest
	ld16.w	d15,[a7]
	ld.a	a7,[sp]20			; puiDest
	ld.w	d7,[sp]16			; uiCnt
	st.w	[sp]8,d7			; uiCnt
	st.a	[sp]4,a7			; puiDest
	st16.w	[sp],d15
	callg	printf
;   85 |		}
	.symb	LINE, 85
_29:
	.symb	LINE, 78
	nop
	ld.a	a7,[sp]20			; puiDest
	add16.a	a7,#4				; puiDest
	st.a	[sp]20,a7			; puiDest
_30:
	nop
	ld.a	a7,[sp]20			; puiDest
	ld16.w	d15,[sp]28			; uiEndAddressRAMbank1Test
	mov16.a	a15,d15				; uiEndAddressRAMbank1Test
	ge.a	d15,a15,a7
	jne	d15,#0,_28
;   86 |	}
;   87 |if (ucErrorFlag == 0) printf("	RAM-BANK_1 O.K. \n");
	.symb	LINE, 87
	ld.bu	d15,[sp]40			; ucErrorFlag
	jne	d15,#0,_31			; ucErrorFlag
	movh.a	a4,#@his(_20)
	lea	a4,[a4]@los(_20)
	callg	printf
_31:
;   88 |
;   89 |//return(ucErrorFlag);
;   90 |
;   91 |// =======================================================================================
;   92 |
;   93 |
;   94 |/*
;   95 |
;   96 |printf("Testing  1MB SRAM U14/U15 at /CS2...\n");
;   97 |// --------------------------- 	checking RAM-Bank 2 for error on data ---------------------
;   98 |    puiDest = (unsigned int *)(uiStartAddressRAMbank2Test);
;   99 |	// write test pattern
;  100 |	for (uiCnt = 0; uiCnt<32; uiCnt++)
;  101 |	{
;  102 |		*puiDest++ = 0x1<<uiCnt;
;  103 |	}
;  104 |	// read test pattern
;  105 |	puiDest = (unsigned int *)(uiStartAddressRAMbank2Test);
;  106 |	for (uiCnt = 0; uiCnt<32; uiCnt++)
;  107 |	{
;  108 |//    printf("DATA read=%08x at addr.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,(0x1<<uiCnt) );
;  109 |		if (*puiDest++ != 0x1<<uiCnt) 
;  110 |		{
;  111 |			ucErrorFlag=1;
;  112 |		    printf("	RAM-BANK2 ERROR: DATA read=%08x at addr.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,(0x1<<uiCnt) );
;  113 |		}
;  114 |	}
;  115 |// --------------------------- 	checking RAM-Bank 2 for error on address -------------------
;  116 |	// write test pattern
;  117 |	uiCnt=0;
;  118 |	for (puiDest=(unsigned int *)(uiStartAddressRAMbank2Test); (puiDest <= (unsigned int *)uiEndAddressRAMbank2Test); puiDest++)
;  119 |	{
;  120 |		*puiDest = uiCnt++;
;  121 |	}
;  122 |
;  123 |    // read test pattern
;  124 |	uiCnt=0;
;  125 |	for (puiDest=(unsigned int *)(uiStartAddressRAMbank2Test); (puiDest <= (unsigned int *)uiEndAddressRAMbank2Test); puiDest++)
;  126 |	{
;  127 |//    printf("data read=%08x at ADDR.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,uiCnt);
;  128 |		if (*puiDest != uiCnt++) 
;  129 |		{
;  130 |			ucErrorFlag=1;
;  131 |		    printf("	RAM-BANK2 ERROR: data read=%08x at ADDR.=%08x check=%08x \n", *(unsigned int *)puiDest,puiDest,uiCnt);
;  132 |		}
;  133 |	}
;  134 |if (ucErrorFlag == 0) printf("	RAM-BANK_2 O.K. \n");
;  135 |
;  136 |*/
;  137 |
;  138 |// End of RAM_Test
;  139 |return(ucErrorFlag);
	.symb	LINE, 139
	nop
	ld.bu	d2,[sp]40			; ucErrorFlag
;  140 |}
	.symb	LINE, 140
_32:
	ret16
	.symb	EFUN
	.symb	ENDF
	.sdecl	"fardata.ram_test",DATA,INIT
	.sect	"fardata.ram_test"
	.align	4
_18:
	.ascii	"	RAM-BANK1 ERROR: DATA read=%08x at addr.=%08x check=%08x "
	.byte	0x0a,0x00
_19:
	.ascii	"	RAM-BANK1 ERROR: data read=%08x at ADDR.=%08x check=%08x "
	.byte	0x0a,0x00
	.symb	TYPE, 268, 'X', 8, #16, 26, 2, #258, #1
	.symb	ALAB, printf, #268
_20:
	.ascii	"	RAM-BANK_1 O.K. "
	.byte	0x0a,0x00
	.align	2
_17:
	.ascii	"Testing  1MB SRAM U16/U17 at /CS1..."
	.byte	0x0a,0x00
	.align	4
	.global	RAM_TEST
	.extern	(CODE) printf
	.calls	"RAM_TEST", "printf"
