forked from xuos/xiuos
Implant USB memory functions
This commit is contained in:
parent
7d78fc6c2a
commit
403d1daab1
|
@ -2,3 +2,44 @@
|
|||
#include "usb_mem.h"
|
||||
|
||||
|
||||
|
||||
void *usb_hc_malloc(size_t size){
|
||||
void *result = malloc(size);
|
||||
|
||||
if (result)
|
||||
{
|
||||
memset(result, 0U, size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void *usb_hc_malloc_align(size_t align, size_t size)
|
||||
{
|
||||
size_t flag, adj_size;
|
||||
|
||||
flag = align & (align - 1);
|
||||
|
||||
/*
|
||||
* align should be a power of 2.
|
||||
*/
|
||||
if(flag != 0)
|
||||
return NULL;
|
||||
|
||||
adj_size = (size + (align - 1)) &~ (align);
|
||||
|
||||
void *result = malloc(size);
|
||||
|
||||
if (result)
|
||||
{
|
||||
memset(result, 0U, size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void usb_hc_free(void* ptr){
|
||||
if(ptr != NULL)
|
||||
free(ptr);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#define USB_MEM_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "usb_config.h"
|
||||
|
||||
#define USB_MEM_ALIGNX __attribute__((aligned(CONFIG_USB_ALIGN_SIZE)))
|
||||
|
||||
|
@ -14,5 +15,9 @@ void *usb_hc_malloc(size_t size);
|
|||
void usb_hc_free();
|
||||
void *usb_hc_malloc_align(size_t align, size_t size);
|
||||
|
||||
#define usb_malloc(size) usb_hc_malloc(size)
|
||||
#define usb_free(ptr) usb_hc_free(ptr)
|
||||
#define usb_align(align, size) usb_hc_malloc_align(align, size)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue