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

📄 ramdemo.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 4 页
字号:
    /*  Copy the name to the buffer.  */
    while (*pfr && *pfr!=' ')
        *pto++ = *pfr++;

    /*  Get a temporary pointer to the extension in the directory entry.  */
    pfr = pstat->fext;

    /*  Place the period in the file name.  */
    if (*pfr != ' ')
        *pto++ = '.';

    /*  Copy the extension.  */
    while (*pfr && *pfr!=' ')
        *pto++ = *pfr++;

    /*  Null terminate the string. */
    *pto = '\0';
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "bail_out"                       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine processes a fatal error and suspends the task      */
/*      that called it.                                                 */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      most functions in demo                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Suspend_Task                     Suspends the caller.        */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      error_no                            Number of error being       */
/*                                          reported.                   */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void bail_out(int error_no)
{
    /*  Validate the error number.  */
    if (RAM_Fatal_Errors_Index > 9)
        RAM_Fatal_Errors_Index = 0;

    /*  Record the error.  */
    RAM_Fatal_Errors[RAM_Fatal_Errors_Index] = error_no;

    /*  Suspend the task.  */
    NU_Suspend_Task(NU_Current_Task_Pointer());
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "looping"                        */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine processes any user input.  It will both start and  */
/*      stop tasks as well as process an exit request if supported.     */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      most functions in demo                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NU_Change_Preemption                Changes task to non-preempt */
/*                                          during formatting and back  */
/*      NU_Suspend_Task                     Suspends the caller.        */
/*      [US_Is_Char]                        Port specific routine for   */
/*                                          determining if there are    */
/*                                          characters available.       */
/*                                                                      */
/*      [US_fgetc]                          Port specific routine for   */
/*                                          reading a character.        */
/*                                                                      */
/*      NU_Resume_Task                      Starts other tasks.         */
/*  INPUTS                                                              */
/*                                                                      */
/*      NONE                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
BOOL looping()
{
char c;
int i;
BOOL stay_in;
OPTION      preempt_status;

    /*  Don't let any other tasks interrupt us here.  */
    preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);

    /* If the user requested the task be stopped, from a previous entry
       into this routine, do so here. */
    if (!task_is_running[NUIP_Current_Task_ID()])
    {
        NU_Suspend_Task(NU_Current_Task_Pointer());
    }
    /* Put inside a do loop in case they pause all of there tasks. This lets
       them run again. */
    stay_in = NO;

#if (INPUT_OK)
    /*  Process any user requests.  */
    do
    {
        /*  See if there is a character available.  */
        if (US_Is_Char())
        {
            /*  Get it. */
            c = (char) US_fgetc();

            /*  See what the user wants to do.  */
            switch (c)
            {
                /*  User wants to either start or stop a task.  */
                case '0':
                case '1':
                case '2':

                    /* Toggle tasks on / off */
                    i = (int) (c - '0');
                    if (task_is_running[TASK0+i])
                    {
                        /* Flag the task off. It will stop itself next time
                           it calls looping(). (We don't want to stop a task 
                           when it owns a resource) */
                        task_is_running[TASK0+i] = NO;
                    }
                    else
                    {
                        NU_Resume_Task(NUIP_PLUS_To_RTX[TASK0+i]);
                        task_is_running[TASK0+i] = YES;
                    }

                    /* In case they disabled all tasks, we want to stay in
                       the loop.  This way they can resume */
                    stay_in = YES;

                    /*  Check and see if they disabled all of them.  */
                    for (i = TASK0; i < HIGHEST_TASK; i++)
                    {
                        if (task_is_running[i])
                            stay_in = NO;
                    }
                    break;

                case 'x':
                case 'X':

                    /*  Many new systems do not have an exit capability.  If
                        your system does, place the exit code here.  */
                    break;

                default:
                    break;
            }
        }
    } while (stay_in);

#endif
    /*  Restore the preemption status that the caller initiated with. */
    NU_Change_Preemption(preempt_status);

    return(YES);
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "error_log"                      */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine processes a non-fatal error.                       */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      most functions in demo                                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      NONE                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      error_no                            Number of error being       */
/*                                          reported.                   */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
int error_log(int error_no)
{
    /*  Validate the error number.  */
    if (RAM_Errors_Index > 9)
        RAM_Errors_Index = 0;

    /*  Store the error.  */
    RAM_Errors[RAM_Errors_Index] = error_no;

    return(error_no);
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "display task"                   */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This routine is responsible for displaying the results of the   */
/*      demonstration program.  It may not be used in your system.      */
/*      If you do not have printf, it may be a good idea to set a       */
/*      breakpoint in this routine to see the results.                  */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                        This is a task started by         */
/*                                    nuf_task_0                        */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      [printf]                      Prints a string to the stdout.    */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      error_no                            Number of error being       */
/*                                          reported.                   */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void display_task(void)
{

    while (NU_TRUE)
    {
#if (PRINT_OUT)
        printf("******************************************************\n\r");
        printf("Press 0, 1, 2 to deactivate/activate task or X to exit\n\r");
        printf("******************************************************\n\r");
        printf("\n\r");
        printf("Task 0 Statistics:\n\r");
        printf("    Directories Scanned: %d\n\r", RAM_Directories_Scanned[0]);
        printf("    Files Scanned:       %d\n\r", RAM_Files_Scanned[0]);
        printf("\n\r");
        printf("Task 1 Statistics:\n\r");
        printf("    Files Created:       %d\n\r", RAM_Files_Created[1]);
        printf("    Files Renamed:       %d\n\r", RAM_Files_Renamed[1]);
        printf("    Files Deleted:       %d\n\r", RAM_Files_Deleted[1]);
        printf("\n\r");
        printf("Task 2 Statistics:\n\r");
        printf("    Files Created:       %d\n\r", RAM_Files_Created[2]);
        printf("    Files Renamed:       %d\n\r", RAM_Files_Renamed[2]);
        printf("    Files Deleted:       %d\n\r", RAM_Files_Deleted[2]);
        printf("\n\r");
        printf("\n\r");
        printf("\n\r");
        printf("\n\r");
        printf("\n\r");

#endif
        /*  Sleep for a while.   This is currently 3 seconds with a 10ms
            tick.*/
        NU_Sleep(30);
    }
}  /* end of display_task  */

/****************************************************************************/
int nu_strcmp(const char *s1, const char *s2)
{
    while( (*s1 == *s2) && (*s1) ) ++s1, ++s2;

    return ((int)(unsigned char)*s1) - ((int)(unsigned char)*s2);
}

char * nu_strcpy(char *s1, char *s2)
{
   char *p = s1;

    while( (*s1++ = *s2++ ) != 0);

    return p;
}


⌨️ 快捷键说明

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