ER irot_rdq(PRI tskpri) { QUEUE *p_queue; ER ercd; LOG_IROT_RDQ_ENTER(tskpri); CHECK_INTCTX_UNL(); CHECK_TPRI(tskpri); i_lock_cpu(); p_queue = &(ready_queue[INT_PRIORITY(tskpri)]); if (queue_empty(p_queue)) { ercd = E_OK; } else if ((((TCB *)(p_queue->p_next))->p_tinib->tskatr & TA_RSTR) != 0U) { ercd = E_NOSPT; } else { if (rotate_ready_queue(p_queue)) { reqflg = true; } ercd = E_OK; } i_unlock_cpu(); error_exit: LOG_IROT_RDQ_LEAVE(ercd); return(ercd); }
ER imrot_rdq(PRI tskpri, ID prcid) { ER ercd; PCB *p_pcb; PCB *my_p_pcb; LOG_IMROT_RDQ_ENTER(tskpri, prcid); CHECK_INTCTX_UNL(); CHECK_TPRI(tskpri); CHECK_PRCID(prcid); i_lock_cpu(); p_pcb = i_acquire_tsk_lock_prcid(prcid); if (rotate_ready_queue(INT_PRIORITY(tskpri), p_pcb)) { my_p_pcb = get_my_p_pcb(); my_p_pcb->reqflg = dispatch_request(p_pcb) ? true : my_p_pcb->reqflg; } ercd = E_OK; release_tsk_lock(p_pcb); i_unlock_cpu(); error_exit: LOG_IMROT_RDQ_LEAVE(ercd); return(ercd); }
ER rot_rdq(PRI tskpri) { uint_t pri; QUEUE *p_queue; ER ercd; LOG_ROT_RDQ_ENTER(tskpri); CHECK_TSKCTX_UNL(); CHECK_TPRI_SELF(tskpri); t_lock_cpu(); pri = (tskpri == TPRI_SELF) ? p_runtsk->priority : INT_PRIORITY(tskpri); p_queue = &(ready_queue[pri]); if (queue_empty(p_queue)) { ercd = E_OK; } else if ((((TCB *)(p_queue->p_next))->p_tinib->tskatr & TA_RSTR) != 0U) { ercd = E_NOSPT; } else { if (rotate_ready_queue(p_queue)) { dispatch(); } ercd = E_OK; } t_unlock_cpu(); error_exit: LOG_ROT_RDQ_LEAVE(ercd); return(ercd); }
ER rot_rdq(PRI tskpri) { uint_t pri; ER ercd; bool_t dspreq = false; PCB *my_p_pcb; LOG_ROT_RDQ_ENTER(tskpri); CHECK_TSKCTX_UNL(); CHECK_TPRI_SELF(tskpri); t_lock_cpu(); my_p_pcb = t_acquire_tsk_lock_self_without_runnable_check(); pri = (tskpri == TPRI_SELF) ? my_p_pcb->p_runtsk->priority : INT_PRIORITY(tskpri); dspreq = rotate_ready_queue(pri, my_p_pcb); ercd = E_OK; release_tsk_lock(my_p_pcb); if (dspreq) { dispatch(); } t_unlock_cpu(); error_exit: LOG_ROT_RDQ_LEAVE(ercd); return(ercd); }
ER mrot_rdq(PRI tskpri, ID prcid) { uint_t pri; ER ercd; bool_t dspreq = false; PCB *p_pcb; LOG_MROT_RDQ_ENTER(tskpri, prcid); CHECK_TSKCTX_UNL(); CHECK_TPRI_SELF(tskpri); CHECK_PRCID(prcid); t_lock_cpu(); p_pcb = t_acquire_tsk_lock_prcid(prcid); pri = (tskpri == TPRI_SELF) ? (get_my_p_pcb())->p_runtsk->priority : INT_PRIORITY(tskpri); if (rotate_ready_queue(pri, p_pcb)) { dspreq = dispatch_request(p_pcb); } ercd = E_OK; release_tsk_lock(p_pcb); if (dspreq) { dispatch(); } t_unlock_cpu(); error_exit: LOG_MROT_RDQ_LEAVE(ercd); return(ercd); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); p_tcb = get_tcb_self(tskid); newpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); t_lock_cpu(); if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { if (change_priority(p_tcb, newpri)) { dispatch(); } ercd = E_OK; } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newbpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); p_tcb = get_tcb_self(tskid); t_lock_cpu(); if (p_tcb->p_tinib->tskatr == TA_NOEXS) { ercd = E_NOEXS; } else if (VIOLATE_ACPTN(p_tcb->p_tinib->acvct.acptn2)) { ercd = E_OACV; } else if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { newbpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); if (!(newbpri >= p_runtsk->p_tinib->p_dominib->minpriority)) { ercd = E_ILUSE; } else if ((!queue_empty(&(p_tcb->mutex_queue)) || TSTAT_WAIT_MTX(p_tcb->tstat)) && !((*mtxhook_check_ceilpri)(p_tcb, newbpri))) { ercd = E_ILUSE; } else { p_tcb->bpriority = newbpri; if (queue_empty(&(p_tcb->mutex_queue)) || !((*mtxhook_scan_ceilmtx)(p_tcb))) { if (change_priority(p_tcb, newbpri, false)) { dispatch(); } } ercd = E_OK; } } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newbpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); /*[NGKI1184][NGKI1185]*/ if (tskid == TSK_SELF) { p_tcb = p_runtsk; /*[NGKI1198]*/ } else { CHECK_ID(VALID_TSKID(tskid)); /*[NGKI1187]*/ p_tcb = get_tcb(tskid); } if (tskpri == TPRI_INI) { newbpri = p_tcb->p_tinib->ipriority; /*[NGKI1199]*/ } else { CHECK_PAR(VALID_TPRI(tskpri)); /*[NGKI1188]*/ newbpri = INT_PRIORITY(tskpri); } lock_cpu(); if (p_tcb->p_tinib->tskatr == TA_NOEXS) { ercd = E_NOEXS; /*[NGKI1189]*/ } else if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; /*[NGKI1191]*/ } else if ((p_tcb->p_lastmtx != NULL || TSTAT_WAIT_MTX(p_tcb->tstat)) && !((*mtxhook_check_ceilpri)(p_tcb, newbpri))) { ercd = E_ILUSE; /*[NGKI1201]*/ } else { p_tcb->bpriority = newbpri; /*[NGKI1192]*/ if (p_tcb->p_lastmtx == NULL || !((*mtxhook_scan_ceilmtx)(p_tcb))) { change_priority(p_tcb, newbpri, false); /*[NGKI1193]*/ if (p_runtsk != p_schedtsk) { dispatch(); } /*[NGKI1197]*/ } ercd = E_OK; } unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER irot_rdq(PRI tskpri) { ER ercd; LOG_IROT_RDQ_ENTER(tskpri); CHECK_INTCTX_UNL(); CHECK_TPRI(tskpri); i_lock_cpu(); if (rotate_ready_queue(INT_PRIORITY(tskpri))) { reqflg = true; } ercd = E_OK; i_unlock_cpu(); error_exit: LOG_IROT_RDQ_LEAVE(ercd); return(ercd); }
SYSCALL ER chg_pri(ID tskid, PRI tskpri) { TCB *tcb; UINT newpri; UINT tstat; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); tcb = get_tcb_self(tskid); newpri = (tskpri == TPRI_INI) ? tcb->tinib->ipriority : INT_PRIORITY(tskpri); t_lock_cpu(); if (TSTAT_DORMANT(tstat = tcb->tstat)) { ercd = E_OBJ; } else if (TSTAT_RUNNABLE(tstat)) { if (change_priority(tcb, newpri)) { dispatch(); } ercd = E_OK; } else { tcb->priority = newpri; if ((tstat & TS_WAIT_WOBJCB) != 0) { wobj_change_priority(((WINFO_WOBJ *)(tcb->winfo)) ->wobjcb, tcb); } ercd = E_OK; } t_unlock_cpu(); exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER rot_rdq(PRI tskpri) { uint_t pri; ER ercd; LOG_ROT_RDQ_ENTER(tskpri); CHECK_TSKCTX_UNL(); CHECK_TPRI_SELF(tskpri); t_lock_cpu(); pri = (tskpri == TPRI_SELF) ? p_runtsk->priority : INT_PRIORITY(tskpri); if (rotate_ready_queue(pri)) { dispatch(); } ercd = E_OK; t_unlock_cpu(); error_exit: LOG_ROT_RDQ_LEAVE(ercd); return(ercd); }
ER irot_rdq(PRI tskpri) { ER ercd; PCB *my_p_pcb; LOG_IROT_RDQ_ENTER(tskpri); CHECK_INTCTX_UNL(); CHECK_TPRI(tskpri); i_lock_cpu(); my_p_pcb = i_acquire_tsk_lock_self(); if (rotate_ready_queue(INT_PRIORITY(tskpri), my_p_pcb)) { my_p_pcb->reqflg = true; } ercd = E_OK; release_tsk_lock(my_p_pcb); i_unlock_cpu(); error_exit: LOG_IROT_RDQ_LEAVE(ercd); return(ercd); }
#ifndef LOG_ISR_LEAVE #define LOG_ISR_LEAVE(intno) #endif /* LOG_ISR_LEAVE */ /* * Task Management Functions */ const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static STK_T _kernel_stack_INIT_TASK[COUNT_STK_T(STACK_SIZE)]; static STK_T _kernel_stack_FUNC1_TASK[COUNT_STK_T(STACK_SIZE)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { { (TA_ACT), (intptr_t)(0), (main), INT_PRIORITY(IDLE_PRIORITY), ROUND_STK_T(STACK_SIZE), (_kernel_stack_INIT_TASK), (TA_NULL), (NULL) }, { (TA_NULL), (intptr_t)(0), (func1_task), INT_PRIORITY(MID_PRIORITY), ROUND_STK_T(STACK_SIZE), (_kernel_stack_FUNC1_TASK), (TA_NULL), (NULL) } }; TCB _kernel_tcb_table[TNUM_TSKID]; const ID _kernel_torder_table[TNUM_TSKID] = { INIT_TASK, FUNC1_TASK }; /* * Semaphore Functions */ const ID _kernel_tmax_semid = (TMIN_SEMID + TNUM_SEMID - 1);
/* Object initializer [task] */ #define TNUM_TSKID 6 const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static __STK_UNIT __stack_TASK_HI[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_TASK_LO[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_MAIN_TASK[__TCOUNT_STK_UNIT(4096)]; static __STK_UNIT __stack_TSK_DEV_POL[__TCOUNT_STK_UNIT(2048)]; static __STK_UNIT __stack_TSK_DEV_AUDIO[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_LOGTASK[__TCOUNT_STK_UNIT(LOGTASK_STACK_SIZE)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { {TA_HLNG, (VP_INT)(0), (FP)(high_task), INT_PRIORITY(2), __TROUND_STK_UNIT(1024), __stack_TASK_HI, TA_NULL, (FP)(NULL)}, {TA_HLNG, (VP_INT)(0), (FP)(low_task), INT_PRIORITY(3), __TROUND_STK_UNIT(1024), __stack_TASK_LO, TA_NULL, (FP)(NULL)}, {TA_HLNG | TA_ACT, (VP_INT)(0), (FP)(main_task), INT_PRIORITY(8), __TROUND_STK_UNIT(4096), __stack_MAIN_TASK, TA_NULL, (FP)(NULL)}, {TA_HLNG | TA_ACT, (VP_INT)(0), (FP)(KzDevPollingTask), INT_PRIORITY(5), __TROUND_STK_UNIT(2048), __stack_TSK_DEV_POL, TA_NULL, (FP)(NULL)}, {TA_HLNG | TA_ACT, (VP_INT)(0), (FP)(KzAudioDspTask), INT_PRIORITY(1), __TROUND_STK_UNIT(1024), __stack_TSK_DEV_AUDIO, TA_NULL, (FP)(NULL)}, {TA_HLNG | TA_ACT, (VP_INT)(( VP_INT ) 2), (FP)(logtask), INT_PRIORITY(LOGTASK_PRIORITY), __TROUND_STK_UNIT(LOGTASK_STACK_SIZE), __stack_LOGTASK, TA_NULL, (FP)(NULL)} }; const ID _kernel_torder_table[TNUM_TSKID] = {1,2,3,4,5,6}; TCB _kernel_tcb_table[TNUM_TSKID]; /* Object initializer [semaphore] */ #define TNUM_SEMID 8
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newpri; ER ercd; bool_t dspreq = false; PCB *p_pcb; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); t_lock_cpu(); p_tcb = get_tcb_self(tskid, get_my_p_pcb()); newpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); p_pcb = t_acquire_tsk_lock(p_tcb); if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { #if TTYPE_KLOCK == G_KLOCK if (change_priority(p_tcb, newpri)) { dspreq = dispatch_request(p_pcb); } #else /* TTYPE_KLOCK != G_KLOCK */ if (!(TSTAT_WAITING(p_tcb->tstat) && TSTAT_WAIT_WOBJ(p_tcb->tstat))) { /* オブジェクト待ち以外の状態の場合 */ if (change_priority(p_tcb, newpri)) { dspreq = dispatch_request(p_pcb); } } else { /* * オブジェクト待ちの場合 * デッドロック回避のため,ロックを取得し直す */ WOBJCB *p_wobjcb = p_tcb->p_wobjcb; p_tcb->pend_chgpri = true; p_tcb->pend_newpri = newpri; release_tsk_lock(p_pcb); /* * あらためて * オブジェクトロック -> タスクロック * の順でロックを取得 */ TEST_G_LABEL("_test_chg_pri"); retry: t_acquire_obj_lock(&GET_OBJLOCK(p_wobjcb)); if ((p_pcb = t_acquire_nested_tsk_lock(p_tcb, &GET_OBJLOCK(p_wobjcb))) == NULL){ goto retry; } /* タスクの状態が変化していないかチェック */ if (!(p_tcb->pend_chgpri)) { /* 既に他の箇所で優先度変更処理がなされた */ release_nested_tsk_lock(p_pcb); release_obj_lock(&GET_OBJLOCK(p_wobjcb)); t_unlock_cpu(); ercd = E_OK; goto error_exit; } p_tcb->priority = p_tcb->pend_newpri; p_tcb->pend_chgpri = false; change_priority(p_tcb, newpri); release_obj_lock(&GET_OBJLOCK(p_wobjcb)); } #endif /* TTYPE_KLOCK != G_KLOCK */ ercd = E_OK; } release_tsk_lock(p_pcb); if (dspreq) { dispatch(); } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
#include "talkthrough.h" #include "ad1836a.h" #include <timer.h> #include <sys_defs.h> /* Object initializer [task] */ #define TNUM_TSKID 1 const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static __STK_UNIT __stack_CODEC_TASK[__TCOUNT_STK_UNIT(512)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { {TA_HLNG | TA_ACT, (VP_INT)(0), (FP)(run_ad1836_task), INT_PRIORITY(3), __TROUND_STK_UNIT(512), __stack_CODEC_TASK, TA_NULL, (FP)(NULL)} }; const ID _kernel_torder_table[TNUM_TSKID] = {1}; TCB _kernel_tcb_table[TNUM_TSKID]; /* Object initializer [semaphore] */ #define TNUM_SEMID 2 const ID _kernel_tmax_semid = (TMIN_SEMID + TNUM_SEMID - 1); const SEMINIB _kernel_seminib_table[TNUM_SEMID] = { {TA_TPRI, 0, 1},
ER_UINT acre_mtx(const T_CMTX *pk_cmtx) { MTXCB *p_mtxcb; MTXINIB *p_mtxinib; ATR mtxatr; PRI ceilpri; ID domid; const DOMINIB *p_dominib; ACPTN acptn; ER ercd; LOG_ACRE_MTX_ENTER(pk_cmtx); CHECK_TSKCTX_UNL(); CHECK_MACV_READ(pk_cmtx, T_CMTX); mtxatr = pk_cmtx->mtxatr; ceilpri = pk_cmtx->ceilpri; if ((mtxatr & MTXPROTO_MASK) == TA_CEILING) { CHECK_VALIDATR(mtxatr, TA_CEILING|TA_DOMMASK); CHECK_PAR(VALID_TPRI(ceilpri)); } else { CHECK_VALIDATR(pk_cmtx->mtxatr, TA_TPRI|TA_DOMMASK); } domid = get_atrdomid(mtxatr); if (domid == TDOM_SELF) { if (rundom == TACP_KERNEL) { domid = TDOM_KERNEL; } else { domid = p_runtsk->p_tinib->domid; } mtxatr = set_atrdomid(mtxatr, domid); } switch (domid) { case TDOM_KERNEL: p_dominib = &dominib_kernel; break; case TDOM_NONE: p_dominib = &dominib_none; break; default: CHECK_RSATR(VALID_DOMID(domid)); p_dominib = get_dominib(domid); break; } CHECK_ACPTN(p_dominib->acvct.acptn1); lock_cpu(); if (tnum_mtx == 0 || queue_empty(&(p_dominib->p_domcb->free_mtxcb))) { ercd = E_NOID; } else { p_mtxcb = (MTXCB *) queue_delete_next(&(p_dominib->p_domcb->free_mtxcb)); p_mtxinib = (MTXINIB *)(p_mtxcb->p_mtxinib); p_mtxinib->mtxatr = mtxatr; p_mtxinib->ceilpri = INT_PRIORITY(ceilpri); acptn = default_acptn(domid); p_mtxinib->acvct.acptn1 = acptn; p_mtxinib->acvct.acptn2 = acptn; p_mtxinib->acvct.acptn3 = p_dominib->acvct.acptn1; p_mtxinib->acvct.acptn4 = acptn; queue_initialize(&(p_mtxcb->wait_queue)); p_mtxcb->p_loctsk = NULL; ercd = MTXID(p_mtxcb); } unlock_cpu(); error_exit: LOG_ACRE_MTX_LEAVE(ercd); return(ercd); }
#define TNUM_TSKID 9 const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static __STK_UNIT __stack_MAIN_TASK[__TCOUNT_STK_UNIT(4096)]; static __STK_UNIT __stack_TCP_TELNET_SRV_TASK[__TCOUNT_STK_UNIT(4096)]; static __STK_UNIT __stack_MONTASK[__TCOUNT_STK_UNIT(2046)]; static __STK_UNIT __stack_NET_TIMER_TASK[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_ETHER_OUTPUT_TASK[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_ETHER_INPUT_TASK[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_TCP_OUTPUT_TASK[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_UDP_OUTPUT_TASK[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_LOGTASK[__TCOUNT_STK_UNIT(LOGTASK_STACK_SIZE)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { {0x00u | 0x02u, (VP_INT)(0), (FP)(main_task), INT_PRIORITY(4), __TROUND_STK_UNIT(4096), __stack_MAIN_TASK, TA_NULL, (FP)(NULL)}, {0, (VP_INT)(TCP_TELNET_SRV_CEPID), (FP)(tcp_telnet_srv_task), INT_PRIORITY(5), __TROUND_STK_UNIT(4096), __stack_TCP_TELNET_SRV_TASK, TA_NULL, (FP)(NULL)}, {0x00u | 0x02u, (VP_INT)(( VP_INT ) 1), (FP)(monitor), INT_PRIORITY(3), __TROUND_STK_UNIT(2046), __stack_MONTASK, TA_NULL, (FP)(NULL)}, {0, (VP_INT)(0), (FP)(net_timer_task), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_NET_TIMER_TASK, TA_NULL, (FP)(NULL)}, {0, (VP_INT)(0), (FP)(_tinet_ether_output_task), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_ETHER_OUTPUT_TASK, TA_NULL, (FP)(NULL)}, {0x00u | 0x02u, (VP_INT)(0), (FP)(_tinet_ether_input_task), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_ETHER_INPUT_TASK, TA_NULL, (FP)(NULL)}, {0, (VP_INT)(0), (FP)(tcp_output_task), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_TCP_OUTPUT_TASK, TA_NULL, (FP)(NULL)}, {0, (VP_INT)(0), (FP)(udp_output_task), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_UDP_OUTPUT_TASK, TA_NULL, (FP)(NULL)}, {0x00u | 0x02u, (VP_INT)(( VP_INT ) 1), (FP)(logtask), INT_PRIORITY(LOGTASK_PRIORITY), __TROUND_STK_UNIT(LOGTASK_STACK_SIZE), __stack_LOGTASK, TA_NULL, (FP)(NULL)} }; const ID _kernel_torder_table[TNUM_TSKID] = {1,2,3,4,5,6,7,8,9}; TCB _kernel_tcb_table[TNUM_TSKID];
&_kernel_prc1_pcb, &_kernel_prc2_pcb }; /* * Task Management Functions */ const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static STK_T _kernel_stack_LOGTASK1[COUNT_STK_T(LOGTASK_STACK_SIZE)] __attribute__((section(".bss._kernel_prc1s_tstack"),nocommon)); static STK_T _kernel_stack_LOGTASK2[COUNT_STK_T(LOGTASK_STACK_SIZE)] __attribute__((section(".bss._kernel_prc2s_tstack"),nocommon)); static STK_T _kernel_stack_TASK2[COUNT_STK_T(STACK_SIZE)] __attribute__((section(".bss._kernel_prc2s_tstack"),nocommon)); const TINIB _kernel_tinib_table[TNUM_TSKID] = { { (TA_ACT), (intptr_t)(LOGTASK_PORTID_PRC1), (logtask_main), INT_PRIORITY(LOGTASK_PRIORITY), ROUND_STK_T(LOGTASK_STACK_SIZE), _kernel_stack_LOGTASK1, (TA_NULL), (NULL), 1, (uint_t)(0x0000000f) }, { (TA_ACT), (intptr_t)(LOGTASK_PORTID_PRC2), (logtask_main), INT_PRIORITY(LOGTASK_PRIORITY), ROUND_STK_T(LOGTASK_STACK_SIZE), _kernel_stack_LOGTASK2, (TA_NULL), (NULL), 2, (uint_t)(0x0000000f) }, { (TA_ACT), (intptr_t)(2), (task), INT_PRIORITY(MID_PRIORITY), ROUND_STK_T(STACK_SIZE), _kernel_stack_TASK2, (TA_NULL), (NULL), 2, (uint_t)(0x0000000f) } }; TCB _kernel_tcb_LOGTASK1 __attribute__((section(".bss._kernel_prc1s_tskcb"),nocommon)); TCB _kernel_tcb_LOGTASK2 __attribute__((section(".bss._kernel_prc2s_tskcb"),nocommon)); TCB _kernel_tcb_TASK2 __attribute__((section(".bss._kernel_prc2s_tskcb"),nocommon)); TCB* const _kernel_p_tcb_table[TNUM_TSKID] ={ &_kernel_tcb_LOGTASK1, &_kernel_tcb_LOGTASK2, &_kernel_tcb_TASK2 };
/* Object initializer [task] */ #define TNUM_TSKID 5 const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static __STK_UNIT __stack_TASK1[__TCOUNT_STK_UNIT(512)]; static __STK_UNIT __stack_TASK2[__TCOUNT_STK_UNIT(512)]; static __STK_UNIT __stack_TASK3[__TCOUNT_STK_UNIT(512)]; static __STK_UNIT __stack_MAIN_TASK[__TCOUNT_STK_UNIT(512)]; static __STK_UNIT __stack_LOGTASK[__TCOUNT_STK_UNIT(LOGTASK_STACK_SIZE)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { {0, (VP_INT)(( VP_INT ) 1), (FP)(task), INT_PRIORITY(10), __TROUND_STK_UNIT(512), __stack_TASK1, 0, (FP)(tex_routine)}, {0, (VP_INT)(( VP_INT ) 2), (FP)(task), INT_PRIORITY(10), __TROUND_STK_UNIT(512), __stack_TASK2, 0, (FP)(tex_routine)}, {0, (VP_INT)(( VP_INT ) 3), (FP)(task), INT_PRIORITY(10), __TROUND_STK_UNIT(512), __stack_TASK3, 0, (FP)(tex_routine)}, {0x00u | 0x02u, (VP_INT)(0), (FP)(main_task), INT_PRIORITY(5), __TROUND_STK_UNIT(512), __stack_MAIN_TASK, TA_NULL, (FP)(NULL)}, {0x00u | 0x02u, (VP_INT)(( VP_INT ) 1), (FP)(logtask), INT_PRIORITY(LOGTASK_PRIORITY), __TROUND_STK_UNIT(LOGTASK_STACK_SIZE), __stack_LOGTASK, TA_NULL, (FP)(NULL)} }; const ID _kernel_torder_table[TNUM_TSKID] = {1,2,3,4,5}; JSP_KERNEL_CFG_DATA TCB _kernel_tcb_table[TNUM_TSKID]; /* Object initializer [semaphore] */ #define TNUM_SEMID 2
ER_UINT acre_tsk(const T_CTSK *pk_ctsk) { ID domid; const DOMINIB *p_dominib; TCB *p_tcb; TINIB *p_tinib; ATR tskatr; SIZE sstksz, ustksz; void *sstk, *ustk; ACPTN acptn; ER ercd; LOG_ACRE_TSK_ENTER(pk_ctsk); CHECK_TSKCTX_UNL(); CHECK_MACV_READ(pk_ctsk, T_CTSK); CHECK_RSATR(pk_ctsk->tskatr, TA_ACT|TARGET_TSKATR|TA_DOMMASK); domid = get_atrdomid(pk_ctsk->tskatr); CHECK_ATRDOMID_ACTIVE(domid); CHECK_ALIGN_FUNC(pk_ctsk->task); CHECK_NONNULL_FUNC(pk_ctsk->task); CHECK_TPRI(pk_ctsk->itskpri); p_dominib = (domid == TDOM_SELF) ? p_runtsk->p_tinib->p_dominib : (domid == TDOM_KERNEL) ? &dominib_kernel : get_dominib(domid); if (p_dominib == &dominib_kernel) { /* * システムタスクの場合 */ ustksz = 0U; ustk = NULL; CHECK_PAR(pk_ctsk->sstk == NULL); CHECK_PAR(pk_ctsk->stksz > 0U); sstksz = pk_ctsk->stksz; sstk = pk_ctsk->stk; if (sstk != NULL) { CHECK_PAR(pk_ctsk->sstksz == 0U); } else { sstksz += pk_ctsk->sstksz; } } else { /* * ユーザタスクの場合 */ ustksz = pk_ctsk->stksz; ustk = pk_ctsk->stk; CHECK_PAR(ustksz >= TARGET_MIN_USTKSZ); CHECK_NOSPT(ustk != NULL); CHECK_TARGET_USTACK(ustksz, ustk, p_dominib); sstksz = pk_ctsk->sstksz; sstk = pk_ctsk->sstk; } CHECK_PAR(sstksz >= TARGET_MIN_SSTKSZ); if (sstk != NULL) { CHECK_ALIGN_STKSZ(sstksz); CHECK_ALIGN_STACK(sstk); } CHECK_ACPTN(sysstat_acvct.acptn3); tskatr = pk_ctsk->tskatr; t_lock_cpu(); if (queue_empty(&free_tcb)) { ercd = E_NOID; } else { if (sstk == NULL) { sstk = kernel_malloc(ROUND_STK_T(sstksz)); tskatr |= TA_MEMALLOC; } if (sstk == NULL) { ercd = E_NOMEM; } else { p_tcb = ((TCB *) queue_delete_next(&free_tcb)); p_tinib = (TINIB *)(p_tcb->p_tinib); p_tinib->p_dominib = p_dominib; p_tinib->tskatr = tskatr; p_tinib->exinf = pk_ctsk->exinf; p_tinib->task = pk_ctsk->task; p_tinib->ipriority = INT_PRIORITY(pk_ctsk->itskpri); #ifdef USE_TSKINICTXB init_tskinictxb(&(p_tinib->tskinictxb), p_dominib, sstksz, sstk, utsksz, ustk, pk_ctsk); #else /* USE_TSKINICTXB */ p_tinib->sstksz = sstksz; p_tinib->sstk = sstk; p_tinib->ustksz = ustksz; p_tinib->ustk = ustk; #endif /* USE_TSKINICTXB */ p_tinib->texatr = TA_NULL; p_tinib->texrtn = NULL; acptn = default_acptn(domid); p_tinib->acvct.acptn1 = acptn; p_tinib->acvct.acptn2 = acptn; p_tinib->acvct.acptn3 = acptn | rundom; p_tinib->acvct.acptn4 = acptn; p_tcb->actque = false; make_dormant(p_tcb); queue_initialize(&(p_tcb->mutex_queue)); if ((p_tcb->p_tinib->tskatr & TA_ACT) != 0U) { make_active(p_tcb); } ercd = TSKID(p_tcb); } } t_unlock_cpu(); error_exit: LOG_ACRE_TSK_LEAVE(ercd); return(ercd); }
ER_UINT acre_tsk(const T_CTSK *pk_ctsk) { TCB *p_tcb; TINIB *p_tinib; ATR tskatr; TASK task; PRI itskpri; size_t stksz; STK_T *stk; ER ercd; LOG_ACRE_TSK_ENTER(pk_ctsk); CHECK_TSKCTX_UNL(); tskatr = pk_ctsk->tskatr; task = pk_ctsk->task; itskpri = pk_ctsk->itskpri; stksz = pk_ctsk->stksz; stk = pk_ctsk->stk; CHECK_RSATR(tskatr, TA_ACT|TA_NOACTQUE|TARGET_TSKATR); CHECK_PAR(FUNC_ALIGN(task)); CHECK_PAR(FUNC_NONNULL(task)); CHECK_PAR(VALID_TPRI(itskpri)); CHECK_PAR(stksz >= TARGET_MIN_STKSZ); if (stk != NULL) { CHECK_PAR(STKSZ_ALIGN(stksz)); CHECK_PAR(STACK_ALIGN(stk)); } lock_cpu(); if (queue_empty(&free_tcb)) { ercd = E_NOID; } else { if (stk == NULL) { stk = kernel_malloc(ROUND_STK_T(stksz)); tskatr |= TA_MEMALLOC; } if (stk == NULL) { ercd = E_NOMEM; } else { p_tcb = ((TCB *) queue_delete_next(&free_tcb)); p_tinib = (TINIB *)(p_tcb->p_tinib); p_tinib->tskatr = tskatr; p_tinib->exinf = pk_ctsk->exinf; p_tinib->task = task; p_tinib->ipriority = INT_PRIORITY(itskpri); #ifdef USE_TSKINICTXB init_tskinictxb(&(p_tinib->tskinictxb), stksz, stk); #else /* USE_TSKINICTXB */ p_tinib->stksz = stksz; p_tinib->stk = stk; #endif /* USE_TSKINICTXB */ p_tcb->actque = false; make_dormant(p_tcb); if ((p_tcb->p_tinib->tskatr & TA_ACT) != 0U) { make_active(p_tcb); } ercd = TSKID(p_tcb); } } unlock_cpu(); error_exit: LOG_ACRE_TSK_LEAVE(ercd); return(ercd); }
/* User specified include files*/ #include "tasks.h" #include "at91sam7s.h" /* Object initializer [task] */ #define TNUM_TSKID 2 const ID _kernel_tmax_tskid = (TMIN_TSKID + TNUM_TSKID - 1); static __STK_UNIT __stack_TSK_MAIN[__TCOUNT_STK_UNIT(1024)]; static __STK_UNIT __stack_TSK_EVENT[__TCOUNT_STK_UNIT(512)]; const TINIB _kernel_tinib_table[TNUM_TSKID] = { {TA_HLNG | TA_ACT, (VP_INT)(TSK_MAIN), (FP)(tsk_main), INT_PRIORITY(5), __TROUND_STK_UNIT(1024), __stack_TSK_MAIN, TA_NULL, (FP)(NULL)}, {TA_HLNG | TA_ACT, (VP_INT)(TSK_EVENT), (FP)(tsk_event), INT_PRIORITY(3), __TROUND_STK_UNIT(512), __stack_TSK_EVENT, TA_NULL, (FP)(NULL)} }; const ID _kernel_torder_table[TNUM_TSKID] = {1,2}; TCB _kernel_tcb_table[TNUM_TSKID]; /* Object initializer [semaphore] */ #define TNUM_SEMID 1 const ID _kernel_tmax_semid = (TMIN_SEMID + TNUM_SEMID - 1); const SEMINIB _kernel_seminib_table[TNUM_SEMID] = {