Exemplo n.º 1
0
void printstuff(u32 foo, u32 bar, u32 blarg)
{
	asm("stmdb sp!, {r0-r3, r12}");
	iprintf("printstuff %08X %08X %08X\n", foo, bar, blarg);
	asm("ldmia sp!, {r0-r3, r12}");
}
Exemplo n.º 2
0
void USB::dumpDevice(usbdesc_device *d) {
	iprintf("Device:\n");
	iprintf("\tUSB Version:  %d.%d\n", d->bcdUSB >> 8, (d->bcdUSB & 0xFF) >> 4);
	iprintf("\tClass:        0x%04X\n", d->bDeviceClass);
	iprintf("\tSubClass:     0x%04X\n", d->bDeviceSubClass);
	iprintf("\tProtocol:     0x%04X\n", d->bDeviceProtocol);
	iprintf("\tMax Packet:   %d\n", d->bMaxPacketSize);
	iprintf("\tVendor:       0x%04X\n", d->idVendor);
	iprintf("\tProduct:      0x%04X\n", d->idProduct);
	iprintf("\tManufacturer: "); dumpString(d->iManufacturer);
	iprintf("\tProduct:      "); dumpString(d->iProduct);
	iprintf("\tSerial:       "); dumpString(d->iSerialNumber);
	iprintf("\tNum Configs:  %d\n", d->bNumConfigurations);
}
Exemplo n.º 3
0
void USB::dumpCDC(uint8_t *d) {
	switch(d[2]) {
		case USB_CDC_SUBTYPE_HEADER: {
			usbcdc_header *h = (usbcdc_header *) d;
            if (h)
            {
                iprintf("\t\t*CDC header\n");
                iprintf("\t\t\tbcdCDC:  0x%04X\n", h->bcdCDC);
            }
			break;
		}
		case USB_CDC_SUBTYPE_UNION: {
			usbcdc_union *u = (usbcdc_union *) d;
            if (u)
            {
                iprintf("\t\t*CDC union\n");
                iprintf("\t\t\tMaster:  %d\n", u->bMasterInterface);
                iprintf("\t\t\tSlave:   %d\n", u->bSlaveInterface0);
            }
			break;
		}
		case USB_CDC_SUBTYPE_CALL_MANAGEMENT: {
			usbcdc_callmgmt *m = (usbcdc_callmgmt *) d;
			iprintf("\t\t*CDC Call Management\n");
			iprintf("\t\t\tCapabilities:  0x%02X ", m->bmCapabilities);
			if (m->bmCapabilities & USB_CDC_CALLMGMT_CAP_CALLMGMT)
				iprintf("(CALLMGMT)");
			if (m->bmCapabilities & USB_CDC_CALLMGMT_CAP_DATAINTF)
				iprintf("(DATAINTF)");
			iprintf("\n");
			iprintf("\t\t\tData Interface: %d\n", m->bDataInterface);
			break;
		}
		case USB_CDC_SUBTYPE_ACM: {
			usbcdc_acm *a = (usbcdc_acm *) d;
			iprintf("\t\t*CDC ACM\n");
			iprintf("\t\t\tCapabilities: 0x%02X ", a->bmCapabilities);
			if (a->bmCapabilities & USB_CDC_ACM_CAP_COMM)
				iprintf("(COMM)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_LINE)
				iprintf("(LINE)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_BRK)
				iprintf("(BRK)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_NOTIFY)
				iprintf("(NOTIFY)");
			iprintf("\n");
			break;
		}
		case USB_CDC_SUBTYPE_ETHERNET: {
			usbcdc_ether *e = (usbcdc_ether *) d;
			iprintf("\t\t*CDC Ethernet\n");
			iprintf("\t\t\tMAC address: "); dumpString(e->iMacAddress);
			iprintf("\t\t\tStatistics: 0x%02lX\n", e->bmEthernetStatistics);
			iprintf("\t\t\tMax Segment Size: %d\n", e->wMaxSegmentSize);
			iprintf("\t\t\tMC Filters: %d\n", e->wNumberMCFilters);
			iprintf("\t\t\tPower Filters: %d\n", e->bNumberPowerFilters);
			break;
		}
	}
}
Exemplo n.º 4
0
/* perform read command */
static int procread(const char *path, int tnum, int omode, bool wb, bool rnd){
  iprintf("<Reading Test>\n  seed=%u  path=%s  tnum=%d  omode=%d  wb=%d  rnd=%d\n\n",
          g_randseed, path, tnum, omode, wb, rnd);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  int rnum = tcfdbrnum(fdb) / tnum;
  TARGREAD targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].wb = wb;
    targs[0].rnd = rnd;
    targs[0].id = 0;
    if(threadread(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].wb = wb;
      targs[i].rnd = rnd;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Exemplo n.º 5
0
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int width, int64_t limsiz,
                       int omode, bool nc, int rratio){
  iprintf("<Typical Access Test>\n  seed=%u  path=%s  tnum=%d  rnum=%d  width=%d  limsiz=%lld"
          "  omode=%d  nc=%d  rratio=%d\n\n",
          g_randseed, path, tnum, rnum, width, (long long)limsiz, omode, nc, rratio);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, width, limsiz)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  TARGTYPICAL targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].nc = nc;
    targs[0].rratio = rratio;
    targs[0].id = 0;
    if(threadtypical(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].nc = nc;
      targs[i].rratio= rratio;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Exemplo n.º 6
0
int main(void)  {

	struct in_addr ip, gateway, mask, dns1, dns2;
	
	// set the mode for 2 text layers and two extended background layers
	videoSetMode(MODE_5_2D);
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);

	consoleDemoInit();
   
	PrintConsole topScreen;
	PrintConsole bottomScreen;
	
	videoSetMode(MODE_0_2D);
	videoSetModeSub(MODE_0_2D);

	vramSetBankA(VRAM_A_MAIN_BG);
	vramSetBankC(VRAM_C_SUB_BG);

	consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
	consoleInit(&bottomScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
   
   consoleSelect(&bottomScreen);
   
   Keyboard *kbd = keyboardDemoInit();
   
   kbd->OnKeyPressed = OnKeyPressed;
   
   consoleSelect(&topScreen);
   
   iprintf("Connecting to WiFi...");
	
	if(!Wifi_InitDefault(WFC_CONNECT)){
		iprintf("Failed to connect!");
		exit(1);
	}
		
		iprintf("Connected\n\n");
		
		uint16 keysPressed = ~(REG_KEYINPUT);
			if(keysPressed & KEY_A){
				debug = true;
			}
		
		ip = Wifi_GetIPInfo(&gateway, &mask, &dns1, &dns2);

		while(Connected == false && debug == false) {
			char wiiIP[256];

			iprintf("Your ip: %s\n",inet_ntoa(ip));
			iprintf("Type in your Wii's IP(or /cmd for the console):\n");
			scanf("%s", wiiIP);

			if(!strcmp(wiiIP, "/cmd")){
				CMD();
				continue;
			}	

			iprintf("\nConnecting To %s\nfrom %s...", wiiIP,inet_ntoa(ip));
			
			int server = 0; server = TCP_ClientConnect(wiiIP, 8593);//TCP_ClientConnect(ip address, port)

			if(server == true){
				Connected = true;
				iprintf("Connected\n");
			}

			while(Connected == true){
				
			}
			
			iprintf("Press start to exit or click any other button to try again:\n");

			scanKeys();
			while(!keysDown()){
				scanKeys();
				if(keysPressed & KEY_START)
					exit(0);
			}

			swiWaitForVBlank();
			consoleClear();
	}
	
	int host = 0;
	int client = 0;
	if(debug == true){
		
		consoleClear();
		iprintf("Welcome To Server Screen\n");
		iprintf("Your ip: %s\n",inet_ntoa(ip));
		host = TCP_Server(PORT, PLAYERS);//TCP_Server(port, number of players)
	}
	
	while(debug == true){
		
		client = PLAYERS; client = TCP_GetClient(host);//TCP_GetClient(host socket)
		if(!clientForServer == 4){
			clientForServer++;
			iprintf("Client connected(%d of %d)\n", clientForServer,PLAYERS);
			iprintf("Client id: %d\n", client);
		}
		
	}

   return 0;
}
Exemplo n.º 7
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

	const int tile_base = 0;
	const int map_base = 20;


	videoSetMode(0);	

	videoSetModeSub(MODE_5_2D);	
	vramSetBankC(VRAM_C_SUB_BG); 

	PrintConsole *console = consoleInit(0, 3, BgType_ExRotation, BgSize_ER_256x256, map_base, tile_base, false, false);

	ConsoleFont font;

	font.gfx = (u16*)fontTiles;
	font.pal = (u16*)fontPal;
	font.numChars = 95;
	font.numColors =  fontPalLen / 2;
	font.bpp = 8;
	font.asciiOffset = 32;
	font.convertSingleColor = false;
	
	consoleSetFont(console, &font);

	int bg3 = console->bgId;

	iprintf("Custom Font Demo\n");
	iprintf("   by Poffy\n");
	iprintf("modified by WinterMute and dovoto\n");
	iprintf("for libnds examples\n");

	
	unsigned int angle = 0;
    int scrollX = 0;
	int scrollY = 0;
	int scaleX = intToFixed(1,8);
	int scaleY = intToFixed(1,8);

	while(1) {
		scanKeys();
		u32 keys = keysHeld();

		if ( keys & KEY_START ) break;

		if ( keys & KEY_L ) angle+=64; 
		if ( keys & KEY_R ) angle-=64;

		if ( keys & KEY_LEFT ) scrollX++;
		if ( keys & KEY_RIGHT ) scrollX--;
		if ( keys & KEY_UP ) scrollY++;
		if ( keys & KEY_DOWN ) scrollY--;

		if ( keys & KEY_A ) scaleX++;
		if ( keys & KEY_B ) scaleX--;

		if( keys & KEY_X ) scaleY++;
		if( keys & KEY_Y ) scaleY--;

		swiWaitForVBlank();


		bgSetRotateScale(bg3, angle, scaleX, scaleY);
		bgSetScroll(bg3, scrollX, scrollY);
		bgUpdate();
	}

}
Exemplo n.º 8
0
void CloseErrCB(int socket) {close(cfd); cfd=0; iprintf("Closed \n");};
Exemplo n.º 9
0
void GameOver::Init()
{
	iprintf("GameOver.Init\n");
}
Exemplo n.º 10
0
bool USBSerial::USBEvent_EPOut(uint8_t bEP, uint8_t bEPStatus)
{
    /*
     * Called in ISR context
     */

    bool r = true;

    iprintf("USBSerial:EpOut\n");
    if (bEP != CDC_BulkOut.bEndpointAddress)
        return false;

    if (rxbuf.free() < MAX_PACKET_SIZE_EPBULK)
    {
//         usb->endpointSetInterrupt(bEP, false);
        return false;
    }

    uint8_t c[MAX_PACKET_SIZE_EPBULK];
    uint32_t size = 64;

    //we read the packet received and put it on the circular buffer
    readEP(c, &size);
    iprintf("Read %ld bytes:\n\t", size);
    for (uint8_t i = 0; i < size; i++) {

        if (flush_to_nl == false)
            rxbuf.queue(c[i]);

        if (c[i] >= 32 && c[i] < 128)
        {
            iprintf("%c", c[i]);
        }
        else
        {
            iprintf("\\x%02X", c[i]);
        }

        if (c[i] == '\n' || c[i] == '\r')
        {
            if (flush_to_nl)
                flush_to_nl = false;
            else
                nl_in_rx++;
        }
        else if (rxbuf.isFull() && (nl_in_rx == 0))
        {
            // to avoid a deadlock with very long lines, we must dump the buffer
            // and continue flushing to the next newline
            rxbuf.flush();
            flush_to_nl = true;
        }
    }
    iprintf("\nQueued, %d empty\n", rxbuf.free());

    if (rxbuf.free() < MAX_PACKET_SIZE_EPBULK)
    {
        // if buffer is full, stall endpoint, do not accept more data
        r = false;

        if (nl_in_rx == 0)
        {
            // we have to check for long line deadlock here too
            flush_to_nl = true;
            rxbuf.flush();

            // and since our buffer is empty, we can accept more data
            r = true;
        }
    }

    usb->readStart(CDC_BulkOut.bEndpointAddress, MAX_PACKET_SIZE_EPBULK);
    iprintf("USBSerial:EpOut Complete\n");
    return r;
}
Exemplo n.º 11
0
int main() {

	// initialize the geometry engine
	glInit();	

	// Setup the Main screen for 3D 
	videoSetMode(MODE_0_3D);
	
	//map some vram to background for printing
	vramSetBankC(VRAM_C_MAIN_BG_0x06000000);
 
	consoleInit(0,1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);

	//put bg 0 at a lower priority than the text background
	bgSetPriority(0, 1);
  

 
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
 
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);
 
	// Set our viewport to be the same size as the screen
	glViewport(0,0,255,191);
 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 100);
 
	//ds specific, several attributes can be set here	
	glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
 
	// Set the current matrix to be the model matrix
	glMatrixMode(GL_MODELVIEW);
 
	iprintf("      Hello DS World\n");
	iprintf("     www.devkitpro.org\n");
	iprintf("   www.drunkencoders.com\n");

	while (1) {
 
		DrawGLScene();
 
		// flush to screen	
		glFlush(0);
 
		// wait for the screen to refresh
		swiWaitForVBlank();

		printf("\x1b[15;5H rtri  = %f     \n", rtri);
		printf("\x1b[16;5H rquad = %f     \n", rquad);
		rtri+=0.9f;										// Increase The Rotation Variable For The Triangle ( NEW )
		rquad-=0.75f;									// Decrease The Rotation Variable For The Quad ( NEW )

		rtri  = fmodf( rtri , 360 );
		rquad = fmodf( rquad, 360 );

	}
 
	return 0;
}
Exemplo n.º 12
0
void titleInit()
{
	consoleClear();	   
	iprintf("\x1b[10;9HPress START or\n     touch the touch screen");      
}
Exemplo n.º 13
0
static void
printCollection(
    c_collectionType type,
    toolActionData actionData)
{
    c_long size, i, offset, esize;
    c_object o, *p;
    c_object arrayElement;
    c_type subtype;
    c_bool isRef;

    o = c_iterObject(actionData->stack, 0);
    switch (type->kind) {
    case C_ARRAY:
    case C_SEQUENCE:
        /* Walk over all entries */
        switch (type->kind) {
        case C_ARRAY:
            if (type->maxSize == 0) {
                size = c_arraySize((c_array)o);
            } else {
                size = type->maxSize;
            }
        break;
        case C_SEQUENCE:
            size = c_arraySize((c_array)o);
        break;
        default:
            size = 0;
            assert(FALSE);
        break;
        }

        if (c_typeIsRef(type->subType)) {
            esize = sizeof(c_voidp);
            isRef = TRUE;
        } else {
            esize = type->subType->size;
            isRef = FALSE;
        }
        p = (c_object *)o;
        offset = 0;
        for (i=0; i<size; i++) {
            iprintf("Element (%d) Offset (%d)\n",i,offset);
            arrayElement = *p;
            if (arrayElement != NULL) {
                OBJECT_PUSH(actionData, arrayElement);
                if (isRef) {
                    subtype = c_getType(arrayElement);
                    printType(subtype, actionData);
                } else {
                    iprintf(" ");
                    printType(type->subType, actionData);
                }
                printf("\n");
                OBJECT_POP(actionData);
            } else {
                iprintf("    <0x0>\n");
            }
            p = C_DISPLACE(p, esize);
            offset += esize;
        }
    break;
    case C_STRING:
        printf(" \"%s\"",(c_char *)o);
    break;
    case C_SET:
    case C_LIST:
    case C_BAG:
    case C_DICTIONARY:
    case C_QUERY:
    {
        if (o != NULL) {
            /* Walk over the elements */
            c_walk(o, (c_action)printCollectionAction, actionData);
            if (c_count(o) == 0) {
                iprintf("<EMPTY>");
            }
        } else {
            iprintf("<NULL>");
        }
    }
    break;
    case C_SCOPE:
        c_scopeWalk(o, printCollectionAction, actionData);
    break;
    default:
        printf("Specified type <0x%x> is not a valid collection type\n",
               (HEXVALUE)type);
    break;
    }
}
Exemplo n.º 14
0
void arm7print(u32 value32, void* userdata)
{
	iprintf(IPC->Dbg_String);
}
Exemplo n.º 15
0
BeamResult SubtileHolder::beamEnters(unsigned int x, unsigned int y, BeamDirection atAngle)
{
  BeamResult res;
  res.action = Pass;
  
  if(destroyed) return res;
  
  unsigned int relX = x - xPos * 4;
  unsigned int relY = y - yPos * 4;
  unsigned int reflectiveSides = 0;
  
  //normal condition
  unsigned int subX = relX / 2;
  unsigned int subY = relY / 2;
  if(relX % 2 == 0 && atAngle > S) subX = relX / 2 - 1;
  if(relY % 2 == 0 && (atAngle > W || atAngle < E)) subY = relY / 2 - 1;
  if(subX > 1 || subY > 1) iprintf("subtile out of range at (%d,%d)!",x,y);
  unsigned int idx = subX + subY*2;
  if(subtiles[idx]) res = subtiles[idx]->beamEnters(x, y, atAngle);
  
  //special check for border between 2 subtiles
  if(relX == 2)
  {
    if(relY > 2)
    {
      if(subtiles[2] && subtiles[3] && (atAngle == N || atAngle == S))
      {
        reflectiveSides = (subtiles[2]->getReflectiveSides()) | (subtiles[3]->getReflectiveSides());
        res.action = Block;
      }
    }
    else
    {
      if(subtiles[0] && subtiles[1] && (atAngle == N || atAngle == S))
      {
        reflectiveSides = (subtiles[0]->getReflectiveSides()) | (subtiles[1]->getReflectiveSides());
        res.action = Block;
      }
    }
    if(((atAngle <= E || atAngle >= W) && (reflectiveSides & DOWN)) || (atAngle >= E && atAngle <= W && (reflectiveSides & UP)))
    { 
      res = Beam::reflectHorizontal(atAngle);
      res.xPos = x;
      res.yPos = y;
    }
    if(relY == 2)
    {
      if(subtiles[0] && subtiles[3])
      {
        if((subtiles[0]->getReflectiveSides() & RIGHT) && 
           (subtiles[3]->getReflectiveSides() & UP) &&
           atAngle <= W && atAngle >= S)
        {
          res.xPos = x;
          res.yPos = y;
          switch (atAngle) {
            case S:
              res.action = Overload;
              res.flag = 1;
              break;
            case SSW:
              res.action = Reflect;
              res.direction = ENE;
              break;
            case SW:
              if(res.action == Block)
              {
                res.action = Overload;
                res.flag = 1;
              }
              break;
            case WSW:
              res.action = Reflect;
              res.direction = NNE;
              break;
            case W:
              res.action = Overload;
              res.flag = 1;
              break;
            default:
              break;
          }
        }
        if((subtiles[0]->getReflectiveSides() & DOWN) && 
           (subtiles[3]->getReflectiveSides() & LEFT) &&
           atAngle <= E)
        {
          res.xPos = x;
          res.yPos = y;
          switch (atAngle) {
            case N:
              res.action = Overload;
              res.flag = 1;
              break;
            case NNE:
              res.action = Reflect;
              res.direction = WSW;
              break;
            case NE:
              if(res.action == Block)
              {
                res.action = Overload;
                res.flag = 1;
              }
              break;
            case ENE:
              res.action = Reflect;
              res.direction = SSW;
              break;
            case E:
              res.action = Overload;
              res.flag = 1;
              break;
            default:
              break;
          }
        }
      }
      if(subtiles[1] && subtiles[2])
      {
        if((subtiles[1]->getReflectiveSides() & LEFT) &&
           (subtiles[2]->getReflectiveSides() & UP) &&
           atAngle >= E && atAngle <= S)
        {
          res.xPos = x;
          res.yPos = y;
          switch (atAngle) {
            case E:
              res.action = Overload;
              res.flag = 1;
              break;
            case ESE:
              res.action = Reflect;
              res.direction = NNW;
              break;
            case SE:
              if(res.action == Block)
              {
                res.action = Overload;
                res.flag = 1;
              }
              break;
            case SSE:
              res.action = Reflect;
              res.direction = WNW;
              break;
            case S:
              res.action = Overload;
              res.flag = 1;
              break;
            default:
              break;
          }
        }
        if((subtiles[1]->getReflectiveSides() & DOWN) &&
           (subtiles[2]->getReflectiveSides() & RIGHT) &&
           (atAngle >= W || atAngle == N))
        {
          res.xPos = x;
          res.yPos = y;
          switch (atAngle) {
            case W:
              res.action = Overload;
              res.flag = 1;
              break;
            case WNW:
              res.action = Reflect;
              res.direction = SSE;
              break;
            case NW:
              if(res.action == Block)
              {
                res.action = Overload;
                res.flag = 1;
              }
              break;
            case NNW:
              res.action = Reflect;
              res.direction = ESE;
              break;
            case N:
              res.action = Overload;
              res.flag = 1;
              break;
            default:
              break;
          }
        }
      }
    }
    if(((!subtiles[0] && !subtiles[2]) || (!subtiles[1] && !subtiles[3])) && (atAngle == N || atAngle == S))
    {
      res.action = Pass;
    }
    if(((!subtiles[0] && !subtiles[1]) || (!subtiles[2] && !subtiles[3])) && (atAngle == W || atAngle == E))
    {
      res.action = Pass;
    }
  }
  else if(relY == 2)
  {
    if(relX < 2)
    {
      if(subtiles[0] && subtiles[2] && (atAngle == E || atAngle == W))
      {
        reflectiveSides = (subtiles[0]->getReflectiveSides()) | (subtiles[2]->getReflectiveSides());
        res.action = Block;
        //iprintf("blocking left(%d,%d)\n",xPos,yPos);
      }
    }
    else
    {
      if(subtiles[1] && subtiles[3] && (atAngle == E || atAngle == W))
      {
        reflectiveSides = (subtiles[1]->getReflectiveSides()) | (subtiles[3]->getReflectiveSides());
        res.action = Block;
        //iprintf("blocking right(%d,%d)\n",xPos,yPos);
      }
    }
    if((atAngle >= S && (reflectiveSides & RIGHT)) || (atAngle <= S && (reflectiveSides & LEFT)))
    {
      //iprintf("reflecting instead");
      res = Beam::reflectVertical(atAngle);
      res.xPos = x;
      res.yPos = y;
    }
    if(((!subtiles[0] && !subtiles[1]) || (!subtiles[2] && !subtiles[3])) && (atAngle == W || atAngle == E))
    {
      res.action = Pass;
    }
  }
  return res;
}
Exemplo n.º 16
0
//---------------------------------------------------------------------------------
void consoleClear(void) {
//---------------------------------------------------------------------------------
	iprintf("\x1b[2J");
}
Exemplo n.º 17
0
void OnKeyPressed(int key) {
   if(key > 0)
      iprintf("%c", key);
}
Exemplo n.º 18
0
/* perform order command */
static int32_t procorder(const char* path, int64_t rnum, int32_t rnd, int32_t etc,
                         int32_t tran, int32_t oflags) {
  KCDB* db;
  KCCUR* cur, *paracur;
  int32_t err;
  char kbuf[RECBUFSIZ], *vbuf, wbuf[RECBUFSIZ], *corepath, *copypath, *snappath;
  size_t ksiz, vsiz, psiz;
  int32_t wsiz;
  int64_t i, cnt;
  double stime, etime;
  VISARG visarg;
  iprintf("<In-order Test>\n  path=%s  rnum=%ld  rnd=%d  etc=%d  tran=%d  oflags=%d\n\n",
          path, (long)rnum, rnd, etc, tran, oflags);
  err = FALSE;
  db = kcdbnew();
  iprintf("opening the database:\n");
  stime = kctime();
  if (!kcdbopen(db, path, KCOWRITER | KCOCREATE | KCOTRUNCATE | oflags)) {
    dberrprint(db, __LINE__, "kcdbopen");
    err = TRUE;
  }
  etime = kctime();
  dbmetaprint(db, FALSE);
  iprintf("time: %.3f\n", etime - stime);
  iprintf("setting records:\n");
  stime = kctime();
  for (i = 1; !err && i <= rnum; i++) {
    if (tran && !kcdbbegintran(db, FALSE)) {
      dberrprint(db, __LINE__, "kcdbbegintran");
      err = TRUE;
    }
    ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
    if (!kcdbset(db, kbuf, ksiz, kbuf, ksiz)) {
      dberrprint(db, __LINE__, "kcdbset");
      err = TRUE;
    }
    if (tran && !kcdbendtran(db, TRUE)) {
      dberrprint(db, __LINE__, "kcdbendtran");
      err = TRUE;
    }
    if (rnum > 250 && i % (rnum / 250) == 0) {
      iputchar('.');
      if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
    }
  }
  etime = kctime();
  dbmetaprint(db, FALSE);
  iprintf("time: %.3f\n", etime - stime);
  if (etc) {
    iprintf("adding records:\n");
    stime = kctime();
    for (i = 1; !err && i <= rnum; i++) {
      if (tran && !kcdbbegintran(db, FALSE)) {
        dberrprint(db, __LINE__, "kcdbbegintran");
        err = TRUE;
      }
      ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
      if (!kcdbadd(db, kbuf, ksiz, kbuf, ksiz) && kcdbecode(db) != KCEDUPREC) {
        dberrprint(db, __LINE__, "kcdbadd");
        err = TRUE;
      }
      if (tran && !kcdbendtran(db, TRUE)) {
        dberrprint(db, __LINE__, "kcdbendtran");
        err = TRUE;
      }
      if (rnum > 250 && i % (rnum / 250) == 0) {
        iputchar('.');
        if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
      }
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  if (etc) {
    iprintf("appending records:\n");
    stime = kctime();
    for (i = 1; !err && i <= rnum; i++) {
      if (tran && !kcdbbegintran(db, FALSE)) {
        dberrprint(db, __LINE__, "kcdbbegintran");
        err = TRUE;
      }
      ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
      if (!kcdbappend(db, kbuf, ksiz, kbuf, ksiz)) {
        dberrprint(db, __LINE__, "kcdbadd");
        err = TRUE;
      }
      if (tran && !kcdbendtran(db, TRUE)) {
        dberrprint(db, __LINE__, "kcdbendtran");
        err = TRUE;
      }
      if (rnum > 250 && i % (rnum / 250) == 0) {
        iputchar('.');
        if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
      }
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  iprintf("getting records:\n");
  stime = kctime();
  for (i = 1; !err && i <= rnum; i++) {
    if (tran && !kcdbbegintran(db, FALSE)) {
      dberrprint(db, __LINE__, "kcdbbegintran");
      err = TRUE;
    }
    ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
    vbuf = kcdbget(db, kbuf, ksiz, &vsiz);
    if (vbuf) {
      if (vsiz < ksiz || memcmp(vbuf, kbuf, ksiz)) {
        dberrprint(db, __LINE__, "kcdbget");
        err = TRUE;
      }
      kcfree(vbuf);
    } else if (!rnd || kcdbecode(db) != KCENOREC) {
      dberrprint(db, __LINE__, "kcdbget");
      err = TRUE;
    }
    if (tran && !kcdbendtran(db, TRUE)) {
      dberrprint(db, __LINE__, "kcdbendtran");
      err = TRUE;
    }
    if (rnum > 250 && i % (rnum / 250) == 0) {
      iputchar('.');
      if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
    }
  }
  etime = kctime();
  dbmetaprint(db, FALSE);
  iprintf("time: %.3f\n", etime - stime);
  if (etc) {
    iprintf("getting records with a buffer:\n");
    stime = kctime();
    for (i = 1; !err && i <= rnum; i++) {
      if (tran && !kcdbbegintran(db, FALSE)) {
        dberrprint(db, __LINE__, "kcdbbegintran");
        err = TRUE;
      }
      ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
      wsiz = kcdbgetbuf(db, kbuf, ksiz, wbuf, sizeof(wbuf));
      if (wsiz >= 0) {
        if (wsiz < (int32_t)ksiz || memcmp(wbuf, kbuf, ksiz)) {
          dberrprint(db, __LINE__, "kcdbgetbuf");
          err = TRUE;
        }
      } else if (!rnd || kcdbecode(db) != KCENOREC) {
        dberrprint(db, __LINE__, "kcdbgetbuf");
        err = TRUE;
      }
      if (tran && !kcdbendtran(db, TRUE)) {
        dberrprint(db, __LINE__, "kcdbendtran");
        err = TRUE;
      }
      if (rnum > 250 && i % (rnum / 250) == 0) {
        iputchar('.');
        if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
      }
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  if (etc) {
    iprintf("traversing the database by the inner iterator:\n");
    stime = kctime();
    cnt = kcdbcount(db);
    visarg.rnum = rnum;
    visarg.rnd = rnd;
    visarg.cnt = 0;
    memset(visarg.rbuf, '+', sizeof(visarg.rbuf));
    if (tran && !kcdbbegintran(db, FALSE)) {
      dberrprint(db, __LINE__, "kcdbbegintran");
      err = TRUE;
    }
    if (!kcdbiterate(db, visitfull, &visarg, TRUE)) {
      dberrprint(db, __LINE__, "kcdbiterate");
      err = TRUE;
    }
    if (rnd) iprintf(" (end)\n");
    if (tran && !kcdbendtran(db, TRUE)) {
      dberrprint(db, __LINE__, "kcdbendtran");
      err = TRUE;
    }
    if (visarg.cnt != cnt) {
      dberrprint(db, __LINE__, "kcdbiterate");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  if (etc) {
    iprintf("traversing the database by the outer cursor:\n");
    stime = kctime();
    cnt = kcdbcount(db);
    visarg.rnum = rnum;
    visarg.rnd = rnd;
    visarg.cnt = 0;
    if (tran && !kcdbbegintran(db, FALSE)) {
      dberrprint(db, __LINE__, "kcdbbegintran");
      err = TRUE;
    }
    cur = kcdbcursor(db);
    if (!kccurjump(cur) && kccurecode(cur) != KCENOREC) {
      dberrprint(db, __LINE__, "kccurjump");
      err = TRUE;
    }
    paracur = kcdbcursor(db);
    while (!err && kccuraccept(cur, &visitfull, &visarg, TRUE, !rnd)) {
      if (rnd) {
        ksiz = sprintf(kbuf, "%08ld", (long)myrand(rnum));
        switch (myrand(3)) {
          case 0: {
            if (!kcdbremove(db, kbuf, ksiz) && kcdbecode(db) != KCENOREC) {
              dberrprint(db, __LINE__, "kcdbremove");
              err = TRUE;
            }
            break;
          }
          case 1: {
            if (!kccurjumpkey(paracur, kbuf, ksiz) && kccurecode(paracur) != KCENOREC) {
              dberrprint(db, __LINE__, "kccurjump");
              err = TRUE;
            }
            break;
          }
          default: {
            if (!kccurstep(cur) && kccurecode(cur) != KCENOREC) {
              dberrprint(db, __LINE__, "kccurstep");
              err = TRUE;
            }
            break;
          }
        }
      }
    }
    iprintf(" (end)\n");
    kccurdel(paracur);
    kccurdel(cur);
    if (tran && !kcdbendtran(db, TRUE)) {
      dberrprint(db, __LINE__, "kcdbendtran");
      err = TRUE;
    }
    if (!rnd && visarg.cnt != cnt) {
      dberrprint(db, __LINE__, "kccuraccept");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  if (etc) {
    iprintf("synchronizing the database:\n");
    stime = kctime();
    if (!kcdbsync(db, FALSE, NULL, NULL)) {
      dberrprint(db, __LINE__, "kcdbsync");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
  }
  if (etc) {
    corepath = kcdbpath(db);
    psiz = strlen(corepath);
    if (strstr(corepath, ".kch") || strstr(corepath, ".kct")) {
      copypath = kcmalloc(psiz + 256);
      sprintf(copypath, "%s.tmp", corepath);
      snappath = kcmalloc(psiz + 256);
      sprintf(snappath, "%s.kcss", corepath);
    } else {
      copypath = kcmalloc(256);
      sprintf(copypath, "kclangctest.tmp");
      snappath = kcmalloc(256);
      sprintf(snappath, "kclangctest.kcss");
    }
    iprintf("copying the database file:\n");
    stime = kctime();
    if (!kcdbcopy(db, copypath)) {
      dberrprint(db, __LINE__, "kcdbcopy");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
    remove(copypath);
    iprintf("dumping records into snapshot:\n");
    stime = kctime();
    if (!kcdbdumpsnap(db, snappath)) {
      dberrprint(db, __LINE__, "kcdbdumpsnap");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
    iprintf("loading records into snapshot:\n");
    stime = kctime();
    cnt = kcdbcount(db);
    if (rnd && myrand(2) == 0 && !kcdbclear(db)) {
      dberrprint(db, __LINE__, "kcdbclear");
      err = TRUE;
    }
    if (!kcdbloadsnap(db, snappath) || kcdbcount(db) != cnt) {
      dberrprint(db, __LINE__, "kcdbloadsnap");
      err = TRUE;
    }
    etime = kctime();
    dbmetaprint(db, FALSE);
    iprintf("time: %.3f\n", etime - stime);
    remove(snappath);
    kcfree(copypath);
    kcfree(snappath);
    kcfree(corepath);
  }
  iprintf("removing records:\n");
  stime = kctime();
  for (i = 1; !err && i <= rnum; i++) {
    if (tran && !kcdbbegintran(db, FALSE)) {
      dberrprint(db, __LINE__, "kcdbbegintran");
      err = TRUE;
    }
    ksiz = sprintf(kbuf, "%08ld", (long)(rnd ? myrand(rnum) + 1 : i));
    if (!kcdbremove(db, kbuf, ksiz) &&
        ((!rnd && !etc) || kcdbecode(db) != KCENOREC)) {
      dberrprint(db, __LINE__, "kcdbremove");
      err = TRUE;
    }
    if (tran && !kcdbendtran(db, TRUE)) {
      dberrprint(db, __LINE__, "kcdbendtran");
      err = TRUE;
    }
    if (rnum > 250 && i % (rnum / 250) == 0) {
      iputchar('.');
      if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08ld)\n", (long)i);
    }
  }
  etime = kctime();
  dbmetaprint(db, TRUE);
  iprintf("time: %.3f\n", etime - stime);
  iprintf("closing the database:\n");
  stime = kctime();
  if (!kcdbclose(db)) {
    dberrprint(db, __LINE__, "kcdbclose");
    err = TRUE;
  }
  etime = kctime();
  iprintf("time: %.3f\n", etime - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  kcdbdel(db);
  return err ? 1 : 0;
}
Exemplo n.º 19
0
int main (void)
{
	cpu_init();

	//ADCInit( ADC_CLK );

	unsigned int resultado1 = 0;
	unsigned int resultado2 = 0;
	unsigned int resultado3 = 0;
	unsigned int resultado4 = 0;
	unsigned int dif = 0;

	Config_MCC_PINS();

	pwm_init();
	int j=0;

	UART_Init(0,9600);
	ADCInit( ADC_CLK );
	IOSET0 = ((1<<3)|(1<<5)|(1<<10)|(1<<12)|(1<<17)|(1<<19));
	//IOCLR0 = (1<<19);
	while (1)
	{
		/*IOSET0 = (1<<3);
		IOSET0 = (1<<5);
		IOSET0 = (1<<10);
		IOSET0 = (1<<12);
		IOSET0 = (1<<17);
		IOSET0 = (1<<19);
		for (j = 0; j < rel; j++ ) asm volatile ("NOP");
		IOCLR0 = (1<<3);
		IOCLR0 = (1<<5);
		IOCLR0 = (1<<10);
		IOCLR0 = (1<<12);
		IOCLR0 = (1<<17);
		IOCLR0 = (1<<19);
		for (j = 0; j < rel; j++ ) asm volatile ("NOP");*/

		resultado1 = ADC0Read(1);
		resultado2 = ADC0Read(2);
		resultado3 = ADC0Read(3);
		resultado4 = ADC0Read(4);
		iprintf("ADC: %d\r\n", resultado1);

		if(resultado1 > resultado4)
		{
			IOCLR0 = (1<<19);
			IOSET0 = (1<<17);
			dif = resultado1 - resultado4;
		}

		if(resultado1 < resultado4)
		{
			IOCLR0 = (1<<17);
			IOSET0 = (1<<19);
			dif = resultado4 - resultado1;
		}

		setpwm5cycle(dif);




		//setpwm5cycle(resultado4); //PWM5 referente ao Fullbridge do DOF1
		//setpwm2cycle(resultado4); //PWM2 referente ao Fullbridge do DOF2
		//setpwm4cycle(resultado4); //PWM4 referente ao Fullbridge do DOF3

	}
	return(0);
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {
    /* Quickly enable the ANSI console */
    consoleDemoInit();

    int nb_a = 0;
    int nb_b = 0;
    int nb_x = 0;
    int nb_y = 0;

    int nb_l = 0;
    int nb_r = 0;

    int nb_up = 0;
    int nb_down = 0;
    int nb_left = 0;
    int nb_right = 0;
    volatile int frame = 0;
    while(1) {
        frame++;
        scanKeys();

        // Clear screen
        iprintf("\x1b[2J");
        printf("Frame:%d\n", frame);

        {
            printf("Pressed:\n");
            int keys = keysHeld();
            printf("A:%d B:%d X:%d Y:%d L:%d R:%d \n",
                   bool(keys & KEY_A),
                   bool(keys & KEY_B),
                   bool(keys & KEY_X),
                   bool(keys & KEY_Y),
                   bool(keys & KEY_L),
                   bool(keys & KEY_R)
                  );
            printf("^:%d v:%d <:%d >:%d \n",
                   bool(keys & KEY_UP),
                   bool(keys & KEY_DOWN),
                   bool(keys & KEY_LEFT),
                   bool(keys & KEY_RIGHT)
                  );
        }

        {
            printf("Counter:\n");
            int keys = keysDown();
            nb_a += bool(keys & KEY_A);
            nb_b += bool(keys & KEY_B);
            nb_x += bool(keys & KEY_X);
            nb_y += bool(keys & KEY_Y);
            nb_r += bool(keys & KEY_R);
            nb_l += bool(keys & KEY_L);
            printf("A:%d B:%d X:%d Y:%d L:%d R:%d\n",
                   nb_a,
                   nb_b,
                   nb_x,
                   nb_y,
                   nb_l,
                   nb_r
                  );
            nb_up += bool(keys & KEY_UP);
            nb_down += bool(keys & KEY_DOWN);
            nb_left += bool(keys & KEY_LEFT);
            nb_right += bool(keys & KEY_RIGHT);
            printf("^:%d v:%d <:%d >:%d \n",
                   nb_up,
                   nb_down,
                   nb_left,
                   nb_right
                  );
        }

        PA_CheckLid();
        swiWaitForVBlank();
    }

    return 0;
}
Exemplo n.º 21
0
/* thread the typical function */
static void *threadtypical(void *targ){
  TCFDB *fdb = ((TARGTYPICAL *)targ)->fdb;
  int rnum = ((TARGTYPICAL *)targ)->rnum;
  bool nc = ((TARGTYPICAL *)targ)->nc;
  int rratio = ((TARGTYPICAL *)targ)->rratio;
  int id = ((TARGTYPICAL *)targ)->id;
  bool err = false;
  TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
  int base = id * rnum;
  int mrange = tclmax(50 + rratio, 100);
  int width = tcfdbwidth(fdb);
  for(int i = 1; !err && i <= rnum; i++){
    char buf[RECBUFSIZ];
    int len = sprintf(buf, "%08d", base + myrandnd(i) + 1);
    int rnd = myrand(mrange);
    if(rnd < 10){
      if(!tcfdbput2(fdb, buf, len, buf, len)){
        eprint(fdb, __LINE__, "tcfdbput2");
        err = true;
      }
      if(map) tcmapput(map, buf, len, buf, len);
    } else if(rnd < 15){
      if(!tcfdbputkeep2(fdb, buf, len, buf, len) && tcfdbecode(fdb) != TCEKEEP){
        eprint(fdb, __LINE__, "tcfdbputkeep2");
        err = true;
      }
      if(map) tcmapputkeep(map, buf, len, buf, len);
    } else if(rnd < 20){
      if(!tcfdbputcat2(fdb, buf, len, buf, len)){
        eprint(fdb, __LINE__, "tcfdbputcat2");
        err = true;
      }
      if(map) tcmapputcat(map, buf, len, buf, len);
    } else if(rnd < 25){
      if(!tcfdbout2(fdb, buf, len) && tcfdbecode(fdb) && tcfdbecode(fdb) != TCENOREC){
        eprint(fdb, __LINE__, "tcfdbout");
        err = true;
      }
      if(map) tcmapout(map, buf, len);
    } else if(rnd < 26){
      if(myrand(10) == 0 && !tcfdbiterinit(fdb) && tcfdbecode(fdb) != TCENOREC){
        eprint(fdb, __LINE__, "tcfdbiterinit");
        err = true;
      }
      for(int j = 0; !err && j < 10; j++){
        if(tcfdbiternext(fdb) < 1 &&
           tcfdbecode(fdb) != TCEINVALID && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbiternext");
          err = true;
        }
      }
    } else {
      int vsiz;
      char *vbuf = tcfdbget2(fdb, buf, len, &vsiz);
      if(vbuf){
        if(map){
          int msiz = 0;
          const char *mbuf = tcmapget(map, buf, len, &msiz);
          if(msiz > width) msiz = width;
          if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
            eprint(fdb, __LINE__, "(validation)");
            err = true;
          }
        }
        tcfree(vbuf);
      } else {
        if(tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget");
          err = true;
        }
        if(map && tcmapget(map, buf, len, &vsiz)){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
      }
    }
    if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
    }
  }
  if(map){
    tcmapiterinit(map);
    int ksiz;
    const char *kbuf;
    while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){
      int vsiz;
      char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
      if(vbuf){
        int msiz = 0;
        const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
        if(msiz > width) msiz = width;
        if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
        tcfree(vbuf);
      } else {
        eprint(fdb, __LINE__, "(validation)");
        err = true;
      }
    }
    tcmapdel(map);
  }
  return err ? "error" : NULL;
}
///////////////////////////////////MAIN FUNCTION//////////////////////////////////////////////
void UserMain( void* pd ){

	/////Usual Routine
	InitializeStack();
	OSChangePrio( MAIN_PRIO );//Change Main Task number to MAIN_PRIO
	EnableAutoUpdate();
	EnableTaskMonitor();
	EnableSmartTraps();

	//serviceWatchDog();

	//Starting the Code
	iprintf("\n\n\n..................Starting Sensor Interface Board.....................\n\n\n");



	//Local Variables
	//////Scan Flag

	/***********Defining Interrupt Timers*****************/
	HiResTimer* timer2=0;//50 Hz Interrupt Timer
	char m=0;



	/***********File Descriptor Variables****************/
	int startup_timeout=0;

	unsigned char F_range_buff[4]={0};//Radio filtered range

	/**********Radio Debug Variable*******************/
	double TotalTime=0;	char time_ms[2]={0};
	/***********Radio control Radiocount and loop counter i********************/
	uint8_t Radiocount3=0,Ant_config=0;

	uint16_t CRME=0;

	/*********Laser Rangefinder Variables***************/
	float laser_range=0;


	/**********ADC channel Array***************************/
	uint16_t ADC_channel[8] = {0};

	/**********Navcomp send buffer and other vriables**********************/
	char Navcomp_send_buff[48]={0};
	Navcomp_send_buff[0]=0x41;
	Navcomp_send_buff[1]=0x7A;
	Navcomp_send_buff[2]=0x05;
	uint16_t netburner_counter=0;//netburner 16 bit counter

	//Initialize pins
	initPINS();

	//Initialize Analog to Digital
	InitSingleEndAD();

	//Initializing Serial Ports
	SerialClose(5);
	SerialClose(7);
	SerialClose(9);
	SerialClose(8);


	fdRadio= OpenSerial( 8, 115200, 1, 8, eParityNone );
	fdDebug = OpenSerial( 5, 115200, 1, 8, eParityNone );
	fdLaser = OpenSerial( 7, 115200, 1, 8, eParityNone );
	fdNAVcomp = OpenSerial( 9, 115200, 1, 8, eParityNone );

	/*
	ReplaceStdio(0,fdDebug);
	ReplaceStdio(1,fdDebug);
	ReplaceStdio(2,fdDebug);
	*/

	//Start the Timers and init the DSPI
	//DSPIInit(1,2000000,16,0x01,0x01,1,1,0,0,0);//initializing SPI

	//printf("Going to wait 3 sec\n");
	//OSTimeDly(3*TICKS_PER_SECOND);
	initTIMERS(timer2);
	J1[7]=0;
	/*startup_timeout=ReadWithTimeout(fdDebug,&m,1,2);
	if(startup_timeout==-1 || startup_timeout==0){
		Start_PAN=StartUpLaserScan(fdLaser);
		if(Start_PAN!=11110)
			Scan_Status=1;
		else
			Scan_Status=0;
	}

	else{
		Scan_Status=0;
		Start_PAN=11110;
	}*/

	//printf("Hi\n");
	Scan_Complete=1;
	/***********packing startup PAN angle*************************/
	Navcomp_send_buff[38] = (uint8_t)((Start_PAN & 0xFF00)>>8);
	Navcomp_send_buff[37] = (uint8_t)(Start_PAN & 0x00FF);
	Navcomp_send_buff[36] = Scan_Status;
	OSSimpleTaskCreate(NAVcompData,MAIN_PRIO-1);
	OSSimpleTaskCreate(RadioData,MAIN_PRIO-2);
	//OSSimpleTaskCreate(MIScompData,MAIN_PRIO+2);
	//enableWatchDog( 1, 0x001F );//0x001C
	//Creating Data Receiving task from the computer

	while(1){

		//printf("Hi\n");
		TotalTime=timer1->readTime();

		//First if statement to command host radio to get ranging data from 101 guest with antenna A
		if(FiveHzflag==1 && Radiocount3==0){
			//printf("In WHile Loop\n");
			CRME=(uint16_t)radio_in_buff1[28]*256+(uint16_t)radio_in_buff1[29];
			if((unsigned char)radio_in_buff1[12]==0 && CRME<60){
				F_range_buff[0]=radio_in_buff1[24];
				F_range_buff[1]=radio_in_buff1[25];
				F_range_buff[2]=radio_in_buff1[26];
				F_range_buff[3]=radio_in_buff1[27];
				F_range_buff[4]=radio_in_buff1[32];
				F_range_buff[5]=radio_in_buff1[33];
				F_range_buff[6]=radio_in_buff1[12];
				Ant_config=radio_in_buff1[11];
			}
			Radiocount3=1;
			FiveHzflag=0;
		}//first if bracket

		//second if statement to command host radio to get ranging data from 102 guest with antenna A
		if(FiveHzflag==1 && Radiocount3==1){

			CRME=(uint16_t)radio_in_buff2[28]*256+(uint16_t)radio_in_buff2[29];
			if((unsigned char)radio_in_buff2[12]==0 && CRME<60){
				F_range_buff[0]=radio_in_buff2[24];
				F_range_buff[1]=radio_in_buff2[25];
				F_range_buff[2]=radio_in_buff2[26];
				F_range_buff[3]=radio_in_buff2[27];
				F_range_buff[4]=radio_in_buff2[32];
				F_range_buff[5]=radio_in_buff2[33];
				Ant_config=radio_in_buff2[11];
			}
			Radiocount3=0;
			FiveHzflag=0;
		}//second if bracket

		if(FiftyHzflag==1){
			if(Scan_Complete==1){
			//printf("Start Pan=%d,Start Pan=%d\n",Start_PAN,(int16_t)Navcomp_send_buff[38]*256+(int16_t)Navcomp_send_buff[37]);
				laser_range=ReadLaser(fdLaser);
				Navcomp_send_buff[36] = Scan_Status;
				Navcomp_send_buff[38] = (uint8_t)((Start_PAN & 0xFF00)>>8);
				Navcomp_send_buff[37] = (uint8_t)(Start_PAN & 0x00FF);
				//printf("laser range=%g\n",laser_range);
				//printf("laser range=%g\n",laser_range);
				//uint32_t Range=(uint32_t)F_range_buff[0]*16777216+(uint32_t)F_range_buff[1]*65536+(uint32_t)F_range_buff[2]*256+(uint32_t)F_range_buff[3];

				//printf("%zu,%u,%u,%u\n",Range,Ant_config,(unsigned char)radio_in_buff[12],(uint16_t)radio_in_buff[32]*256+(uint16_t)radio_in_buff[33]);
				StartAD();
				while (!ADDone()){}
				asm("nop");
				for (int i = 0; i < 8; i++)
					ADC_channel[i] = (unsigned short int)(1000 * (((double)GetADResult(i)) * 3.3 / (32768.0)));

				//printf("%d \n", ADC_channel[1]);

				sprintf(time_ms,"%lf",TotalTime);
				//send data to the computer
				SendtoNAVCOMP(Navcomp_send_buff,ADC_channel,time_ms,netburner_counter,laser_range,F_range_buff,PanAngle,fdNAVcomp,fdDebug,sizeof(Navcomp_send_buff),Ant_config);
				netburner_counter ++;


				//printf("%g\n",dYaw);
				//dYaw=0;
				StartAD();
				 while (!ADDone()){}
				asm("nop");

				//dYaw=93;

				uint16_t ServoPot = GetADResult(0);
				////Servo PAN 1 numbers
				Pulse=12287-dYaw*20.51;
				//printf("%d\n",ServoPot);

				if(Pulse<8594 || Pulse==8594)
					sim1.mcpwm.sm[1].val[5]=8594;
				if(Pulse>15980 || Pulse==15980)
					sim1.mcpwm.sm[1].val[5]=15980;
				else
					sim1.mcpwm.sm[1].val[5]=Pulse;//PAN control

				/*////Servo PAN 2 numbers
				Pulse=12287-dYaw*20.14;

				if(Pulse<8594 || Pulse==8310)
					sim1.mcpwm.sm[1].val[5]=8310;
				if(Pulse>15980 || Pulse==15560)
					sim1.mcpwm.sm[1].val[5]=15560;
				else
					sim1.mcpwm.sm[1].val[5]=Pulse;//PAN control*/

				double cYaw=(ServoPot-12885)/63;//PAN 1
				//double cYaw=(ServoPot-14667)/63.05;//PAN 2

				//Calibration PAN servo 1
				//0-8594
				//90-10440
				//180-12287 Position in which PAN faces front
				//270-14844
				//360-15980

				//Calibration pot PAN servo 1
				//360=1564
				//180=12885 //position in which PAN faces front
				//270=7270
				//90=18560
				//0=24290

				//Calibration PAN servo 2
				//0-8310
				//90-10440
				//180-12287 Position in which PAN faces front
				//270-13900
				//360-15560

				//Calibration pot PAN servo 2
				//360=3264
				//180=14667 //position in which PAN faces front
				//270=8999
				//90=20085
				//0=25971

				pwmr_comp=sim1.mcpwm.mcr;
				sim1.mcpwm.mcr |=LDOK;

				PanAngle = cYaw * 10;
				//printf("%g\n",cYaw);


			}
				FiftyHzflag=0;

			//serviceWatchDog();//
		}//FiftyHzflag bracket

	}//Main While loop Bracket
Exemplo n.º 23
0
/* perform wicked command */
static int procwicked(const char *path, int tnum, int rnum, int omode, bool nc){
  iprintf("<Writing Test>\n  seed=%u  path=%s  tnum=%d  rnum=%d  omode=%d  nc=%d\n\n",
          g_randseed, path, tnum, rnum, omode, nc);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof(int)) * rnum * tnum)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  TARGWICKED targs[tnum];
  pthread_t threads[tnum];
  TCMAP *map = tcmapnew();
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].nc = nc;
    targs[0].id = 0;
    targs[0].map = map;
    if(threadwicked(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].nc = nc;
      targs[i].id = i;
      targs[i].map = map;
      if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  if(!nc){
    if(!tcfdbsync(fdb)){
      eprint(fdb, __LINE__, "tcfdbsync");
      err = true;
    }
    if(tcfdbrnum(fdb) != tcmaprnum(map)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
    }
    int end = rnum * tnum;
    for(int i = 1; i <= end && !err; i++){
      char kbuf[RECBUFSIZ];
      int ksiz = sprintf(kbuf, "%d", i);
      int vsiz;
      const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
      int rsiz;
      char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
      if(vbuf){
        iputchar('.');
        if(vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
        if(!rbuf){
          eprint(fdb, __LINE__, "tcfdbget");
          err = true;
        } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
      } else {
        iputchar('*');
        if(rbuf || tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
      }
      tcfree(rbuf);
      if(i % 50 == 0) iprintf(" (%08d)\n", i);
    }
    if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
  }
  tcmapdel(map);
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Exemplo n.º 24
0
int main(int   argc,
         char *argv[])
{
    size_t     threads, i;
    aligned_t *rets;
    qtimer_t   t;
    unsigned int iter, iterations = 10;
    double tot = 0.0;

    assert(qthread_initialize() == 0);
    t = qtimer_create();

    CHECK_VERBOSE();
    NUMARG(iterations, "ITERATIONS");

    threads = qthread_num_workers();
    iprintf("%i shepherds...\n", qthread_num_shepherds());
    iprintf("%i threads...\n", (int)threads);

    initme = calloc(threads, sizeof(aligned_t));
    assert(initme);

    rets = malloc(threads * sizeof(aligned_t));
    assert(rets);

    iprintf("Creating a barrier to block %i threads\n", threads);
    wait_on_me = qt_barrier_create(threads, REGION_BARRIER, 0);     // all my spawnees plus me
    assert(wait_on_me);

    for (iter = 0; iter < iterations; iter++) {
        iprintf("%i: forking the threads\n", iter);
        for (i = 1; i < threads; i++) {
            void *arg[2] = {wait_on_me, (void*)(intptr_t)i};
            qthread_spawn(barrier_thread, arg, sizeof(void*)*2, rets + i, 0, NULL, i, 0);
        }
        iprintf("%i: done forking the threads, entering the barrier\n", iter);
        qtimer_start(t);
        qt_barrier_enter(wait_on_me, 0);
        qtimer_stop(t);
        iprintf("%i: main thread exited barrier in %f seconds\n", iter, qtimer_secs(t));
        tot += qtimer_secs(t);

        // reset
        initme_idx = 1;

        // check retvals
        for (i = 1; i < threads; i++) {
            qthread_readFF(NULL, rets + i);
            if (initme[i] != iter + 1) {
                iprintf("initme[%i] = %i (should be %i)\n", (int)i,
                        (int)initme[i], iter + 1);
            }
            assert(initme[i] == iter + 1);
        }
    }

    iprintf("Average barrier time = %f\n", tot / iterations);

    iprintf("Destroying the barrier...\n");
    qt_barrier_destroy(wait_on_me);

    iprintf("Success!\n");

    return 0;
}
Exemplo n.º 25
0
/* thread the wicked function */
static void *threadwicked(void *targ){
  TCFDB *fdb = ((TARGWICKED *)targ)->fdb;
  int rnum = ((TARGWICKED *)targ)->rnum;
  bool nc = ((TARGWICKED *)targ)->nc;
  int id = ((TARGWICKED *)targ)->id;
  TCMAP *map = ((TARGWICKED *)targ)->map;
  bool err = false;
  for(int i = 1; i <= rnum && !err; i++){
    uint64_t kid = myrand(rnum * (id + 1)) + 1;
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%llu", (unsigned long long)kid);
    char vbuf[RECBUFSIZ];
    int vsiz = myrand(RECBUFSIZ);
    memset(vbuf, '*', vsiz);
    vbuf[vsiz] = '\0';
    char *rbuf;
    if(!nc) tcglobalmutexlock();
    switch(myrand(16)){
      case 0:
        if(id == 0) iputchar('0');
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 1:
        if(id == 0) iputchar('1');
        if(!tcfdbput3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbput3");
          err = true;
        }
        if(!nc) tcmapput2(map, kbuf, vbuf);
        break;
      case 2:
        if(id == 0) iputchar('2');
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 3:
        if(id == 0) iputchar('3');
        if(!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep3");
          err = true;
        }
        if(!nc) tcmapputkeep2(map, kbuf, vbuf);
        break;
      case 4:
        if(id == 0) iputchar('4');
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 5:
        if(id == 0) iputchar('5');
        if(!tcfdbputcat3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbputcat3");
          err = true;
        }
        if(!nc) tcmapputcat2(map, kbuf, vbuf);
        break;
      case 6:
        if(id == 0) iputchar('6');
        if(myrand(2) == 0){
          if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout2");
            err = true;
          }
          if(!nc) tcmapout(map, kbuf, ksiz);
        }
        break;
      case 7:
        if(id == 0) iputchar('7');
        if(myrand(2) == 0){
          if(!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout3");
            err = true;
          }
          if(!nc) tcmapout2(map, kbuf);
        }
        break;
      case 8:
        if(id == 0) iputchar('8');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))){
          if(tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbget2");
            err = true;
          }
          rbuf = tcsprintf("[%d]", myrand(i + 1));
          vsiz = strlen(rbuf);
        }
        vsiz += myrand(vsiz);
        if(myrand(3) == 0) vsiz += PATH_MAX;
        rbuf = tcrealloc(rbuf, vsiz + 1);
        for(int j = 0; j < vsiz; j++){
          rbuf[j] = myrand(0x100);
        }
        if(!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
        tcfree(rbuf);
        break;
      case 9:
        if(id == 0) iputchar('9');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget2");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 10:
        if(id == 0) iputchar('A');
        if(!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbge3");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 11:
        if(id == 0) iputchar('B');
        if(myrand(1) == 0) vsiz = 1;
        if((vsiz = tcfdbget4(fdb, kid, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget4");
          err = true;
        }
        break;
      case 14:
        if(id == 0) iputchar('E');
        if(myrand(rnum / 50) == 0){
          if(!tcfdbiterinit(fdb)){
            eprint(fdb, __LINE__, "tcfdbiterinit");
            err = true;
          }
        }
        for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
          if(tcfdbiternext(fdb) < 1){
            int ecode = tcfdbecode(fdb);
            if(ecode != TCEINVALID && ecode != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbiternext");
              err = true;
            }
          }
        }
        break;
      default:
        if(id == 0) iputchar('@');
        if(tcfdbtranbegin(fdb)){
          if(myrand(2) == 0){
            if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
              eprint(fdb, __LINE__, "tcfdbput");
              err = true;
            }
            if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
          } else {
            if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbout");
              err = true;
            }
            if(!nc) tcmapout(map, kbuf, ksiz);
          }
          if(nc && myrand(2) == 0){
            if(!tcfdbtranabort(fdb)){
              eprint(fdb, __LINE__, "tcfdbtranabort");
              err = true;
            }
          } else {
            if(!tcfdbtrancommit(fdb)){
              eprint(fdb, __LINE__, "tcfdbtrancommit");
              err = true;
            }
          }
        } else {
          eprint(fdb, __LINE__, "tcfdbtranbegin");
          err = true;
        }
        if(myrand(1000) == 0){
          if(!tcfdbforeach(fdb, iterfunc, NULL)){
            eprint(fdb, __LINE__, "tcfdbforeach");
            err = true;
          }
        }
        if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
        break;
    }
    if(!nc) tcglobalmutexunlock();
    if(id == 0){
      if(i % 50 == 0) iprintf(" (%08d)\n", i);
      if(id == 0 && i == rnum / 4){
        if(!tcfdboptimize(fdb, RECBUFSIZ, -1) && tcfdbecode(fdb) != TCEINVALID){
          eprint(fdb, __LINE__, "tcfdboptimize");
          err = true;
        }
        if(!tcfdbiterinit(fdb)){
          eprint(fdb, __LINE__, "tcfdbiterinit");
          err = true;
        }
      }
    }
  }
  return err ? "error" : NULL;
}
Exemplo n.º 26
0
int main(int   argc,
         char *argv[])
{
    size_t       threads = 1000, i;
    aligned_t   *rets;
    qtimer_t     t;
    unsigned int iter, iterations = 10;

    assert(qthread_initialize() == 0);
    t = qtimer_create();

    CHECK_VERBOSE();
    NUMARG(threads, "THREADS");
    NUMARG(iterations, "ITERATIONS");

    initme = (aligned_t *)calloc(threads, sizeof(aligned_t));
    assert(initme);

    rets = (aligned_t *)malloc(iterations * threads * sizeof(aligned_t));
    assert(rets);

    iprintf("creating the barrier for %zu threads\n", threads + 1);
    wait_on_me = qt_feb_barrier_create(threads + 1);    // all my spawnees plus me
    assert(wait_on_me);

    for (iter = 0; iter < iterations; iter++) {
        iprintf("%i: forking the threads\n", iter);
        for (i = 0; i < threads; i++) {
            qthread_fork(barrier_thread, wait_on_me, rets + (iter * threads) + i);
        }
        iprintf("%i: done forking the threads, entering the barrier\n", iter);
        qtimer_start(t);
        qt_feb_barrier_enter(wait_on_me);
        qtimer_stop(t);
        iprintf("%i: main thread exited barrier in %f seconds\n", iter, qtimer_secs(t));

        initme_idx = 0;

        for (i = 0; i < threads; i++) {
            if (initme[i] != iter + 1) {
                iprintf("initme[%i] = %i (should be %i)\n", (int)i,
                        (int)initme[i], iter + 1);
            }
            assert(initme[i] == iter + 1);
        }
    }

    iprintf("Destroying barrier...\n");
    qt_feb_barrier_destroy(wait_on_me);

    iprintf("Success!\n");

    /* this loop shouldn't be necessary... but seems to avoid crashes in rare
     * cases (in other words there must a race condition in qthread_finalize()
     * if there are outstanding threads out there) */
    for (i = 0; i < threads * 2; i++) {
        aligned_t tmp = 1;
        qthread_readFF(&tmp, rets + i);
        assert(tmp == 0);
    }
    return 0;
}
Exemplo n.º 27
0
void USB::dumpInterface(usbdesc_interface *i) {
	iprintf("\t*Interface\n");
	iprintf("\t\tNumber:        %d\n", i->bInterfaceNumber);
	iprintf("\t\tAlternate:     %d\n", i->bAlternateSetting);
	iprintf("\t\tNum Endpoints: %d\n", i->bNumEndPoints);
	iprintf("\t\tClass:         0x%02X ", i->bInterfaceClass);
	switch(i->bInterfaceClass) {
		case UC_COMM:
			iprintf("(COMM)");
			break;
		case UC_MASS_STORAGE:
			iprintf("(MSC)");
			break;
		case UC_CDC_DATA:
			iprintf("(CDC DATA)");
			break;
	}
	iprintf("\n");
	iprintf("\t\tSubClass:      0x%02X ", i->bInterfaceSubClass);
	switch(i->bInterfaceClass) {
		case UC_COMM: {
			switch(i->bInterfaceSubClass) {
				case USB_CDC_SUBCLASS_ACM:
					iprintf("(ACM)");
					break;
				case USB_CDC_SUBCLASS_ETHERNET:
					iprintf("(ETHERNET)");
					break;
			}
			break;
		}
		case UC_MASS_STORAGE: {
			switch(i->bInterfaceSubClass) {
				case MSC_SUBCLASS_SCSI:
					iprintf("(SCSI)");
					break;
			}
			break;
		}
	}
	iprintf("\n");
	iprintf("\t\tProtocol:      0x%02X ", i->bInterfaceProtocol);
	iprintf("\n");
	iprintf("\t\tInterface:     "); dumpString(i->iInterface);
}
Exemplo n.º 28
0
/*-------------------------------------------------------------------
 TCP Server Task 
 -------------------------------------------------------------------*/
void TcpServerTask(void * pd)
{
    int ListenPort = (int) pd;

	// Set up the listening TCP socket
	int fdListen = listen(INADDR_ANY, ListenPort, 5);

	if (fdListen > 0)
	{
		IPADDR	client_addr;
		WORD	port;

		while(1)
		{
            // The accept() function will block until a TCP client requests
            // a connection. Once a client connection is accepting, the 
            // file descriptor fdnet is used to read/write to it. 
			iprintf( "Wainting for connection on port %d...\n", ListenPort );
			int fdnet = accept(fdListen, &client_addr, &port, 0);

			iprintf("Connected to: "); ShowIP(client_addr);
			iprintf(":%d\n", port);

			writestring(fdnet, "Welcome to the NetBurner TCP Server\r\n");
			char s[20];
			IPtoString(EthernetIP, s);
			siprintf(RXBuffer, "You are connected to IP Address %s, port %d\r\n", s, TCP_LISTEN_PORT);
			writestring(fdnet, RXBuffer);

			int tcp_timeout = 0;
			while (fdnet > 0)
			{
                // declare file descriptor sets
				fd_set read_fds;
				fd_set error_fds;

                // Clear all bits in fd sets
				FD_ZERO(&read_fds);
				FD_ZERO(&error_fds);

                // Set bits in fd sets for our fd, fdnet
				FD_SET(fdnet, &read_fds);
				FD_SET(fdnet, &error_fds);

                // Select will block until an event occurs and a fd set bit is
                // set, or a timeout occurs. A timeout is ok in this situation,
                // we just use it to illustrate the task is still running.  
				if (select(FD_SETSIZE, &read_fds,(fd_set *)0, &error_fds, 30 * TICKS_PER_SECOND))
				{
					if (FD_ISSET(fdnet,&read_fds))		// Network data available to be read
					{
						int n = read(fdnet, RXBuffer, RX_BUFSIZE);
						RXBuffer[n] = '\0';
						iprintf("Read %d bytes: %s\n", n, RXBuffer);
						//writestring(fdnet, RXBuffer);
					}

					if (FD_ISSET(fdnet, &error_fds) && !FD_ISSET(fdnet, &read_fds))		// Network error condition
					{
						iprintf("Network Error, closing socket\n");
						close(fdnet);
						fdnet = 0;
					}
				}
				else
				{   // Select timed out. If timeout exceeds 10 timeout
					// periods, the connection will be closed. 
					iprintf("select() timeout\n");
					tcp_timeout++;
					if (tcp_timeout > 10)
					{
						iprintf("Connection timed out, closing socket\n");
                        close(fdnet);
						fdnet = 0;
					}
				} // Select
			} // While fdnet is valid
		} // while(1)
	} // while listen
}
Exemplo n.º 29
0
int main(void) {
	consoleDemoInit();

	while(1) {
		swiWaitForVBlank();

		consoleClear();
		iprintf("      Hello DS dev'rs\n");
		iprintf("     \x1b[32mwww.devkitpro.org\n");
		iprintf("   \x1b[32;1mwww.drunkencoders.com\x1b[39m");


		iprintf("\x1b[4;0Hgba header 96h: %02X\n",GBA_HEADER.is96h);
		iprintf("0x08000000: %04X\n",*(vu16*)0x08000000);

		if(guitarGripIsInserted())
		{
			guitarGripScanKeys();
			u8 keys = guitarGripKeysHeld();
			iprintf("\x1b[7;0HguitarGrip: %02X\n",keys);
			iprintf("  [%s]  [%s]  [%s]  [%s]",(keys&GUITARGRIP_BLUE)?"BLU":"   ",(keys&GUITARGRIP_YELLOW)?"YEL":"   ",(keys&GUITARGRIP_RED)?"RED":"   ",(keys&GUITARGRIP_GREEN)?"GRN":"   ");
		}

		if(pianoIsInserted())
		{
			pianoScanKeys();
			PianoKeys keys;
			keys.VAL = pianoKeysHeld();
			iprintf("\x1b[7;0Hpiano: %04X\n",pianoKeysHeld());
			iprintf("  %s  %s     %s  %s  %s   \n",keys.c_sharp?"C#":"  ",keys.d_sharp?"D#":"  ",keys.f_sharp?"F#":"  ",keys.g_sharp?"G#":"  ",keys.a_sharp?"A#":"  ");
			iprintf("%s  %s  %s %s  %s  %s  %s  %s\n",keys.c?"C ":"  ",keys.d?"D ":"  ",keys.e?"E ":"  ",keys.f?"F ":"  ",keys.g?"G ":"  ",keys.a?"A ":"  ",keys.b?"B ":"  ",keys.high_c?"C ":"  ");
		}

		if(paddleIsInserted())
		{
			iprintf("\x1b[7;0Hpaddle: %04X\n",paddleRead());
		}


	}

	return 0;
}
Exemplo n.º 30
0
int main(void)
{
	int i;
	
	defaultExceptionHandler();
	
	irqEnable(IRQ_VBLANK);
	irqEnable(IRQ_HBLANK);
	
	irqSet(IRQ_VBLANK, vblank_idle);
	
	fifoSetValue32Handler(FIFO_USER_02, arm7print, NULL);
	fifoSetValue32Handler(FIFO_USER_03, sleepMode, NULL);
	
	//vramSetBankA(VRAM_A_LCD);
	videoSetMode(MODE_0_2D);

	// map some VRAM
	// bank C to ARM7, bank H for subscreen graphics
	*(vu8*)0x04000242 = 0x82;
	*(vu8*)0x04000248 = 0x81;
	
	videoSetModeSub(MODE_0_2D);
	consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, false, true);
	
	*(vu16*)0x0400100A = 0x0300;
	
	setBackdropColorSub(0x7C00);
	
	// configure BLDCNT so that backdrop becomes black
	*(vu16*)0x04001050 = 0x00E0;
	*(vu8*)0x04001054 = 16;
	
	// enable window 0 and disable color effects inside it
	*(vu16*)0x04001000 |= 0x2000;
	*(vu16*)0x04001048 = 0x001F;
	*(vu16*)0x0400104A = 0x003F;
	
	toggleConsole(false);
	
#ifdef NITROFS_ROM
	if (!nitroFSInit())
#else
	if (!fatInitDefault())
#endif
	{
		toggleConsole(true);
		iprintf("FAT init failed\n");
		return -1;
	}
	
	makeROMList();
	
	makeMenu();

	iprintf("lolSnes " VERSION " -- by Mega-Mario\n");
	
	for (;;)
	{
		if (keypress != 0x03FF)
		{
			if (!(keypress & 0x0040)) // up
			{
				menusel--;
				if (menusel < 0) menusel = 0;
				if (menusel < menuscroll) menuscroll = menusel;
				makeMenu();
			}
			else if (!(keypress & 0x0080)) // down
			{
				menusel++;
				if (menusel > nfiles-1) menusel = nfiles-1;
				if (menusel-21 > menuscroll) menuscroll = menusel-21;
				makeMenu();
			}
			else if ((keypress & 0x0003) != 0x0003) // A/B
			{
				strncpy(fullpath, "snes/", 5);
				strncpy(fullpath + 5, &filelist[menusel << 8], 256);
				
				if (!Mem_LoadROM(fullpath))
				{
					iprintf("ROM loading failed\n");
					continue;
				}
				
				*(vu16*)0x04001000 &= 0xDFFF;
				toggleConsole(true);
				iprintf("ROM loaded, running\n");

				CPU_Reset();
				fifoSendValue32(FIFO_USER_01, 1);
				
				swiWaitForVBlank();
				fifoSendValue32(FIFO_USER_01, 2);
				
				irqSet(IRQ_VBLANK, vblank);
				irqSet(IRQ_HBLANK, PPU_HBlank);

				swiWaitForVBlank();
				CPU_Run();
			}
			
			keypress = 0x03FF;
		}
		
		swiWaitForVBlank();
	}

	return 0;
}