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

📄 demo1.c

📁 S3C2410学习的基础资料 大部分实验源码及工程
💻 C
字号:
/***********************************************************************
 * demo1.c                                                             *
 *                                                                     *
 * task_1发送一个4字节的消息到邮箱,Task2从邮箱中接收消息           *
 *                                                                     *
 * designed by bobey                                                   *
 ***********************************************************************/


/* Include necessary files.  */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include"2410addr.h"
#include"2410lib.h"

/* Include necessary Nucleus PLUS files.  */
#include  "nucleus.h"



extern void ENABLE_INTERRUPT(void);

/* Application Structures */
NU_TASK         Task_1;
NU_TASK         Task_2;
NU_MEMORY_POOL  System_Memory;

NU_MAILBOX		Mailbox;

extern  int ERC_System_Error(int);
/* Function Prototypes */
VOID    task_1(UNSIGNED argc, VOID *argv);
VOID    task_2(UNSIGNED argc, VOID *argv);

/* Define the Application_Initialize routine that determines the initial
   Nucleus PLUS application environment.  */
void    Application_Initialize(void *first_available_memory)
{

VOID           *pointer;
STATUS         status;

/*--------------------------uart initialize---------------------------------*/
     ChangeClockDivider(1,1);
     ChangeMPllValue(0xa1,0x3,0x1);   
     Port_Init();
     Uart_Select(0);
     Uart_Init(0,115200);
     Uart_Printf("Nucleus is running!\n");
     EnableTimer0();
/*----------------------------end-------------------------------------------*/

    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
    status = NU_Create_Memory_Pool(&System_Memory, "SYSMEM",
                        first_available_memory, 25000, 50, NU_FIFO);
    if (status != NU_SUCCESS)
    {
    
        ERC_System_Error(status);
    }
    else
    {
        Uart_Printf("System_Memory have been cteated!\n");
    }

    /* Create each task in the system.  */

    /* Create task1.*/
    NU_Allocate_Memory(&System_Memory, &pointer, 512, NU_NO_SUSPEND);
    status=NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NULL, pointer,
                                      512, 3, 10, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
    	
    	ERC_System_Error(status);
    }
    else
    {
        Uart_Printf("Task1 have been created\n");
    
    }
    /* Create task2.*/
    NU_Allocate_Memory(&System_Memory, &pointer, 512, NU_NO_SUSPEND);
    status=NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NULL, pointer,
                                      512, 3, 20, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
    	    	
    	ERC_System_Error(status);
    }
    else
    {
        Uart_Printf("task2 have been created\n");
    }
    
   
    /* Create a Mailbox */
    NU_Allocate_Memory(&System_Memory, &pointer, 4*sizeof(UNSIGNED),NU_NO_SUSPEND);
    status=NU_Create_Mailbox(&Mailbox,"MAILBOX",NU_FIFO);
    if (status != NU_SUCCESS)
    {
    	    	
    	ERC_System_Error(status);
    }
    else
    {
        Uart_Printf("Mailbox have been created\n");
    }
    
}

/* Define the system timer task.  More complicated systems might use a
   routine like this to perform periodic message sending and other time
   oriented functions.  */
   
void task_1(UNSIGNED argc, VOID *argv)
{
	STATUS  status;
    int     i=1;
   	UNSIGNED	Smessage[4]={11110000,11112222,33334444,55556666,};
	
	status =  (STATUS) argc + (STATUS) argv;
    
	while(1)
	{
 	    i++;
 	    Uart_Printf("Task1 is %d\n",i);
 	    NU_Sleep(3);
 	    if(i==10)
 	    {
 	     status=NU_Send_To_Mailbox(&Mailbox,&Smessage[0],25);
		 if(status==NU_SUCCESS)
		  Uart_Printf("SMail\n");
		
		 else
		  Uart_Printf("send mailbox error!\n");
		}
		
	}
	
    
}	
//==============================================================	
void task_2(UNSIGNED argc, VOID *argv)
{
	STATUS  status;
	int     i=1,j;
	UNSIGNED Dmessage[4];
    status =  (STATUS) argc + (STATUS) argv;

	while(1)
	{
        i++;
        Uart_Printf("Task2 is %d\n",i);
        NU_Sleep(8);
        if(i==20)
        {
		 NU_Suspend_Task(&Task_1); 
		 status=NU_Receive_From_Mailbox(&Mailbox,&Dmessage[0],20);
		 if(status==NU_SUCCESS)
		 {
		  for(j=0;j<=4;j++)
		  Uart_Printf("DMail is %d\n",Dmessage[j]);
		 } 
		 else
		  Uart_Printf("receive mailbox error!\n");
		}	
	}
}	

⌨️ 快捷键说明

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