static void test_task1(void * pParam) { RAW_U8* addr; while(1) { if(RAW_SUCCESS == raw_byte_allocate(&byte_pool, (void**)&addr, 16)) { count ++; __put_char("ok1 ", 4); }else { __put_char("error1 ", 7); } raw_sleep(20); if(RAW_SUCCESS == raw_byte_allocate(&byte_pool, (void**)&addr, 30)) { count ++; __put_char("ok2 ", 4); }else { __put_char("error2 ", 7); } raw_sleep(20); } }
void test_block() { if(1 == test_switch) { return; } test_switch = 1; if (RAW_SUCCESS != raw_block_pool_create(&mem_pool, "pool_block1", 32, buffer, 1024)) { __put_char("error ", 6); return; } raw_task_create(&test_task_obj, (RAW_U8 *)"task1", 0, 5, 10, test_task_stack1, TEST_TASK_STK_SIZE , test_task1, 1); }
static void test_task1(void * pParam) { RAW_U8* addr; while(1) { if(RAW_SUCCESS == raw_block_allocate(&mem_pool, (void**)&addr)) { count ++; __put_char("ok ", 3); }else { __put_char("error ", 6); } raw_sleep(20); } }
int from_string(FILE *str, char *b, char sep, int fw, int fp, bool to_right) { int len = strlen(b); if(fw < len) fw = len; int pad_count = fw - len; if(to_right) { while(pad_count--) __put_char(str, sep); } if(fp == -1) __put_str(str, b); else __put_nstr(str, b, fp); while(pad_count-- > 0) __put_char(str, sep); return fw; }
int vfprintf(FILE *stream, const char *fmt, va_list ap) { if(!stream || ISUNSET(stream->status,_FST_OPEN)) return -1; __check_buf(stream); int tot = 0; char buf[INTERNAL_BUF]; char *pbuf; uint32_t arg_u32; if(!stream || !fmt) { errno = EINVAL; return -1; } for (; *fmt; fmt++) { pbuf = 0; switch (*fmt) { case '%': { fmt++; int field_width = 0; int field_precision = -1; int *val = &field_width; char separator = ' '; bool pad_to_right = TRUE; bool done = FALSE; // zjedz flagi while(!done) { switch (*fmt) { case '-': pad_to_right = FALSE; fmt++; break; case '*': *val = va_arg(ap, int); fmt++; if(*val<0) { *val=-*val; pad_to_right = FALSE; //? } break; case '.': val = &field_precision; *val = 0; fmt++; break; case '0': if(*val == 0) separator = '0'; else *val *= 10; fmt++; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': *val = 10*(*val) + (*(fmt++) - '0'); break; default: done=TRUE; break; } } if(!pad_to_right) separator = ' '; if(*fmt == 'l') //long fmt++; // flagi zjedzone - do roboty switch (*fmt) { case '%': __put_char(stream, '%'); tot++; break; case 'u': arg_u32 = va_arg(ap, uint32_t); pbuf = convert_uint32(buf, arg_u32, 10); break; case 'd': case 'i': arg_u32 = va_arg(ap, int32_t); pbuf = convert_int32(buf, (int32_t)arg_u32, 10); break; case 'x': arg_u32 = va_arg(ap, uint32_t); pbuf = convert_uint32(buf, arg_u32, 16); break; case 'o': arg_u32 = va_arg(ap, uint32_t); pbuf = convert_uint32(buf, arg_u32, 8); break; case 'b': arg_u32 = va_arg(ap, uint32_t); pbuf = convert_uint32(buf, arg_u32, 2); break; case 'p': arg_u32 = va_arg(ap, uintptr_t); pbuf = convert_uint32(buf, arg_u32, 16); *(--pbuf) = 'x'; *(--pbuf) = '0'; break; case 's': pbuf = va_arg(ap, char *); break; case 'c': __put_char(stream, (unsigned char)va_arg(ap, int)); tot++; break; } if (pbuf) tot+=from_string(stream, pbuf, separator, field_width, (*fmt=='s')?field_precision:-1, pad_to_right); break; } default: __put_char(stream, *fmt); break; } } return tot; }