dyn. memory alloc

This commit is contained in:
Olaf Rempel 2008-02-06 14:20:47 +01:00
parent f2e8d126e5
commit d74bef5e61
7 changed files with 50 additions and 56 deletions

View File

@ -1,9 +1,12 @@
#ifndef STATIC_ALLOC_H_
#define STATIC_ALLOC_H_
#ifndef MEMALLOC_H_
#define MEMALLOC_H_
void * static_alloc(uint32_t size);
uint32_t static_alloc_used(void);
uint32_t next_powerof2(uint32_t value);
#endif /*STATIC_ALLOC_H_*/
void * static_alloc(uint32_t size);
void * alloc(uint32_t size);
void free(void *p);
#endif /*MEMALLOC_H_*/

2
main.c
View File

@ -26,7 +26,7 @@
#include "at91_twi.h"
#include "at91_tc1.h"
#include "static_alloc.h"
#include "memalloc.h"
#include "board.h"
#include <stdio.h>

View File

@ -22,7 +22,6 @@
#include "AT91SAM7S256.h"
#include "board.h"
#include "at91_pitc.h"
#include "static_alloc.h"
static uint16_t adc_result[4];

View File

@ -20,7 +20,7 @@
#include "at91_pitc.h"
#include "at91_sysc.h"
#include "board.h"
#include "static_alloc.h"
#include "memalloc.h"
/* PIV is 20bit -> min. 3Hz @48MHz MCK */
#define HZ_TO_PIV(HZ) (MCK / (16 * HZ))

View File

@ -19,7 +19,7 @@
#include "AT91SAM7S256.h"
#include "atomic.h"
#include "fifo.h"
#include "static_alloc.h"
#include "memalloc.h"
#define FIFO_MASK(x) ((x)->size -1)
@ -80,15 +80,15 @@ uint32_t fifo_rxpdc(struct fifo *fifo, AT91S_PDC *pdc, uint16_t maxsize)
/* account previous PDC transfer */
fifo->in += fifo->pdc_rx;
uint32_t free = fifo->size - fifo_used(fifo);
if (free) {
uint32_t left = fifo->size - fifo_used(fifo);
if (left) {
/* calc pointer for next transfer */
uint32_t first_idx = (fifo->in & FIFO_MASK(fifo));
pdc->PDC_RPR = (uint32_t)(fifo->buf + first_idx);
/* check for buffer end -> split transfer */
if (first_idx + free <= (fifo->size -1)) {
fifo->pdc_rx = free;
if (first_idx + left <= (fifo->size -1)) {
fifo->pdc_rx = left;
} else {
fifo->pdc_rx = fifo->size - first_idx;
}

View File

@ -20,8 +20,9 @@
#include <stdio.h>
#include "AT91SAM7S256.h"
#include "board.h"
#include "static_alloc.h"
#include "memalloc.h"
// TODO: make generic version and find better place
#define ALIGN(x) (((x) +3) & ~3)
/* extern symbols, defined in ldscript */
@ -91,7 +92,7 @@ static struct memchunk * alloc_add(uint32_t size)
struct memchunk *newblock = static_alloc(size);
/* struct at end of memory block */
struct memchunk *endblock = (void *)newblock + size - sizeof(struct memchunk);
struct memchunk *endblock = (void *)((uint32_t)newblock + size - sizeof(struct memchunk));
/* link between them */
newblock->next = endblock;
@ -161,7 +162,7 @@ try_next:
/* if we split the chunk, the remaining piece must be large enough */
if (((uint32_t)GET_NEXT(found) - (uint32_t)found) > (size + 2 * sizeof(struct memchunk))) {
struct memchunk *end = (void *)found + size;
struct memchunk *end = (void *)((uint32_t)found + size);
end->next = SET_FLAGS(GET_NEXT(found), 0);
found->next = SET_FLAGS(end, FLAG_CHUNKINUSE);

View File

@ -21,6 +21,7 @@
#include <string.h>
#include "board.h" // ARRAY_SIZE()
#include "telemetrie.h"
#include "memalloc.h"
/* extern symbols, defined in ldscript */
extern struct tdc_value _tdc_value_table;
@ -60,16 +61,6 @@ int32_t tdc_transmit(uint32_t addr, const uint8_t *data, uint32_t size)
return -1;
}
static void * alloc(uint32_t size)
{
return NULL;
}
static void free(void *p)
{
}
/*
void *blub = NULL;
func(&blub);