Пример #1
0
// Cause CPU Sucker to go between ON and OFF.
void modulate( int pid, int on_time, int off_time )
{
    int RC;
    signal( SIGUSR1, mod_usr1_handle );
    while ( stopSucker == 0 ) {
	u_sleep(0, on_time);
	kill( childPid, SIGUSR1 );
	
	u_sleep(0, off_time);
	kill( childPid, SIGUSR2 );
    }

    kill( childPid, SIGKILL );
}
Пример #2
0
void check_obf()
{
	unsigned long temp;
	int i;

	xxcprintf(g_e, "Waiting for OBF\n");
	temp = pucPtr[HT6542_STAT];
	xxcprintf(g_e, "HT6542B Status = %x\n", temp);

	for (i = 0; i < HT6542_MAX_WAIT; i++)
	{
		if (pucPtr[HT6542_STAT] & HT6542_STAT_OBF)
			break;

		u_sleep(10);
	}

	if (pucPtr[HT6542_STAT] & HT6542_STAT_OBF)
		xxcprintf(g_e, "Got an OBF\n");
	else
		xxcprintf(g_e, "Missed an OBF\n");

	// did we get aninterrupt on eint1?
	temp = pulPtr[HwIntStatus >> 2];
	temp = temp & HwIrqExt1;
	xxcprintf(g_e, "Interrupt Status Register = %x\n", temp);
}
Пример #3
0
static void
kbd_out(int port, uByte val)
{
	DPRINTF(("kbd_out: port=%#x val=%#x\n", port, (uInt)val));
	*(uByte *)port = val;
	u_sleep(10);
}
Пример #4
0
/*-------------------------------------------------------------------------*/
int frontpanel_ice::fp_available(const char *device, int force)
{
#ifdef RBMINI   
	return 0;
#else
	struct stat sbuf;
	if (!force) {
		if (!stat(CAP_ICE,&sbuf))
			return 1;
		if (!stat(CAP_NOICE,&sbuf))
			return 0;
	}
	frontpanel_ice fp(device);
	fp.fp_noop();
	fp.fp_noop();
	fp.fp_noop();
	fp.fp_noop();
	fp.fp_get_version();
	unsigned char buf[20];
	int l;
	u_sleep(20*1000);
	l=fp.fp_read_msg(buf,NULL);
	if (l>0)
		return 1;
	else
		return 0;
#endif
}
Пример #5
0
/*-------------------------------------------------------------------------*/
void frontpanel_rs232::fp_display_data(char *data, int l)
{
	char buf[64]={0xa5,0x05,l+2,+1};
	memcpy(buf+4,data,l);
	fp_write(buf,l+4);
	u_sleep(3000);
}
Пример #6
0
void check_ibf()
{
	unsigned long temp;
	xxcprintf(g_e, "Waiting for IBF\n");
	temp = pucPtr[HT6542_STAT];
	xxcprintf(g_e, "HT6542B Status = %x\n", temp);

	while(pucPtr[HT6542_STAT] & HT6542_STAT_IBF)
		u_sleep(10);
}
Пример #7
0
/* I/O routines to talk to ISA ports */
static uByte
kbd_in(int port)
{
	uByte val = 0;

	val = *(uByte *)port;
	u_sleep(10);
	DPRINTF(("kbd_in: port=%#x val=%#x\n", port, (uInt)val));
	return val;
}
Пример #8
0
// send a command to the keyboard.  re-sends if requested.
// returns 0 if the keyboard response is bad, otherwise
// returns the response data.
unsigned char send_kbd_cmd(unsigned char data)
{
	unsigned char temp;
	int i;

	// flush obf
	flush_obf();

	// send the first time
	check_ibf();
	pucPtr[HT6542_DAT] = data;
	u_sleep(10);

	for (i = 0; i < HT6542_MAX_RESENDS; i++)
	{
		if(!check_tx())
		{
			check_obf();
			temp = pucPtr[HT6542_DAT];

			if (temp == 0x30)
			{
				check_obf();
				temp = pucPtr[HT6542_DAT];
			}

			if( temp == KBD_STAT_RESEND)
			{
				pucPtr[HT6542_DAT] = data;
			}
			else	// if not re-send, then see if it's ack
			{
				if(temp == KBD_STAT_ACK)
				{
					return temp;
				}
				else 	// not re-send or ack so return with error
				{
					xxcprintf(g_e, "No Resend or ACK, data %x\n", temp);
					return temp;
				}
			}
		} // if !check_tx
		else
		{
			xxcprintf(g_e, "TX Timeout\n");
			return 1;		
		}
	} // while 1

	xxcprintf(g_e, "Too many resends\n");
	return 1;		
} // main
Пример #9
0
void flush_send_buffers(struct sb_config *sb, struct connection_pair *cp)
{
	register int i, cb, pb;

	pthread_mutex_lock(&sb->lock);
	cb = sb->current_buffer;
	pb = sb->prev_buffer;
	pthread_mutex_unlock(&sb->lock);

	/* if buffer has made some head way, flush everything that lies before
	 * the current_buffer in reverse order.
	 */
	if (cb > 0) {
		for (i = (cb - 1); i != 0; --i)
			__flush_send_buffer(&sb->buffers[i], cp);

		__flush_send_buffer(&sb->buffers[0], cp);
	}

	/* if the current_buffer has wrapped around take care of tail end */
	if (pb > cb) {
		fprintf(stderr, "looks like buffer wrapped around. (%d, %d)", pb, cb);
		for (i = pb; i < sb->n_buffers; ++i)
			__flush_send_buffer(&sb->buffers[i], cp);
	}

	/* if the current_buffer is slow to fill up give it 8 chances before 
	 * forcing a flush on it.
	 */
	if (pb == cb) {
		if (sb->skips == 8) {
			fprintf(stderr, "buffer %d had 8 chances to fill but did not!\n", cb);
			if(__flush_send_buffer(&sb->buffers[cb], cp) <= 0){
				u_sleep(0, FLUSH_TIMEOUT);
			}else{
				sb->skips = 0;
			}
		} else {
			++(sb->skips);
		}
	}

	pthread_mutex_lock(&sb->lock);
	sb->prev_buffer = cb;
	pthread_mutex_unlock(&sb->lock);
}
Пример #10
0
// Suck CPU
void suck_cpu() {
  int i = 0;

  signal( SIGUSR1, suck_usr1_handle );
  signal( SIGUSR2, suck_usr2_handle );

  while (1) {
    if (suckerOn) {
      i++;
      if (((i % 5000) == 0) && suckerOn) {
	sched_yield();
      }
    } else {
      u_sleep(0, 100);
    }
  }
}
Пример #11
0
void flush_send_buffers(struct sb_config *sb, struct connection_pair *cp)
{
	register int i, cb;

	lock_whole_buffer(sb);
	cb = sb->current_buffer;
	unlock_whole_buffer(sb);

	/* flush all buffers preceding current_buffer */
	if (cb > 0) {
		for (i = (cb - 1); i != 0; --i)
			flush_send_buffer(sb, &sb->buffers[i], cp);
		flush_send_buffer(sb, &sb->buffers[0], cp);
	}

	/* current_buffer may have wrapped around */
	lock_whole_buffer(sb);
	if (sb->prev_buffer > cb) {
		fprintf(stderr, "looks like buffer wrapped around. (%d, %d)", sb->prev_buffer, cb);
		for (i = sb->prev_buffer; i < sb->n_buffers; ++i)
			flush_send_buffer(sb, &sb->buffers[i], cp);
	}
	unlock_whole_buffer(sb);

	/* current_buffer may be too slow to fill */
	lock_whole_buffer(sb);
	if(sb->prev_buffer != cb){
		sb->prev_buffer = cb;
		unlock_whole_buffer(sb);
		return;
	}

	if (sb->skips == 8) {
		fprintf(stderr, "buffer %d had 8 chances to fill but did not!\n", cb);
		if(flush_send_buffer(sb, &sb->buffers[cb], cp) == 0){
			unlock_whole_buffer(sb);
			u_sleep(0, FLUSH_TIMEOUT); /* ZZZZzzzzzz */
		}else{
			(sb->skips) = 0;
			unlock_whole_buffer(sb);
		}
	} else {
		++(sb->skips);
		unlock_whole_buffer(sb);
	}
}
Пример #12
0
int check_tx()
{
	int i;
	xxcprintf(g_e, "Waiting for OBF or TX Timeout\n");

	for (i = 0; i < HT6542_MAX_WAIT; i++)
	{
		if (pucPtr[HT6542_STAT] & HT6542_STAT_TX)
		{
			return 1;	// tx means no keyboard present
		}
		if (pucPtr[HT6542_STAT] & HT6542_STAT_OBF)
		{
			return 0;	// obf is good
		}
		u_sleep(10);
	}

	return 1;
}
Пример #13
0
void flush_obf()
{
	unsigned long temp;
	int i;

	xxcprintf(g_e, "Clearing OBF\n");
	temp = pucPtr[HT6542_STAT];
	xxcprintf(g_e, "HT6542B Status = %x\n", temp);

	for (i = 0; i < HT6542_MAX_WAIT; i++)
	{
		if (!(pucPtr[HT6542_STAT] & HT6542_STAT_OBF))
			break;

		temp = pucPtr[HT6542_DAT];
		xxcprintf(g_e, "HT6542B Flush Data = %x\n", temp);
		u_sleep(10);
	}

	if (i >= HT6542_MAX_WAIT)
		xxcprintf(g_e, "HT6542B Flush Failed\n");
}
Пример #14
0
/* {{{ libssh2_blocking_read
 * Force a blocking read, regardless of socket settings
 */
static int libssh2_blocking_read(LIBSSH2_SESSION *session, unsigned char *buf, size_t count)
{
	size_t bytes_read = 0;
#if !defined(HAVE_POLL) && !defined(HAVE_SELECT)
	int polls = 0;
#endif

#ifndef WIN32
	fcntl(session->socket_fd, F_SETFL, 0);
#else
	{
		u_long block = FALSE;
		ioctlsocket(session->socket_fd, FIONBIO, &block);
	}
#endif

#ifdef LIBSSH2_DEBUG_TRANSPORT
	_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Blocking read: %d bytes", (int)count);
#endif

	while (bytes_read < count) {
		int ret;

		ret = recv(session->socket_fd, buf + bytes_read, count - bytes_read, LIBSSH2_SOCKET_RECV_FLAGS(session));
		if (ret < 0) {
#ifdef WIN32
			switch (WSAGetLastError()) {
				case WSAEWOULDBLOCK:	errno = EAGAIN;		break;
				case WSAENOTSOCK:		errno = EBADF;		break;
				case WSAENOTCONN:
				case WSAECONNABORTED:	errno = ENOTCONN;	break;
				case WSAEINTR:			errno = EINTR;		break;
			}
#endif
			if (errno == EAGAIN) {
#ifdef HAVE_POLL
				struct pollfd read_socket;

				read_socket.fd = session->socket_fd;
				read_socket.events = POLLIN;

				if (poll(&read_socket, 1, 30000) <= 0) {
					return -1;
				}
#elif defined(HAVE_SELECT)
				fd_set read_socket;
				struct timeval timeout;

				FD_ZERO(&read_socket);
				FD_SET(session->socket_fd, &read_socket);

				timeout.tv_sec = 30;
				timeout.tv_usec = 0;

				if (select(session->socket_fd + 1, &read_socket, NULL, NULL, &timeout) <= 0) {
					return -1;
				}
#else
				if (polls++ > LIBSSH2_SOCKET_POLL_MAXLOOPS) {
					return -1;
				}
				u_sleep(LIBSSH2_SOCKET_POLL_UDELAY);
#endif /* POLL/SELECT/SLEEP */
				continue;
			}
			if (errno == EINTR) {
				continue;
			}
			if ((errno == EBADF) || (errno == EIO) || (errno == ENOTCONN)) {
				session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
			}
			return -1;
		}
		if (ret == 0) continue;

		bytes_read += ret;
	}

#ifdef LIBSSH2_DEBUG_TRANSPORT
	_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Blocking read: %d bytes actually read", (int)bytes_read);
#endif

	return bytes_read;
}
Пример #15
0
static int
run_sequence(Environ *e, Self *s, const Sequence *seq, int offset, 
	uByte *data)
{
	uInt off;
	int w = s->width;
	uByte *t = &s->buf[w];

	if (offset < 0 || offset >= s->meths->size)
		return 0;

	for (; seq->type; seq++)
	{
#ifdef DEBUG2
		DPRINTF(("run_seq: seq %p, type %d\n", seq, seq->type));
#endif

		if (seq->offset < 0)
			off = offset;
		else
		{
			off = seq->offset * s->partswide;

			if (!FLASH_MAP_ADDR(s, &off))
				return 0;
		}

		switch (seq->type)
		{
		case FLASH_SEQ_WRITE:
			/* fill buf with data */
			fill_buffer(e, s, t, seq->data);

			/* map data in buf */
			if (!(FLASH_MAP_DATA(s, t)))
				return 0;

			/* write data */
			if (!FLASH_WRITE(s, off, t))
				return 0;

			break;
		case FLASH_SEQ_WRITE_DATA:
			if (!FLASH_WRITE(s, off, data))
				return 0;

			break;
		case FLASH_SEQ_READ_MANUF:
		case FLASH_SEQ_READ_DATA:
			if (!FLASH_READ(s, off, data))
				return 0;

			break;
		case FLASH_SEQ_READ_DEVID:
			if (!FLASH_READ(s, off, &data[s->width]))
				return 0;

			break;
		case FLASH_SEQ_WAIT_STATUS:
		case FLASH_SEQ_WAIT_TOGGLE:
		case FLASH_SEQ_WAIT_INVERT:
			{
				uByte *mask = &s->buf[2 * w];
				uByte *opdata = &s->buf[3 * w];
				fill_buffer(e, s, mask, seq->mask);
				fill_buffer(e, s, opdata, seq->data);

				if (!FLASH_MAP_DATA(s, mask))
					return 0;

				if (!FLASH_MAP_DATA(s, opdata))
					return 0;

				if (seq->type == FLASH_SEQ_WAIT_STATUS)
				{
					if (!flash_wait_status(e, s, off, mask, opdata))
						return 0;
				}
				else if (seq->type == FLASH_SEQ_WAIT_TOGGLE)
				{
					if (!flash_wait_toggle(e, s, off, mask, opdata))
						return 0;
				}
				else
				{
					if (!flash_wait_invert(e, s, off, mask, data))
						return 0;
				}
			}

			break;
		case FLASH_SEQ_DELAY:
			u_sleep(seq->data);
			break;
		default:
			return 0;
		}
	}

	return 1;
}