initial printf
snprintf blows up the size printf isn't too small either (about 10KB now)
This commit is contained in:
parent
191e408bb7
commit
ac0691ea9c
4 changed files with 466 additions and 2 deletions
|
@ -12,6 +12,7 @@ TARGETS := blink-red blink-green blink-blue blink-white blink-allio \
|
|||
tmr tmr-ints \
|
||||
sleep \
|
||||
rftest-rx rftest-tx \
|
||||
printf
|
||||
|
||||
|
||||
include $(MC1322X)/Makefile.include
|
||||
|
|
65
tests/printf.c
Normal file
65
tests/printf.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <mc1322x.h>
|
||||
#include <board.h>
|
||||
|
||||
#include "tests.h"
|
||||
#include "config.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *ptr = "Hello world!";
|
||||
char *np = 0;
|
||||
int i = 5;
|
||||
unsigned int bs = sizeof(int)*8;
|
||||
int mi;
|
||||
char buf[80];
|
||||
|
||||
uart_init(INC, MOD);
|
||||
|
||||
mi = (1 << (bs-1)) + 1;
|
||||
printf("%s\n", ptr);
|
||||
printf("printf test\n");
|
||||
printf("%s is null pointer\n", np);
|
||||
printf("%d = 5\n", i);
|
||||
printf("%d = - max int\n", mi);
|
||||
printf("char %c = 'a'\n", 'a');
|
||||
printf("hex %x = ff\n", 0xff);
|
||||
printf("hex %02x = 00\n", 0);
|
||||
printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
|
||||
printf("%d %s(s)%", 0, "message");
|
||||
printf("\n");
|
||||
printf("%d %s(s) with %%\n", 0, "message");
|
||||
// sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
|
||||
// sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
|
||||
// sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
|
||||
// sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
|
||||
// sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
|
||||
// sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
|
||||
// sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
|
||||
// sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* this should display (on 32bit int machine) :
|
||||
*
|
||||
* Hello world!
|
||||
* printf test
|
||||
* (null) is null pointer
|
||||
* 5 = 5
|
||||
* -2147483647 = - max int
|
||||
* char a = 'a'
|
||||
* hex ff = ff
|
||||
* hex 00 = 00
|
||||
* signed -3 = unsigned 4294967293 = hex fffffffd
|
||||
* 0 message(s)
|
||||
* 0 message(s) with %
|
||||
* justif: "left "
|
||||
* justif: " right"
|
||||
* 3: 0003 zero padded
|
||||
* 3: 3 left justif.
|
||||
* 3: 3 right justif.
|
||||
* -3: -003 zero padded
|
||||
* -3: -3 left justif.
|
||||
* -3: -3 right justif.
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue