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

📄 root.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的动态下载程序源码。
💻 C
字号:
/*
 * Copyright (c) 1995,2000 TriMedia Technologies Inc.         
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : root.c    1.8
 *
 *  Last update              : 17:07:21 - 00/06/16
 *
 *
 *  Description              :  pSOS based command interpreter,
 *                              for starting parallel applications.
 *
 */

/*----------------------------includes----------------------------------------*/

#include "sys_conf.h"
#include <stdio.h>
#include <psos.h>
#include <probe.h>
#include <tmlib/tmtypes.h>
#include <tmlib/DynamicLoader.h>


/*----------------- Command Line Unraveling Functions ------------------------*/


Int
count_words(String buffer)
{
    Int         result = 0;

    while (*buffer == ' ')
        buffer++;

    while (*buffer != 0) {
        result++;
        while (*buffer != ' ')
            buffer++;
        while (*buffer == ' ')
            buffer++;
    }

    return result;
}



Int
get_words(String buffer, String * argv)
{
    Int         result = 0;

    while (*buffer == ' ')
        buffer++;

    while (*buffer != 0) {
        String      p;

        *(argv++) = buffer;
        while (*buffer != ' ')
            buffer++;
        p = buffer;
        while (*buffer == ' ')
            buffer++;
        *p = 0;
    }

    return result;
}


/*------------------------ Application Shell ---------------------------------*/

typedef     Int(*Main_Function) ();


void
application_shell(Int argc, String * argv)
{
    Int         run_status;
    DynLoad_Status load_status;
    DynLoad_Code_Segment_Handle module;


    load_status = DynLoad_load_application(argv[0], &module);

    if (load_status != DynLoad_OK) {
        printf("** loading of `%s` failed with status %d\n",
               argv[0], load_status);
    }
    else {
        run_status = ((Main_Function) module->start) (argc, argv);
        printf("** `%s` done with status %d\n", argv[0], run_status);
        DynLoad_unload_application(module);
    }

    free(argv);

    t_delete(0);
}


/*-------------------------- Command Loop ------------------------------------*/


void
root(void)
{
    while (1) {
        ULONG       task;
        ULONG       arguments[4];

        Char        buffer[200];
        Int         argc;
        String     *argv;

        printf("> ");
        fflush(stdout);
        gets(buffer);
        strcpy(&buffer[strlen(buffer)], " ");

        argc = count_words(buffer);

        if (argc > 0) {

            /*
             * Allocate space for argv plus a copy of the command
             * string; this will be passed to the application
             * shell task, and can be deallocated as one unit
             */
            argv = (Pointer) malloc(argc * sizeof (Pointer) + strlen(buffer));
            strcpy((Pointer) (argv + argc), buffer);

            get_words((Pointer) (argv + argc), argv);

            /*
             * After that, create a new task for the command to
             * run on, and pass it the argc/argv pair; Give it a
             * priority of 231, which is higher than this root
             * task, otherwise the task will never run in tmsim
             * with its blocking input. the 10000's are the
             * required sizes for user- and system stack:
             */
            arguments[0] = (ULONG) argc;
            arguments[1] = (ULONG) argv;

            t_create("aaaa", 231, 10000, 10000, 0, &task);
            t_start(task, T_PREEMPT | T_TSLICE | T_ASR | T_ISR,
                application_shell, arguments);
        }
    }
}

⌨️ 快捷键说明

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