forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTI_heap_wrapper.c
75 lines (59 loc) · 1.62 KB
/
TI_heap_wrapper.c
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
68
69
70
71
72
73
74
75
#include "bget.h"
#include <ti/drivers/dpl/HwiP.h>
#include <ti/drivers/dpl/SwiP.h>
typedef unsigned int dpl_CSState;
typedef union _dpl_cs_state_union_t
{
/** critical section variable as declared in the interface */
dpl_CSState state;
/** @internal field used to access internal data */
struct _dpl_cs_state_aggr_t
{
/** field to store Swi_disable() return value */
uint_least16_t swikey;
/** field to store Hwi_disable() return value */
uint_least16_t hwikey;
} each;
} dpl_CSStateUnion;
/* This is enter critical section for DPL supported devices */
dpl_CSState dpl_enterCSImpl(void)
{
dpl_CSStateUnion cu;
cu.each.swikey = (uint_least16_t) SwiP_disable();
cu.each.hwikey = (uint_least16_t) HwiP_disable();
return cu.state;
}
/* This is exit critical section for DPL supported devices */
void dpl_leaveCSImpl(dpl_CSState key)
{
dpl_CSStateUnion * cu = (dpl_CSStateUnion *) &key;
HwiP_restore((uint32_t) cu->each.hwikey);
SwiP_restore((uint32_t) cu->each.swikey);
}
/* Protected allocation */
void * pvPortMalloc(size_t xWantedSize)
{
void * retVal = NULL;
dpl_CSState state;
state = dpl_enterCSImpl();
retVal = bget(xWantedSize);
dpl_leaveCSImpl(state);
return retVal;
}
/* Protected Deallocation */
void vPortFree(void * pv)
{
dpl_CSState state;
state = dpl_enterCSImpl();
brel(pv);
dpl_leaveCSImpl(state);
}
void * pvPortRealloc(void * pv, size_t size)
{
void * retVal = NULL;
dpl_CSState state;
state = dpl_enterCSImpl();
retVal = bgetr(pv, size);
dpl_leaveCSImpl(state);
return retVal;
}