Ejemplo n.º 1
0
void memTest(void) {
  int memSize = 8 * 1024 * 1024; // 8MB
  void *base;
  base = (void *)0xC0000000;
  int i;
  // 4MB test
  const uint32_t a = 22695477;
  const uint32_t c = 1;
  //write
  volatile int iter = 0;
  volatile int niter = 16;
  volatile int niter2 = 16;
  // linear write with linear congruential generator values
  // 362 ms execution cycle at 8MB : 22MB/s read+write+compute
  for (iter = 0; iter < niter; iter++) {
    uint32_t x = iter;
    // write
    for (i = 0; i < memSize / 4; i++) {
      x = (a * x) + c;
      //
      ((volatile uint32_t *)base)[i] = x;
    }
    // read/verify
    x = iter;
    for (i = 0; i < memSize / 4; i++) {
      x = (a * x) + c;
      if (((volatile uint32_t *)base)[i] != x) {
        setErrorFlag(ERROR_SDRAM);
        while (1) {
          chThdSleepMilliseconds(100);
        }
      }
    }
  }
  // scattered byte write at linear congruential generator addresses
  // 300 ms execution time for one iteration: 3.3M scattered read+write per second
  // equals 68
  for (iter = 0; iter < niter2; iter++) {
    uint32_t x = iter;
    // write
    for (i = 0; i < 1024 * 1024; i++) {
      x = (a * x) + c;
      ((volatile uint8_t *)base)[x & (memSize - 1)] = (uint8_t)i;
    }
    // read/verify
    x = iter;
    for (i = 0; i < 1024 * 1024; i++) {
      x = (a * x) + c;
      if (((volatile uint8_t *)base)[x & (memSize - 1)] != (uint8_t)i) {
        setErrorFlag(ERROR_SDRAM);
        while (1) {
          chThdSleepMilliseconds(100);
        }
      }
    }
  }
}
TCP_NetClient::TCP_NetClient(const char hostname[], ushort port) : TCP_NetBase()
{
	IPaddress addr;
	SDLNet_ResolveHost(&addr, hostname, port); //TODO NET change from local host to real session later
	mySocket = SDLNet_TCP_Open(&addr);
	if (mySocket == NULL) {
		NETMSG("Failed to initialize TCP client socket");
		setErrorFlag();
		return;
	}

	recvThread = SDL_CreateThread(reinterpret_cast<int (*)(void *)>(recvThreadFunc), this);
	if (recvThread == NULL) {
		NETMSG("Failed to initialize TCP client receive thread");
		setErrorFlag();
		return;
	}
}
TCP_NetServer::TCP_NetServer(ushort port) : TCP_NetBase(),
		remoteMutex(SDL_CreateMutex())
{
	memset(&remote, 0, sizeof(remote));

	IPaddress addr;
	addr.host = INADDR_ANY;
	SDLNet_Write16(port, &addr.port);
	mySocket = SDLNet_TCP_Open(&addr);
	if (mySocket == NULL) {
		NETMSG("Failed to initialize TCP server socket");
		setErrorFlag();
		return;
	}
}