Exemplo n.º 1
0
double transfer(struct adafs_touch_state ts[],
    enum state *s, enum event ev, double in) {
  switch (*s) {
  case ST_CON:
    if (ev == EV_USER) {
      update_hist_int(ts, ST_CON, in);
      update_timer(ts, ST_CON);
      return threshold(ts);
    } else if (ev == EV_TIMER) {
      *s = ST_DIS;
      return predict_int(ts);
    } else fprintf(stderr, "Invalid event %d on state %d\n", ev, *s);
    break;
  case ST_DIS:
    rec_result(ts, in);
    if (ev == EV_USER) {
      if (in <= threshold(ts)) {
        *s = ST_CON;
        update_hist_int(ts, ST_CON, in);
        update_timer(ts, ST_CON);
        return threshold(ts);
      } else {
        *s = ST_DIS_DOWN;
        update_hist_int(ts, ST_DIS, in);
        return threshold(ts);
      }
    } else if (ev == EV_TIMER) {
      *s = ST_DIS_UP;
    } else fprintf(stderr, "Invalid event %d on state %d\n", ev, *s); 
    break;
  case ST_DIS_DOWN:
    if (ev == EV_USER) {
      *s = ST_CON;
      update_hist_int(ts, ST_CON, in);
      update_timer(ts, ST_CON);
      return threshold(ts);
    } else if (ev == EV_TIMER) {
      *s = ST_DIS;
      return predict_int(ts);
    } else fprintf(stderr, "Invalid event %d on state %d\n", ev, *s);
    break;
  case ST_DIS_UP:
    if (ev == EV_USER) {
      *s = ST_CON;
      update_hist_int(ts, ST_DIS, in);
      return threshold(ts);
    } else fprintf(stderr, "Invalid event %d on state %d\n", ev, *s);
    break;
  }
  return INVAL_TIME;
}
Exemplo n.º 2
0
static void timer_queue_push(uint32_t core_id, task_t* task)
{
	task_list_t* timer_queue = &readyqueues[core_id].timers;

	spinlock_irqsave_lock(&readyqueues[core_id].lock);

	task_t* first = timer_queue->first;

	if(!first) {
		timer_queue->first = timer_queue->last = task;
		task->next = task->prev = NULL;

#ifdef DYNAMIC_TICKS
		update_timer(task);
#endif
	} else {
		// lookup position where to insert task
		task_t* tmp = first;
		while(tmp && (task->timeout >= tmp->timeout))
			tmp = tmp->next;

		if(!tmp) {
			// insert at the end of queue
			task->next = NULL;
			task->prev = timer_queue->last;

			// there has to be a last element because there is also a first one
			timer_queue->last->next = task;
			timer_queue->last = task;
		} else {
			task->next = tmp;
			task->prev = tmp->prev;
			tmp->prev = task;

			if(task->prev)
				task->prev->next = task;

			if(timer_queue->first == tmp) {
				timer_queue->first = task;

#ifdef DYNAMIC_TICKS
				update_timer(task);
#endif
			}
		}
	}

	spinlock_irqsave_unlock(&readyqueues[core_id].lock);
}
Exemplo n.º 3
0
int riotcore_snapshot_write_module(riot_context_t *riot_context, snapshot_t *p)
{
    snapshot_module_t *m;

    m = snapshot_module_create(p, riot_context->myname,
                               RIOT_DUMP_VER_MAJOR, RIOT_DUMP_VER_MINOR);
    if (m == NULL)
        return -1;

    update_timer(riot_context);

    SMW_B(m, riot_context->riot_io[0]);
    SMW_B(m, riot_context->riot_io[1]);
    SMW_B(m, riot_context->riot_io[2]);
    SMW_B(m, riot_context->riot_io[3]);

    SMW_B(m, riot_context->r_edgectrl);
    SMW_B(m, (BYTE)(riot_context->r_irqfl | (riot_context->r_irqline ? 1 : 0)));

    SMW_B(m, (BYTE)(riot_context->r_N - (*(riot_context->clk_ptr)
          - riot_context->r_write_clk)
          / riot_context->r_divider));
    SMW_W(m, (WORD)(riot_context->r_divider));
    SMW_W(m, (BYTE)((*(riot_context->clk_ptr) - riot_context->r_write_clk)
          % riot_context->r_divider));
    SMW_B(m, (BYTE)(riot_context->r_irqen ? 1 : 0));

    snapshot_module_close(m);

    return 0;
}
Exemplo n.º 4
0
void mc146818_device::nvram_default()
{
	// populate from a memory region if present
	if (m_region != NULL)
	{
		UINT32 bytes = m_region->bytes();

		if (bytes > data_size())
			bytes = data_size();

		memcpy(&m_data[0], m_region->base(), bytes);
	}
	else
	{
		memset(&m_data[0], 0, data_size());
	}

	if(m_binary)
		m_data[REG_B] |= REG_B_DM;
	if(m_hour)
		m_data[REG_B] |= REG_B_24_12;

	set_base_datetime();
	update_timer();
	update_irq();
}
Exemplo n.º 5
0
/**
 * uart_tty_receive() - Called by TTY low level driver when receive data is available.
 * @tty:	Pointer to TTY instance data
 * @data:	Pointer to received data
 * @flags:	Pointer to flags for data
 * @count:	Count of received data in bytes
 */
static void uart_tty_receive(struct tty_struct *tty, const u8 *data,
			     char *flags, int count)
{
	CG2900_INFO("uart_tty_receive");

	if (tty != uart_info->tty)
		return;

	CG2900_DBG_DATA("Received data with length = %d and first byte 0x%02X",
			count, data[0]);
	CG2900_DBG_DATA_CONTENT("uart_tty_receive", data, count);
#ifdef BAUD_RATE_FIX
	del_timer(&uart_info->timer);
#endif /* BAUD_RATE_FIX */

	/* Restart data ccd timer */
	spin_lock(&uart_info->rx_lock);
#ifndef BAUD_RATE_FIX
	update_timer();
#endif /* BAUD_RATE_FIX */
	uart_receive_skb(data, count);
	spin_unlock(&uart_info->rx_lock);

#ifndef BAUD_RATE_FIX
	/* Open TTY for more data */
	tty_unthrottle(tty);
#endif /* BAUD_RATE_FIX */
}
Exemplo n.º 6
0
void check_timers(void)
{
	readyqueues_t* readyqueue = &readyqueues[CORE_ID];
	spinlock_irqsave_lock(&readyqueue->lock);

	// since IRQs are disabled, get_clock_tick() won't increase here
	const uint64_t current_tick = get_clock_tick();

	// wakeup tasks whose deadline has expired
	task_t* task;
	while ((task = readyqueue->timers.first) && (task->timeout <= current_tick))
	{
		// pops task from timer queue, so next iteration has new first element
		wakeup_task(task->id);
	}

#ifdef DYNAMIC_TICKS
	task = readyqueue->timers.first;
	if (task) {
		update_timer(task);
	}
#endif

	spinlock_irqsave_unlock(&readyqueue->lock);
}
Exemplo n.º 7
0
int on_write(int epoll_fd, int sockfd)
{
	char* str;
	socket_buf sb;
	int total_to_write, len;

	sb = find_socket_buf(sockfd);
	assert(sb != NULL);

	total_to_write = sb->wb_size;
	str = sb->write_buf;
	while(total_to_write > 0){
		if ((len = write(sockfd, str, 
						(total_to_write >= MAX_LINE) ? MAX_LINE : total_to_write)) < 0) {
			if(errno == EINTR)
				continue;
			else {
				perror("write failed:");
				return L_HTTP_FAIL;
			}
		}
		else if(len == 0) {
			return L_HTTP_FAIL;
		}

		str += len;
		total_to_write -= len;
	}

	sb->wb_size = 0;
	update_timer(sb->timer);
	
	return epoll_modify_mod(epoll_fd, EPOLLIN, sockfd);
}
Exemplo n.º 8
0
Arquivo: timer.c Projeto: tolsac/zappy
int		setup_timer(t_player *p, t_init *data)
{
  char		*cmd;
  int		x;

  x = -1;
  cmd = p->buf.get(&(p->buf));
  if (cmd == NULL)
    return (1);
  update_timer(p);
  p->end = 0;
  while (data->cmd[++x])
    if ((strncmp(data->cmd[x], cmd, strlen(data->cmd[x]))) == 0)
      p->end =  time(NULL) + (data->time[x] / data->speed);
  if (p->end == 0)
    {
      cmd = p->buf.read_buffer(&(p->buf));
      cmd[strlen(cmd) - 1] = '\0';
      write(1, STR_IGNORED, strlen(STR_IGNORED));
      write(1, cmd, strlen(cmd));
      write(1, STR_COMMAND, strlen(STR_COMMAND));
      free(cmd);
    }
  return (0);
}
Exemplo n.º 9
0
int CHelperUnit::HangupNotify (void)
{
	log_debug("CHelperUnit object hangup notify: fd[%d]", netfd);
	update_timer();
	process_pkg();
	reset_helper();
	return POLLER_COMPLETE;
}
Exemplo n.º 10
0
void mc146818_device::nvram_read(emu_file &file)
{
	file.read(m_data, data_size());

	set_base_datetime();
	update_timer();
	update_irq();
}
Exemplo n.º 11
0
static TIMER_CALLBACK( display_enable_changed_timer_cb )
{
	crtc6845_state *chip = ptr;

	/* call the callback function -- we know it exists */
	chip->intf->display_enable_changed(is_display_enabled(chip));

	update_timer(chip);
}
Exemplo n.º 12
0
int CHelperUnit::InputNotify (void)
{
	update_timer();
	int ret = recv_from_cgi();
	if (ret < 0)
	{
		log_error("call recv failed, helper client netfd[%d]", netfd); 
		reset_helper();
		return POLLER_COMPLETE;
	}
	return POLLER_SUCC;
}
Exemplo n.º 13
0
static bool network_update_next_timeout(network_t * network)
{
    probe_t * probe;
    double    next_timeout;

    if ((probe = network_get_oldest_probe(network))) {
        next_timeout = network_get_probe_timeout(network, probe);
    } else {
        // The timer will be disarmed since there is no more flying probes
        next_timeout = 0;
    }
    return update_timer(network->timerfd, next_timeout);
}
Exemplo n.º 14
0
void UpdateElement::start(Host *host)
{
    h = host ;
    thread  = new updatethread(this) ;
    thread->setHosts(hosts);
    thread->setServerIndex(index) ;
    thread->start();
    QTimer *timer = host->getTimer() ;
    //if (timer != NULL) timer->stop(); delete timer ;
    timer = new QTimer() ;
    h->setTimer(timer);
    QObject::connect(timer, SIGNAL(timeout()), this, SLOT(update_timer())) ;
    timer->start(50000);
}
Exemplo n.º 15
0
inline void Gbs_Core::write_io_inline( int offset, int data, int base )
{
	if ( (unsigned) (offset - (apu_.io_addr - base)) < apu_.io_size )
		apu_.write_register( time(), offset + base, data & 0xFF );
	else if ( (unsigned) (offset - (0xFF06 - base)) < 2 )
		update_timer();
	else if ( offset == io_base - base )
		ram [base - ram_addr + offset] = 0; // keep joypad return value 0
	else
		ram [base - ram_addr + offset] = 0xFF;
	
	//if ( offset == 0xFFFF - base )
	//  dprintf( "Wrote interrupt mask\n" );
}
Exemplo n.º 16
0
static int testmod_sysctl_handler(ctl_table *ctl, int write, 
	void __user *buffer, size_t *lenp, loff_t *ppos)
{

	int ret = 0;

	ret = proc_dointvec(ctl, write, buffer, lenp, ppos);

	printk(KERN_INFO "Updating\n");

	update_timer();

	return ret;

}
Exemplo n.º 17
0
static void configure_screen(crtc6845_state *chip, int postload)
{
	if (chip->intf)
	{
		/* compute the screen sizes */
		UINT16 horiz_total = (chip->horiz_total + 1) * chip->intf->hpixels_per_column;
		UINT16 vert_total = (chip->vert_total + 1) * (chip->max_ras_addr + 1) + chip->vert_total_adj;

		/* determine the visible area, avoid division by 0 */
		UINT16 max_x = chip->horiz_disp * chip->intf->hpixels_per_column - 1;
		UINT16 max_y = chip->vert_disp * (chip->max_ras_addr + 1) - 1;

		/* update only if screen parameters changed, unless we are coming here after loading the saved state */
		if (postload ||
		    (horiz_total != chip->last_horiz_total) || (vert_total != chip->last_vert_total) ||
			(max_x != chip->last_max_x) || (max_y != chip->last_max_y))
		{
			/* update the screen only if we have valid data */
			if ((chip->horiz_total > 0) && (max_x < horiz_total) && (chip->vert_total > 0) && (max_y < vert_total))
			{
				rectangle visarea;

				attoseconds_t refresh = HZ_TO_ATTOSECONDS(chip->intf->clock) * (chip->horiz_total + 1) * vert_total;

				visarea.min_x = 0;
				visarea.min_y = 0;
				visarea.max_x = max_x;
				visarea.max_y = max_y;

				if (LOG) logerror("CRTC6845 config screen: HTOTAL: %x  VTOTAL: %x  MAX_X: %x  MAX_Y: %x  FPS: %f\n",
								  horiz_total, vert_total, max_x, max_y, 1 / ATTOSECONDS_TO_DOUBLE(refresh));

				video_screen_configure(chip->intf->scrnum, horiz_total, vert_total, &visarea, refresh);

				chip->has_valid_parameters = TRUE;
			}
			else
				chip->has_valid_parameters = FALSE;

			chip->last_horiz_total = horiz_total;
			chip->last_vert_total = vert_total;
			chip->last_max_x = max_x;
			chip->last_max_y = max_y;

			update_timer(chip);
		}
	}
}
Exemplo n.º 18
0
void stop_elev(){
  
  update_timer();
  
  if (current_state == UP) {
    elev_set_speed(-300);
    usleep(5000);
    elev_set_speed(0);
  } 
  
  if (current_state == DOWN) {
    elev_set_speed(300);
    usleep(5000);
    elev_set_speed(0);
  }
}
Exemplo n.º 19
0
int on_read(int epoll_fd, int sockfd)
{
	int total, len;
	socket_buf sb;
	sb = find_socket_buf(sockfd);
	assert(sb != NULL);

	if(ioctl(sockfd, FIONREAD, &total) < 0) {
		printf("ioctl fail");
		return L_HTTP_FAIL;
	}
	
	if(total <= 0)
		return L_HTTP_FAIL;	

	if(socket_read_buf_alloc(sb, total) == L_HTTP_FAIL)
		return L_HTTP_FAIL;	

	while(total > 0) {
		if((len = read(sockfd, sb->read_buf, (total > MAX_LINE)? MAX_LINE : total)) < 0) {
			if(errno == EINTR) {
				continue;
			} 
			else {
				perror("read fail");
				return L_HTTP_FAIL;
			}
		} 
		else if(len == 0) {
			return L_HTTP_FAIL;
		}
	
		total -= len;
		sb->rb_size += len;
	}
	
	printf("read_buf:%s\n", sb->read_buf);

	sb->state = STATE_HTTP_WRITE;			
	if(handle_connection(sb) == L_HTTP_FAIL) {
		return L_HTTP_FAIL;
	}
	
	update_timer(sb->timer);

	return epoll_modify_mod(epoll_fd, EPOLLOUT, sockfd);
}
Exemplo n.º 20
0
static void timer_queue_remove(uint32_t core_id, task_t* task)
{
	if(BUILTIN_EXPECT(!task, 0)) {
		return;
	}

	task_list_t* timer_queue = &readyqueues[core_id].timers;

#ifdef DYNAMIC_TICKS
	// if task is first in timer queue, we need to update the oneshot
	// timer for the next task
	if(timer_queue->first == task) {
		update_timer(task->next);
	}
#endif

	task_list_remove_task(timer_queue, task);
}
Exemplo n.º 21
0
magnetic::magnetic(QWidget *parent) :
    MainWindow(parent),
    ui(new Ui::magnetic)
{
    ui->setupUi(this);
    createActions();
    createMenus();
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update_timer()));
    fd = open(devname, O_RDWR);
    if (fd < 0)
          printf("open error\n");

    timer->start(5000);
    printf("##################\n");
    get_decode("下");
    printf("##################\n");
}
Exemplo n.º 22
0
static void riotcore_clk_overflow_callback(CLOCK sub, void *data)
{
    riot_context_t *riot_context;

    riot_context = (riot_context_t *)data;

    if (riot_context->enabled == 0)
        return;

    update_timer(riot_context);

    riot_context->r_write_clk -= sub;

    if (riot_context->read_clk > sub)
        riot_context->read_clk -= sub;
    else
        riot_context->read_clk = 0;
}
Exemplo n.º 23
0
/* This can only be called with packet-buf filled with a packet and
   it's attributes */
int
transmit_buffer_add_packet(clock_time_t time, uint8_t id)
{
  int i;
  for(i = 0; i < MAX_TX_BUF; i++) {
    if(buffers[i].len == 0) {
      /* copy the packet data into the buffer */
      /* what more needs to be stored? */
      buffers[i].len = packetbuf_datalen();
      buffers[i].id = id;
      memcpy(buffers[i].packet, packetbuf_dataptr(), packetbuf_datalen());
      buffers[i].time = time;
      buffers[i].txmits = packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
      update_timer();
      return 1;
    }
  }
  return 0;
}
Exemplo n.º 24
0
TimeLineWidget::TimeLineWidget(QWidget* parent)
:	QGraphicsView(parent),
	offset_(0.),
	scale_(1.),
	current_(10.),
	length_(100.),
	cursor_(nullptr),
	time_lbl_(nullptr),
	preview_time_(0),
	playing_(false),
	preview_(nullptr)
{
	instance_ = this;

	setScene(&scene_);
	scene_.setSceneRect(QRectF(0, 0, 4000, 150));
	scene_.setItemIndexMethod(QGraphicsScene::NoIndex);

	setMinimumSize(640, 250);
	
	setRenderHint(QPainter::Antialiasing);

	cursor_ = new TimeLineCursorWidget(this);
	cursor_->setCursor(QCursor(Qt::SizeHorCursor));
	cursor_->setPos(0, 0);
	cursor_->setZValue(1.); 
	cursor_->sync();
	scene_.addItem(cursor_);

	time_lbl_ = new QLabel;
	update_time_label();

	timer_ = new QTimer(this);
	connect(timer_, SIGNAL(timeout()), this, SLOT(update_timer()));
    
	set_playing(false);

	connect(this, SIGNAL(set_playing(bool)), this, SLOT(setup_timer(bool)));
    
	/*QGraphicsProxyWidget* proxy = scene_.addWidget(time_lbl_);
	proxy->setPos(100, 50);
	proxy->setZValue(0.5);*/
}
Exemplo n.º 25
0
void mc146818_device::nvram_default()
{
	// populate from a memory region if present
	if (m_region != NULL)
	{
		UINT32 bytes = m_region->bytes();

		if (bytes > data_size())
			bytes = data_size();

		memcpy(m_data, m_region->base(), bytes);
	}
	else
	{
		memset(m_data, 0, data_size());
	}

	set_base_datetime();
	update_timer();
	update_irq();
}
Exemplo n.º 26
0
/*---------------------------------------------------------------------------*/
static void
handle_send_timer(void *ptr)
{
  struct tx_buffer *buf;
  buf = (struct tx_buffer *) ptr;

  if(buf != NULL) {
    /* Here is when the packets needs to be transmitted!!! */
    /* Prepare packetbuf */
    packetbuf_copyfrom(buf->packet, buf->len);
    packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, buf->txmits);
    /* time to send the packet. */
    serial_radio_send_packet(buf->id);
    PRINTF("TRB: timed packet sent at: tgt:%lu time:%lu %u bytes id:%u\n",
	   (unsigned long)buf->time, (unsigned long)clock_time(), buf->len, buf->id);

    /* done - set length to zero to avoid using this again */
    buf->len = 0;
  }
  update_timer();
}
Exemplo n.º 27
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setImgPaths();
    QPixmap bg(path+"/images/dsknight.png");
    QPalette p(palette());
    p.setBrush(QPalette::Background, bg);
    setAutoFillBackground(true);
    setPalette(p);
    mines_left = MINES;

    QWidget::setWindowIcon(QIcon(QString(path+"/images/skull.png")));
    QWidget::setFixedSize(this->size());

    //initialize the high scores
    for(unsigned int i=0; i<10; i++) {
        scores.push_back(9999);
        names.push_back("noname");
    }
    //read in the high scores from the files
    read_in_highscores();
    //construct and display the grid
    prepare_grid(50, 100, GRID_SIZE, this);
    //initialize counter for number of tiles uncovered
    numUncovered = 0;
    //initialize timer
    elapsed_time = 0;
    timer = new QTimer(this);
    timer->start(1000);
    connect (timer, SIGNAL(timeout()), this, SLOT(update_timer()));
    //set the reset button icon
    ui->reset_button->setIcon(QIcon(okay));
    ui->reset_button->setStyleSheet( "background-color: rgba( 50, 50, 50, 60% ); color: white;" );
    ui->label_2->setStyleSheet("color: white;");
    ui->mine_left_label->setStyleSheet("color: white;");
    ui->mines_left_display->setStyleSheet("color: white;");
    ui->timer_label->setStyleSheet("color: white;");
}
Exemplo n.º 28
0
/**
 * uart_write() - Transmit data to CG2900 over UART.
 * @dev:	Transport device information.
 * @skb:	SK buffer to transmit.
 *
 * Returns:
 *   0 if there is no error.
 *   Errors from create_work_item.
 */
static int uart_write(struct cg2900_trans_dev *dev, struct sk_buff *skb)
{
	int err;

#ifdef BAUD_RATE_FIX
	/* Delete sleep timer. */
	(void)del_timer(&uart_info->timer);
#else /* BAUD_RATE_FIX */
	update_timer();
#endif /* BAUD_RATE_FIX */

	/* Queue the sk_buffer... */
	skb_queue_tail(&uart_info->tx_queue, skb);

	CG2900_DBG_DATA_CONTENT("uart_write", skb->data, skb->len);
	/* ...and start TX operation */
	err = create_work_item(uart_info->wq, work_do_transmit, NULL);
	if (err)
		CG2900_ERR("Failed to create work item (%d) uart_tty_wakeup",
			   err);

	return err;
}
Exemplo n.º 29
0
void ixx_event_loop_update(IxxEventLoop* self)
{
    int timeout = calc_timeout(self);

    FD_ZERO(&self->read_fds);
    FD_ZERO(&self->write_fds);

    int nfd = 0;
    for (IxxEvent* event = self->events.first;
         event;
         event = event->node.next)
    {
        int fd = 0;

        switch (event->type) {
        case IXX_EVENT_UNDEFINED:
            break;
        case IXX_EVENT_TIMER:
            break;
        case IXX_EVENT_THREAD:
            break;
        case IXX_EVENT_SOCKET_CONNECT:
            fd = event->socket_connect.socket;
            FD_SET(fd, &self->write_fds);
            break;
        case IXX_EVENT_SOCKET_ACCEPT:
            fd = event->socket_accept.socket;
            FD_SET(fd, &self->read_fds);
            break;
        case IXX_EVENT_SOCKET_READ:
            fd = event->socket_read.socket;
            FD_SET(fd, &self->read_fds);
            break;
        case IXX_EVENT_SOCKET_WRITE:
            fd = event->socket_write.socket;
            FD_SET(fd, &self->write_fds);
            break;
        default:
            break;
        }

        if (fd > nfd) {
            nfd = fd;
        }
    }

    int err;

    unsigned long long before_tick = ixx_time_tick();

    if (timeout < 0) {
        if (0 == nfd) {
            ixx_sleep(timeout);
            err = IXX_OK;
        }
        else {
            err = select(nfd, &self->read_fds, &self->write_fds, NULL, NULL);
        }
    }
    else {
        if (0 == nfd) {
            ixx_sleep(timeout);
            err = IXX_OK;
        }
        else {
            struct timeval tv;
            tv.tv_sec = timeout / 1000;
            tv.tv_usec = (timeout % 1000) * 1000;
            err = select(nfd, &self->read_fds, &self->write_fds, NULL, &tv);
        }
    }

    unsigned long long after_tick = ixx_time_tick();

    IxxEvent* next_event = NULL;
    for (IxxEvent* event = self->events.first;
         event;
         event = next_event)
    {
        next_event = event->node.next;

        event->elapsed = after_tick - event->start_tick;

        switch (event->type) {
        case IXX_EVENT_UNDEFINED:
            break;
        case IXX_EVENT_TIMER:
            update_timer(event, self);
            break;
        case IXX_EVENT_THREAD:
            break;
        case IXX_EVENT_SOCKET_CONNECT:
            break;
        case IXX_EVENT_SOCKET_ACCEPT:
            break;
        case IXX_EVENT_SOCKET_READ:
            break;
        case IXX_EVENT_SOCKET_WRITE:
            break;
        default:
            break;
        }
    }
}
Exemplo n.º 30
0
Arquivo: maze.c Projeto: zzt93/os-lab0
/* 游戏主循环。
 * 在初始化工作结束后,main函数就跳转到主循环执行。
 * 在主循环执行期间随时会插入异步的中断。时钟中断最终调用timer_event,
 * 键盘中断最终调用keyboard_event。中断处理完成后将返回主循环原位置继续执行。
 *
 * tick是时钟中断中维护的信号,数值含义是“系统到当前时刻已经发生过的时钟中断数”
 * HZ是时钟控制器硬件每秒产生的中断数,在include/device/timer.h中定义
 * now是主循环已经正确处理的时钟中断数,即游戏已经处理到的物理时间点
 *
 * 由于qemu-kvm在访问内存映射IO区域时每次都会产生陷入,在30FPS时,
 * 对显存区域每秒会产生30*320*200/4次陷入,从而消耗过多时间导致跳帧的产生(实际FPS<30)。
 * 在CFLAGS中增加-DSLOW可以在此情况下提升FPS。如果FPS仍太小,可以尝试
 * -DTOOSLOW,此时将会采用隔行扫描的方式更新屏幕(可能会降低显示效果)。
 * 这些机制的实现在device/video.c中。
 * */
void
maze_loop(void) {
	int now = 0, target;
	int num_draw = 0;
	bool redraw;

    Result res = LET;
    while ( (res = winOrLose()) == LET) {
		wait_for_interrupt();
		disable_interrupt();
		if (now == tick) {
			enable_interrupt();
			continue;
		}
		assert(now < tick);
		target = tick; /* now总是小于tick,因此我们需要“追赶”当前的时间 */
		enable_interrupt();

		redraw = FALSE;
		while (update_you())
			;

		/* 依次模拟已经错过的时钟中断。一次主循环如果执行时间长,期间可能到来多次时钟中断,
		 * 从而主循环中维护的时钟可能与实际时钟相差较多。为了维持游戏的正常运行,必须补上
		 * 期间错过的每一帧游戏逻辑。 */
		while (now < target) {
			/* 每隔一定时间更新屏幕上字符的位置 */
			if (now % (HZ / UPDATE_PER_SECOND) == 0) {
                update_monster();
			}
            // update timer every second
            if ((now % HZ) == 0) {
                update_timer();
            }

			/* 每隔一定时间需要刷新屏幕。注意到这里实现了“跳帧”的机制:假设
			 *   HZ = 1000, FPS = 100, now = 10, target = 1000
			 * 即我们要模拟990个时钟中断之间发生的事件,其中包含了9次屏幕更新,
			 * 但redraw flag只被置一次。 */
			if (now % (HZ / FPS) == 0) {
				redraw = TRUE;
			}
			/* 更新fps统计信息 */
			if (now % (HZ / 2) == 0) {
				int now_fps = num_draw * 2 + 1;
				if (now_fps > FPS) now_fps = FPS;
				set_mfps(now_fps);
				num_draw = 0;
			}
			now ++;
		}

		if (redraw) { /* 当需要重新绘图时重绘 */
			num_draw ++;
			redraw_timerMonsterAndYou();
		}
	}
    draw_end(res);
    printk("ending\n");
    //release_enter();
}