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

📄 app.c

📁 嵌入式实时操作系统内核
💻 C
字号:
//Example Application File:
//Copyright (c) 2008 www.evvei.com, All Rights Reserved.
//_____________________________________________________________________________________
//File Name: app.c
//Abstract:  This file is the "c" example source code for application of the e-kernel.
//

#include "..\library\kernel.h"

//Define the kernel objects.
KTIMER    Timer;
KLOCK     Lock;
KMUTEX    Mutex;
KMAILBOX  Mailbox;
KPOOL     MemoryPool;
KTHREAD   Thread1,Thread2,Thread3;

//Global data buffer definitions.
UINT32    Data1[20],Data2[20];

//The routine of Thread1.
STATUS  Routine1(UINT32 argc, VOID *argv)
{
    UINT32 i;
    
    
    for(;;)
    {
       KeEnterMutex(&Mutex,NA);
       
       for(i=0;i<20;i++)
          Data1[i] = i;
       
       KeLeaveMutex(&Mutex);
    }
    
}


//The thread2 routine.
STATUS  Routine2(UINT32 argc, VOID *argv)
{
    UINT32 i;
    
    for(;;)
    {
       KeLock(&Lock);
       
       for(i=0;i<20;i++)
          Data2[i] = 20-i;
       
       KeUnlock(&Lock);
       
    }
}

//The thread3 routine.
STATUS  Routine3(UINT32 argc, VOID *argv)
{
    STATUS Status;
    DWORD  m, Msg[4];
    
    UINT32 i;
    
    Msg[0] = 0;
    Msg[1] = 0;
    Msg[2] = 0;
    Msg[3] = 0;
    
    
    while(1)
    {
       Status = KeReceiveMailbox(&Mailbox,Msg,NA);
       
       if(Status = RS_SUCCESSFUL)
          m = Msg[1];
       else
          m = 0;
       
       
       KeEnterMutex(&Mutex,NA);
       
       for(i=0;i<20;i++)
          Data1[i] = 20-i;
       
       KeLeaveMutex(&Mutex);
       
       
       KeLock(&Lock);
       
       for(i=0;i<20;i++)
          Data2[i] = 20-i;
       
       KeUnlock(&Lock);

    }
}

//Used for timer routine.
VOID  Routine4(UINT32 argc, VOID *argv)
{
    DWORD Msg[4];
    
    Msg[0] = 1;
    Msg[1] = 2;
    Msg[2] = 3;
    Msg[3] = 4;
    
    KeSendMailbox(&Mailbox,Msg,0);
}


VOID ApplicationInitialize(VOID *dssAddress, UINT32 dssSize)
{
    VOID *p1,*p2,*p3;
    
    //Initialize the timer
    KeInitializeTimer(&Timer,2,Routine4,0,NULL,OPT_ACTIVING+OPT_REPEAT+OPT_EXISTING);
    
    //Create a memory pool at the start address of dynamic store section.
    KeInitializePool(&MemoryPool,dssAddress,dssSize,1024,OPT_PRIOR_WAITING+OPT_EXISTING);
    
    //Allocate the memory space for thread stack.
    p1 = KeAllocateMemory(&MemoryPool,4096,0);
    p2 = KeAllocateMemory(&MemoryPool,10240,0);
    p3 = KeAllocateMemory(&MemoryPool,40960,0);
    
    //Initialize threads.
    KeInitializeThread(&Thread1,PRI_NORMAL10,Routine1,0,NULL,p1,4096,OPT_READY);
    KeInitializeThread(&Thread2,PRI_NORMAL10,Routine2,0,NULL,p2,10240,OPT_READY);
    KeInitializeThread(&Thread3,PRI_REALTIME3,Routine3,0,NULL,p3,40960,OPT_READY);
    
    //Initialize other kernel objects.
    KeInitializeLock(&Lock);
    KeInitializeMutex(&Mutex,OPT_PRIOR_WAITING+OPT_EXISTING);
    KeInitializeMailbox(&Mailbox,OPT_PRIOR_WAITING+OPT_EXISTING);
    
    
}






⌨️ 快捷键说明

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