gonzui


Format: Advanced Search

mtkernel_3/kernel/sysdepend/cpu/core/armv7m/cpu_task.hbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.03
    4:  *
    5:  *    Copyright (C) 2006-2021 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2021/03/31.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      cpu_task.h (ARMv7-M)
   16:  *      CPU-Dependent Task Start Processing
   17:  */
   18: 
   19: #ifndef _SYSDEPEND_CPU_CORE_CPUTASK_
   20: #define _SYSDEPEND_CPU_CORE_CPUTASK_
   21: 
   22: /*
   23:  * System stack configuration at task startup
   24:  */
   25: typedef struct {
   26:         UW     exp_ret;    /* Exception return */
   27:         UW     r_[8];              /* R4-R11 */
   28:         // Exception entry stack
   29:         UW     r[4];               /* R0-R3 */
   30:         UW     ip;         /* R12 */
   31:         void   *lr;              /* lr */
   32:         void   *pc;              /* pc */
   33:         UW     xpsr;               /* xpsr */
   34: } SStackFrame;
   35: 
   36: /*
   37:  * Size of system stack area destroyed by 'make_dormant()'
   38:  * In other words, the size of area required to write by 'knl_setup_context().'
   39:  */
   40: #define DORMANT_STACK_SIZE      ( sizeof(VW) * 7 ) /* To 'R4' position */
   41: 
   42: #if USE_FPU
   43: typedef struct {
   44:         UW     ufpu;               /* FPU usage flag */
   45:         UW     s_[16];             /* S16-S31 */
   46: 
   47:         UW     exp_ret;    /* Exception return */
   48:         UW     r_[8];              /* R4-R11 */
   49: 
   50:         // Exception entry stack
   51:         UW     r[4];               /* R0-R3 */
   52:         UW     ip;         /* R12 */
   53:         void   *lr;              /* lr */
   54:         void   *pc;              /* pc */
   55:         UW     xpsr;               /* xpsr */
   56: 
   57:         UW     s[16];              /* S0-S15 */
   58:         UW     fpscr;              /* fpscr */
   59: } SStackFrame_wFPU;
   60: 
   61: #define EXPRN_NO_FPU            0x00000010        /* FPU usage flag  0:use 1:no use */
   62: 
   63: #endif /* USE_FPU */
   64: 
   65: /*
   66:  * Create stack frame for task startup
   67:  *      Call from 'make_dormant()'
   68:  */
   69: Inline void knl_setup_context( TCB *tcb )
   70: {
   71:         SStackFrame    *ssp;
   72: 
   73:         ssp = tcb->isstack;
   74:         ssp--;
   75: 
   76:         /* CPU context initialization */
   77:         ssp->exp_ret   = 0xFFFFFFF9;
   78:         ssp->lr                = 0;
   79:         ssp->xpsr      = 0x01000000;                /* Initial SR */
   80:         ssp->pc = (void*)((UW)tcb->task & ~0x00000001UL);      /* Task startup address */
   81: 
   82:         tcb->tskctxb.ssp = ssp;                /* System stack pointer */
   83: }
   84: 
   85: /*
   86:  * Set task startup code
   87:  *      Called by 'tk_sta_tsk()' processing.
   88:  */
   89: Inline void knl_setup_stacd( TCB *tcb, INT stacd )
   90: {
   91:         SStackFrame    *ssp;
   92:         
   93:         ssp = tcb->tskctxb.ssp;
   94: 
   95:         ssp->r[0] = stacd;
   96:         ssp->r[1] = (VW)tcb->exinf;
   97: }
   98: 
   99: /*
  100:  * Delete task contexts
  101:  */
  102: Inline void knl_cleanup_context( TCB *tcb )
  103: {
  104: #if USE_FPU             /* Clear CONTROL.FPCA */
  105:         UW     control;
  106: 
  107:         if(tcb == knl_ctxtsk) {
  108:                 /* Clear CONTROL.FPCA */
  109:                 Asm("mrs %0, control":"=r"(control));
  110:                 control &= (1<<2);
  111:                 Asm("msr control, %0"::"r"(control));
  112:         }
  113: #endif
  114: }
  115: 
  116: #endif /* _SYSDEPEND_CPU_CORE_CPUTASK_ */