/* file "watch.c" * Reads the PowerPC Time Base Facility on Excimer and prints out a twenty * second count to the terminal emulator. Chuck Corley 981214 */ #include #include "Excimer.h" /* File of Excimer board-specific constants */ #include "Exercise.h" /* File of common typedefs */ #define printf dink_printf /* Enables Dynamic Fuct. So you can print to dink */ double dtime(); /* Given bus freq, returns time in seconds. */ unsigned long get_HID1(); /* Returns HID1 register. */ int main() { double begin_time, current_time, delta_time = 0.0, seconds = 0.0; int int_seconds; unsigned long HID1_Reg; set_up_transfer_base(); /* Capture the dink transfer table address enabling the ability to printf */ printf("PowerPC Timer Test.\n"); printf("Beginning a twenty second count assuming bus speed of 66.67MHz.\n"); printf("Please time me.\n"); printf("If your stopwatch time differs significantly from 20 seconds, \n"); printf("we can compute the actual bus speed.\n"); begin_time = dtime(); for (int_seconds = -1; int_seconds <= 20; int_seconds++) /*Countup to start.*/ { while (delta_time < 1.0) { current_time = dtime(); delta_time = current_time - (int_seconds) - begin_time; } delta_time = 0.0; switch (int_seconds) { case -1 : break; /* Delay to get stopwatch ready. */ case 0 : printf("Start now!\n"); /* Begin timing at zero seconds. */ break; case 1: printf("%d second\n", int_seconds); break; default: printf("%d seconds\n", int_seconds); } /* End of int_seconds switch */ }; printf("If your time was not 20 seconds,\n"); printf("bus speed is (20 / your_time) * 66.67MHz.\n"); /* Bonus Exercise. Given the bus speed, calculate the processor (core) speed.*/ HID1_Reg = get_HID1() >> 28; /* Move HID1[0:3] to [28:31] */ printf("HID1 indicates PLL_CFG=%x.\n", HID1_Reg ); printf("If bus=%dMHz, ", IBUS_MHz); switch (HID1_Reg) { case 0x4: /* PLL_CFG = 0b0100 */ printf("Core Freq(2x)=%dMHz & ", 2*IBUS_MHz); printf("VCO Freq(2x)=%dMHz\n", 2*IBUS_MHz); break; case 0x5: /* PLL_CFG = 0b0101 */ printf("Core Freq(2x)=%dMHz & ", 2*IBUS_MHz); printf("VCO Freq(4x)=%dMHz\n", 4*IBUS_MHz); break; case 0x6: /* PLL_CFG = 0b0110 */ printf("Core Freq(2.5x)=%dMHz & ", (int)(2.5*(float)IBUS_MHz)); printf("VCO Freq(2x)=%dMHz\n", 5*IBUS_MHz); break; case 0x8: /* PLL_CFG = 0b1000 */ printf("Core Freq(3x)=%dMHz & ", 3*IBUS_MHz); printf("VCO Freq(2x)=%dMHz\n", 6*IBUS_MHz); break; case 0xe: /* PLL_CFG = 0b1110 */ printf("Core Freq(3.5x)=%dMHz & ",(int)(3.5*(float)IBUS_MHz)); printf("VCO Freq(2x)=%dMHz\n", 7*IBUS_MHz); break; case 0xa: /* PLL_CFG = 0b1010 */ printf("Core Freq(4x)=%dMHz & ", 4*IBUS_MHz); printf("VCO Freq(2x)=%dMHz\n", 8*IBUS_MHz); break; case 0x7: /* PLL_CFG = 0b0111 */ printf("Core Freq(4.5x)=%dMHz & ",(int)(4.5*(float)IBUS_MHz)); printf("VCO Freq(2x)=%dMHz\n", 9*IBUS_MHz); break; case 0xb: /* PLL_CFG = 0b1011 */ printf("Core Freq(5x)=%dMHz & ", 5*IBUS_MHz); printf("VCO Freq(2x)=%dMHz\n", 10*IBUS_MHz); break; case 0x9: /* PLL_CFG = 0b1001 */ printf("Core Freq(5.5x)=%dMHz & ",(int)(5.5*(float)IBUS_MHz)); printf("VCO Freq(2x)=%dMHz\n", 11*IBUS_MHz); break; case 0xd: /* PLL_CFG = 0b1101 */ printf("Core Freq(6x)=%dMHz & ", 6*IBUS_MHz); printf("VCO Freq(2x)=%dMHz\n", 12*IBUS_MHz); break; case 0x3: /* PLL_CFG = 0b0011 */ printf("PLL in bypass!\n"); break; case 0xf: /* PLL_CFG = 0b0011 */ printf("CLOCK OFF! How can this be???\n"); break; default: printf("ERROR - INVALID PLL_CFG!"); } /* End of HID1 switch */ return 0; }