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

📄 monitor.c

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ================================================================= */
/* Thread edit page
 *
 * A page on which the thread's state may be edited. This tests forms
 * handling.
 */

static char thread_edit_blurb[] =
"<p>This table contains an entry for each property of the thread"
"that you can edit. The properties are:\n"
"<p><b>State:</b> Change thread's state. The <em>Suspend</em> button"
"will suspend the thread. The <em>Run</em> button will undo any previous"
"suspends. The <em>Release</em> button will release the thread out of"
"any sleep it is currently in.\n"
"<p><b>Priority:</b> Change the thread's priority.\n"
"<p>Once the new state has been selected, press the <em>Submit</em>"
"button to make the change, or <em>Reset</em> to clear it."
;

static cyg_bool cyg_monitor_thread_edit( FILE * client, char *filename,
                                         char *formdata, void *arg )
{
    /* If any form data has been supplied, then change the thread's
     * state accordingly.
     */
    if( formdata != NULL )
    {
        char *formlist[6];
        char *state;
        char *pri_string;
        char *id_string;
        cyg_handle_t thread = 0;
        cyg_uint16 id;

        /* Parse the data */
        cyg_formdata_parse( formdata, formlist, 6 );

        /* Get the thread id from the hidden control */
        id_string = cyg_formlist_find( formlist, "thread");

        sscanf( id_string, "%04hx", &id );

        thread = cyg_thread_find( id );

        /* If there is a pri field, change the priority */
        pri_string = cyg_formlist_find( formlist, "pri");

        if( pri_string != NULL )
        {
            cyg_priority_t pri;

            sscanf( pri_string, "%d", &pri );

            cyg_thread_set_priority( thread, pri );
        }

        /* If there is a state field, change the thread state */
        state = cyg_formlist_find( formlist, "state");

        if( state != NULL )
        {
            if( strcmp( state, "run" ) == 0 )
                cyg_thread_resume( thread );
            if( strcmp( state, "suspend" ) == 0 )
                cyg_thread_suspend( thread );
            if( strcmp( state, "release" ) == 0 )
                cyg_thread_release( thread );
        }
    }

    /* Now generate a page showing the current thread state, and
     * including form controls to change it.
     */
    
    html_begin(client);

    html_head(client,"eCos Thread Editor", "");

    html_body_begin(client,"");
    {
        cyg_uint16 id;
        cyg_thread_info info;
        cyg_handle_t thread = 0;
        char idbuf[16];
        
        sscanf( filename, "/monitor/thread-%04hx.html", &id );

        thread = cyg_thread_find( id );
        cyg_thread_get_info(thread, id, &info );
        
        html_heading(client, 2, "Thread State Editor" );

        html_para_begin( client, "" );
        
        fprintf( client, "Editing Thread %04x %s\n",id,
                 info.name?info.name:NULL_THREAD_NAME);

        fputs( thread_edit_blurb, client );
        
        html_form_begin( client, filename, "" );        
        {
            html_table_begin( client, "border" );
            {
                html_table_header( client, "Property", "" );
                html_table_header( client, "Value", "" );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fputs( "State", client );

                    html_table_data_begin( client, "" );

                    html_form_input_radio( client, "state", "run", (info.state&0x04)==0 );
                    fputs( "Run", client );
                    html_form_input_radio( client, "state", "suspend", (info.state&0x04)!=0 );
                    fputs( "Suspend", client );
                    html_form_input_radio( client, "state", "release", 0 );
                    fputs( "Release", client );
                }
                html_table_row_end( client );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fputs( "Priority", client );

                    html_table_data_begin( client, "" );
                    fprintf(client,"<input type=\"text\" name=\"pri\" size=\"10\" value=\"%d\">\n",
                            info.set_pri);                    
                }
                html_table_row_end( client );

            }
            html_table_end( client );

            /* Add submit and reset buttons */
            html_form_input(client, "submit", "submit", "Submit", "");                
            html_form_input(client, "reset", "reset", "Reset", "");

            /* Pass the thread ID through to our next incarnation */
            sprintf( idbuf, "%04x", id );
            html_form_input_hidden(client, "thread", idbuf );            

        }
        html_form_end( client );
        
        draw_navbar(client);
    }
    html_body_end(client);

    html_end(client);
    
    return 1;
}

CYG_HTTPD_TABLE_ENTRY( cyg_monitor_thread_edit_entry,
                       "/monitor/thread-*",
                       cyg_monitor_thread_edit,
                       NULL );

/* ================================================================= */
/* Interrupt monitor
 *
 * At present this just generates a table showing which interrupts
 * have an ISR attached.
 */

static cyg_bool cyg_monitor_interrupts( FILE * client, char *filename,
                                        char *formdata, void *arg )
{
    html_begin(client);

    html_head(client,"eCos Interrupt Monitor", "");

    html_body_begin(client,"");
    {
        html_heading(client, 2, "Interrupt Monitor" );

        html_table_begin( client, "border" );
        {
            int i;
            int maxint = CYGNUM_HAL_ISR_MAX;

#ifdef CYGPKG_HAL_I386
            maxint = CYGNUM_HAL_ISR_MIN+16;
#endif
            
            html_table_header( client, "ISR", "" );
            html_table_header( client, "State", "" );
            
            for( i = CYGNUM_HAL_ISR_MIN; i <= maxint ; i++ )
            {
                cyg_bool_t inuse;
                HAL_INTERRUPT_IN_USE( i, inuse );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fprintf( client, "%d", i);
                    html_table_data_begin( client, "" );
                    fprintf( client, "%s", inuse?"In Use":"Free");
                }
                html_table_row_end( client );
            }
        }
        html_table_end( client );

        draw_navbar(client);
    }
    html_body_end(client);

    html_end(client);
    
    return 1;
    
}

CYG_HTTPD_TABLE_ENTRY( cyg_monitor_interrupts_entry,
                       "/monitor/interrupts.htm*",
                       cyg_monitor_interrupts,
                       NULL );

/* ================================================================= */
/* Memory monitor
 *
 * Generates a table showing a 256 byte page of memory. Form controls
 * allow changes to the base address and display element size.
 */

static cyg_bool cyg_monitor_memory( FILE * client, char *filename,
                                    char *formdata, void *arg )
{
    char *formlist[10];
    cyg_uint32 base = 0;
    unsigned int datasize = 1;
    int size = 256;
    char *p;
    bool valid_base = true;

    
    cyg_formdata_parse( formdata, formlist, 10 );

    p = cyg_formlist_find( formlist, "base" );

    /* If the page is requested without a 'base' parameter, do not attempt
     * to access any memory locations to prevent illegal memory accesses
     * on targets where '0' is not a valid address.
     */
    if( p != NULL )
        sscanf( p, "%x", &base );
    else
        valid_base = false;

    p = cyg_formlist_find( formlist, "datasize" );

    if( p != NULL )
        sscanf( p, "%x", &datasize );

    if( cyg_formlist_find( formlist, "next" ) != NULL )
        base += size;

    if( cyg_formlist_find( formlist, "prev" ) != NULL )
        base -= size;
        
    html_begin(client);

    html_head(client,"eCos Memory Monitor", "");

    html_body_begin(client,"");
    {
        html_heading(client, 2, "Memory Monitor" );

        html_form_begin( client, "/monitor/memory.html", "" );
        {

            /* Text input control for base address
             */
            html_para_begin( client, "" );
            fprintf(client,
                    "Base Address: 0x<input type=\"text\" name=\"base\" size=\"10\" value=\"%x\">\n",
                    base);

            fprintf(client,
                    "WARNING: entering an illegal base address can crash the system.\n");

            /* A little menu for the element size
             */
            html_para_begin( client, "" );

            fputs( "Element Size: ", client );
            html_form_select_begin( client, "datasize", "" );
            html_form_option( client, "1", "bytes", datasize==1 );
            html_form_option( client, "2", "words", datasize==2 );
            html_form_option( client, "4", "dwords", datasize==4 );
            html_form_select_end( client );
                        
            html_para_begin( client, "" );

            /* Submit and reset buttons
             */
            html_form_input(client, "submit", "submit", "Submit", "");                
            html_form_input(client, "reset", "reset", "Reset", "");

            html_para_begin( client, "" );

            /* Previous page button */
            html_form_input(client, "submit", "prev", "Prev Page", "");

            /* Switch to monospaced font */
            cyg_html_tag_begin( client, "font", "face=\"monospace\"" );
            
            html_table_begin( client, "" );

            if (valid_base == true) {

⌨️ 快捷键说明

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