diff --git a/lib/CPUs/MIPS/bsp/examples/testbench.c b/lib/CPUs/MIPS/bsp/examples/testbench.c index 3bee759..529820c 100644 --- a/lib/CPUs/MIPS/bsp/examples/testbench.c +++ b/lib/CPUs/MIPS/bsp/examples/testbench.c @@ -14,9 +14,12 @@ #define TEST10_ERROR (ERROR | 0x10) #define TEST11_ERROR (ERROR | 0x11) #define TEST12_ERROR (ERROR | 0x12) +#define TEST13_ERROR (ERROR | 0x13) +#define TEST14_ERROR (ERROR | 0x14) +#define TEST15_ERROR (ERROR | 0x15) char buffer[16384]; -int i; +int g_i; extern int paranoia(int argc, char **argv); @@ -28,14 +31,35 @@ void handler3(void) while((0x10 & *pUART_stat)) { - buffer[i] = (char)*pUART_data; - *pLED = buffer[i]*buffer[i]; - i = (i+1)%sizeof(buffer); - + buffer[g_i] = (char)*pUART_data; + _cg_putchar(buffer[g_i]); + g_i = (g_i+1)%sizeof(buffer); } } +int g_cnt; +void handler7(void) +{ + UINT32 volatile *pGPIO0 = (UINT32*)sys_gpio0; + UINT32 volatile *pTim_stat = (UINT32*)sys_itim_stat; + UINT32 volatile *pTim_cmp = (UINT32*)sys_itim_cmp; + UINT32 volatile *pTim_ctrl = (UINT32*)sys_itim_ctrl; + if (*pTim_cmp < 0x200) + { +// *pTim_ctrl &= ~1; + *pTim_cmp = 0x200; +// printf("pTim_cmp = %8.8X\n", *pTim_cmp); + } + if (*pTim_stat & 1) + { + *pTim_stat = 1; + *pGPIO0 = g_cnt++; + } + + +} + int fibonacci(int f0, int f1, int *pDst, int len) { int i; @@ -56,22 +80,24 @@ int fibonacci(int f0, int f1, int *pDst, int len) void PrintCPUinfo(void) { int result, rev_id; + int cache_size, cache_line; char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"}; // Print Status register result = CP0_SR_read(); - printf("Status : %8.8X\n", result); + printf("--------------------------------------------------\n"); + printf("Status : %8.8X\n", result); // Print Revision result = CP0_PRID_read(); rev_id = (result >> 8) & 0xFF; - printf("CPU type: "); + printf("CPU type : MIPS "); if ((rev_id > 0) && (rev_id < 0x07)) { printf(cpu_type_str[rev_id]); - printf(" Rev."); + printf(" Rev. "); rev_id = result & 0xFF; printf("%d", rev_id); } @@ -79,6 +105,13 @@ void PrintCPUinfo(void) printf("Unknown"); printf("\n"); + cache_size = (result >> 16) & 7; + cache_line = (result >> 19) & 7; + printf("I-Cache : %d kBytes (%d Bytes per line)\n", 4*(int)pow(2.0, (double)(8+cache_size))/1024, 4*(int)pow(2.0, (double)(cache_line))); + cache_size = (result >> 24) & 7; + cache_line = (result >> 27) & 7; + printf("D-Cache : %d kBytes (%d Bytes per line)\n", 4*(int)pow(2.0, (double)(8+cache_size))/1024, 4*(int)pow(2.0, (double)(cache_line))); + printf("--------------------------------------------------\n"); } @@ -250,8 +283,10 @@ int Test12_MulDiv() int mix, i, j; int s1, s2, sp, st; div_t div_res; + long cl; - srand(0x19701031); + cl = (long)clock(); + srand(cl); for (i=0; i < 100; i++) { for (j=1; j < 100; j++) @@ -262,6 +297,12 @@ int Test12_MulDiv() mix = (int)rand(); mix = (mix << 8) ^ (mix << 16); s2 = (int)rand() ^ mix; + if (!s2) + { + fprintf(stderr, "Test12_MulDiv(): Division by zero!\n"); + fprintf(stderr, "Clock() was 0x%8.8X\n", cl); + continue; + } div_res = div(s1, s2); @@ -274,34 +315,129 @@ int Test12_MulDiv() return NO_ERROR; } +int Test13_COP0_Load_Store(void) +{ + int i,size; + UINT32 *pSrc32, *pDst32; + + size = 0x2000; + pSrc32 = (UINT32*)0xBFC00000; + pDst32 = (UINT32*)calloc(size,sizeof(UINT32)); + for (i=0; i < size/4; i++) + { + CP0_TR_read_ptr(&pSrc32[i]); + CP0_TR_write_ptr(&pDst32[i]); + } + for (i=size/4-1; i >= 0; i--) + if (pDst32[i] != pSrc32[i]) + break; + + free(pDst32); + i++; + if (i) + return TEST13_ERROR; + + return NO_ERROR; +} + +int Test14_DCACHE_invalidate(void) +{ + int i,size; + UINT32 *pSrc32, *pDst32; + + size = 0x2000; + pSrc32 = (UINT32*)0xBFC00000; + pDst32 = (UINT32*)calloc(size,sizeof(UINT32)); + for (i=0; i < size/4; i++) + { + pDst32[i] = pSrc32[i]; + DCACHE_invalidate_at(&pDst32[i]); + } + for (i=size/4-1; i >= 0; i--) + { + DCACHE_invalidate_at(&pDst32[i]); + if (pDst32[i] != pSrc32[i]) + break; + } + + free(pDst32); + i++; + if (i) + return TEST14_ERROR; + + pDst32 = (UINT32*)calloc(size,sizeof(UINT32)); + for (i=0; i < size/4; i++) + { + pDst32[i] = pSrc32[i]; + } + DCACHE_invalidate_all(); + for (i=size/4-1; i >= 0; i--) + if (pDst32[i] != pSrc32[i]) + break; + + free(pDst32); + i++; + if (i) + return TEST14_ERROR; + + return NO_ERROR; +} + #define PI_SCALE 10000 #define PI_MAXARR 2800 #define PI_ARRINIT 2000 -int pi_calc() +int Test15_pi_calc() { - int i, j; - int carry = 0; - int arr[PI_MAXARR+1]; + int i, j, k; + int carry = 0; + int arr[PI_MAXARR+1]; + UINT32 int_part, result; + UINT16 pi_res[200] = {0}; + UINT16 pi_ref[200] = + { + 3141,5926,5358,9793,2384,6264,3383,2795, 288,4197,1693,9937,5105,8209,7494,4592,3078,1640,6286,2089,9862,8034,8253,4211, + 7067,9821,4808,6513,2823, 664,7093,8446, 955, 582,2317,2535,9408,1284,8111,7450,2841, 270,1938,5211, 555,9644,6229,4895, + 4930,3819,6442,8810,9756,6593,3446,1284,7564,8233,7867,8316,5271,2019, 914,5648,5669,2346, 348,6104,5432,6648,2133,9360, + 7260,2491,4127,3724,5870, 660,6315,5881,7488,1520,9209,6282,9254, 917,1536,4367,8925,9036, 11,3305,3054,8820,4665,2138, + 4146,9519,4151,1609,4330,5727, 365,7595,9195,3092,1861,1738,1932,6117,9310,5118,5480,7446,2379,9627,4956,7351,8857,5272, + 4891,2279,3818,3011,9491,2983,3673,3624,4065,6643, 860,2139,4946,3952,2473,7190,7021,7986, 943,7027,7053,9217,1762,9317, + 6752,3846,7481,8467,6694, 513,2000,5681,2714,5263,5608,2778,5771,3427,5778,9609,1736,3717,8721,4684,4090,1224,9534,3014, + 6549,5853,7105, 792,2796,8925,8923,5420,1995,6112,1290,2196, 864, 344,1815,9813,6297,7477,1309,9605,1870,7211,3499,9999, + 8372,9780,4995,1059,7317,3281,6096,3185 + }; -// setbuf(stdout, NULL); + // setbuf(stdout, NULL); + k = 0; + for (i = 0; i <= PI_MAXARR; ++i) + arr[i] = PI_ARRINIT; - for (i = 0; i <= PI_MAXARR; ++i) - arr[i] = PI_ARRINIT; - for (i = PI_MAXARR; i; i -= 14) - { - int sum = 0; - for (j = i; j > 0; --j) - { - sum = sum*j + PI_SCALE*arr[j]; - arr[j] = sum % (j*2-1); - sum /= (j*2-1); - } - printf("%04d", carry + sum/PI_SCALE); - carry = sum % PI_SCALE; - } - printf("\n"); - return 0; + for (i = PI_MAXARR; i; i -= 14) + { + int sum = 0; + for (j = i; j > 0; --j) + { + sum = sum*j + PI_SCALE*arr[j]; + arr[j] = sum % (j*2-1); + sum /= (j*2-1); + } + result = carry + sum/PI_SCALE; + int_part = PI_SCALE * (result / PI_SCALE); + pi_res[k] = (UINT16)(result - int_part); + carry = sum % PI_SCALE; + k++; + } + + for (k=0; k < sizeof(pi_ref)/sizeof(UINT16); k++) + { + printf("%d", pi_res[k]); + } + printf("\n"); + + if(memcmp(pi_res, pi_ref, sizeof(pi_ref))) + return TEST15_ERROR; + + return NO_ERROR; } #define TEST_SIZE (16*1024*1024) // Bytes @@ -309,11 +445,24 @@ int pi_calc() int main (void) { int result, i, j, cnt, size; - volatile UINT32 *pUART_baud = (UINT32*)sys_uart_baud; - volatile UINT32 *pReg = (UINT32*)sys_led_port; - volatile UINT32 *pReg_usec = (UINT32*)sys_timer_usec; - volatile UINT32 *pReg_sec = (UINT32*)sys_timer_sec; - volatile UINT32 *pSSRAM = (UINT32*)sys_ssram_io; + UINT32 volatile *pUART_baud = (UINT32*)sys_uart_baud; + UINT32 volatile *pReg = (UINT32*)sys_led_port; + UINT32 volatile *pReg_usec = (UINT32*)sys_timer_usec; + UINT32 volatile *pReg_sec = (UINT32*)sys_timer_sec; + UINT32 volatile *pSSRAM = (UINT32*)sys_ssram_io; + UINT32 volatile *pTim_ctrl = (UINT32*)sys_itim_ctrl; + UINT32 volatile *pTim_stat = (UINT32*)sys_itim_stat; + UINT32 volatile *pTim_cnt = (UINT32*)sys_itim_cnt; + UINT32 volatile *pTim_cmp = (UINT32*)sys_itim_cmp; + + g_cnt = 1; + + srand(clock()); + + *pTim_cnt = 0; + *pTim_cmp = (UINT32)(rand() & 0x3FF); + *pTim_stat = 1; + *pTim_ctrl = 3; time_t curr_date; struct tm *pDate, date; UINT32 start, end; @@ -331,9 +480,13 @@ int main (void) setbuf(stdout, NULL); PrintCPUinfo(); - i = 0; + g_i = 0; memset(buffer, 0, sizeof(buffer)); interrupt_register(3, handler3); + fprintf(stderr, "UART interrupt registered.\n"); + + interrupt_register(7, handler7); + fprintf(stderr, "Timer interrupt registered.\n"); // ---------------------------------------------------------- // Memtest BEGIN @@ -365,9 +518,6 @@ int main (void) printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1000*(end-start))); */ // ---------------------------------------------------------- - printf("Dump Flash\n"); - PrintBuffer8((UINT8*)0, 16, 256); - // Memtest BEGIN printf("SDRAM Memory Test\n"); printf("Test size %d kByte\n\n", TEST_SIZE/1024); @@ -460,13 +610,16 @@ int main (void) else printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1000*(end-start))); + free(ram16); ram32 = (UINT32*)calloc(TEST_SIZE/4,sizeof(UINT32)); printf("Write (32-Bit access)..."); start = clock(); for (i=0; i < TEST_SIZE/4; i++) + { ram32[i] = (UINT32)i; + } end = clock(); printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1000*(end-start))); @@ -474,8 +627,10 @@ int main (void) printf("Verify (32-Bit access)..."); start = clock(); for (i=TEST_SIZE/4-1; i >= 0; i--) + { if (ram32[i] != (UINT32)i) break; + } end = clock(); i++; @@ -498,6 +653,8 @@ int main (void) end = clock(); printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1000*(end-start))); + // ------------------------------------------------------------------- + // Verify printf("Verify (32-Bit access)..."); start = clock(); for (j=0; j < TEST_SIZE/SMALL_TEST_SIZE; j++) @@ -512,6 +669,8 @@ int main (void) else printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1000*(end-start))); + // ------------------------------------------------------------------- + free(ram32); printf("Memcpy() Test \n"); @@ -530,21 +689,7 @@ int main (void) size = 0x2000; pSrc32 = (UINT32*)0xBFC00000; pDst32 = (UINT32*)calloc(size,sizeof(UINT32)); - printf("Copying %d kBytes...", size/1024); - start = clock(); memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - memcpy(pDst32, pSrc32, size); - end = clock(); - printf("done (%.2f MByte/s)\n", (double)10*size/(1000*(end-start))); - memdump((UINT8*)pSrc32, 0, 16, size); printf("Verify Boot code..."); for (i=size/4-1; i >= 0; i--) if (pDst32[i] != pSrc32[i]) @@ -557,10 +702,16 @@ int main (void) free(pDst32); + memdump((UINT8*)pSrc32, 0, 16, size); + // Memtest END // ---------------------------------------------------------- sputs("\r\n"); + printf("Aktuelles Datum\n"); + curr_date = time(NULL); + pDate = gmtime(&curr_date); + puts(asctime(pDate)); printf("Datum und Uhrzeit setzen? [j/N]: "); scanf("%s", sel); if (toupper(sel[0]) == 'J') @@ -602,9 +753,19 @@ int main (void) } interrupt_enable(3); + interrupt_enable(7); cnt = 0; while (1) { + for (i=0; i < 100000; i++) + { + interrupt_disable(7); + } + for (i=0; i < 100000; i++) + { + interrupt_enable(7); + } + *pReg = cnt & 0x3FFFFFFF; printf("-------------------------------------------\n"); @@ -632,15 +793,33 @@ int main (void) printf("passed\n\n"); printf("-------------------------------------------\n"); - printf("-- Paranoia -------------------------------\n"); + printf("-- Cop0 LWZ0 and SWC0 ---------------------\n"); printf("-------------------------------------------\n"); - paranoia(1, NULL); + result = Test13_COP0_Load_Store(); + if (IS_ERROR(result)) + break; + printf("passed\n\n"); + + printf("-------------------------------------------\n"); + printf("-- D-Cache invalidate ---------------------\n"); + printf("-------------------------------------------\n"); + result = Test14_DCACHE_invalidate(); + if (IS_ERROR(result)) + break; printf("passed\n\n"); printf("-------------------------------------------\n"); printf("-- PI calc --------------------------------\n"); printf("-------------------------------------------\n"); - pi_calc(); + result = Test15_pi_calc(); + if (IS_ERROR(result)) + break; + printf("passed\n\n"); + + printf("-------------------------------------------\n"); + printf("-- Paranoia -------------------------------\n"); + printf("-------------------------------------------\n"); + paranoia(1, NULL); printf("passed\n\n"); printf("Iteration %d: Passed\n", cnt); @@ -648,11 +827,13 @@ int main (void) pDate = gmtime(&curr_date); puts(asctime(pDate)); cnt++; + *pTim_cmp = (UINT32)(rand() & 0x3FF); + *pTim_ctrl |= 1; // printf("V=%.17e\n", pow((double)cnt-1, (double)cnt)); } *pReg = 0x40000000 | cnt; - printf("Failed with error %8.8X\n", result); + fprintf(stderr, "Failed with error %8.8X\n", result); return 1;