Timing.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:5k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: Timing.c $
- *
- * Description:
- * ============
- * core timing services
- *
- * Log:
- * ====
- * $Revision: 8 $
- * Last Modified by $Author: Nirm $ at $Modtime: 1/05/02 9:28 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I49/H49V/Playcore/Timing/Timing.c $
- *
- * 8 7/05/02 15:59 Nirm
- * Code cleanup.
- *
- * 7 23/04/02 9:36 Nirm
- * - Added dependency in "Config.h".
- *
- * 6 18/02/02 11:01 Atai
- * make global to static
- *
- * 5 16/01/02 16:00 Atai
- * Change debug printing
- *
- * 4 13/01/02 16:34 Atai
- * Remove old Defines
- *
- * 3 9/01/02 16:55 Nirm
- * Corrected Include-Paths.
- *
- * 2 30/12/01 13:13 Atai
- * Remove unnecessary variable
- **************************************************************************************** */
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include <stdio.h>
- #include "Includesysdefs.h"
- #include "CPUtimefunc.h"
- #include "PlaycoreTimingtiming.h"
- #define MAX_DOUBLE_WORD 0xFFFFFFFFL
- #ifdef EVENT_LOG_ENABLED
- typedef struct Time_Field
- {
- char *str;
- unsigned long TimeRecord;
- } Time_Field;
- #define MAX_TIME_RECORDS 1 /* don't use any memory now */
- Time_Field TimeRecordAr[MAX_TIME_RECORDS];
- unsigned Record_idx = 0;
- static unsigned Total_Records = 0;
- static unsigned wrap_around = 0;
- void timing_init(void)
- {
- // Initialize local vairables
- timing_reset();
- gen_timer(); // Start the timer and interrupt services.
- }
- void timing_reset( void )
- {
- // Resets the Timing Module array & vars
- Record_idx = 0;
- Total_Records = 0;
- wrap_around = 0;
- }
- void timing_record( char *str )
- {
- // Records the current timerX reading in a cyclic readings array
- // Records the time + the ID to enable tarceing
- TimeRecordAr[ Record_idx ].str = str;
- TimeRecordAr[ Record_idx ].TimeRecord = gen_timer();
- Record_idx++;
- if (wrap_around == 0)
- {
- Total_Records++;
- }
- if (Record_idx == MAX_TIME_RECORDS)
- {
- Record_idx = 0; // Cyclic buffer
- wrap_around = 1;
- }
- }
- void timing_print(void)
- {
- // Prints the timing array in mSec resolution and resets the array
- unsigned i, j;
- unsigned long last;
- dbg_printf((" ***************** TIMING RECORDS ******************** n "));
- if (wrap_around)
- {
- j = Record_idx;
- }
- else
- {
- j = 0;
- }
-
- last = TimeRecordAr [j].TimeRecord;
- for (i=0; (i < Total_Records) ; i++)
- {
- dbg_printf(("#%02d: time=%08lx[us] , delta=%08lu[us], '%s'n ",
- j,
- TimeRecordAr[j].TimeRecord,
- TimeRecordAr[j].TimeRecord - last,
- TimeRecordAr[j].str));
- last = TimeRecordAr [j].TimeRecord;
- j++;
- if (j == MAX_TIME_RECORDS)
- {
- j = 0; // Cyclic buffer
- }
- }
- dbg_printf((" **************** TIMING RECORDS END ***************** n "));
- }
- #endif // EVENT_LOG_ENABLED
- /////////////////////////////////////////////////////////////////////////////
- // Function name : delay_us
- // Purpose :
- // Input Parameters :
- // Return type : none.
- // Output Parameters: none.
- /////////////////////////////////////////////////////////////////////////////
- void delay_us(ULONG period_us)
- {
- volatile ULONG count1, count2, diff;
- count1 = gen_timer();
- diff = 0;
- while (diff < period_us) {
- count2 = gen_timer();
- if ( count2 < count1 )
- diff = ((MAX_DOUBLE_WORD - count1) + count2 + 1);
- else
- diff = (count2 - count1);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : timing_get_clock
- // Purpose : Get a time stamp (in micro seconds).
- // Input Parameters : The time stamp.
- // Return type : none.
- // Output Parameters: none.
- /////////////////////////////////////////////////////////////////////////////
- ULONG timing_get_clock(void)
- {
- return gen_timer();
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : timing_get_diff
- // Purpose : Calculate the difference between 2 time stamps.
- // Input Parameters : start - The start timestamp.
- // end - the end timestamp.
- // Return type : the difference between the timestamps.
- // Output Parameters: none.
- /////////////////////////////////////////////////////////////////////////////
- ULONG timing_get_diff(ULONG start, ULONG end)
- {
- if (end < start)
- {
- return (MAX_DOUBLE_WORD - start) + end + 1;
- }
- else
- {
- return end - start;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : timing_is_timeout
- // Purpose :
- // Input Parameters :
- // Return type :
- // Output Parameters: none.
- /////////////////////////////////////////////////////////////////////////////
- BOOL timing_is_timeout(ULONG start_time, ULONG timeout)
- {
- ULONG cur_time = gen_timer();
- return (timing_get_diff(start_time, cur_time) >= timeout) ? TRUE : FALSE;
- }