APM:Libraries
Util.cpp
Go to the documentation of this file.
1 /*
2  (c) 2017 night_ghost@ykoctpa.ru
3 
4 */
5 
6 
7 #include <AP_HAL/AP_HAL.h>
8 #include "Semaphores.h"
9 #include "Scheduler.h"
10 #include "Util.h"
11 
12 using namespace F4Light;
13 
14 void *Util::malloc_type(size_t size, Memory_Type mem_type) {
15  void *ptr;
16  switch(mem_type) {
18  ptr = sbrk_ccm(size);
19  if(ptr != ((caddr_t)-1)) {
20  memset(ptr,0,size);
21  return ptr;
22  }
23  // no break!
25  ptr = malloc(size);
26  if(ptr != NULL) {
27  memset(ptr,0,size);
28  return ptr;
29  }
30  // no break!
31 
32  default:
33  return NULL;
34  }
35 }
36 
37 void Util::free_type(void *ptr, size_t size, Memory_Type mem_type) {
38  switch(mem_type) {
40  free(ptr);
41  break;
42 
43  case AP_HAL::Util::MEM_FAST: // can't free CCM memory
44  break;
45  }
46 
47 }
caddr_t sbrk_ccm(int nbytes)
Definition: syscalls.c:121
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
void free_type(void *ptr, size_t size, Memory_Type mem_type) override
Definition: Util.cpp:37
void * malloc(size_t size)
Definition: malloc.c:61
#define NULL
Definition: hal_types.h:59
void free(void *ptr)
Definition: malloc.c:81
void * malloc_type(size_t size, Memory_Type mem_type) override
Definition: Util.cpp:14