Example #1
0
/* print a signed integer */
static void putd(const int d)
{
	if (d >= 0) {
		putu((unsigned int)d);
	} else {
		putchar('-'); /* negative sign */
		putu((unsigned int)-d);
	}
}
Example #2
0
int xmitTest(void){
    // initialize strings
    char* myname;
    myname = "Ashley Towne";
    serial_init(9600);

    // initialize LCD
    LCD_init();
    LCD_display_on();
    set_output_device(2); // select LCD as output

    // output to LCD
    LCD_clear();
    LCD_setpos(0,0);
    printf("%s",myname);
    LCD_setpos(1,0);

    // output to terminal
    set_output_device(1); // select UART as output device
    printf("This goes to terminal\n"); // write to the screen
    printf("%s\n", myname);
    // loop
    int foo = 0;
    unsigned char mystr;
    int ctr = 0;
    while(ctr<10)
    {
        ctr = ctr + 1;
        if (foo==0){mystr='0';}
        else if(foo==1){mystr = '1';}
        else if(foo==2){mystr = '2';}
        else if(foo==3){mystr = '3';}
        else if(foo==4){mystr = '4';}
        else if(foo==5){mystr = '5';}
        else if(foo==6){mystr = '6';}
        else if(foo==7){mystr = '7';}
        else if(foo==8){mystr = '8';}
        else if(foo==9){
            mystr = '9';
            foo = -1;
        }

        set_output_device(2);
        putu((char)(100+foo));
        set_output_device(1);
        LCD_char((char)(100+foo));

        foo = foo + 1;
    }

    putu('z');
    LCD_char('z');
    putu(EOF);
    return 1;
}
Example #3
0
VOID
putu(
    ULONG u
    )

/*++

Routine Description:

    Write an unsigned long to display

Arguments:

    u - unsigned

Returns:

    Nothing

--*/

{
    if(u/10) {
        putu(u/10);
    }
    pTextCharOut((UCHAR)((u%10)+'0'));

}
Example #4
0
//
// output an unsigned long
//
VOID putu(__in ULONG u)
{
	if(u / 10)
		putu(u / 10);

	UCHAR Value											= static_cast<UCHAR>(u % 10) + '0';
	ULONG Count;
	ArcWrite(BlConsoleOutDeviceId,&Value,sizeof(Value),&Count);
}
Example #5
0
File: uart0.c Project: gepp88/Meiji
int putd(long v)
{
	int w = 0;
	if (v < 0) {
		w += putc('-');
		v = -v;
	}
	w += putu(v);
	return w;
}
Example #6
0
File: uart0.c Project: gepp88/Meiji
int putf(double v, int prec)
{
	int i, w = 0;
	if (v < 0.0) {
		w += putc('-');
		v = -v;
	}
	w += putu(v);
	w += putc('.');
	for (i = 0; i < prec; ++i) {
		v = v - (int)v;
		v = v * 10;
		w += putc('0' + (int)v + (i + 1 == prec && v - (int)v > .5));
	}
	return w;
}
Example #7
0
File: tasks.c Project: gepp88/Meiji
int create_task(job_t job, void *arg, unsigned long period,
		unsigned long delay, unsigned long prio_dead, int type, const char *name)
{
	int i;
	struct task *t;
	for (i = 1; i < MAX_NUM_TASKS; ++i)	/* skip task 0 (idle task) */
		if (!taskset[i].valid)
			break;
	if (i == MAX_NUM_TASKS)
		return -1;
	t = taskset + i;
	t->job = job;
	t->arg = (arg == NULL ? t : arg);
	t->name = name;
	t->period = period;
	t->releasetime = ticks + delay;
	if (type == EDF) {
		/* this is an EDF task
		 * priority is set to the absolute deadline of the first job
		 * a small absolute deadline yields a large priority */
		if (prio_dead == 0)
			return -1;
		t->priority = prio_dead + t->releasetime;
		t->deadline = prio_dead;
	} else {
		/* this is a fixed-priority task
		 * to be run in background if no other EDF job is pending */
		t->priority = prio_dead;
		t->deadline = 0;
	}
	t->released = 0;
	init_task_context(t, i);
	__memory_barrier();
	irq_disable();
	++num_tasks;
	t->valid = 1;
	irq_enable();
	puts("Task ");
	puts(name);
	puts(" created, TID=");
	putu(i);
	putnl();
	return i;
}
Example #8
0
VOID putu(
    ULONG u
    )
/*++

Routine Description:

    Write an unsigned long to display

Arguments:

    u - unsigned


--*/

{
    if (u/10)
        putu(u/10);

    putc((char)((u%10)+'0'));

}
Example #9
0
int nvprintf(size_t size, const char *fmt, va_list ap)
{
	u32 i;

	return_val_if_fail(fmt != NULL, -1);

	for (i = 0; i < size; i++) {
		if (fmt[i] == '%') {
			if ((i + 1) < size && fmt[i+1] != '%') {
				char conv = fmt[i+1];

				switch (conv) {

				case 'c':
				{
					char c = va_arg(ap, char);
					putchar(c);
					i++;
					break;
				}

				case 'u':
				{
					unsigned int u = va_arg(ap,
								unsigned int);
					putu(u);
					i++;
					break;
				}

				case 'x':
				case 'X':
				{
					unsigned int x = va_arg(ap,
								unsigned int);
					putx(x);
					i++;
					break;
				}

				case 'd':
				case 'i':
				{
					int d = va_arg(ap, int);
					putd(d);
					i++;
					break;
				}

				case 'p':
				{
					void *p = va_arg(ap, void *);
					putp(p);
					i++;
					break;
				}

				case 's':
				{
					const char *s = va_arg(ap, char *);
					puts(s);
					i++;
					break;
				}
				}
			}
		} else {
Example #10
0
//
// standard printf function with a subset of formating features supported.
//
// supported
//	%d, %ld - signed short, signed long
//	%u, %lu - unsigned short, unsigned long
//	%c, %s  - character, string
//	%x, %lx - unsigned print in hex, unsigned long print in hex
//	%wS,%wZ	- unicode string
//
//	does not do:
//
//	- field width specification
//	- floating point.
//
VOID BlPrint(__in PCHAR cp,...)
{
	PVOID ap											= Add2Ptr(&cp,sizeof(PCHAR),PVOID);
	USHORT b											= 0;
	ULONG Count											= 0;
	ULONG DeviceId										= BlConsoleOutDeviceId ? BlConsoleOutDeviceId : 1;

	while(b = *cp ++)
	{
		if(b == '%')
		{
			USHORT c									= *cp ++;
			switch(c)
			{
			case 'c':
				ArcWrite(DeviceId,ap,sizeof(UCHAR),&Count);
				ap										= Add2Ptr(ap,sizeof(LONG),PVOID);
				break;

			case 'd':
				puti(*static_cast<PLONG>(ap));
				ap										= Add2Ptr(ap,sizeof(LONG),PVOID);
				break;

			case 'l':
				{
					USHORT d							= *cp ++;
					switch(d)
					{
					case 'd':
						puti(*static_cast<PLONG>(ap));
						ap								= Add2Ptr(ap,sizeof(LONG),PVOID);
						break;

					case 'u':
						putu(*static_cast<PUSHORT>(ap));
						ap								= Add2Ptr(ap,sizeof(LONG),PVOID);
						break;

					case 'x':
						{
							ULONG x						= *static_cast<PULONG>(ap);
							ULONG ZeroLength			= (x < 0x10) + (x < 0x100) + (x < 0x1000) + (x < 0x10000) + (x < 0x100000) + (x < 0x1000000) + (x < 0x10000000);
							while(ZeroLength --)
								ArcWrite(DeviceId,"0",sizeof(UCHAR),&Count);
							putx(x);
							ap							= Add2Ptr(ap,sizeof(LONG),PVOID);
						}
						break;
					}
				}
				break;

			case 's':
				{
					PCHAR String						= *static_cast<PCHAR*>(ap);
					ArcWrite(DeviceId,String,strlen(String),&Count);
					ap									= Add2Ptr(ap,sizeof(PCHAR),PVOID);
				}
				break;

			case 'u':
				putu(*static_cast<PUSHORT>(ap));
				ap										= Add2Ptr(ap,sizeof(LONG),PVOID);
				break;

			case 'w':
				{
					USHORT d							= *cp ++;
					switch(d)
					{
					case 'S':
					case 'W':
						putwS(*static_cast<PUNICODE_STRING*>(ap));
						ap								= Add2Ptr(ap,sizeof(PUNICODE_STRING),PVOID);
						break;
					}
				}
				break;

			case 'x':
				{
					USHORT x							= *static_cast<PUSHORT>(ap);
					ULONG ZeroLength					= (x < 0x10) + (x < 0x100) + (x < 0x1000);
					while(ZeroLength --)
						ArcWrite(DeviceId,"0",sizeof(UCHAR),&Count);
					putx(x);
					ap									= Add2Ptr(ap,sizeof(LONG),PVOID);
				}
				break;

			default:
				ArcWrite(DeviceId,&b,sizeof(UCHAR),&Count);
				ArcWrite(DeviceId,&c,sizeof(UCHAR),&Count);
				break;
			}
		}
		else
		{
			if(!DbcsLangId || !GrIsDBCSLeadByte(cp[-1]))
			{
				ArcWrite(DeviceId,cp - 1,1,&Count);
			}
			else
			{
				ArcWrite(DeviceId,cp - 1,2,&Count);
				cp										+= 1;
			}
		}
	}
}
Example #11
0
VOID
BlPrint(
    PCHAR cp,
    ...
    )

/*++

Routine Description:

    Standard printf function with a subset of formating features supported.

    Currently handles

     %d, %ld - signed short, signed long
     %u, %lu - unsigned short, unsigned long
     %c, %s  - character, string
     %x, %lx - unsigned print in hex, unsigned long print in hex

    Does not do:

     - field width specification
     - floating point.

Arguments:

    cp - pointer to the format string, text string.


Returns:

    Nothing


--*/

{
    USHORT b,c,w,len;
    PUCHAR ap;
    ULONG l;

    //
    // Cast a pointer to the first word on the stack
    //

    ap = (PUCHAR)&cp + sizeof(PCHAR);
    sc = ' '; // default padding char is space

    //
    // Process the arguments using the descriptor string
    //


    while (b = *cp++)
        {
        if (b == '%')
            {
            c = *cp++;

            switch (c)
                {
                case 'd':
                    puti((long)*((int *)ap));
                    ap += sizeof(int);
                    break;

                case 's':
                    BlPuts(*((PCHAR *)ap));
                    ap += sizeof (char *);
                    break;

                case 'c':
                    putc(*((char *)ap));
                    ap += sizeof(int);
                    break;

                case 'x':
                    w = *((USHORT *)ap);
                    len = ZLEN_SHORT(w);
                    while(len--) putc('0');
                    putx((ULONG)*((USHORT *)ap));
                    ap += sizeof(int);
                    break;

                case 'u':
                    putu((ULONG)*((USHORT *)ap));
                    ap += sizeof(int);
                    break;

                case 'l':
                    c = *cp++;

                switch(c) {

                    case 'u':
                        putu(*((ULONG *)ap));
                        ap += sizeof(long);
                        break;

                    case 'x':
                        l = *((ULONG *)ap);
                        len = ZLEN_LONG(l);
                        while(len--) putc('0');
                        putx(*((ULONG *)ap));
                        ap += sizeof(long);
                        break;

                    case 'd':
                        puti(*((ULONG *)ap));
                        ap += sizeof(long);
                        break;

                }
                break;

                default :
                    putc((char)b);
                    putc((char)c);
                }
            }
        else
            putc((char)b);
        }

}
Example #12
0
VOID
BlPrint(
    PCHAR cp,
    ...
    )

/*++

Routine Description:

    Standard printf function with a subset of formating features supported.

    Currently handles

     %d, %ld - signed short, signed long
     %u, %lu - unsigned short, unsigned long
     %c, %s  - character, string
     %x, %lx - unsigned print in hex, unsigned long print in hex

    Does not do:

     - field width specification
     - floating point.

Arguments:

    cp - pointer to the format string, text string.

Returns:

    Nothing

--*/

{
    USHORT b,c,w,len;
    PUCHAR ap;
    ULONG l;

    //
    // Cast a pointer to the first word on the stack
    //
    ap = (PUCHAR)&cp + sizeof(PCHAR);

    //
    // Process the arguments using the descriptor string
    //
    while(b = *cp++) {
        if(b == '%') {

            c = *cp++;

            switch (c) {

            case 'd':
                puti((long)*((int *)ap));
                ap += sizeof(int);
                break;

            case 's':
                TextStringOut(*((PCHAR *)ap));
                ap += sizeof(char *);
                break;

            case 'c':
                //
                // Does not handle dbcs chars
                //
                pTextCharOut(*((char *)ap));
                ap += sizeof(int);
                break;

            case 'x':
                w = *((USHORT *)ap);
                len = (USHORT)ZLEN_SHORT(w);
                while(len--) pTextCharOut('0');
                putx((ULONG)*((USHORT *)ap));
                ap += sizeof(int);
                break;

            case 'u':
                putu((ULONG)*((USHORT *)ap));
                ap += sizeof(int);
                break;

            case 'w':
                c = *cp++;
                switch (c) {
                case 'S':
                case 'Z':
                    putwS(*((PUNICODE_STRING *)ap));
                    ap += sizeof(PUNICODE_STRING);
                    break;
                }
                break;

            case 'l':
                c = *cp++;

                switch(c) {

                case '0':
                    break;

                case 'u':
                    putu(*((ULONG *)ap));
                    ap += sizeof(long);
                    break;

                case 'x':
                    l = *((ULONG *)ap);
                    len = (USHORT)ZLEN_LONG(l);
                    while(len--) pTextCharOut('0');
                    putx(*((ULONG *)ap));
                    ap += sizeof(long);
                    break;

                case 'd':
                    puti(*((ULONG *)ap));
                    ap += sizeof(long);
                    break;
                }
                break;

            default :
                pTextCharOut((char)b);
                pTextCharOut((char)c);
            }
        } else {
            //
            // Could be a double-byte char.
            //
            cp = TextCharOut(cp-1);
        }
    }
}