Exemple #1
0
static int magic_variation_staircase(int dim) // Moran's method C, Variation of the staircase method
{
    int x,y,a,b,count;

    count=1;
    x=y=(dim>>1);
    x++; // Rule one
    putnum(x,y,count++);

    while (count<=dim*dim)
    {
        a=x;
        b=y;
        x++;
        y--; // Rule two, diagonally upwards
        if (y<0) y=dim-1;
        if (x>=dim) x=0;
        if (checknum(x,y)) putnum(x,y,count++);
        else
        {
            x=a+2;
            y=b;
            if (x>=dim) x=x-dim;
            if (y<0) y=dim-1;
            putnum(x,y,count++);
        }
    }
    return(1);
}
int main()
{
	uint8_t ret;

	init_stdout();

#ifdef VERBOSE    
	print ("\r\nSREC Bootloader\r\n");
	print ("Loading SREC image from flash @ address: ");
	putnum (FLASH_IMAGE_BASEADDR);
	print ("\r\n");
#endif

	flbuf = (uint8_t*)FLASH_IMAGE_BASEADDR;
	ret = load_exec ();

	/* If we reach here, we are in error */

#ifdef VERBOSE
	if (ret > LD_SREC_LINE_ERROR) {
		print ("ERROR in SREC line: ");
		putnum (srec_line);
		print (errors[ret]);
	} else {
		print ("ERROR: ");
		print (errors[ret]);
	}
#endif

	return ret;
}
Exemple #3
0
static int magic_staircase(int dim) // Moran's method A, the staircase method
{
    int x,y,a,b,count;

    count=1;
    y=0;
    x=(dim>>1); // Rule one
    putnum(x,y,count++);

    while (count<=dim*dim)
    {
        a=x;
        b=y;
        x++;
        y--; // Rule two, diagonally upwards
        if (y<0) y=dim-1;
        if (x>=dim) x=0;
        if (checknum(x,y)) putnum(x,y,count++);
        else
        {
            x=a;
            y=b+1;
            if (y>=dim) y=0;
            if (y<0) y=dim-1;
            putnum(x,y,count++);
        }
    }
    return(1);
}
void test_memory_range(struct memory_range_s *range) {
    XStatus status;

    /* This application uses print statements instead of xil_printf/printf
     * to reduce the text size.
     *
     * The default linker script generated for this application does not have
     * heap memory allocated. This implies that this program cannot use any
     * routines that allocate memory on heap (printf is one such function).
     * If you'd like to add such functions, then please generate a linker script
     * that does allocate sufficient heap memory.
     */

    print("Testing memory region: "); print(range->name);  print("\n\r");
    print("    Memory Controller: "); print(range->ip);  print("\n\r");
    print("         Base Address: 0x"); putnum(range->base); print("\n\r");
    print("                 Size: 0x"); putnum(range->size); print (" bytes \n\r");

    status = Xil_TestMem32((u32*)range->base, 1024, 0xAAAA5555, XIL_TESTMEM_ALLMEMTESTS);
    print("          32-bit test: "); print(status == XST_SUCCESS? "PASSED!":"FAILED!"); print("\n\r");

    status = Xil_TestMem16((u16*)range->base, 2048, 0xAA55, XIL_TESTMEM_ALLMEMTESTS);
    print("          16-bit test: "); print(status == XST_SUCCESS? "PASSED!":"FAILED!"); print("\n\r");

    status = Xil_TestMem8((u8*)range->base, 4096, 0xA5, XIL_TESTMEM_ALLMEMTESTS);
    print("           8-bit test: "); print(status == XST_SUCCESS? "PASSED!":"FAILED!"); print("\n\r");

}
Exemple #5
0
void segment_write(IFILE *file, Segment seg)				/*;segment_write*/
{
	short	dim;

	seg_check(seg);
	putnum(file, "segment-kind", seg->seg_kind);
	dim = seg->seg_maxpos + 1;
	putnum(file, "segment-dim", dim);
	fwrite(seg->seg_data, seg->seg_size, dim, file->fh_file);
}
Exemple #6
0
int main()
{
	init_platform();

	print("Hello World\n\r");



	int *hdList;
	int i,j;
	for(i =0; i < 21; i++){
		SysAlloc_init();

		int log2ListSize = i;
		int *hdList = NULL;

		putnum(log2ListSize);
		print(" ");

		XIo_Out32(COUNTER_BASE + 4 * 1, START);
		hdList = RandListGen(log2ListSize, hdList);
		XIo_Out32(COUNTER_BASE + 4 * 1, STOP);

		XIo_Out32(COUNTER_BASE + 4 * 2, START);
		hdList = ReverseList(hdList);
		XIo_Out32(COUNTER_BASE + 4 * 2, STOP);

		XIo_Out32(COUNTER_BASE + 4 * 3, START);
		hdList = DeleteList(hdList);
		XIo_Out32(COUNTER_BASE + 4 * 3, STOP);



		for(j = 1; j <4; j++){
			// read counter result back
			int high_value = XIo_In32(COUNTER_BASE + 4 * (j + 8));
			if(high_value != 0){
				putnum(high_value);
			}
			putnum(XIo_In32(COUNTER_BASE + 4 * j));
			print(" ");

			// reset counter
			XIo_Out32(COUNTER_BASE + 4 * j,RESET);
		}
		print("\n");
	}

	print("\n all done\n");

	cleanup_platform();
	return 0;
}
Exemple #7
0
int main()
{
	init_platform();
	init_ddr();
	print("Hello World\n\r");

	int log2ListSize;

	XClistnew myIP;
	int list_set_up;

	int i;
	for(i = 0; i < 21; i++){

		log2ListSize = i;

		list_set_up = XClistnew_Initialize(&myIP, XPAR_CLISTNEW_0_DEVICE_ID);
		list_set_up = XClistnew_IsReady(&myIP);

		Xil_Out32(LIST_BASE + 0x20, log2ListSize);

		// start list IP
		XClistnew_Start(&myIP);

		// check if list IP is done
		int flag_done = 0;
		flag_done = XClistnew_IsDone(&myIP);
		while(flag_done != 1){
			flag_done = XClistnew_IsDone(&myIP);
		}

		// read counter result back
		putnum(Xil_In32(COUNTER_BASE + 4 * 1));
		print(" ");
		putnum(Xil_In32(COUNTER_BASE + 4 * 2));
		print(" ");
		putnum(Xil_In32(COUNTER_BASE + 4 * 3));
		print("\n");

		// reset counter
		Xil_Out32(COUNTER_BASE + 4 * 1,RESET);
		Xil_Out32(COUNTER_BASE + 4 * 2,RESET);
		Xil_Out32(COUNTER_BASE + 4 * 3,RESET);
	}
	print("\n all done\n");

	cleanup_platform();
	return 0;
}
Exemple #8
0
int main(void)
{
    wdt_disable();
    cli();

    DDRD=0xFE;
    DDRB=0xFf;
    uart_init();
    uart_stdio();
    str(1);

    unsigned char num=0;
    for(;;){    /* main event loop */

      putnum(num++);
      if(num > 12) num = 0;
      str(0);
      wait();
      str(1);
      wait();
      str(0);

      //printf("Hello world\r\n");
      _delay_ms(200);
    }
    return 0;
}
Exemple #9
0
void kernel_main(struct multiboot_info *mboot, int initial_stack)
{
    long int mem = 0;
	mboot_info = mboot;
	start_video();
    putstr("Init Descriptor Tables................."); 
    gdt_install(); 
    idt_install();
    putstr("[OK]\n"); 
    putstr("Init ISRs.............................."); 
    isr_install();    
    putstr("[OK]\n"); 
    putstr("Init IRQs.............................."); 
    irq_install(); 
    __asm__ __volatile__ ("sti");   
    putstr("[OK]\n"); 
    putstr("Init PIT..............................."); 
    timer_install();
    putstr("[OK]\n");    
    putstr("Amount of memory......................");
    mem = mboot->mem_upper / 1024; 
    putnum(mem);
    putstr("MB\n");
	putstr("Init Memory............................");
	init_memory_manager();
    putstr("\n\n");     
    putstr("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWelcome to Plex!");
    for (;;); 
}
static void display_progress (uint32_t count)
{
	/* Send carriage return */
	outbyte (CR);
	print  ("Bootloader: Processed (0x)");
	putnum (count);
	print (" S-records");
}
Exemple #11
0
void put_cde_slots(IFILE *file, int ifaxq)					/*;put_cde_slots*/
{
	long	dpos;

	dpos = iftell(file); /* get current position */
	putnum(file, "n-code_slots", tup_size(CODE_SLOTS));
	putnum(file, "n-data-slots", tup_size(DATA_SLOTS));
	putnum(file, "n-exception-slots", tup_size(EXCEPTION_SLOTS));
	put_slot(file, CODE_SLOTS);
	put_slot(file, DATA_SLOTS);
	put_slot(file, EXCEPTION_SLOTS);
	/* now replace word at start of  file with long giving offset to 
	 *start of information just written.
	 */
	file->fh_slots = dpos;
	ifclose(file);
}
int mfs_ls_r(int recurse) {
  int fd = mfs_dir_open(".");
  int entry_type;
  int entry_size;
  char *entry_name;
  while (mfs_dir_read(fd, &entry_name, &entry_size, &entry_type) != 0) {
    if (entry_type == MFS_BLOCK_TYPE_DIR) {
      
      if (!(entry_name[0] == '.' && entry_name[1] == '\0') &&
          !(entry_name[0] == '.' && entry_name[1] == '.' && entry_name[2] == '\0')) {
	print("Directory ");
	print(entry_name); 
	print(" ");
	putnum(entry_size);
	print("\r\n");
	if (recurse != 0) {
	  if (!mfs_change_dir(entry_name)) {
	    print("Failed\r\n");
	    mfs_dir_close(fd);
	    return 0;
	  }
	  if (!mfs_ls_r(recurse-1)) {
	    mfs_dir_close(fd);
	    return 0;
	  }
	  if(mfs_change_dir(".."))
	    print("cd..\r\n");
	  else {
	    print("Failed..\r\n");
	    mfs_dir_close(fd);
	    return 0;
	  }
	}
      }
    }
    else {
      print(entry_name);
      print(" ");
      putnum(entry_size);
      print("\r\n");
    }
  }
  mfs_dir_close(fd);
  return 1;
}
Exemple #13
0
void InitMessage(){
		putstring("DDS generator driver v_");
		putnum(10);
		USART_Transmit(  '\n' );
		USART_Transmit(  '\r' );
		putstring("Type help for command list");
		USART_Transmit(  '\n' );
		USART_Transmit(  '\r' );
}
Exemple #14
0
static void put_slot(IFILE *file, Tuple tup)					/*;put_slot*/
{
	/* This procedure writes out the SLOTS information. These are maps from
	 * symbols to unit names. The interpreter needs only to know the names
	 * of the symbols so we write their names if available, else
	 * an empty string.
	 */

	int i, n;
	Slot slot;

	n = tup_size(tup);
	putnum(file, "slot-entries", n);
	for (i = 1; i <= n; i++) {
		slot = (Slot) tup[i];
		if (slot == (Slot)0) {
			if (compiling_predef)
				chaos("undefined slot compiling predef");
			putnum(file, "slot-exists", 0);
		}
		else {
			putnum(file, "slot-exists", 1);
			putnum(file, "slot-seq", slot->slot_seq);
			putnum(file, "slot-unit", slot->slot_unit);
			putnum(file, "slot-number", slot->slot_number);
			putstr(file, "slot-name", slot->slot_name);
		}
	}
}
Exemple #15
0
static uint8_t load_exec ()
{
    uint8_t ret;
    void (*laddr)();
    int8_t done = 0;

    srinfo.sr_data = sr_data_buf;

    while (!done) {
        if ((ret = flash_get_srec_line (sr_buf)) != 0)
	    return ret;

	if ((ret = decode_srec_line (sr_buf, &srinfo)) != 0)
	    return ret;

#ifdef VERBOSE
        display_progress (srec_line);
#endif
	switch (srinfo.type) {
	    case SREC_TYPE_0:
		break;
	    case SREC_TYPE_1:
	    case SREC_TYPE_2:
	    case SREC_TYPE_3:
		memcpy ((void*)srinfo.addr, (void*)srinfo.sr_data, srinfo.dlen);
		break;
	    case SREC_TYPE_5:
		break;
	    case SREC_TYPE_7:
	    case SREC_TYPE_8:
	    case SREC_TYPE_9:
		laddr = (void (*)())srinfo.addr;
		done = 1;
		ret = 0;
		break;
	}
    }

#ifdef VERBOSE
    print ("\r\nExecuting program starting at address: ");
    putnum ((uint32_t)laddr);
    print ("\r\n");
#endif

    (*laddr)();

    /* We will be dead at this point */
    return 0;
}
Hint VAM_MAZE_PATH(int mg[][MCOL], PosType start, PosType end, SqStack *s) {
  PosType curpos;
  int Status;

  SElemType Static_Stack[20]; // 20 is the MAX depth of stack. Change later if need.
  Status = InitStack(s, Static_Stack);
  if (Status != SUCCESS) {putnum(0xdead000C); return FAILURE;}
  SElemType e;
  int curstep;

  curpos  = start;  // Set the start as the current step
  curstep = 0;    // Step Counter

  do {
    // If the current pos can be passed
    if (Pass(mg, curpos)) {
      //Leave Foot Print
      FootPrint(mg, curpos, MAZE_PASSED);
      e.di   = 1; // Direction
      e.ord  = curstep;
      e.seat = curpos;
      Push(s,e); // Push to stack
      if (curpos.x == end.x && curpos.y == end.y) {
        // Touch Down! Reach the Des
        return SUCCESS;
      }
      curpos = NextPos(&curpos, 1);
      curstep++;
    }
    else {
      if (!StackEmpty(s)) {
        Pop(s, &e);
        while (e.di == 4 && !StackEmpty(s)) {
          FootPrint(mg, e.seat, MAZE_BLOACKED);
          Pop(s, &e);
        }
        if (e.di < 4) {
          e.di++;
          Push(s, e);
          curpos = NextPos(&e.seat, e.di);
        }
      }
    }
  }while (!StackEmpty(s));
  return FAILURE;
}
Exemple #17
0
void Console_SetMax( char ch){

    switch (maxcounter) {
    case 0: if (ch=='m') maxcounter++; else maxcounter=0; break;
    case 1: if (ch=='a') maxcounter++; else maxcounter=0; break;
    case 2: if (ch=='x') maxcounter++; else maxcounter=0; break;
    case 3: if (ch>47 && ch<58) { maxcounter++; temp_szazas= ch-48; } else maxcounter=0; break;
	case 4: if (ch>47 && ch<58) { maxcounter++; temp_tizes= ch-48; } else maxcounter=0; break;
	case 5: if (ch>47 && ch<58) { maxcounter++; temp_egyes= ch-48; } else maxcounter=0; break;
    }

	if (maxcounter ==6){
		putstring("max jott ");
		putnum(100*temp_szazas + 10*temp_tizes + temp_egyes);
		maxcounter=0;
	}

}
Exemple #18
0
main()
{
	uint32 eod;
	uint32 klen;
	uint32 dlen;
	seek_pos rest;
	int r;

	cdb_init(&c,0);

	getnum(&eod);

	numrecords = (c.size - eod) / 8; 

	putnum(numrecords);
	putflush();
	_exit(0);
}
//----------------------------------------------------------------------------------------------------//
//  @func - sched_prio
//! @desc 
//!   Pre-emptive strict priority scheduler
//! @return
//!   - Nothing
//! @note
//!   - None
//----------------------------------------------------------------------------------------------------//
void sched_prio ()
{
    int i;
    signed char ready = -1;

    // Enqueue only currently running processes. Else,
    // If PROC_DEAD, no need to enqueue
    // If PROC_WAIT or PROC_TIMED_WAIT, already enqueued in appropriate wait queue
    // If PROC_DELAY, is in one of the timer queues
    // If idle_task, then does not need to enter the queue
    if (current_process->state == PROC_RUN) {
	ptable[current_pid].state = PROC_READY;
	if (current_pid != idle_task_pid)
	    penq (&ready_q[ptable[current_pid].priority], current_pid, 0);
    }
    
    SET_CURRENT_PROCESS (-1);

    for (i=0; i <= PRIO_LOWEST; i++) {
	while (ready_q[i].item_count != 0) {
	    pdeq (&ready_q[i], &ready, 0);
	    if (ptable[ready].state == PROC_DEAD) {   // Flush out dead processes
		ready = -1;
		continue;
	    }
	    else break;
	}
	
	if (ready != -1)
	    break;
    }

    if (ready == -1) 
	ready = idle_task_pid;  
  
#if 0 
    DBG_PRINT ("XMK: Scheduler: scheduled pid: ");
    putnum (ready);
    DBG_PRINT ("\r\n");
#endif

    ptable[ready].state = PROC_RUN;
    SET_CURRENT_PROCESS (ready);
}
Exemple #20
0
int main(void)
{
	int b, i;
	putnum();	
	for (i = 0; i < N; i++)
	{
		b = a[i];
		do
		{
			count[b%10]++;
			b = b/10;
			
		        }while(b !=0);
            }
	for (i = 0; i < 10; i++)	
		printf("%d is %d times.\n", i, count[i]);

	return 0;
}
Exemple #21
0
int main()
{
	int my_addr;
	
    init_platform();

	print("What's up World!\n");
	
	/* to set up the empty allocation tree */
    init_ddr(); 
    init_ddr();

	my_addr = hw_malloc(1000); //malloc
	
	print("Allocated memory address is ");
    putnum(result);
	
	hw_mfree(my_addr);//mfree   

	return 0;
}
Exemple #22
0
unsigned int serial_load(void *dst)
{
	unsigned char *p = dst;
	unsigned int idle, len;

	putstr("Send binary now...");

	len = 0;
	while (len == 0) {
		for (idle = 0; (idle < 200000); idle++) {
			if (checkch()) {
				*p++ = getch();
				len++;
				idle = 0;
			}
		}
	}

	putstr("\nReceived 0x");
	putnum(len);
	putstr(" bytes\n");

	return len;
}
Exemple #23
0
static int magic_pyramid(int dim) // Moran's method B, the pyramid method
{
    int i,j,x,y,a,b,count;

    count=1;
    y=(dim>>1);
    x=-y;
    for (i=0; i<dim; i++)
    {
        for (j=0; j<dim; j++)
        {
            a=x+j;
            b=y-j;
            if (a<0) a=dim+a;
            if (a>=dim) a=a-dim;
            if (b<0) b=dim+b;
            if (b>=dim) b=b-dim;
            putnum(a,b,count++);
        }
        x++;
        y++;
    }
    return(1);
}
Exemple #24
0
int main()
{
	init_platform();
	init_ddr(); // uncomment if using SysAlloc
	print("Hello World\n\r");

	int log2_tree_size;

	/*
	// Code for measuring the latency of RNG
	int k;
	for(k = 0; k <10; k++){
		XIo_Out32(COUNTER_BASE + 4 * k, START);
		RandGen(10);
		XIo_Out32(COUNTER_BASE + 4 * k, STOP);
		putnum(XIo_In32(COUNTER_BASE + 4 * k));
		XIo_Out32(COUNTER_BASE + 4 * k,RESET);
		print("\n");
	}	
	*/

	int *root = NULL;
	int i,j;
	//for(i = 0; i < 21; i++){
		log2_tree_size = 6;
		root = NULL;
		xor_rng_init();

		XIo_Out32(COUNTER_BASE + 4 * 1, START);
		root = PM_1_INSERTION(root, log2_tree_size);
		XIo_Out32(COUNTER_BASE + 4 * 1, STOP);

		XIo_Out32(COUNTER_BASE + 4 * 2, START);
		root = PM_2_CHECK_INSERTION(root, log2_tree_size);
		XIo_Out32(COUNTER_BASE + 4 * 2, STOP);

		XIo_Out32(COUNTER_BASE + 4 * 3, START);
		root = PM_3_UPDATE(root, log2_tree_size);
		XIo_Out32(COUNTER_BASE + 4 * 3, STOP);
		XIo_Out32(COUNTER_BASE + 4 * 4, START);
		root = PM_4_DELETION(root);
		XIo_Out32(COUNTER_BASE + 4 * 4, STOP);

		// read counter result back
		for(j = 1; j<5; j++){
			if(i > 17){
				putnum(XIo_In32(COUNTER_BASE + 4 * (j + 8) ));
			}
			putnum(XIo_In32(COUNTER_BASE + 4 * j));
			print(" ");
			// reset counter
			XIo_Out32(COUNTER_BASE + 4 * j, RESET);
		}
		print("\n");
	//}

	print("\n all done\n");

	cleanup_platform();
	return 0;
}
Exemple #25
0
int
main(int argc, char **argv)
{
	struct knc_stream	*s;
	int			 i;
	int			 len;
	char			*buf;
	char			*tmp;

	s = knc_init_stream();
	buf = malloc(1024);

	strncpy(buf, TEST_STRING, strlen(TEST_STRING));

	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));
	knc_put_stream(s, buf, strlen(TEST_STRING));

	for (i=0; i < 1024; i++)
		putnum(s, i);

	for (;;) {

		len = knc_get_ostream_contig(s, &tmp, 77);
		if (len == -1)
			break;
		write(1, tmp, len);

		knc_stream_drain(s, len);
	}

	len = knc_get_ostream(s, &tmp, 1024);
	if (len > 0)
		write(1, tmp, len);
	return 0;
}
Exemple #26
0
void mainCRTStartup(void) {
    char *argv[3], *buf = GetCommandLine();
    enum { S_WHITESPACE, S_PARAM, S_QUOTE } state = S_WHITESPACE;
    int argc, size, esize;
    HANDLE f;
    for (argc = 0;  (argc < 1022) && buf[argc];  ++argc)
        cmdline[argc] = buf[argc];
    cmdline[argc] = 0;
    for (buf = cmdline, argc = 0;  *buf;  ++buf) {
        switch (state) {
            case S_WHITESPACE:
                if (buf[0] == 32)
                    buf[0] = 0;
                else {
                    if (argc >= 3) ExitProcess(2);
                    if (buf[0] == 34) {
                        argv[argc++] = buf + 1;
                        state = S_QUOTE;
                    } else {
                        argv[argc++] = buf;
                        state = S_PARAM;
                    }
                }
                break;
            case S_PARAM:
                if (buf[0] == 32) {
                    buf[0] = 0;
                    state = S_WHITESPACE;
                } else if (buf[0] == 34) {
                    argv[argc - 1] = buf + 1;
                    state = S_QUOTE;
                }
                break;
            case S_QUOTE:
                if (buf[0] == 34) {
                    buf[0] = 0;
                    state = S_WHITESPACE;
                }
                break;
        }
    }
    if (argc < 2) ExitProcess(2);

    f = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    if (f == INVALID_HANDLE_VALUE) ExitProcess(1);
    size = (int) SetFilePointer(f, 0, NULL, FILE_END);
    buf = LocalAlloc(LMEM_FIXED, size);
    if (!buf) ExitProcess(1);
    SetFilePointer(f, 0, NULL, FILE_BEGIN);
    ReadFile(f, buf, size, (LPDWORD) &esize, NULL);
    CloseHandle(f);

    njInit();
    if (njDecode(buf, esize)) ExitProcess(1);
    f = CreateFile((argc > 2) ? argv[2] : (njIsColor() ? "nanojpeg_out.ppm" : "nanojpeg_out.pgm"),
        GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
    if (f == INVALID_HANDLE_VALUE) ExitProcess(1);
    if (njIsColor()) header[1] = '6';
    putnum(&header[7], njGetWidth());
    putnum(&header[13], njGetHeight());
    WriteFile(f, header, 19, (LPDWORD) &esize, NULL);
    WriteFile(f, njGetImage(), njGetImageSize(), (LPDWORD) &esize, NULL);
    njDone();

    ExitProcess(0);
}
Exemple #27
0
static int magic_knights_move(int dim,int offs,int move) // Moran's method D, The knight's move method
{
    int x,y,a,b,count;

    count=1;
    y=(int)offs/dim;
    x=offs%dim; // Starting place
    putnum(x,y,count++);

    while (count<=dim*dim)
    {
        a=x;
        b=y;
        switch (move)
        {
        default:
        case 1:
            y-=2;
            x+=1;
            break; // 2 up 1 right
        case 2:
            y-=1;
            x+=2;
            break; // 1 up 2 right
        case 3:
            y+=1;
            x+=2;
            break; // 1 down 2 right
        case 4:
            y+=2;
            x+=1;
            break; // 2 down 1 right
        case 5:
            y+=2;
            x-=1;
            break; // 2 down 1 left
        case 6:
            y+=1;
            x-=2;
            break; // 1 down 2 left
        case 7:
            y-=1;
            x-=2;
            break; // 1 up 2 left
        case 8:
            y-=2;
            x-=1;
            break; // 2 up 1 left
        }
        if (x<0) x=dim+x;
        if (x>=dim) x=x-dim;
        if (y<0) y=dim+y;
        if (y>=dim) y=y-dim;
        if (checknum(x,y)) putnum(x,y,count++);
        else
        {
            x=a;
            y=b+1; // Blocked move one down
            if (x<0) x=dim+x;
            if (x>=dim) x=x-dim;
            if (y<0) y=dim+y;
            if (y>=dim) y=y-dim;
            putnum(x,y,count++);
        }
    }
    return(1);
}
Exemple #28
0
int vprintf(int (*ofnc)(void*, char), void *arg, const char *fmt, va_list ap){
	/* Warning:
		there is NO error checking on 
		width, precision, or base
		so do not pass in unreasonable values
		or bad things will happen
	*/

	const char *p = fmt;
	char *s;
	long val, width = 0, prec = 0;
	u_char* addr;
	u_long  addrl;
	u_short flags;
	int base;
	int pos = 0;
	
	while(*p){
		prec = width = flags = 0;
		base = 10;
		if(*p != '%'){
			(*ofnc)(arg, *p++);
			pos++;
		}else{
rflag:
			p++;
reswitch:
			switch(*p){
			  case 's':
				/* %s - string */
				s = va_arg(ap, char*);
				val = 0;
				while(*s){
					(*ofnc)(arg, *s++);
					pos ++;
					/* no more than prec chars out */
					/* width is meaningless */
					if(prec && (++val>prec)) break;
				}
				break;
			  case 'I':
				/* %I - IP addy */
				addrl = va_arg(ap, u_long);
				addr  = (u_char*)&addrl;

				for(val=0; val<4; val++){
					if( val ){
						(*ofnc)(arg, '.');
						pos++;
					}
					pos += putnum(ofnc, arg, addr[val], 10, width, prec, flags);
				}
				break;
				
			  case '&':		/* magic zero-width character */
				break;
			  case '%':
				(*ofnc)(arg, '%');
				pos ++;
				break;
			  case 'c':
				val = va_arg(ap, int);
					/* char gets passed as int */
				(*ofnc)(arg, val);
				pos ++;
			  	break;
			  case 'd':
			  case 'D':
				flags |= B(PF_SIGNED);
				/* fall thru - weeee!!! */
			  case 'u':
			  case 'U':
				base = 10;
				goto donum;
			  case 'o':
				base = 8;
				goto donum;
			  case '=':
				/* arbitrary base */
				if(!prec) prec = 16;
				if(*++p == '*'){
					val = va_arg(ap, int);
					base = (val<0)?-val:val;
					goto donum;
				}
				val = 0;
				while( isdig(*p) ){
					val =  10*val + *p -'0';
					p++;
				}
				base = val;
				p--; /* push back */
				goto donum;
			  case 'x':
				flags |= B(PF_ALT);
				/* fallthru' */
			  case 'X':
				base = 0x10;
		    donum:			
				if( flags & B(PF_DLONG) )
					val = va_arg(ap, u_long);
				else
					val = va_arg(ap, unsigned int);
#if 1				
			 	/* sign extend */
				if(flags & B(PF_SIGNED)){
					if(!(flags & B(PF_DLONG))){
						if(!(flags & B(PF_LONG))){
							/* 8bit */
							val = (long)(char)val;
						}else{
							/* 16 bit */
							val = (long)(short)val;
						}
					}
				}
#else
				if(!(flags & B(PF_LONG)))  val &= 0xff;
#endif
				pos += putnum(ofnc, arg, val, base, width, prec, flags);
				break;
  			  case '*':
				width = va_arg(ap,int);
				goto rflag;		
			  case '.':
				/* set prec */
				if(*++p == '*'){
					prec = va_arg(ap, int);
					goto rflag;
				}
				val = 0;
				while( isdig(*p) ){
					val =  10*val + *p -'0';
					p++;
				}
				prec = val;
				goto reswitch;
			  case '1': case '2': case '3':
			  case '4': case '5': case '6': 
			  case '7': case '8': case '9':
				/* set width */
				val = 0;
				while( isdig(*p) ){
					val = 10*val + *p - '0';
					p++;
				}
				width = val;
				goto reswitch;
#ifndef TESTING
			  case 'p':
				/* spin */
				while(prec--){
					(*ofnc)(arg, spinchar[prec%4]);
					msleep(width);
					(*ofnc)(arg, '\b');
				}
#endif				
				break;
			  case '\0':
				return;
			  case 'L': 
				flags |= B(PF_DLONG);
				/* fall thru' */
			  case 'l': /* long arg */
				flags |= B(PF_LONG);
				goto rflag;
			  case '#':
				flags |= B(PF_ALT);
				goto rflag;
			  case '0': 
				flags |= B(PF_ZERO);
				goto rflag;
  			  case '+':
				flags |= B(PF_SHOW_PLS);
				goto rflag;
			  case '-':
				flags |= B(PF_LEFT);
				goto rflag;
			  default:
				break;

			}
			p++;
		}
Exemple #29
0
int main()
{
    init_platform();
    init_ddr();
    print("Hello World\n\r");


    /*
    int l;
    int addr;
    print("mallocs\n");
    for(l = 0; l < 1000000; l ++){
    	addr = hw_malloc(8);
    	Xil_Out32(DEBUG_BASE + 4 * l, addr);
    }

    putnum(addr);
    print("frees\n");
    for(l = 0; l < 1000000; l ++){
    	addr = Xil_In32(DEBUG_BASE + 4 * l);
    	hw_mfree(addr);
    }
    putnum(addr);
    print("done!\n");

    putnum(hw_malloc(8));
    */


    XClist myIP;
    int list_set_up;
    list_set_up = XClist_Initialize(&myIP, XPAR_CLIST_0_DEVICE_ID);
    list_set_up = XClist_IsReady(&myIP);

    Xil_Out32(LIST_BASE + 0x20, 10);

    // start list IP
    XClist_Start(&myIP);


    // check if list IP is done

    int flag_done = 0;
    flag_done = XClist_IsDone(&myIP);
    while(flag_done != 1) {
        flag_done = XClist_IsDone(&myIP);
    }


    // read counter result back

    print("Overall ");
    putnum(Xil_In32(COUNTER_BASE + 4 * 0));
    print("\n");

    print("Creating ");
    putnum(Xil_In32(COUNTER_BASE + 4 * 1));
    print("\n");

    print("Reversing ");
    putnum(Xil_In32(COUNTER_BASE + 4 * 2));
    print("\n");

    print("Destroying ");
    putnum(Xil_In32(COUNTER_BASE + 4 * 3));
    print("\n");

    int myPtr;
    myPtr = Xil_In32(LIST_BASE + 0x10);
    putnum(myPtr);
    // putnum(hw_malloc(8));
    /*
    int hdPtr;
    hdPtr = Xil_In32(LIST_BASE + 0x10);

    print("hdPtr = ");
    putnum(hdPtr);
    print("\n");

    signed offset;
    offset = Xil_In32(hdPtr);

    print("offset = ");
    putnum(offset);
    print("\n");

    int data;
    data = Xil_In32(hdPtr + 4);

    print("data = ");
    putnum(data);
    print("\n");
    */
    //-----------
    /*
    hdPtr = hdPtr + offset;

    print("hdPtr = ");
    putnum(hdPtr);
    print("\n");

    offset = Xil_In32(hdPtr);

    print("offset = ");
    putnum(offset);
    print("\n");

    data = Xil_In32(hdPtr + 4);

    print("data = ");
    putnum(data);
    print("\n");
    */
    //-----------
    /*
    int l;
    int nowPtr;

    l = 0;
    int i;
    // while(hdPtr != 0){
    for(i = 0; i <10; i++){
    	nowPtr = hdPtr;
    	offset = Xil_In32(hdPtr);
    	hdPtr = hdPtr + offset;
    	hw_mfree(nowPtr);
    	putnum(hdPtr);
    	print("\n");
    }

    print("finished processing\n");
    putnum(hw_malloc(8));
    */

    cleanup_platform();
    return 0;
}
Exemple #30
0
int main()
{
    SYSACE_FILE *srec_file;
    char         file_name[20];
    char        *p;
    uint8_t      ret;
    int          choice, bytes, total_bytes;

    /* Set a well-known "return to loader" vector*/
    set_ret_to_loader_vec();

    /* Initialize RS232_Uart_1 - Set baudrate and number of stop bits */
    XUartNs550_SetBaud(XPAR_RS232_UART_1_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ,
                       9600);
    XUartNs550_SetLineControlReg(XPAR_RS232_UART_1_BASEADDR,
                                  XUN_LCR_8_DATA_BITS);

    print("\n\r********************************************************");
    print("\n\r********************************************************");
    print("\n\r**     Xilinx Virtex-6 FPGA ML605 Evaluation Kit      **");
    print("\n\r********************************************************");
    print("\n\r********************************************************\r\n");

    do {
        print("Choose Feature to Test:\r\n");
        print("1: UART Test\r\n");
        print("2: LED Test\r\n");
        print("3: Timer Test\r\n");
        print("4: FLASH Test\r\n");
        print("5: IIC Test\r\n");
        print("6: Ethernet Loopback Test\r\n");
        print("7: Switch Test\r\n");
        print("8: External Memory Test\r\n");
        print("9: System Monitor Test\r\n");
        print("A: PushButton Test\r\n");
        print("B: LCD Test\r\n");
        print("C: System ACE CF Test\r\n");
        print("D: DVI/VGA Test\r\n");
        choice = inbyte();

        if (isalpha(choice)) {
            choice = toupper(choice);
        }

    } while (!isdigit(choice) && (choice < 'A' || choice > 'D')) ;
    xil_printf("%c\r\n", choice);

    sprintf(file_name, "bist\\%c.rec", choice);
    srec_file = sysace_fopen(file_name, "r");
    if (srec_file == 0) {
        printf("\r\nUnable to open %s\r\n", file_name);
        return 1;
    }

    /*
     * Read the SRECORDS in the selected file into RAM.
     */
    flbuf = (char*)(XPAR_DDR3_SDRAM_MPMC_BASEADDR + 0x100000);
    p = flbuf;
    total_bytes = 0;
    xil_printf("Reading SRECORDS from Compact Flash file %s:\r\n", file_name);
    do {
        bytes = sysace_fread(p, 1, 0x100000, srec_file);
        p += bytes;
        total_bytes += bytes;
    } while (bytes > 0);
    sysace_fclose(srec_file);

    xil_printf("\r\n%d bytes read from file. SRECORDS at: 0x%x\r\n",
        total_bytes, (unsigned)flbuf);

    ret = load_exec ();

    /* If we reach here, we are in error */

#ifdef VERBOSE
    if (ret > LD_SREC_LINE_ERROR) {
        print ("ERROR in SREC line: ");
        putnum (srec_line);
        print (errors[ret]);
    } else {
        print ("ERROR: ");
        print (errors[ret]);
    }
#endif

    return ret;
}