summaryrefslogtreecommitdiff
path: root/lcmodule/source/cnh1605551_ldr_utilities/include/r_memmory_utils.h
blob: fb4d54fd0c14c12116dafcf3c2d9f6de99b77e44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/
#ifndef _R_MEMMORY_UTILS_H_
#define _R_MEMMORY_UTILS_H_

/**
 * @addtogroup ldr_utilities
 * @{
 *   @addtogroup memmory_utils
 *   @{
 */

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <stdlib.h>
#include "error_codes.h"
#include "t_basicdefinitions.h"
#ifdef CFG_ENABLE_LOADER_TYPE
#include "cpu_support.h"

/*******************************************************************************
 * Macro that release allocated memory space in heap.
 ******************************************************************************/
#define BUFFER_FREE(Buffer) \
if (NULL != (Buffer)) \
{ \
  CPU_Irq_State_t IRQ_status; \
  \
  IRQ_status = CPU_IrqDisable();\
  free(Buffer); \
  (Buffer) = NULL; \
  \
  if (IRQ_status == CPU_IRQ_ENABLE)\
  {\
    CPU_IrqEnable();\
  }\
}
#else //CFG_ENABLE_LOADER_TYPE
#define BUFFER_FREE(Buffer) \
if (NULL != (Buffer)) \
{ \
  free(Buffer); \
  (Buffer) = NULL; \
}
#endif // CFG_ENABLE_LOADER_TYPE

/**
 * Macro that check alignment. If variable is not aligned it set the status
 * variable ReturnValue to appropriate error code and send the function to error
 * label.
 *
 * @param [in] x           Variable for alignemend check.
 *
 * @sigbased No - Macro
 */
#define IS_ALIGNED(x)  if(((x) & 3)) \
                       { \
                         ReturnValue = E_UNALIGNED_DATA; \
                         goto ErrorExit; \
                       } \
 
/** @} */
/** @} */
#endif /*_R_MEMMORY_UTILS_H_*/