⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 task3.c

📁 三个semephor实现的进程之间通讯
💻 C
字号:
/*
  Copyright(c) Micro-Star International Co. Ltd.
  The copyright to the computer program(s) herein is the property of
  Micro-Star International Co. Ltd.
  The program(s) may be used and/or copied only with the written
  permission of MSI or in accordance with the terms and conditions
  stipulated in the agreement/contract under which the program(s) have
  been supplied.
*/
/*
 * MODULE FILE NAME: TASK3.C
 *
 * DESCRIPTION:
 *
 *
 * NOTES:
 *
 *
 * HISTORY:
 *
 * $Log$
 
/* INCLUDE FILES */

/* system-wise, independent */
#include "syslib.h"
#include "sys_hdr/sys_type.h"
#include "sys_hdr/uitron.h"
#include "sys_bld.h"

/* kernel service */

/* project dependent */

/* third party */

/* other components */

/* this component */
#include "core/task3/hdr/task3.h" 

/* CONSTANT AND MACRO DECLARATIONS */
#define TASK3_TIME_SLIP 500


/*
 * FUNCTION NAME: TASK3_Init
 * PURPOSE:
 *      Initialize for TASK3 operations.
 *
 * INPUT:
 *      None
 * OUTPUT:
 *       None
 * RETURN:
 *       BOOL
 * NOTES:
 *      
 */ 

BOOL TASK3_Init(void)
{
	/* LOCAL VARIABLES DECLARATIONS */
	T_CSEM t_csem;      /* semaphore */
	ER ercd;
	/* Init semaphore */
	t_csem.sematr = TA_TFIFO;
	t_csem.isemcnt = 0;
	t_csem.exinf = SYS_BLD_TASK3_SEM_NAME; /* store task name */
	t_csem.maxsem = 1;

	/* create semaphore sema id SYS_BLD_SMTPC_SEM_ID */
	ercd=cre_sem( SYS_BLD_TASK3_SEM_ID , &t_csem);

	if (ercd!= E_OK)     
    {                                                       
    	printf("TASK3 wait semaphore error %d\n", ercd);   
        return FALSE;                                       
    }
	return TRUE;  
}

/*
 * FUNCTION NAME: TASK3_TskMain
 * PURPOSE:
 *      this is task3 information.
 *
 * INPUT:
 *      None
 * OUTPUT:
 *       None
 * RETURN:
 *       None
 * NOTES:
 *      
 */ 
void TASK3_TskMain(void)
{	
	while(TRUE)
	{
		wai_sem(SYS_BLD_TASK3_SEM_ID);
      	printf("\n I'm task C! \n");
        tslp_tsk(TASK3_TIME_SLIP);
		sig_sem(SYS_BLD_TASK1_SEM_ID);
	}
}

/*
 * FUNCTION NAME: TASK3_CreateTask
 * PURPOSE:
 *      Create the task of TASK3 Alerter.
 *
 * INPUT:
 *      None
 * OUTPUT:
 *       None
 * RETURN:
 *      BOOL -- return TRUE/FALSE 
 * NOTES:
 *      
 */ 
BOOL TASK3_CreateTask(void)
{		
	/* LOCAL VARIABLES DECLARATIONS */
	T_CTSK t_ctsk;          /* task */ 
	ER ercd3;
    
    /* FUNCTION BODY */

    memset(&t_ctsk, 0 , sizeof(t_ctsk));	

    t_ctsk.task    = (FP)&TASK3_TskMain;
    t_ctsk.itskpri = SYS_BLD_TASK3_TASK_PRIORITY;
    t_ctsk.stksz   = SYS_BLD_GENERIC_STACK_SIZE;
    t_ctsk.tskatr  = TA_HLNG;
    t_ctsk.exinf   = SYS_BLD_TASK3_TASK_NAME; /* assign task name */
    
    ercd3 = cre_tsk( SYS_BLD_TASK3_TASK_ID, &t_ctsk); 
    
    if(ercd3 != E_OK )
    {
       	printf(" Create Task3 Error ! ercd3 = %d\n",ercd3);
       	return FALSE;
    }

	ercd3 = sta_tsk (SYS_BLD_TASK3_TASK_ID,0);

	if(ercd3!= E_OK)
	{
		printf(" Start Task3 Error ! ercd = %d\n",ercd3);
		return FALSE;
	} 
	return TRUE;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -