/* AS/400 High-Resolution Clock Reader Choose your browser's option to 'Save As...' to download this code example. Send the program to your AS/400 using FTP or similar method and compile it using the development facilities supplied there. This program was developed on a V4R3 system. This small program that is furnished by IBM is a simple example to provide an illustration. This example has not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of this program. All programs contained herein are provided to you "AS IS". THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. ----------------------------------------------------------------------- You can use the Materialize Time-of-Day (mattod) function to get the current tick on the system clock. Currently, the system clock is really only 49 bits long, but it is returned nicely in a 64-bit unsigned integer as the first (high-order) 49 bits. The low-order 15 bits are not clocked. They are used, though. No 2 succeeding calls to the mattod() function will return the same number. The low-order 15 bits are incremented to cover the situation of 2 calls within the same clock tick. Naturally, the 2 calls ought not return the same time. There are 8 microseconds to a single clock tick. This is the finest resolution presented by the clock above the MI. This translates to a precision of 0.008 ms. (Actually, the potenial for sub-nanosecod precision is built in, but the low 15 bits are not clocked as of V4R3.) Simply right-shift the 64-bit int by 15 bits to get the number of ticks. Interestingly enough, this number will be 0x0FFFFFFFFFFFF at the end of 1999, and 0x1000000000000 in the first instant of the year 2000. How's that for century-checking efficiency, required by Y2K fixes? (This was done way before 1990!) This sample program ignores the last 15 bits and displays 10 tick counts. Note that this uses 64-bit integer support, which is first implemented by ILE C at V4R3. For earlier releases, use a structure of 2 32-bit unsigned integers or the _MI_Time type, which would be syntactically correct. */ #include #include #include void main() { unsigned long long t[10]; int i; /* get 10 consecutive time readings */ for (i=0; i<10; i++){ mattod((char*)&(t[i])); printf(" "); /* slight delay */ } printf("\n"); for (i=0; i<10; i++) { printf("Original Hex:0x%llX " , t[i]); /* right-shift the clock bits from high to low for number of ticks */ t[i] = t[i] >> 15; printf("ticks:%lld \n", t[i]); } }