📄 demo0.c
字号:
/***************************************************************
* demo1.c *
* *
* task_1和task_2基于时间片轮转调度,两个任务为同优先级的任务 *
* *
* 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"
/* Application Structures */
NU_TASK Task_1;
NU_TASK Task_2;
NU_MEMORY_POOL System_Memory;
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 created!\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, 10, NU_PREEMPT, NU_START);
if (status != NU_SUCCESS)
{
ERC_System_Error(status);
}
else
{
Uart_Printf("task2 have been created\n");
Uart_Printf("-----------------------\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=0;
status = (STATUS) argc + (STATUS) argv;
while(1)
{
i++;
Uart_Printf("task1 is:%d\n",i);
NU_Sleep(6);
}
}
/*********************************************************************/
void task_2(UNSIGNED argc, VOID *argv)
{
STATUS status;
int j=1;
status = (STATUS) argc + (STATUS) argv;
while(1)
{
j++;
Uart_Printf("task2 is:%d\n",j);
NU_Sleep(6);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -