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

📄 semaphore.c

📁 嵌入式VxWorks开发所需典型例程源代码
💻 C
字号:
#include "vxWorks.h"
#include "stdio.h"
#include "stdlib.h"
#include "taskLib.h"
#include "semLib.h"



int		tidStart;
int		tidEnd;



void	helloStart();
void	helloEnd();
STATUS    helloStop();
STATUS    tHelloStart();
SEM_ID    semHello; 


STATUS tHelloStart() 
{

    /* Spawn start Task */


    semHello=semBCreate( SEM_Q_PRIORITY,SEM_FULL);
    if(semHello==NULL)
    {
	printf("Something is wrong when create semaphore\n");
	return ERROR;
    }


    tidStart = taskSpawn(NULL, 80, 0, 2000, (FUNCPTR)helloStart,
	      0,0,0,0,0,0,0,0,0,0);
    if(tidStart==NULL)
    {
	printf("Something is wrong when create taskStart\n");
	return ERROR;
    }
    
    /* Spawn end Task */
    tidEnd = taskSpawn(NULL, 80, 0, 2000, (FUNCPTR)helloEnd,
	      0,0,0,0,0,0,0,0,0,0);
    if(tidEnd==NULL)
    {
	printf("Something is wrong when create taskEnd\n");
	return ERROR;
    }

    
    return (OK);
}


void helloStart()
{
   for(;;)
   {
      semTake(semHello, WAIT_FOREVER);
      printf("Hello, I am Echo\n");
      semGive(semHello);
      taskDelay (sysClkRateGet ( ) / 2);
   }
}

void helloEnd()
{
   for(;;)
   {
      semTake(semHello, WAIT_FOREVER);
      printf("Hello, I am not Echo\n");
      semGive(semHello);
      taskDelay (sysClkRateGet ( ) / 2);
   }
  
}

STATUS helloStop() 
{

    /* delete tasks */
    taskDelete(tidStart);

    taskDelete (tidEnd);
    
return(OK);
}

⌨️ 快捷键说明

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