?? time_utils.c
字號:
/*
*
* Lucent PCI modem diagnostics tool.
*
* Copyright (c) 1999 Richard J.M. Close
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "time_utils.h"
// Time functions.
unsigned int VMODEM_Get_System_Time(void)
{
// Returns the number of milliseconds elasped based on the
// time since epoch (1/1/1970), but masked to fit into 64 bits.
struct timeval tv;
unsigned long sec_count;
gettimeofday (&tv, 0);
sec_count = tv.tv_sec;
// Mask to prevent overflow.
sec_count = sec_count & 0x3fffff;
return ((sec_count * 1000) + (tv.tv_usec / 1000));
}
unsigned short x_current_time(void)
{
return (unsigned short)(VMODEM_Get_System_Time() & 0xffff);
}
// Returns time elapsed from an absolute time to now
// in milliseconds.
unsigned short x_elapsed_time(unsigned short from)
{
#if !TRY_INTERRUPTS
dp_dsp_isr(); // Bodge for use with 'soft' IRQ!
#endif
return (0xffff &(x_current_time() - from));
}
// Returns time elapsed from an absolute time to now
// in milliseconds.
unsigned int x_elapsed_time_long(unsigned int from)
{
#if !TRY_INTERRUPTS
dp_dsp_isr(); // Bodge for use with 'soft' IRQ!
#endif
return (VMODEM_Get_System_Time() - from);
}
// Returns the number of milliseconds since the time held
// in the long timer structure argument.
// Not yet debugged.
unsigned int x_elapsed_long_time (struct lt_timer* long_timer_ptr)
{
unsigned short elapsed_mins, elapsed_ms;
// Crude first attempt!
// bottom two bytes hold minute count.
elapsed_mins = (unsigned short)x_minute_count - long_timer_ptr->t_min;
// top two bytes hold milliseconds portion.
elapsed_ms = (unsigned short)x_elapsed_time(x_minute_timer) - long_timer_ptr->t_msec;
return ((elapsed_mins * 600) + elapsed_ms);
}
// Sleeps for 'howlong' milliseconds.
void x_sleep(int howlong)
{
struct timeval tv;
tv.tv_sec = howlong / 1000;
tv.tv_usec = (howlong % 1000) * 1000;
select (0, 0, 0, 0, &tv);
}
void wait_for_core_read(void)
{
dp_cmd_timer = x_current_time();
// Wait for bit to be set, timing out after 100 milliseconds.
while ((dp_regread(0xD8) & 0x10) == 0)
{
if (x_elapsed_time(dp_cmd_timer) >= 100) break;
}
}
void x_wakeup (void)
{
// As per 565 ;)
if (!VMODEM_Timer_Active)
// If timer is not started then start it.
VMODEM_Start_Timer (5);
}
void VMODEM_Start_Timer(int arg)
{
if (arg !=0) {
VMODEM_Timer_Active = 1;
// Don't know what is going on here!
// *timerList = *jiffies + 1;
// *timerList = timertick_function;
// *timerList = 0;
timer_set = true ;
// add_timer(timerList);
}
else {
timer_stop = true;
VMODEM_Timer_Active = 0;
}
}
void x_set_current_time(struct lt_timer* time_ptr)
{
// bottom two bytes hold minute count.
time_ptr->t_min = (unsigned short)x_minute_count;
// top two bytes hold milliseconds portion.
time_ptr->t_msec = (unsigned short)x_elapsed_time(x_minute_timer);
}
unsigned short x_elapsed_minutes(struct lt_timer* time_ptr)
{
unsigned short ax;
if (x_minute_count == (*time_ptr).t_min) return 0;
ax = (x_minute_count - (*time_ptr).t_min);
if (x_elapsed_time(x_minute_timer) < (*time_ptr).t_msec)
ax--;;
return ax;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -