Changeset 442 for EcnlProtoTool/trunk/asp3_dcre/mbed/mbed_stub.c
- Timestamp:
- Jul 13, 2020, 8:07:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/mbed/mbed_stub.c
r439 r442 46 46 #include <sil.h> 47 47 #include "us_ticker_api.h" 48 #include <sys/types.h> 49 #include <errno.h> 48 #include "mbed_retarget.h" 50 49 #include "kernel_cfg.h" 51 50 #include "t_syslog.h" … … 80 79 sta_ker(); 81 80 } 81 82 void _exit(int status) 83 { 84 ext_ker(); 85 } 86 87 int malloc_lock_sem_count[TNUM_TSKID]; 88 89 void __malloc_lock(void * reent) 90 { 91 ER ercd; 92 ID tskid = 0; 93 94 ercd = get_tid(&tskid); 95 if (ercd != E_OK) { 96 goto error; 97 } 98 99 if (malloc_lock_sem_count[tskid - 1] == 0) { 100 ercd = wai_sem(SEM_MALLOC); 101 if (ercd != E_OK) { 102 goto error; 103 } 104 } 105 106 malloc_lock_sem_count[tskid - 1]++; 107 return; 108 error: 109 syslog(LOG_ERROR, "%s (%d) __malloc_lock error.", 110 itron_strerror(ercd), SERCD(ercd)); 111 DebugBreak(); 112 } 113 114 void __malloc_unlock(void * reent) 115 { 116 ER ercd; 117 ID tskid = 0; 118 int count; 119 120 ercd = get_tid(&tskid); 121 if (ercd != E_OK) { 122 goto error; 123 } 124 125 malloc_lock_sem_count[tskid - 1]--; 126 if (malloc_lock_sem_count[tskid - 1] > 0) 127 return; 128 129 if (malloc_lock_sem_count[tskid - 1] < 0) { 130 goto error; 131 } 132 133 ercd = sig_sem(SEM_MALLOC); 134 if (ercd != E_OK) { 135 goto error; 136 } 137 return; 138 error: 139 syslog(LOG_ERROR, "%s (%d) __malloc_unlock error.", 140 itron_strerror(ercd), SERCD(ercd)); 141 DebugBreak(); 142 } 143 144 extern uint32_t __HeapBase; 145 extern uint32_t __HeapLimit; 146 extern uint32_t __end__; 147 148 void *_sbrk(int incr) 149 { 150 static unsigned char *heap = (unsigned char *)&__end__; 151 unsigned char *prev_heap = heap; 152 unsigned char *new_heap = heap + incr; 153 154 if (new_heap >= (unsigned char *)&__HeapLimit) { 155 errno = ENOMEM; 156 return (void *) -1; 157 } 158 159 heap = new_heap; 160 return (void *) prev_heap; 161 }
Note:
See TracChangeset
for help on using the changeset viewer.