Esempio n. 1
0
//int main(int argc, char *argv[], char *envp[])
int main(int argc, char *argv[])
{
    puts("Starting morrigan.");

    unsigned short port = 0;
    if (1 < argc)
    {
        port = (unsigned short) atoi(argv[1]);
        if (!port)
        {
            port = PORT;
        }
        printf("Using port: %d.\n", port);
    }

    check(SIG_ERR != signal(SIGINT, __stop), "Failed to set signal handler.", "");
    check(SIG_ERR != signal(SIGTERM, __stop), "Failed to set signal handler.", "");

    srand((unsigned) (time(NULL) ^ _getpid()));

    l = landscape_load("land.dat", 32, 1.0);
    check(l, "Failed to load landscape.", "");
    check(net_start(port), "Failed to start network interface.", "");
    check(server_start(), "Failed to start server.", "");
    check(game_start(l, server_get_clients()), "Failed to start game.", "");

    do
    {
        printf(">");
        input = bgets(fgetc, stdin, '\n');

        if (NULL == input || 0 == strcmp("exit\n", bdata(input)))
        {
            break;
        }

        bdestroy(input);
        input = NULL;
    } while(true);

    __stop(0);
    return EXIT_SUCCESS;

    error:
    fprintf(stderr, "Error exit.\n");
    __stop(0);
    return EXIT_FAILURE;
}
Esempio n. 2
0
int SoftI2C_Read(const SoftI2C *i2c, uint8_t addr, uint8_t *dat, int len) {
	int i;

	__start(i2c); // start
	__onebyte(i2c, (addr << 1)  + 1); // addr + Write
	if (0 != __onebit(i2c, 1)) { // check ACK
		return 0;
	}

	for (i = 0; i < len; ++i) {
		*dat++ = __onebyte(i2c, 0xFF);
		__onebit(i2c, 0); // ACK
	}
	__stop(i2c);
	return i;
}
Esempio n. 3
0
/*****************************************************************************
Name:         Run_RTC_Scheduler  
Parameters:   none                  
Returns:      none  
Description:  Starts Round Robin Scheduler.  Should be call in Main program after
completing initialization.  Only enabled tasks will be scheduled and run. 
*****************************************************************************/
void Run_RTC_Scheduler(void)
{
  int i;
  GBL_run_scheduler = 1;
  /* Loop forever */
  while (1) {
    /* Check each task */
    for (i=0 ; i<MAX_TASKS ; i++) {
      
      /* If this is a scheduled task */
      if (GBL_task_list[i].task != NULL) { /* valid task */
				if (GBL_task_list[i].enabled == 1) { /* enabled */
				  if (GBL_task_list[i].ready == 1) {  /* ready to run */
#if RTC_MONITOR_ACTIVITY
//						RTC_ACTIVE_OUTPUT = 0; // Indicate task is active
#endif // RTC_MONITOR_ACTIVITY	

				    /* Run the task */
				    GBL_task_list[i].task();

#if RTC_MONITOR_ACTIVITY
//						RTC_ACTIVE_OUTPUT = 1; // Indicate task is inactive
#endif // RTC_MONITOR_ACTIVITY	

				    /* Reset the task ready flag */
				    GBL_task_list[i].ready = 0;
				    break;
	  			}
        } 
      } 
    }
		// reached end of loop, so start at top again
#if RTC_HALT_WHEN_IDLE
		RTC_STANDBY_OUTPUT = 0; // Sleeping
		__halt();
		RTC_STANDBY_OUTPUT = 1; // Not sleeping
#endif // RTC_HALT_WHEN_IDLE

#if RTC_STOP_WHEN_IDLE
		RTC_STANDBY_OUTPUT = 0; // Sleeping
		__stop();
		RTC_STANDBY_OUTPUT = 1; // Not sleeping
#endif // RTC_STOP_WHEN_IDLE
	
  }
}
Esempio n. 4
0
int SoftI2C_Write(const SoftI2C *i2c, uint8_t addr, const uint8_t *dat, int len) {
	int i;

	__start(i2c); // start
	__onebyte(i2c, addr << 1); // addr + Write
	if (0 != __onebit(i2c, 1)) { // check ACK
		return 0;
	}

	for (i = 0; i < len; ++i) {
		__onebyte(i2c, *dat++);
		if (0 != __onebit(i2c, 1)) { // check ACK
			break;
		}
	}
	__stop(i2c);
	return i;
}
Esempio n. 5
0
void main (void)
{
  P0=P1=P2=P3=P4=P5=P6=P7=P12=P14=0;
  // configura todos os pinos como saídas
  PM0=PM1=PM2=PM3=PM4=PM5=PM6=PM7=PM12=PM14=0;
  // configura pinos analógicos para modo digital
  ADPC = 1;
  PMC0=PMC12=PMC14=0;
  CMC = 0;	// desativa osciladores X1 e XT1
  PM5_bit.no0 = 1;    // pino P5.0 como entrada
  PU5_bit.no0 = 1;    // liga pull-up do pino P5.0
  EGN0 = BIT1;        // interrupção INTP1 na borda de descida
  PIF1 = 0;           // limpa o flag da interrupção INTP1
  PMK1 = 0;           // habilita a interrupção INTP1
  while(1)
  {
    pisca();          // pisca 10 vezes o led
    __stop();         // entra em modo stop
    // ocorreu um sinal de wake-up
    PIF1 = 0;         // limpa o flag da interrupção
  }
}
Esempio n. 6
0
void CMainLoop::stop()
{
	__is_run = false;
	emit __stop();
}