[ion] Ion::Log::print(int)

Change-Id: I5cdb33194d32b5ac219b92cb26d77fcc978cbcb4
This commit is contained in:
Romain Goyet
2017-02-16 10:56:46 +01:00
parent a94e8c314f
commit a447c8d0b8
7 changed files with 35 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ include ion/src/$(PLATFORM)/Makefile
objs += $(addprefix ion/src/shared/, \
c.o \
events.o \
log_integer.o \
)
tests += $(addprefix ion/test/,\

View File

@@ -1,11 +1,14 @@
#ifndef ION_C_H
#define ION_C_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void ion_log_print(const char * message);
void ion_log_print_string(const char * message);
void ion_log_print_integer(uint32_t integer);
#ifdef __cplusplus
}

View File

@@ -1,10 +1,13 @@
#ifndef ION_LOG_H
#define ION_LOG_H
#include <stdint.h>
namespace Ion {
namespace Log {
void print(const char * message);
void print(uint32_t number);
}
}

View File

@@ -4,6 +4,7 @@ objs += $(addprefix ion/src/shared/, \
events.o \
events_stdin.o \
log_printf.o \
log_integer.o \
power.o \
)

View File

@@ -1,6 +1,10 @@
#include <ion.h>
#include <ion/c.h>
void ion_log_print(const char * message) {
void ion_log_print_integer(uint32_t i) {
Ion::Log::print(i);
}
void ion_log_print_string(const char * message) {
Ion::Log::print(message);
}

View File

@@ -0,0 +1,13 @@
#include <ion/log.h>
#include <stdio.h>
void Ion::Log::print(uint32_t i) {
char buffer[9];
for (int j=0; j<8; j++) {
uint8_t v = (i & 0xF);
buffer[8-1-j] = (v>9) ? 'A'+v-10 : '0'+v;
i = i >> 4;
}
buffer[8] = 0;
print(buffer);
}

View File

@@ -3,17 +3,7 @@
#include <private/memconfig.h>
#if LIBA_LOG_DYNAMIC_MEMORY
#include <stdint.h>
#include <ion/c.h>
void write_uint32_in_buffer(uint32_t n, char * buffer) {
for (int i=0; i<2*sizeof(uint32_t); i++) {
unsigned char v = (n & 0xF);
char c = (v>9) ? 'A'+v-10 : '0'+v;
buffer[2*sizeof(uint32_t)-1-i] = c;
n = n >> 4;
}
}
#endif
extern char _heap_start;
@@ -41,9 +31,9 @@ static void configure_heap() {
void free(void *ptr) {
#if LIBA_LOG_DYNAMIC_MEMORY
char message[5+2*sizeof(uint32_t)+1] = {'F', 'R', 'E', 'E', '-'};
write_uint32_in_buffer((uint32_t)ptr, message+5);
ion_log_print(message);
ion_log_print_string("FREE-");
ion_log_print_integer((uint32_t)ptr);
ion_log_print_string("\n");
#endif
if (ptr != NULL) {
memsys5FreeUnsafe(ptr);
@@ -59,12 +49,11 @@ void * malloc(size_t size) {
p = memsys5MallocUnsafe(memsys5Roundup(size));
}
#if LIBA_LOG_DYNAMIC_MEMORY
char message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)+1] = {'M','A','L','L','O','C','-'};
write_uint32_in_buffer((uint32_t)p, message+7);
message[7+2*sizeof(uint32_t)] = '-';
write_uint32_in_buffer(size, message+7+2*sizeof(uint32_t)+1);
message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)] = 0;
ion_log_print(message);
ion_log_print_string("MALLOC-");
ion_log_print_integer((uint32_t)p);
ion_log_print_string("-");
ion_log_print_integer((uint32_t)size);
ion_log_print_string("\n");
#endif
return p;
}