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

📄 demo.c.bak

📁 NucleusPLUS嵌入式操作系统是目前最受欢迎的操作系统NucleusPLUS是为实时嵌入式应用而设计的一个抢先式多任务操作系统内核
💻 BAK
📖 第 1 页 / 共 2 页
字号:
/* Include Nucleus C-Library file */
//#include "ncl\inc\nu_ncl.h"

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

/* Define serial output/input functionality. To disable serial I/O,
   replace NU_TRUE with NU_FALSE */

#define NU_SERIAL_OUTPUT  NU_TRUE
#define NU_SERIAL_INPUT   NU_TRUE

#if (NU_SERIAL_OUTPUT)
#include "nu_sd.h"            /* Nucleus Serial Driver interface */
#endif

/* Define Application data structures.  */

NU_TASK         Task_0;
NU_TASK         Task_1;
NU_TASK         Task_2;
NU_TASK         Task_3;
NU_TASK         Task_4;
NU_TASK         Task_5;
NU_QUEUE        Queue_0;
NU_SEMAPHORE    Semaphore_0;
NU_EVENT_GROUP  Event_Group_0;
NU_MEMORY_POOL  System_Memory;


/* Allocate global counters. */
UNSIGNED  Task_Time;
UNSIGNED  Task_2_messages_received;
UNSIGNED  Task_2_invalid_messages;
UNSIGNED  Task_1_messages_sent;
NU_TASK  *Who_has_the_resource;
UNSIGNED  Event_Detections;

#if (NU_SERIAL_OUTPUT)
NU_SERIAL_PORT  port;
#endif

#ifdef NU_FIQ_DEMO
UINT32 FIQ_Count;
#endif

extern  UNSIGNED TMD_System_Clock;

/* Define prototypes for function references.  */
VOID    task_0(UNSIGNED argc, VOID *argv);
VOID    task_1(UNSIGNED argc, VOID *argv);
VOID    task_2(UNSIGNED argc, VOID *argv);
VOID    task_3_and_4(UNSIGNED argc, VOID *argv);
VOID    task_5(UNSIGNED argc, VOID *argv);
CHAR    buffer[12]; /* temp buffer for Itoa conversion */
INT     n; /* strlen */



/* Define the Application_Initialize routine that determines the initial
   Nucleus PLUS application environment.  */

void    Application_Initialize(void *first_available_memory)
{

VOID           *pointer;
STATUS         status;

    /* 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);
    }

    /* Create each task in the system.  */

    /* Create task 0.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, pointer, 2000, 1, 20,
                                                      NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 1.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, pointer, 2000, 10, 5,
                                                      NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 2.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NU_NULL, pointer, 2000, 10, 5,
                                                      NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 3.  Note that task 4 uses the same instruction area.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_3, "TASK 3", task_3_and_4, 0, NU_NULL, pointer,
                                        2000, 5, 0, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 4.  Note that task 3 uses the same instruction area.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_4, "TASK 4", task_3_and_4, 0, NU_NULL, pointer,
                                        2000, 5, 0, NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 5.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 2000, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_5, "TASK 5", task_5, 0, NU_NULL, pointer, 2000, 7, 0,
                                                      NU_PREEMPT, NU_START);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }


    /* Create communication queue.  */
    NU_Allocate_Memory(&System_Memory, &pointer, 100*sizeof(UNSIGNED),
                                                        NU_NO_SUSPEND);
    status = NU_Create_Queue(&Queue_0, "QUEUE 0", pointer, 100, NU_FIXED_SIZE, 1,
                                                                      NU_FIFO);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create synchronization semaphore.  */
    status = NU_Create_Semaphore(&Semaphore_0, "SEM 0", 1, NU_FIFO);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create event flag group.  */
    status = NU_Create_Event_Group(&Event_Group_0, "EVGROUP0");
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }


}

/* 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_0(UNSIGNED argc, VOID *argv)
{

STATUS          status;


#if (NU_SERIAL_OUTPUT)
CHAR            msg[40];
INT             i;

CHAR            ch;
#endif /* NU_SERIAL_OUTPUT */


#if (NU_SERIAL_OUTPUT)
    /* Init the serial port. */
    port.com_port   = DEFAULT_UART_PORT;
    port.baud_rate  = DEFAULT_UART_BAUD;
    port.data_bits  = DEFAULT_UART_DATA;
    port.stop_bits  = DEFAULT_UART_STOP;
    port.parity     = DEFAULT_UART_PARITY;
    port.data_mode  = DEFAULT_UART_MODE;
    port.communication_mode = SERIAL_MODE;
    port.sd_buffer_size   =   DEFAULT_UART_BUFFER;

    status = NU_SD_Init_Port (&port);
    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

#endif /* NU_SERIAL_OUTPUT */


    /* Access argc and argv just to avoid compilation warnings.  */
    status =  (STATUS) argc + (STATUS) argv;

    /* Set the clock to 0.  This clock ticks every 18 system timer ticks. */
    Task_Time =  0;

        while(1)
        {

            /* Sleep for 100 timer ticks.  The value of the tick is programmable
               in INT.S and is relative to the speed of the target system.  */
            NU_Sleep(100);

#if (NU_SERIAL_OUTPUT)
            NU_SD_Put_String("\n\r****************************************", &port);
            NU_SD_Put_String("***************************************\n\r", &port);
            NU_SD_Put_String(NU_Release_Information(), &port);
            NU_SD_Put_String("\n\r", &port);

            NU_SD_Put_String("****************************************", &port);
            NU_SD_Put_String("***************************************\n\n\r", &port);
            NU_SD_Put_String("System Variable Status: \n\n\r", &port);

            strcpy(msg, "Task 0 time:                      ");
            ultoa(Task_Time, buffer, 10);
            n = strlen(buffer);
            if (n>=8)
            {
                strcat(msg, buffer);
                strcat(msg, "\n\r");
            }
            else
            {
                for (i=0;i<(8-n);i++)
                    strcat(msg, " ");
                strcat(msg, buffer);
                strcat(msg, "\n\r");
            }

            NU_SD_Put_String(msg, &port);

            strcpy(msg, "Event detections:                 ");
            ultoa(Event_Detections, buffer, 10);
            n = strlen(buffer);
            if (n>=8)
            {
                strcat(msg, buffer);
                strcat(msg, "\n\n\n\r");
            }
            else
            {
                for (i=0;i<(8-n);i++)
                    strcat(msg, " ");
                strcat(msg, buffer);
                strcat(msg, "\n\n\n\r");
            }

            NU_SD_Put_String(msg, &port);

            strcpy(msg, "Task 1 messages sent:             ");
            ultoa(Task_1_messages_sent, buffer, 10);
            n = strlen(buffer);
            if (n>=8)
            {
                strcat(msg, buffer);
                strcat(msg, "\n\r");

⌨️ 快捷键说明

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