void kernel_footprint(void)
{
	init();

	// generate code for process
	struct Process *p =
		proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
	proc_setPri(p, 5);
	proc_yield();

	// generate code for msg
	Msg msg;
	msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
	msg_put(&in_port, &msg);
	msg_peek(&in_port);
	Msg *msg_re = msg_get(&in_port);
	msg_reply(msg_re);

	// generate code for signals
	sig_send(p, SIG_USER0);

	// generate code for msg
	Semaphore sem;
	sem_init(&sem);
	sem_obtain(&sem);
	sem_release(&sem);

	sig_wait(SIG_USER0);
}
Exemple #2
0
static void NORETURN lp_process(void)
{
	while (1)
	{
		start = get_hp_ticks();
		sig_send(hp_proc, SIG_USER0);
		sig_wait(SIG_USER0);
	}
}
Exemple #3
0
static void NORETURN hp_process(void)
{
	while (1)
	{
		sig_wait(SIG_USER0);
		end = get_hp_ticks();
		timer_delay(100);
		sig_send(lp_proc, SIG_USER0);
	}
}
Exemple #4
0
int main(void)
{
	/* Hardware initialization */
	init();

	proc_new(usb_serial_process, (iptr_t)USB_TO_SERIAL,
			KERN_MINSTACKSIZE * 2, NULL);
	proc_new(usb_serial_process, (iptr_t)SERIAL_TO_USB,
			KERN_MINSTACKSIZE * 2, NULL);

	/* Main process will never be scheduled. */
	sig_wait(SIG_USER0);
	ASSERT(0);
}
Exemple #5
0
static void NORETURN hp_process(void)
{
	while (1)
	{
		sig_wait(SIG_USER0);
		#if CONFIG_USE_LED
			LED_ON();
		#endif
		#if CONFIG_USE_HP_TIMER
			end = timer_hw_hpread();
		#endif
		sig_send(main_proc, SIG_USER0);
	}
}
Exemple #6
0
/** add comments here */
Fight::Fight( QWidget * parent , const char * name )
	: QWidget( parent, name )
{
	_socket = 0;
	_game = 0;
	_popup = 0;
	_isAttack = true;
	_isActive = false;
	_isCreature = false;
	_activeUnit = 0;
	_lostAttack = new QList<GenericFightUnit>;
	_lostAttack->setAutoDelete( true );
	_lostDefense = new QList<GenericFightUnit>;
	_lostDefense->setAutoDelete( true );

	for( int i = 0; i < MAX_UNIT; i ++ ) {
		_unitsAtt[i] = 0;
		_unitsDef[i] = 0;
	}

	//setBackgroundPixmap( IMAGE_PATH + "fight/background_0.png" );

	QVBoxLayout * layout = new QVBoxLayout( this );
	//layout->addSpacing( 120 );

	_map = new FightMap( this );
	_map->setBackgroundPixmap( QPixmap( IMAGE_PATH + "fight/background_0.png" ) );


	_view = new FightMapView( _map, this );
	layout->addWidget( _view, 1 );

	_control = new FightControl( this );
	layout->addWidget( _control );

	_map->resize( 800, 500 );


	layout->activate();

	connect( _control, SIGNAL( sig_wait( ) ), SLOT( slot_wait( ) ) );
	connect( _control, SIGNAL( sig_retreat( ) ), SLOT( slot_flee( ) ) );
	connect( _control, SIGNAL( sig_defend() ), SLOT( slot_defend() ) );

	connect( _view, SIGNAL( sig_mouseMoved( FightCell * ) ), SLOT( slot_mouseMoved( FightCell * ) ) );
	connect( _view, SIGNAL( sig_mouseRightPressed( FightCell * ) ), SLOT( slot_mouseRightPressed( FightCell * ) ) );
	connect( _view, SIGNAL( sig_mouseLeftPressed( FightCell * ) ), SLOT( slot_mouseLeftPressed( FightCell * ) ) );
	connect( _view, SIGNAL( sig_mouseReleased() ), SLOT( slot_mouseReleased() ) );
}
int main(int argc, char* argv[])
{
    // Check command line arguments.
    if(argc != 4)
    {
        std::cerr <<
            "Usage: " << argv[0] << " <address> <port> <threads>\n"
            "  For IPv4, try: " << argv[0] << " 0.0.0.0 8080 1\n"
            "  For IPv6, try: " << argv[0] << " 0::0 8080 1\n"
            ;
        return EXIT_FAILURE;
    }

    // Decode command line options
    auto address = ip::address::from_string(argv[1]);
    unsigned short port = static_cast<unsigned short>(std::atoi(argv[2]));
    unsigned short threads = static_cast<unsigned short>(std::atoi(argv[3]));

    // Allow permessage-deflate
    // compression on all connections
    websocket::permessage_deflate pmd;
    pmd.client_enable = true;
    pmd.server_enable = true;
    pmd.compLevel = 3;

    // Create our server
    server s{&std::cout, threads};
    s.on_new_stream(set_stream_options{pmd});

    // Open the listening port
    beast::error_code ec;
    s.open(tcp::endpoint{address, port}, ec);
    if(ec)
    {
        std::cerr << "Error: " << ec.message();
        return EXIT_FAILURE;
    }

    // Wait for CTRL+C. After receiving CTRL+C,
    // the server should shut down cleanly.
    //
    sig_wait();

    return EXIT_SUCCESS;
}
Exemple #8
0
static void NORETURN led_process(void)
{
	unsigned i;

	for (i = 0; ; i++)
	{
		if (!led_blinking)
		{
			LED_OFF(0);
			LED_OFF(1);
			LED_OFF(2);
			sig_wait(SIG_USER0);
		}
		LED_ON(i % 3);
		LED_OFF((i-1) % 3);
		timer_delay(200);
	}
}
Exemple #9
0
/**
 * Start an ADC convertion.
 * If a kernel is present, preempt until convertion is complete, otherwise
 * a busy wait on ADCS bit is done.
 */
uint16_t adc_hw_read(void)
{
	// Ensure another convertion is not running.
	ASSERT(!(ADCSRA & BV(ADSC)));

	// Start convertion
	ADCSRA |= BV(ADSC);

	#if CONFIG_KERN
		// Ensure IRQs enabled.
		IRQ_ASSERT_ENABLED();
		adc_process = proc_current();
		sig_wait(SIG_ADC_COMPLETE);
	#else
		//Wait in polling until is done
		while (ADCSRA & BV(ADSC)) ;
	#endif

	return(ADC);
}
Exemple #10
0
void NORETURN context_switch(void)
{
	IRQ_ENABLE;
	timer_init();
	proc_init();

	#if CONFIG_USE_HP_TIMER
		ser_init(&out, CONFIG_CTX_DEBUG_PORT);
		ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
	#endif

	#if CONFIG_USE_LED
		LED_INIT();
	#endif

	proc_forbid();
	hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
	lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
	main_proc = proc_current();
	proc_setPri(hp_proc, 2);
	proc_setPri(lp_proc, 1);
	proc_permit();

	while (1)
	{
		timer_delay(100);

		sig_send(lp_proc, SIG_USER0);
		sig_wait(SIG_USER0);

		#if CONFIG_USE_HP_TIMER
			kfile_printf(&out.fd,
				"Switch: %lu.%lu usec\n\r",
				hptime_to_us((end - start)),
				hptime_to_us((end - start) * 1000) % 1000);
		#endif
	}
}
Exemple #11
0
/**
 * Sleep until any of the signals in \a sigs or \a timeout ticks elapse.
 * If the timeout elapse a SIG_TIMEOUT is added to the received signal(s).
 * \return the signal(s) that have awoken the process.
 * \note Caller must check return value to check which signal awoke the process.
 */
sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
{
	Timer t;
	sigmask_t res;
	cpu_flags_t flags;

	ASSERT(!sig_check(SIG_TIMEOUT));
	ASSERT(!(sigs & SIG_TIMEOUT));
	/* IRQ are needed to run timer */
	ASSERT(IRQ_ENABLED());

	timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
	timer_setDelay(&t, timeout);
	timer_add(&t);
	res = sig_wait(SIG_TIMEOUT | sigs);

	IRQ_SAVE_DISABLE(flags);
	/* Remove timer if sigs occur before timer signal */
	if (!(res & SIG_TIMEOUT) && !sig_check(SIG_TIMEOUT))
		timer_abort(&t);
	IRQ_RESTORE(flags);
	return res;
}
Exemple #12
0
Fight::Fight( QWidget * parent, Game * game, AttalSocket * socket, const char * name  )
    : QWidget( parent )
{

	setWindowTitle( QString ( name ));
	_socket = socket;
	_game = game;
	_currentCell = NULL;
	_isAttack = true;
	_isActive = false;
	_isCreature = false;
	_period = 40;
	_idTimeFight = -1;
	_idTimeAnim = startTimer(_period);
	_activeUnit = NULL;
	_animatedUnit = NULL;
	_lostAttack = new QList<GenericFightUnit *>;
	_lostDefense = new QList<GenericFightUnit *>;
	_attData = new QList<attalFightData>;

	for( int i = 0; i < MAX_UNIT; i ++ ) {
		_unitsAtt[i] = NULL;
		_unitsDef[i] = NULL;
	}

	_map = new FightMap( this );
	_pixmap = new QPixmap( IMAGE_PATH + "fight/background_0.png" );
	_map->setBackgroundBrush(QBrush ( * _pixmap));

	_view = new FightMapView( _map, this );
	_control = new FightControl( this );
	
	_layH = new QHBoxLayout();

	
	_map->setSceneRect( 0,0,  _pixmap->width(), _pixmap->height() );
	_view->setMaximumSize( _pixmap->width(), _pixmap->height() );
	_layH->addWidget( _view, 1, Qt::AlignVCenter );

	_layout = new QVBoxLayout( this );
	_layout->addLayout( _layH, 1 );
	_layout->addWidget( _control );
	_layout->activate();
	//_view->fitInView( _view->frameRect(), Qt::KeepAspectRatioByExpanding);
	_view->fitInView( QRect(0,0,0,0), Qt::KeepAspectRatioByExpanding);

	updateDispositionMode();

	AttalSettings::FightSettings fsettings = AttalSettings::getInstance()->getFightSettings();

	if( fsettings.areCellsVisible ) {
		_map->showCells();
	} else {
		_map->hideCells();
	}
	
	connect( _control, SIGNAL( sig_wait( ) ), SLOT( slot_wait( ) ) );
	connect( _control, SIGNAL( sig_retreat( ) ), SLOT( slot_flee( ) ) );
	connect( _control, SIGNAL( sig_defend() ), SLOT( slot_defend() ) );
	connect( _control, SIGNAL( sig_control() ), SLOT( slot_control() ) );
	connect( _control, SIGNAL( sig_message( QString ) ), SLOT( slot_message( QString ) ) );
	
	connect( _view, SIGNAL( sig_mouseMoved( FightCell * , bool) ), SLOT( slot_mouseMoved( FightCell * , bool) ) );
	connect( _view, SIGNAL( sig_mouseRightPressed( FightCell * ) ), SLOT( slot_mouseRightPressed( FightCell * ) ) );
	connect( _view, SIGNAL( sig_mouseLeftPressed( FightCell * , bool) ), SLOT( slot_mouseLeftPressed( FightCell *, bool ) ) );
	connect( _view, SIGNAL( sig_mouseReleased() ), SLOT( slot_mouseReleased() ) );
	connect( this , SIGNAL( sig_showResults() ) , SLOT ( showFightResults() ) );
}