Beispiel #1
0
static void ProcessCtrlC(void)                                  // print system state to the console
{
  PrintParameters();

  size_t FreeHeap = xPortGetFreeHeapSize();

  xSemaphoreTake(UART1_Mutex, portMAX_DELAY);                   // ask exclusivity on UART1

  Format_String(UART1_Write, "Task  Pr. Stack, ");
  Format_UnsDec(UART1_Write, (uint32_t)FreeHeap, 4, 3);
  Format_String(UART1_Write, "kB free\n");
  // xSemaphoreGive(UART1_Mutex);                                  // give back UART1 to other tasks

  UBaseType_t uxArraySize = uxTaskGetNumberOfTasks();
  TaskStatus_t *pxTaskStatusArray = (TaskStatus_t *)pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  if(pxTaskStatusArray==0) goto Exit;
  uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );
  for(UBaseType_t T=0; T<uxArraySize; T++)
  { TaskStatus_t *Task = pxTaskStatusArray+T;
    // uint8_t Len=strlen(Task->pcTaskName);
    // memcpy(Line, Task->pcTaskName, Len);
    uint8_t Len=Format_String(Line, Task->pcTaskName);
    for( ; Len<=configMAX_TASK_NAME_LEN; )
      Line[Len++]=' ';
    Line[Len++]='0'+Task->uxCurrentPriority; Line[Len++]=' ';
    Len+=Format_UnsDec(Line+Len, Task->usStackHighWaterMark, 3);
    Line[Len++]='\n'; Line[Len++]=0;
    // xSemaphoreTake(UART1_Mutex, portMAX_DELAY);                   // ask exclusivity on UART1
    Format_String(UART1_Write, Line);
    // xSemaphoreGive(UART1_Mutex);                                  // give back UART1 to other tasks
  }
  vPortFree( pxTaskStatusArray );
Exit:
  xSemaphoreGive(UART1_Mutex);                                       // give back UART1 to other tasks
}
Beispiel #2
0
	unsigned portBASE_TYPE MPU_uxTaskGetSystemState( xTaskStatusType *pxTaskStatusArray, unsigned portBASE_TYPE uxArraySize, unsigned long *pulTotalRunTime )
	{
	unsigned portBASE_TYPE uxReturn;
	portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();

		uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
		portRESET_PRIVILEGE( xRunningPrivileged );
		return xReturn;
	}
Beispiel #3
0
UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime )
{
    UBaseType_t uxReturn;
    BaseType_t xRunningPrivileged = prvRaisePrivilege();

    uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
    portRESET_PRIVILEGE( xRunningPrivileged );
    return xReturn;
}
Beispiel #4
0
	UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime )
	{
	UBaseType_t uxReturn;
	BaseType_t xRunningPrivileged = xPortRaisePrivilege();

		uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
		vPortResetPrivilege( xRunningPrivileged );
		return uxReturn;
	}
/********************************************************************* 
* 
*       _cbSendTaskList()
*
*  Function description
*    This function is part of the link between FreeRTOS and SYSVIEW.
*    Called from SystemView when asked by the host, it uses SYSVIEW
*    functions to send the entire task list to the host.
*/
static void _cbSendTaskList(void) {
  TaskStatus_t*         pxTaskStatusArray;
  UBaseType_t           uxArraySize;
  UBaseType_t           x;
  char                  cStatus;

#if INCLUDE_xTaskGetIdleTaskHandle
  TaskHandle_t          hIdle;
  hIdle = xTaskGetIdleTaskHandle();
#endif

  /* Take a snapshot of the number of tasks in case it changes while this
  function is executing. */
  uxArraySize = uxTaskGetNumberOfTasks();

  /* Allocate an array index for each task. */
  pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );

  if( pxTaskStatusArray != NULL ) {
    /* Generate the (binary) data. */
    uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );

#if INCLUDE_xTaskGetIdleTaskHandle
    /* only get Idle task handle if scheduler has been started */
    if (xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED) {
      hIdle = xTaskGetIdleTaskHandle();
    } else {
      hIdle = NULL;
    }
#endif
    
    /* Create a human readable table from the binary data. */
    for( x = 0; x < uxArraySize; x++ ) {
      uint8_t* pStack;
#if INCLUDE_pxTaskGetStackStart
      pStack = pxTaskGetStackStart(pxTaskStatusArray[x].xHandle);
#else
      pStack = (uint8_t*)0;
#endif

#if INCLUDE_xTaskGetIdleTaskHandle
      if (pxTaskStatusArray[x].xHandle != hIdle) {
        SYSVIEW_SendTaskInfo((unsigned)pxTaskStatusArray[x].xHandle, pxTaskStatusArray[x].pcTaskName, pxTaskStatusArray[x].uxCurrentPriority, (unsigned int)pStack, 0);
      }
#else
      if (memcmp(pxTaskStatusArray[x].pcTaskName, "IDLE", 5) != 0) {
        SYSVIEW_SendTaskInfo((unsigned)pxTaskStatusArray[x].xHandle, pxTaskStatusArray[x].pcTaskName, pxTaskStatusArray[x].uxCurrentPriority, (unsigned int)pStack, 0);
      }
#endif
    }

    /* Free the array again. */
    vPortFree( pxTaskStatusArray );
  }
}
Beispiel #6
0
/**
  * @brief  Update process manager view.
  * @param  hItem: pointer to window handle
  * @retval None
  */
static void _UpdateProcessManagerView(WM_HWIN  hItem) {
  int      Idx;
  char     str[3];
  int16_t  tasks_nbr;
  
  tasks_nbr = uxTaskGetSystemState( ProcessStatus, 16, NULL );
  
  /*Limit view size */
  if(tasks_nbr > 16)
  {
    tasks_nbr = 16;
  }
  
  for (Idx = 0; Idx < tasks_nbr ; Idx ++)
  {
    LISTVIEW_SetItemText(hItem, 0, Idx, (char *)(ProcessStatus[Idx].pcTaskName)); 
    sprintf(str, "%lu", ProcessStatus[Idx].uxCurrentPriority);
    LISTVIEW_SetItemText(hItem, 1, Idx, str);
    
    switch (ProcessStatus[Idx].eCurrentState)
    {
    case eReady:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Ready"); 
      break;
      
    case eBlocked:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Blocked"); 
      break;
      
    case eDeleted:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Deleted"); 
      break;
      
    case eSuspended:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Suspended"); 
      break;
      
    case eRunning:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Running"); 
      break;        
      
    default:
      LISTVIEW_SetItemText(hItem, 2, Idx, "Unknown"); 
      break;        
    }
  }
  LISTVIEW_SetSort(hItem, 1, 0);
}
Beispiel #7
0
static int TaskCommand(int argc, const char **argv) {
  if (argc != 1) return -1;

  TaskStatus_t status[MAX_TASK_COUNT];
  uint32_t total_run_time;

  UBaseType_t count = uxTaskGetSystemState(status,
                                           MAX_TASK_COUNT,
                                           &total_run_time);
  if (count == 0) {
    printf("Too many tasks. Increase MAX_TASK_COUNT.\r\n");
    return -2;
  }

  printf("\tName\t\tState\tPri\tStack\tCPU\r\n");

  total_run_time /= 100;
  if (!total_run_time) total_run_time = 1;

  TaskStatus_t * task = &status[0];
  while (count--) {
    char state = 'X';
    switch (task->eCurrentState) {
      case eRunning:
      case eReady  :   state = 'R'; break;
      case eBlocked:   state = 'B'; break;
      case eSuspended: state = 'S'; break;
      case eDeleted:   state = 'D'; break;
    }

    uint32_t percent = task->ulRunTimeCounter / total_run_time;

    printf("%u\t%s\t\t%c\t%u\t%u\t%u%%\r\n",
           (unsigned) task->xTaskNumber,
           task->pcTaskName,
           state,
           (unsigned) task->uxCurrentPriority,
           (unsigned) task->usStackHighWaterMark,
           (unsigned) percent);
    ++task;
  }
  return 0;
}
Beispiel #8
0
void dumpsys_task_func(void)
{
#if configUSE_TRACE_FACILITY
    TaskStatus_t *pxTaskStatusArray;
    volatile UBaseType_t uxArraySize, x;
    uint32_t ulTotalRunTime, ulStatsAsPercentage;

    uxArraySize = uxTaskGetNumberOfTasks();
    pxTaskStatusArray = malloc( uxArraySize * sizeof( TaskStatus_t ) );
    if( pxTaskStatusArray == NULL )
        return;

    uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
    // For percentage calculations.
    ulTotalRunTime /= 100UL;

    // Avoid divide by zero errors.
    if( ulTotalRunTime > 0 )
    {
        // For each populated position in the pxTaskStatusArray array,
        // format the raw data as human readable ASCII data
        for( x = 0; x < uxArraySize; x++ )
        {
            // What percentage of the total run time has the task used?
            // This will always be rounded down to the nearest integer.
            // ulTotalRunTimeDiv100 has already been divided by 100.
            ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;

            if( ulStatsAsPercentage > 0UL )
            {
                printf("%s\t\t%u\t\t%u%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
            }
            else
            {
                printf("%s\t\t%u\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
            }
        }
    }

    free( pxTaskStatusArray );
#endif
}
Beispiel #9
0
static int get_task_state(int argc, char **argv)
{
    TaskStatus_t *pxTaskStatusArray;
	volatile UBaseType_t uxArraySize, x;
	uint32_t ulTotalRunTime, ulStatsAsPercentage;

	uxArraySize = uxTaskGetNumberOfTasks();
    
	pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
	if( pxTaskStatusArray != NULL )
	{
        printf("任务名\t\tID\t优先级\t堆栈\tCPU使用率\r\n");
		uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
        if( ulTotalRunTime > 0 )
	    {
            for( x = 0; x < uxArraySize; x++ )
    		{
                ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime * 100;
                if( ulStatsAsPercentage > 0UL )
				{
        			printf("%-16s%-8d%-8d%-8d%d%%\r\n", pxTaskStatusArray[x].pcTaskName,pxTaskStatusArray[x].xTaskNumber,
                        pxTaskStatusArray[x].uxCurrentPriority, pxTaskStatusArray[x].usStackHighWaterMark, ulStatsAsPercentage);
                    vTaskDelay(100/portTICK_RATE_MS);
                }
                else
                {
                    printf("%-16s%-8d%-8d%-8d<1%%\r\n", pxTaskStatusArray[x].pcTaskName,pxTaskStatusArray[x].xTaskNumber,
                        pxTaskStatusArray[x].uxCurrentPriority, pxTaskStatusArray[x].usStackHighWaterMark);
                    vTaskDelay(100/portTICK_RATE_MS);
                }
    		}
    		
        }
        vPortFree( pxTaskStatusArray );
	}
    printf("\r\n");
    size_t freeHeapSize = xPortGetFreeHeapSize();
    printf("the free heapsize is %d\r\n", freeHeapSize);  
    vTaskDelay(50/portTICK_RATE_MS);
    return 0;
}
/*******************************************************************************
 * PRIVATE FUNCTIONS (STATIC)
 ******************************************************************************/
#if configFRTOS_MEMORY_SCHEME!=1 /* this scheme does not allow deallocation of memory */
static uint8_t PrintTaskList( Shell_ConstStdIO_t *io )
{
    UBaseType_t nofTasks, nof, i;
    TaskStatus_t *pxTaskStatusArray;
    uint8_t buf[32], tmpBuf[16], res;

    res = ERR_OK;
    nofTasks = uxTaskGetNumberOfTasks();
    pxTaskStatusArray = pvPortMalloc(nofTasks * sizeof(TaskStatus_t));
    if ( pxTaskStatusArray != NULL ) {
        nof = uxTaskGetSystemState(pxTaskStatusArray, nofTasks, NULL);
        if ( nof != nofTasks ) { /* error, array was to small? */
            Shell_SendStr((unsigned char*) "***GetSystemState failed!\r\n", io->stdErr);
            res = ERR_FAILED; /* out of memory */
        } else {
#define PAD_STAT_TASK_TCB         5
#define PAD_STAT_TASK_HANDLE      11
#define PAD_STAT_TASK_NAME        (configMAX_TASK_NAME_LEN+1)
#define PAD_STAT_TASK_STATE       10
#define PAD_STAT_TASK_PRIO        8
#define PAD_STAT_TASK_RUNTIME     11
#define PAD_STAT_TASK_STACK_MARK  11
            /* header */
            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "TCB#", ' ',
            PAD_STAT_TASK_TCB);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "Handle", ' ',
            PAD_STAT_TASK_HANDLE);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "Name", ' ',
            PAD_STAT_TASK_NAME);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "State", ' ',
            PAD_STAT_TASK_STATE);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "Prio", ' ',
            PAD_STAT_TASK_PRIO);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "Runtime", ' ',
            PAD_STAT_TASK_RUNTIME);
            Shell_SendStr(buf, io->stdOut);

            buf[0] = '\0';
            strcatPad(buf, sizeof(buf), (const unsigned char*) "Stack", ' ',
            PAD_STAT_TASK_STACK_MARK);
            Shell_SendStr(buf, io->stdOut);

            Shell_SendStr((unsigned char*) "\r\n", io->stdOut);
            for ( i = 0; i < nof; i++ ) {
                /* TCB */
                tmpBuf[0] = '\0';
                strcatNum32u(tmpBuf, sizeof(tmpBuf), (uint32_t) pxTaskStatusArray[i].xTaskNumber);
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_TCB);
                Shell_SendStr(buf, io->stdOut);
                /* task handle */
                tmpBuf[0] = '\0';
                custom_strcat(tmpBuf, sizeof(tmpBuf), (unsigned char*) "0x");
                strcatNum32Hex(tmpBuf, sizeof(tmpBuf), (uint32_t) pxTaskStatusArray[i].xHandle);
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_HANDLE);
                Shell_SendStr(buf, io->stdOut);

                /* task name */
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), (const unsigned char*) pxTaskStatusArray[i].pcTaskName,
                        ' ', PAD_STAT_TASK_NAME);
                Shell_SendStr(buf, io->stdOut);

                /* state */
                switch ( pxTaskStatusArray[i].eCurrentState ) {
                    case eRunning:
                        custom_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*) "Running");
                        break;
                    case eReady:
                        custom_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*) "Ready");
                        break;
                    case eSuspended:
                        custom_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*) "Suspended");
                        break;
                    case eBlocked:
                        custom_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*) "Blocked");
                        break;
                    default:
                        custom_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*) "UNKNOWN!");
                        break;
                }
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_STATE);
                Shell_SendStr(buf, io->stdOut);

                /* (baseprio,currprio) */
                tmpBuf[0] = '\0';
                chcat(tmpBuf, sizeof(tmpBuf), '(');
                strcatNum32s(tmpBuf, sizeof(tmpBuf), pxTaskStatusArray[i].uxBasePriority);
                chcat(tmpBuf, sizeof(tmpBuf), ',');
                strcatNum32s(tmpBuf, sizeof(tmpBuf), pxTaskStatusArray[i].uxCurrentPriority);
                chcat(tmpBuf, sizeof(tmpBuf), ')');
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_PRIO);
                Shell_SendStr(buf, io->stdOut);

                /* runtime */
                tmpBuf[0] = '\0';
                custom_strcat(tmpBuf, sizeof(tmpBuf), (unsigned char*) "0x");
                strcatNum32Hex(tmpBuf, sizeof(tmpBuf), pxTaskStatusArray[i].ulRunTimeCounter);
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_RUNTIME);
                Shell_SendStr(buf, io->stdOut);

                /* stack high water mark */
                tmpBuf[0] = '\0';
                strcatNum16u(tmpBuf, sizeof(tmpBuf), pxTaskStatusArray[i].usStackHighWaterMark);
                buf[0] = '\0';
                strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_STACK_MARK);
                Shell_SendStr(buf, io->stdOut);

                Shell_SendStr((unsigned char*) "\r\n", io->stdOut);
            }
        }
    } else {
        Shell_SendStr((unsigned char*) "***alloc failed!\r\n", io->stdErr);
        res = ERR_FAILED; /* out of memory */
    }
    if ( pxTaskStatusArray != NULL ) { /* free memory */
        vPortFree(pxTaskStatusArray);
    }
    return res;
}
Beispiel #11
0
void QuadFC_RuntimeStats( uint8_t * buffer , uint16_t bufferLength)
{
#ifdef QuadFCStats
//#if 1
  TaskStatus_t *pxTaskStatusArray;
  volatile UBaseType_t uxArraySize, x;
  uint32_t ulTotalTime, ulStatsAsPercentage;

  *buffer = 0x00;

  /* Take a snapshot of the number of tasks in case it changes while this
    function is executing. */
  uxArraySize = uxTaskGetNumberOfTasks();

  /* Allocate an array index for each task. */
  pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );

  if( pxTaskStatusArray != NULL )
  {
    /* Generate the (binary) data. */
    uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );

    /* For percentage calculations. */
    ulTotalTime /= 100UL;


    /* Avoid divide by zero errors. */
    if( ulTotalTime > 0 )
    {
      /* Create a human readable table from the binary data. */
      for( x = 0; x < uxArraySize; x++ )
      {
        /* What percentage of the total run time has the task used?
        This will always be rounded down to the nearest integer.
        ulTotalRunTimeDiv100 has already been divided by 100. */
        ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;

        if( ulStatsAsPercentage > 0UL )
        {
          snprintf((char *) buffer, bufferLength , "\n%s,%u,%u,%u,%u%%,",
              pxTaskStatusArray[ x ].pcTaskName,
              ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
              ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
              ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter,
              ( unsigned int ) ulStatsAsPercentage );
        }
        else
        {
          snprintf((char *) buffer, bufferLength , "\n%s,%u,%u,%u,<1%%,",
              pxTaskStatusArray[ x ].pcTaskName,
              ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority,
              ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark,
              ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );
        }

        size_t len = strlen((char *) buffer );
        buffer += len;
        bufferLength -= len;
      }
    }

    /* Free the array again. */
    vPortFree( pxTaskStatusArray );
  }
#else
  snprintf((char *) buffer, bufferLength , "\nRun time statistics is not available");
#endif
}