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

📄 demo.c.bak

📁 已移植到TI OMAP1610处理器的Nucleus操作系统源码
💻 BAK
📖 第 1 页 / 共 2 页
字号:
            }
            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, "Task 2 messages received:         ");
            ultoa(Task_2_messages_received, buffer, 10);
            n = strlen(buffer);
            if (n>=8)
            {
                strcat(msg, buffer);
                strcat(msg, "\n\n\r");
            }
            else
            {
                for (i=0;i<(8-n);i++)
                    strcat(msg, " ");
                strcat(msg, buffer);
                strcat(msg, "\n\n\r");
            }

            NU_SD_Put_String(msg, &port);

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

            NU_SD_Put_String(msg, &port);

            if (Who_has_the_resource == &Task_3)
               NU_SD_Put_String("Who has the resource:               Task 3", &port);
            else if (Who_has_the_resource == &Task_4)
               NU_SD_Put_String("Who has the resource:               Task 4", &port);
            else
               NU_SD_Put_String("Who has the resource:               Nobody", &port);
            NU_SD_Put_String("\n\n\n\r", &port);

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

            NU_SD_Put_String(msg, &port);

            NU_SD_Put_String("Buffer:  ", &port);

#if (NU_SERIAL_INPUT)
            while (NU_SD_Data_Ready(&port))
            {
                ch = NU_SD_Get_Char(&port);
                NU_SD_Put_Char(ch, &port);
            }
#endif /* NU_SERIAL_INPUT */


            NU_SD_Put_String("\n\n\r", &port);


#endif /* NU_SERIAL_OUTPUT */
            /* Increment the time.  */
            Task_Time++;

            /* Set an event flag to lift the suspension on task 5.  */
            status =  NU_Set_Events(&Event_Group_0, 1, NU_OR);

        }

}


/* Define the queue sending task.  Note that the only things that cause
   this task to suspend are queue full conditions and the time slice
   specified in the configuration file.  */

void   task_1(UNSIGNED argc, VOID *argv)
{

STATUS         status;
UNSIGNED       Send_Message;

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

    /* Initialize the message counter.  */
    Task_1_messages_sent =  0;

    /* Initialize the message contents.  The receiver will examine the
       message contents for errors.  */
    Send_Message = 0;

    while(1)
    {
    
         /* Send the message to Queue_0, which task 2 reads from.  Note
            that if the destination queue fills up this task suspends until
            room becomes available.  */
         status =  NU_Send_To_Queue(&Queue_0, &Send_Message, 1, NU_SUSPEND);
         
         /* Determine if the message was sent successfully.  */
         if (status == NU_SUCCESS)
             Task_1_messages_sent++;
             
         /* Modify the contents of the next message to send.  */
         Send_Message++;
    }
}


/* Define the queue receiving task.  Note that the only things that cause
   this task to suspend are queue empty conditions and the time slice
   specified in the configuration file.   */

void   task_2(UNSIGNED argc, VOID *argv)
{

STATUS         status; 
UNSIGNED       Receive_Message;
UNSIGNED       received_size;
UNSIGNED       message_expected;

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

    /* Initialize the message counter.  */
    Task_2_messages_received =  0;

    /* Initialize the message error counter.  */
    Task_2_invalid_messages =  0;

    /* Initialize the message contents to expect.  */
    message_expected =  0;
    
    while(1)
    {
    
         /* Retrieve a message from Queue_0, which task 1 writes to.  Note
            that if the source queue is empty this task suspends until
            something becomes available.  */
         status =  NU_Receive_From_Queue(&Queue_0, &Receive_Message, 1, 
                                &received_size, NU_SUSPEND);
         
         /* Determine if the message was received successfully.  */
         if (status == NU_SUCCESS)
             Task_2_messages_received++;
             
         /* Check the contents of the message against what this task
            is expecting.  */
         if ((received_size != 1) ||
             (Receive_Message != message_expected))
             Task_2_invalid_messages++;
         
         /* Modify the expected contents of the next message.  */
         message_expected++;
    }
}


/* Tasks 3 and 4 want a single resource.  Once one of the tasks gets the
   resource, it keeps it for 100 clock ticks before releasing it.  During
   this time the other task suspends waiting for the resource.  Note that
   both task 3 and 4 use the same instruction areas but have different 
   stacks.  */
   
void  task_3_and_4(UNSIGNED argc, VOID *argv)
{

STATUS  status;

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

    /* Loop to allocate and deallocate the resource.  */
    while(1)
    {
    
         /* Allocate the resource.  Suspend until it becomes available.  */
         status =  NU_Obtain_Semaphore(&Semaphore_0, NU_SUSPEND);
         
         /* If the status is successful, show that this task owns the 
            resource.  */
         if (status ==  NU_SUCCESS)
         {
         
             Who_has_the_resource =  NU_Current_Task_Pointer();
             
             /* Sleep for 100 ticks to cause the other task to suspend on 
                the resource.  */
             NU_Sleep(100);
             
             /* Release the semaphore.  */
             NU_Release_Semaphore(&Semaphore_0);
        }
    }
}


/* Define the task that waits for the event to be set by task 0.  */

void  task_5(UNSIGNED argc, VOID *argv)
{

STATUS          status;
UNSIGNED        event_group;

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

    /* Initialize the event detection counter.  */
    Event_Detections =  0;

    /* Continue this process forever.  */
    while(1)
    {
        /* Wait for an event and consume it.  */
        status =  NU_Retrieve_Events(&Event_Group_0, 1, NU_OR_CONSUME,
                                     &event_group, NU_SUSPEND);

        /* If the status is okay, increment the counter.  */
        if (status == NU_SUCCESS)
        {
          Event_Detections++;

        }
    }
}


#ifdef NU_FIQ_DEMO
void FIQ_LISR(VOID)
{
    FIQ_Count++;
}
#endif


⌨️ 快捷键说明

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