Moved the uPause function to timmings.h for modularity and easier porting to BSD.
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
*
|
||||
* Modified October 2001 to read the configfile.
|
||||
*
|
||||
* Moved the delay timing code by Charles Steinkuehler to timing.h.
|
||||
* Guillaume Filion <gfk@logidac.com>, December 2001
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
* COPYING file distributed with this package.
|
||||
*
|
||||
@@ -49,31 +52,7 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include "port.h"
|
||||
|
||||
// Uncomment one of the lines below to select your desired delay generation
|
||||
// mechanism. If both defines are commented, the original I/O read timing
|
||||
// loop is used. Using DELAY_NANOSLEEP seems to provide the best performance.
|
||||
//#define DELAY_GETTIMEOFDAY
|
||||
#define DELAY_NANOSLEEP
|
||||
|
||||
# if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
# else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
// Only one alternate delay method at a time, please ;-)
|
||||
#if defined DELAY_GETTIMEOFDAY
|
||||
# undef DELAY_NANOSLEEP
|
||||
#elif defined DELAY_NANOSLEEP
|
||||
# include <sched.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
#include "timing.h"
|
||||
|
||||
#include "shared/str.h"
|
||||
#include "render.h"
|
||||
@@ -116,7 +95,6 @@ static int *dispSizes = NULL;
|
||||
char have_keypad = 0; // off by default
|
||||
char have_backlight = 0; // off by default
|
||||
char extIF = 0; // off by default
|
||||
int delayMult = 0; // Delay multiplier for slow displays
|
||||
char delayBus = 0; // Delay if the computer can send data too fast over
|
||||
// its bus to LPT port
|
||||
|
||||
@@ -175,7 +153,7 @@ void HD44780_draw_frame (char *dat);
|
||||
char HD44780_getkey ();
|
||||
|
||||
void HD44780_position (int x, int y);
|
||||
static void uPause (int delayCalls);
|
||||
//static void uPause (int delayCalls);
|
||||
unsigned char HD44780_scankeypad();
|
||||
static int parse_span_list (int *spanListArray[], int *spLsize, int *dispOffsets[], int *dOffsize, int *dispSizeArray[], char *spanlist);
|
||||
|
||||
@@ -253,19 +231,8 @@ HD44780_init (lcd_logical_driver * driver, char *args)
|
||||
fprintf (stderr, "Error mallocing for display sizes list\n");
|
||||
}
|
||||
|
||||
|
||||
#if defined DELAY_NANOSLEEP
|
||||
// Change to Round-Robin scheduling for nanosleep
|
||||
{
|
||||
// Set priority to 1
|
||||
struct sched_param param;
|
||||
param.sched_priority=1;
|
||||
if (( sched_setscheduler(0, SCHED_RR, ¶m)) == -1) {
|
||||
fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (timing_init() == -1)
|
||||
return -1;
|
||||
|
||||
// Make sure the frame buffer is there...
|
||||
if (!HD44780->framebuf)
|
||||
@@ -317,7 +284,7 @@ HD44780_init (lcd_logical_driver * driver, char *args)
|
||||
if ((hd44780_functions = (HD44780_functions *) malloc (sizeof (HD44780_functions))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
hd44780_functions->uPause = uPause;
|
||||
hd44780_functions->uPause = timing_uPause;
|
||||
hd44780_functions->scankeypad = HD44780_scankeypad;
|
||||
|
||||
connectionMapping[connectiontype_index].init_fn (hd44780_functions, driver, args, port);
|
||||
@@ -350,47 +317,6 @@ common_init ()
|
||||
hd44780_functions->uPause (1600);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// IO delay to avoid a task switch
|
||||
//
|
||||
void
|
||||
uPause (int usecs)
|
||||
{
|
||||
int delay = usecs * delayMult; // To correct for slower displays
|
||||
|
||||
#if defined DELAY_GETTIMEOFDAY
|
||||
struct timeval current_time,delay_time,wait_time;
|
||||
|
||||
// Get current time first thing
|
||||
gettimeofday(¤t_time,NULL);
|
||||
|
||||
// Calculate when delay is over
|
||||
delay_time.tv_sec = 0;
|
||||
delay_time.tv_usec = delay;
|
||||
timeradd(¤t_time,&delay_time,&wait_time);
|
||||
|
||||
do {
|
||||
gettimeofday(¤t_time,NULL);
|
||||
} while (timercmp(¤t_time,&wait_time,<));
|
||||
|
||||
#elif defined DELAY_NANOSLEEP
|
||||
struct timespec delay_time,remaining;
|
||||
|
||||
delay_time.tv_sec = 0;
|
||||
delay_time.tv_nsec = delay * 1000;
|
||||
while ( nanosleep(&delay_time,&remaining) == -1 )
|
||||
{
|
||||
delay_time.tv_sec = remaining.tv_sec;
|
||||
delay_time.tv_nsec = remaining.tv_nsec;
|
||||
}
|
||||
#else // using I/O timing
|
||||
// Assuming every call takes 1us (which can be quite incorrect)
|
||||
int i;
|
||||
for (i = 0; i < delay; ++i)
|
||||
port_in (port);
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Clean-up
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user