Ignore:
Timestamp:
Jul 13, 2020, 8:07:55 PM (4 years ago)
Author:
coas-nagasima
Message:

ntshellアプリはnewlibを使うよう変更し、syscallの実装部分と区別がつくよう更新。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/mbed/mbed_stub.c

    r439 r442  
    4646#include <sil.h>
    4747#include "us_ticker_api.h"
    48 #include <sys/types.h>
    49 #include <errno.h>
     48#include "mbed_retarget.h"
    5049#include "kernel_cfg.h"
    5150#include "t_syslog.h"
     
    8079        sta_ker();
    8180}
     81
     82void _exit(int status)
     83{
     84        ext_ker();
     85}
     86
     87int malloc_lock_sem_count[TNUM_TSKID];
     88
     89void __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;
     108error:
     109        syslog(LOG_ERROR, "%s (%d) __malloc_lock error.",
     110                itron_strerror(ercd), SERCD(ercd));
     111        DebugBreak();
     112}
     113
     114void __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;
     138error:
     139        syslog(LOG_ERROR, "%s (%d) __malloc_unlock error.",
     140                itron_strerror(ercd), SERCD(ercd));
     141        DebugBreak();
     142}
     143
     144extern uint32_t __HeapBase;
     145extern uint32_t __HeapLimit;
     146extern uint32_t __end__;
     147
     148void *_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.