demo.c

来自「基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7」· C语言 代码 · 共 702 行 · 第 1/2 页

C
702
字号
/****************************************************************************/
/*                                                                          */
/*      Copyright (c) 2000 by Accelerated Technology, Inc.                  */
/*                                                                          */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the subject */
/* matter of this material.  All manufacturing, reproduction, use and sales */
/* rights pertaining to this subject matter are governed by the license     */
/* agreement.  The recipient of this software implicity accepts the terms   */
/* of the license.                                                          */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/* FILE NAME                                        VERSION                 */
/*                                                                          */
/*      demo.c                                PLUS/KS32C41000 1.11.1        */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*                                                                          */
/* FUNCTIONS                                                                */
/*                                                                          */
/*      Nucleus demo program                                                */
/*                                                                          */
/*        task_0                                                            */
/*        task_1                                                            */
/*        task_2                                                            */
/*        task_3_and_4                                                      */
/*        task_5                                                            */
/*                                                                          */
/* DEPENDENCIES                                                             */
/*                                                                          */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*         NAME         DATE                    REMARKS                     */
/*                                                                          */
/*    Bobby Iden    04-18-2000     Created initial version 1.11.1 for the   */
/*                                 the Samsung KS32C41000.                  */ 
/****************************************************************************/

/* 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_FALSE
** #define NU_SERIAL_INPUT   NU_FALSE
*/
#define NU_SERIAL_OUTPUT  NU_TRUE
#define NU_SERIAL_INPUT   NU_TRUE


#if (NU_SERIAL_OUTPUT)

#include "44b.h"

#include "sd_extr.h"   /* Nucleus Serial Driver interface */
/* For strcpy, strcat & strlen functions */
#include <string.h>

#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_TASK         Task_Steve;
NU_QUEUE        Queue_0;
NU_SEMAPHORE    Semaphore_0;
NU_EVENT_GROUP  Event_Group_0;
NU_MEMORY_POOL  System_Memory;

/*Specifies the number of bytes in the memory pool */
#define MEMORY_POOL_SIZE   8192    

/* SPECIFY TASK STACK SIZE */
#define TASK_STACK_SIZE    1024

/* 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

extern UNSIGNED TMD_System_Clock;
extern VOID  ERC_System_Error(INT error_code);

/* Define prototypes for function references.  */
char    *DEMO_Ultoa(unsigned long, char *, int);

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[10]; /* temp buffer for Itoa conversion */
int     n;          /* for 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, MEMORY_POOL_SIZE, 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, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, pointer, 
                             TASK_STACK_SIZE, 1, 20, NU_PREEMPT, NU_START);

    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 1.  */
    NU_Allocate_Memory(&System_Memory, &pointer, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, pointer, 
                             TASK_STACK_SIZE, 10, 5, NU_PREEMPT, NU_START);

    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 2.  */
    NU_Allocate_Memory(&System_Memory, &pointer, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NU_NULL, pointer, 
                             TASK_STACK_SIZE, 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, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_3, "TASK 3", task_3_and_4, 0, NU_NULL, pointer,
                             TASK_STACK_SIZE, 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, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_4, "TASK 4", task_3_and_4, 0, NU_NULL, pointer,
                             TASK_STACK_SIZE, 5, 0, NU_PREEMPT, NU_START);

    if (status != NU_SUCCESS)
    {
        ERC_System_Error(status);
    }

    /* Create task 5.  */
    NU_Allocate_Memory(&System_Memory, &pointer, TASK_STACK_SIZE, NU_NO_SUSPEND);
    status = NU_Create_Task(&Task_5, "TASK 5", task_5, 0, NU_NULL, pointer,
                             TASK_STACK_SIZE, 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    ch, msg[40];
int     i;

VOID (*old_lisr)(INT);

#endif

/************************ Board Specific Code *************************
** Define a pointer to the board's User LEDs in Port_E_DATA regester.
** Low nibble (3--0) @ 0x1d20024:
**                                Bit Set to 1 = LED Off
**                                Bit Set to 0 = LED On
**********************************************************************/
volatile unsigned int * LEDS; 
static int      toggle = 0; 
/********************* End Board Specific Code ***********************/

#if (NU_SERIAL_OUTPUT)
    
    //PORT E GROUP
    //ENDIAN GPE7 GPE6 GPE5 GPE4 TOUT0 RXD0 TXD0 GPE0 
    //    00   01   01   01   01    10   10   10   01
    rPCONE=0x55a9;	
    rPUPE=0x6;	
    
    /* Init the serial port. */
    port.com_port   = UART1;
    /* NOTE: Numeric baudrate value will be converted for the KS32C41000
    **       Baudrate Divisor register using the MCLK frequency (40MHz)! */
    port.baud_rate  = 115200;  
    port.data_bits  = DATA_BITS_8;
    port.stop_bits  = STOP_BITS_1;
    port.parity     = PARITY_NONE;
    port.data_mode  = MODE_NORMAL;
    port.communication_mode = SERIAL_MODE;
	port.sd_buffer_size   =   100;
	NU_Register_LISR(0x03, (VOID (*)(INT))SDC_LISR, &old_lisr);
	NU_Register_LISR(0x7, (VOID (*)(INT))SDC_LISR, &old_lisr); 
    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)
        {
          /********************* Board Specific Code ***********************/

           /* PORT-E Data register's low nibble controls the 4 User LEDs */
            LEDS = (volatile unsigned int *) 0x1d20024;
            toggle = *LEDS;
            toggle = toggle ^ 0x0000000F;
            *LEDS = toggle;  
          /****************** End Board Specific Code ********************/
        
            /* Sleep for 100 timer ticks.  The value of the tick is programmable
               in INT_SAMS.S and is relative to the speed of the target system.  */
            NU_Sleep(200);

#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);
            
            /* sprintf(msg, "Task 0 time:                      %8d\n\r",
                    Task_Time); */
            strcpy(msg, "Task 0 time:                      ");
            DEMO_Ultoa(Task_Time, buffer, 10);
            n = strlen(buffer);

            if (n >= 8)
            {
                strcat(msg, buffer); /* Add converted number to message */
                strcat(msg, "\n\r"); /* Add CR/LF to message */
            }
            else
            {
                strcpy(msg, "Task 0 time:                      "); /* Rewrite without spaces */

                for (i=0; i < (8-n); i++)
                    strcat(msg, " ");       /* Add spaces   */
                strcat(msg, buffer);        /* Add Number   */
                strcat(msg, "\n\r");        /* CR/LF        */  
            }
          
            NU_SD_Put_String(msg, &port);
            
            /* sprintf(msg, "Event detections:                 %8d\n\n\n\r",
                    Event_Detections); */
            strcpy(msg, "Event Detections:                ");
            DEMO_Ultoa(Event_Detections, buffer, 10);
            n = strlen(buffer);

            if (n >= 8)
            {
                strcat(msg, buffer); /* Add converted number to message */
                strcat(msg, "\n\r"); /* Add CR/LF to message */
                strcat(msg, "\n\r"); /* Add CR/LF to message */
            }
            else
            {
                strcpy(msg, "Event Detections:                 "); /* Rewrite without spaces */

                for (i=0; i < (8-n); i++)
                    strcat(msg, " ");       /* Add spaces   */

⌨️ 快捷键说明

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