Пример #1
0
STATUS taskLibInit(
    void
    )
{
    STATUS status;

    if (taskLibInstalled == TRUE)
    {
        status = OK;
    }
    else
    {
        if (classInit(taskClassId,
                STACK_ROUND_UP(sizeof(TCB) + TASK_EXTRA_BYTES),
                OFFSET(TCB, objCore),
                memSysPartId,
                (FUNCPTR) taskCreat,
                (FUNCPTR) taskInit,
                (FUNCPTR) taskDestroy
                ) != OK)
        {
            /* errno set by classInit() */
            status = ERROR;
        }
        else
        {
            taskLibInstalled = TRUE;
            status = OK;
        }
    }

    return status;
}
Пример #2
0
void* taskStackAllot(
    int      taskId,
    unsigned size
    )
{
    TCB_ID tcbId;
    char  *pStackPrev;
    void  *pNewMem;

    /* Get task context */
    tcbId = taskTcb(taskId);
    if (tcbId == NULL)
    {
        pNewMem = NULL;
    }
    else
    {
        /* TASK_ID_VERIFY() already done by taskTcb() */

        /* Round up */
        size = STACK_ROUND_UP(size);

        /* Check if size is ok */
        if (size > (tcbId->pStackLimit - tcbId->pStackBase) * _STACK_DIR)
        {
            errnoSet(S_taskLib_STACK_OVERFLOW);
            pNewMem = NULL;
        }
        else
        {
#if (_STACK_DIR == _STACK_GROWS_DOWN)
            pStackPrev          = tcbId->pStackLimit;
            tcbId->pStackLimit += size;
            pNewMem = pStackPrev;
#else /* _STACK_GROWS_UP */
            tcbId->pStackLimit -= size;
            pNewMem = tcbId->pStackLimit;
#endif /* _STACK_DIR */
        }
    }

    return pNewMem;
}
Пример #3
0
int taskCreat(
    const char *name,
    unsigned    priority,
    int         options,
    unsigned    stackSize,
    FUNCPTR     func,
    ARG         arg0,
    ARG         arg1,
    ARG         arg2,
    ARG         arg3,
    ARG         arg4,
    ARG         arg5,
    ARG         arg6,
    ARG         arg7,
    ARG         arg8,
    ARG         arg9
    )
{
    static char digits[] = "0123456789";

    TCB_ID  tcbId;
    char   *pTaskMem;
    char   *pStackBase;
    char    newName[20];
    int     value;
    int     nBytes;
    int     nPreBytes;
    char   *pBufStart;
    char   *pBufEnd;
    char    ch;

    /* Check if task lib is installed */
    if (taskLibInstalled != TRUE)
    {
        errnoSet(S_taskLib_NOT_INSTALLED);
        tcbId = NULL;
    }
    else
    {
        /* If NULL name create default name for task */
        if (name == NULL)
        {
            strcpy(newName, namelessPrefix);
            nBytes    = strlen(newName);
            nPreBytes = nBytes;
            value     = ++namelessCount;

            /* Do while value is non-zero */
            do
            {
                newName[nBytes++] = digits[value % 10];
                value /= 10;
            } while(value != 0);

            /* Calculate start/end positions in name */
            pBufStart = newName + nPreBytes;
            pBufEnd   = newName + nBytes - 1;

            /* While startbuffer lt. end buffer */
            while (pBufStart < pBufEnd)
            {
                ch         = *pBufStart;
                *pBufStart = *pBufEnd;
                *pBufEnd   = ch;
                pBufStart++;
                pBufEnd--;
            }

            /* Terminate string */
            newName[nBytes] = EOS;

            /* Use this a the name for the task */
            name = newName;
        }

        /* Round up stack size */
        stackSize = STACK_ROUND_UP(stackSize);

        /* Allocate new TCB plus stack */
        pTaskMem = objAllocPad(
                       taskClassId,
                       (unsigned) stackSize,
                       (void **) NULL
                       );
        if (pTaskMem == NULL)
        {
            /* errno set by objAllocPad() */
            tcbId = NULL;
        }
        else
        {
            /* Setup stack vars */

#if (_STACK_DIR == _STACK_GROWS_DOWN)
            pStackBase = pTaskMem + stackSize;
            tcbId      = (TCB_ID) pStackBase;
#else /* _STACK_GROWS_UP */
            tcbId      = (TCB_ID) (pTaskMem + TASK_EXTRA_BYTES);
            pStackBase = STACK_ROUND_UP(
                             pTaskMem + TASK_EXTRA_BYTES + sizeof(TCB)
                             );
#endif /* _STACK_DIR */

            /* Initialize task */
            if (taskInit(
                    tcbId,
                    name,
                    priority,
                    options,
                    pStackBase,
                    stackSize,
                    func,
                    arg0,
                    arg1,
                    arg2,
                    arg3,
                    arg4,
                    arg5,
                    arg6,
                    arg7,
                    arg8,
                    arg9
                    ) != OK)
            {
                /* errno set by taskInit() */
                objFree(taskClassId, tcbId);
                tcbId = NULL;
            }
        }
    }

    return (int) tcbId;
}
Пример #4
0
GEN_OFFSET_SYM(NANO_ESF, a7);

GEN_OFFSET_SYM(NANO_ESF, mepc);
GEN_OFFSET_SYM(NANO_ESF, mstatus);

#if defined(CONFIG_SOC_RISCV32_PULPINO)
GEN_OFFSET_SYM(NANO_ESF, lpstart0);
GEN_OFFSET_SYM(NANO_ESF, lpend0);
GEN_OFFSET_SYM(NANO_ESF, lpcount0);
GEN_OFFSET_SYM(NANO_ESF, lpstart1);
GEN_OFFSET_SYM(NANO_ESF, lpend1);
GEN_OFFSET_SYM(NANO_ESF, lpcount1);
#endif

/*
 * RISC-V requires the stack to be 16-bytes aligned, hence SP needs to grow or
 * shrink by a size, which follows the RISC-V stack alignment requirements
 * Hence, ensure that __tTCS_NOFLOAT_SIZEOF and __tTCS_NOFLOAT_SIZEOF sizes
 * are aligned accordingly.
 */
GEN_ABSOLUTE_SYM(__NANO_ESF_SIZEOF, STACK_ROUND_UP(sizeof(NANO_ESF)));

/*
 * size of the struct k_thread structure sans save area for floating
 * point regs
 */
GEN_ABSOLUTE_SYM(_K_THREAD_NO_FLOAT_SIZEOF,
		 STACK_ROUND_UP(sizeof(struct k_thread)));

GEN_ABS_SYM_END