This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

task defined with lower priority get higher priority in ROV

Hi,

I am working with a couple of tasks, task1 defined in daemonnew  and task2

defined with the follow code

    Task_Params_init(&taskParams);
    taskParams.stackSize = 0x4000;
    taskParams.priority = 0x02;
    task0= Task_create((Task_FuncPtr)connect2server, &taskParams, &eb);
    if(task0 == NULL) {
        System_abort("Task created failed");
    }

so task1 has priority 5 and task2 has priority 2.

The problem come because it seems task1 is never executed. So

I opened ROV and I see that task2 has a priority 9 and task 1 has priority 5.

I was wonder if something extra is needed to set task2 priority correctly ?

Thanks in advance

Julian

  • Hi Julian,

    You are setting the task priority correctly. Can you share the entire source file or atleast the entire Task create code ?

    Can you also provide the below info ?

    - Build Target

    - SYS/BIOS version

    Best,

    Ashish

  • Hi Ashish,

    thank you for your quick reply.

    The connect2server task is set inside NetworkIPAddr function that is  a callback function

    for NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr ) function.

    NC_NetStart is called from parse_main task that has a priority 5.

    So the flow is as follow:

    parse_main-> NC_NetStart-> NewtworkIPAddr->connect2server

    NetworkIPAddr code is:

    static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd )
    {
        static uint fAddGroups = 0;
        IPN IPTmp;
    
    	Task_Params taskParams;
    	Task_Handle task0;
    	Error_Block eb;
    
        if( fAdd )
            platform_write("Network Added: ");
        else
            platform_write("Network Removed: ");
    
        /* Print a message */
        IPTmp = ntohl( IPAddr );
        platform_write("If-%d:%d.%d.%d.%d \n", IfIdx,
                (UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
                (UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF );
    
    
        /* This is a good time to join any multicast group we require */
        if( fAdd && !fAddGroups )
        {
            fAddGroups = 1;
            /*      IGMPJoinHostGroup( inet_addr("224.1.2.3"), IfIdx ); */
        }
    
    
    
    	Error_init(&eb);
    
    	Task_Params_init(&taskParams);
    	taskParams.stackSize = 0x4000;
    	taskParams.priority = 0x02;
    	task0= Task_create((Task_FuncPtr)connect2server, &taskParams, &eb);
    	if(task0 == NULL) {
    		System_abort("Task created failed");
    	}
    
        return;
    }

    parse_main code is:

    int parse_main() {
    
        HANDLE hCfg;
        CI_SERVICE_HTTP   http;            /* Configuration data for http including handle */
        CI_SERVICE_DHCPC dhcpservice;    /* Configuration data for dhcp client including handle */
        uint8_t dhcp_options[] = {DHCPOPT_SERVER_IDENTIFIER, DHCPOPT_ROUTER};
        HeapBufMP_Handle heapHandle;
        HeapBufMP_Params heapBufParams;
        Int              status;
        int rc;
    #ifdef C66_PLATFORMS
        QMSS_CFG_T      qmss_cfg;
        CPPI_CFG_T      cppi_cfg;
    #endif
    
    	Task_Params taskParams;
    	Task_Handle task0;
    	Error_Block eb;
    	Error_init(&eb);
    
        platform_uart_init();
        platform_uart_set_baudrate(115200);
        platform_write_configure(PLATFORM_WRITE_ALL);
    
        platform_write("\n\nMCSDK IMAGE PROCESSING DEMONSTRATION\n\n");
    
    #ifdef C66_PLATFORMS
    
        /* Initialize the components required to run this application:
        *  (1) QMSS
        *  (2) CPPI
        *  (3) Packet Accelerator
        */
    
        /* Initialize QMSS */
        if (platform_get_coreid() == 0)
        {
            qmss_cfg.master_core        = 1;
        }
        else
        {
            qmss_cfg.master_core        = 0;
        }
        qmss_cfg.max_num_desc       = MAX_NUM_DESC;
        qmss_cfg.desc_size          = MAX_DESC_SIZE;
        qmss_cfg.mem_region         = Qmss_MemRegion_MEMORY_REGION0;
        if (res_mgr_init_qmss (&qmss_cfg) != 0)
        {
            platform_write ("Failed to initialize the QMSS subsystem \n");
            goto close_n_exit;
        } else {
            platform_write ("QMSS successfully initialized \n");
        }
    
        /* Initialize CPPI */
        if (platform_get_coreid() == 0)
        {
            cppi_cfg.master_core        = 1;
        } else {
            cppi_cfg.master_core        = 0;
        }
        cppi_cfg.dma_num            = Cppi_CpDma_PASS_CPDMA;
        cppi_cfg.num_tx_queues      = NUM_PA_TX_QUEUES;
        cppi_cfg.num_rx_channels    = NUM_PA_RX_CHANNELS;
        if (res_mgr_init_cppi (&cppi_cfg) != 0)
        {
            platform_write ("Failed to initialize CPPI subsystem \n");
            goto close_n_exit;
        } else {
            platform_write ("CPPI successfully initialized \n");
        }
    
    
        if (res_mgr_init_pass()!= 0) {
            platform_write ("Failed to initialize the Packet Accelerator \n");
            goto close_n_exit;
        } else {
            platform_write ("PA successfully initialized \n");
        }
    #endif
    
        status = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
        if(status != NC_OPEN_SUCCESS)
        {
            platform_write("NC_SystemOpen Failed (%d)\n",status);
            goto close_n_exit;
        }
    
        /* Create the heap that will be used to allocate messages. */
        HeapBufMP_Params_init(&heapBufParams);
        heapBufParams.regionId       = 0;
        heapBufParams.name           = IMAGE_PROCESSING_HEAP_NAME;
        heapBufParams.numBlocks      = NCORES*3;
        heapBufParams.blockSize      = sizeof(MyMessage);
        heapHandle = HeapBufMP_create(&heapBufParams);
        if (heapHandle == NULL) {
            platform_write("Main: HeapBufMP_create failed\n" );
            goto close_n_exit;
        }
    
        /* Register this heap with MessageQ */
        status = MessageQ_registerHeap((IHeap_Handle)heapHandle, IMAGE_PROCESSING_HEAPID);
        if(status != MessageQ_S_SUCCESS) {
            platform_write("Main: MessageQ_registerHeap failed\n" );
            goto close_n_exit;
        }
        alloc_messages();
    
    
        /* Create a new configuration */
        hCfg = CfgNew();
        if( !hCfg )
        {
            platform_write("Unable to create configuration\n");
            goto close_n_exit;
        }
    
        /* Validate the length of the supplied names */
        if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
                strlen( HostName ) >= CFG_HOSTNAME_MAX )
        {
            platform_write("Domain or Host Name too long\n");
            goto close_n_exit;
        }
    
        /* Add our global hostname to hCfg (to be claimed in all connected domains) */
        CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
                strlen(HostName), (UINT8 *)HostName, 0 );
    
        /*
         ** Read User SW 1
         ** If user SW 1 = OFF position: static IP mode (default), SW 1 = ON: client mode
         */
        if (!platform_get_switch_state(1)) {
            CI_IPNET NA;
            CI_ROUTE RT;
            IPN      IPTmp;
    
            /* Setup an IP address to this EVM */
            bzero( &NA, sizeof(NA) );
            NA.IPAddr  = inet_addr(EVMStaticIP);
            NA.IPMask  = inet_addr(LocalIPMask);
            strcpy( NA.Domain, DomainName );
    
            /* Add the address to interface 1 */
            CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );
    
            /* Add the default gateway (back to user PC) */
            bzero( &RT, sizeof(RT) );
            RT.IPDestAddr = inet_addr(PCStaticIP);
            RT.IPDestMask = inet_addr(LocalIPMask);
            RT.IPGateAddr = inet_addr(GatewayIP);
    
            /* Add the route */
            CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );
    
            /* Manually add the DNS server when specified */
            IPTmp = inet_addr(DNSServer);
            if( IPTmp )
                CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
                        0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
    
            platform_write("EVM in StaticIP mode at %s\n", EVMStaticIP);
            platform_write("Set IP address of PC to %s\n", PCStaticIP);
        } else {
            platform_write("Configuring DHCP client\n");
    
            bzero( &dhcpservice, sizeof(dhcpservice) );
            dhcpservice.cisargs.Mode   = CIS_FLG_IFIDXVALID;
            dhcpservice.cisargs.IfIdx  = 1;
            dhcpservice.cisargs.pCbSrv = &ServiceReport;
            dhcpservice.param.pOptions = dhcp_options;
            dhcpservice.param.len = 2;
            CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
                    sizeof(dhcpservice), (UINT8 *)&dhcpservice, &(dhcpservice.cisargs.hService) );
        }
    
        /* Add web files */
        image_processing_webfiles_add();
    
        /* Specify HTTP service */
        bzero( &http, sizeof(http) );
        http.cisargs.IPAddr = INADDR_ANY;
        http.cisargs.pCbSrv = &ServiceReport;
        CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_HTTP, 0,
                sizeof(http), (UINT8 *)&http, &(http.cisargs.hService) );
    
        /*
         ** Configure IPStack/OS Options
         */
    
        /* Set debug message level */
        status = DBG_WARN;
        CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
                CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&status, 0 );
    
        //
        // This code sets up the TCP and UDP buffer sizes
        // (Note 8192 is actually the default. This code is here to
        // illustrate how the buffer and limit sizes are configured.)
        //
    //ADDED
        // UDP Receive limit
        rc = 10 * 8192;
    
        CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
                     CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    
        /*
         ** Boot the system using this configuration
         **
         ** We keep booting until the function returns 0. This allows
         ** us to have a "reboot" command.
         */
    
        do
        {
            status = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
        } while( status > 0 );
    
    
    
    
        platform_write ("Shutting things down\n");
    
    close_n_exit:
    
        /* Free the WEB files */
        image_processing_webfiles_remove();
        /* Delete Configuration */
        CfgFree( hCfg );
        NC_SystemClose();
        return 0;
    
    }

    parse_main was statically defined so in cfg file:

    var tskSlaveThread       = Task.create("&parse_main");
    tskSlaveThread.stackSize = 0x4000;
    tskSlaveThread.priority  = 0x5;
    tskSlaveThread.instance.name = "parse_main"; 

    I have attached the complete main c file and the cfg file 8546.main_and_cfg.zip

    - The target is  tmdsevm6678le board.

    - SYS/BIOS version is 6.33.6.50

    It seems like the connect2server task is inheriting the priority or raising it at some point.

    Regards

    Julian

  • Hi Julian,

    This does seem very odd. The only API that I am aware of that automatically raises the priority of a task is GateMutexPri but that is not being used here and even if it were being used, it would never change the priority to 9 as there is no other task with priority 9.

    Can you try the following ?

    - Add a breakpoint in NetworkIPAddr() at Task_create(), step over and check the task priority immediately after task creation. I want to know if the task priority is correct when the task got created and gets elevated later on. You could also step into the Task_create() function.

    - Add a breakpoint at the beginning of connect2server() function and when the breakpoint hits check the task priority.

    Best,

    Ashish

  • Ashish,

    I tried what you advised me, and now the task has the correct priority in ROV.

    I suspect that was a problem that was solved with the project rebuild. I have tested

    and the problem had gone away.

    Thank you.

    Julian