GomSpace/libcsp — Issue #19: Move architecture specific code to src/arch
Author: jledet
Created: 2011-11-23 08:02:55+00:00
State: open
Labels: Medium, Task

The src/arch dir contains architecture specific code for task create, semaphores and so on. However, some of our code still contains constructs like (csp_service_handler.c):

```#if defined(CSP_FREERTOS)
/* Try to malloc a lot */
uint32_t size = 1000000, total = 0, max = UINT32_MAX;
void * pmem;
while (1) {
pmem = csp_malloc(size + total);
if (pmem == NULL) {
max = size + total;
size = size / 2;
} else {
total += size;
if (total + size >= max)
size = size / 2;
csp_free(pmem);
}
if (size < 32) break;
}
#elif defined(CSP_POSIX)
/* Read system statistics */
uint32_t total = 0;
struct sysinfo info;
sysinfo(&info);
total = info.freeram * info.mem_unit;
#elif defined(CSP_MACOSX)
uint32_t total = 0; /* TODO: Fix memory free on OSX */
#elif defined(CSP_WINDOWS)
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
DWORDLONG freePhysicalMem = statex.ullAvailPhys;
size_t total = (size_t) freePhysicalMem;
#endif```

which looks awful...

This functionality should be moved to four functions in the src/arch dir.