예제 #1
0
파일: death.c 프로젝트: Carrotman42/cs4534
void vCreateSuicidalTasks( unsigned portBASE_TYPE uxPriority )
{
unsigned portBASE_TYPE *puxPriority;

	/* Create the Creator tasks - passing in as a parameter the priority at which 
	the suicidal tasks should be created. */
	puxPriority = ( unsigned portBASE_TYPE * ) pvPortMalloc( sizeof( unsigned portBASE_TYPE ) );
	*puxPriority = uxPriority;

	xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) puxPriority, uxPriority, NULL );

	/* Record the number of tasks that are running now so we know if any of the 
	suicidal tasks have failed to be killed. */
	uxTasksRunningAtStart = uxTaskGetNumberOfTasks();
}
예제 #2
0
파일: bash.c 프로젝트: felipeband/lua_p24
static void b_stack(int argc, char **argv) {
    (void) argc;
    (void) argv;

    if (argc != 1) {
        msg_erro_nos_argumentos();
        return;
    }

    usb_print("\r\nquantidade de tarefas: ");
    printf("%u", uxTaskGetNumberOfTasks());

    usb_print("\r\nlivre:");
    printf("\r\n - bash   : %u", s_uso_bash);
    printf("\r\n - usb    : %u", stack_uso_usb);
}
void IBN_ShowTaskStatusAll (void)
{
	u32 i;


	CI_LocalPrintf ("Taskstatus\r\n");
	CI_LocalPrintf ("\r\n");
	CI_LocalPrintf ("Taskcount : %d\r\n",uxTaskGetNumberOfTasks ());
	CI_LocalPrintf ("Tick      : %d - %d sec\r\n",xTickCount,xTickCount/configTICK_RATE_HZ);
	CI_LocalPrintf ("                                   Stack      Runtime      Last Minute\r\n");
	CI_LocalPrintf ("Taskname              State   Prio  free    usec       %%        %%      Starts\r\n");

	for (i=0;i<IBN_TasklistCounter_u8;i++)
	{
		IBN_Taskdata (i);
	}

}
예제 #4
0
파일: aos_freertos.c 프로젝트: wosayttn/aos
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
}
예제 #5
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;
}
void runtimestats_print(void)
{
  char *buf;

  /* Allocate memory */
  vTaskSuspendAll();
  buf = (char *) calloc(uxTaskGetNumberOfTasks() * 40, sizeof(char));
  xTaskResumeAll();

  if (buf != NULL)
  {
    /* Get a runtime stats report and write it on the UART */
    vTaskGetRunTimeStats((signed char*) buf);
    uart_write((INT8U *) buf, strlen((char *) buf), portMAX_DELAY);

    /* Free the memory again */
    vTaskSuspendAll();
    free(buf);
    xTaskResumeAll();
  }
}
예제 #7
0
void vCreateSuicidalTasks( unsigned portBASE_TYPE uxPriority )
{
unsigned portBASE_TYPE *puxPriority;

	/* Create the Creator tasks - passing in as a parameter the priority at which
	the suicidal tasks should be created. */
	puxPriority = ( unsigned portBASE_TYPE * ) pvPortMalloc( sizeof( unsigned portBASE_TYPE ) );
	*puxPriority = uxPriority;

	xTaskCreate( vCreateTasks, ( signed char * ) "CREATOR", deathSTACK_SIZE, ( void * ) puxPriority, uxPriority, NULL );

	/* Record the number of tasks that are running now so we know if any of the
	suicidal tasks have failed to be killed. */
	uxTasksRunningAtStart = ( unsigned portBASE_TYPE ) uxTaskGetNumberOfTasks();
	
	/* FreeRTOS.org versions before V3.0 started the idle-task as the very
	first task. The idle task was then already included in uxTasksRunningAtStart.
	From FreeRTOS V3.0 on, the idle task is started when the scheduler is
	started. Therefore the idle task is not yet accounted for. We correct
	this by increasing uxTasksRunningAtStart by 1. */
	uxTasksRunningAtStart++;
}
예제 #8
0
파일: death.c 프로젝트: peterliu2/tivaWare
/* This is called to check that the creator task is still running and that there
are not any more than four extra tasks. */
BaseType_t xIsCreateTaskStillRunning( void )
{
    static uint16_t usLastCreationCount = 0xfff;
    BaseType_t xReturn = pdTRUE;
    static UBaseType_t uxTasksRunningNow;

    if( usLastCreationCount == usCreationCount ) {
        xReturn = pdFALSE;
    } else {
        usLastCreationCount = usCreationCount;
    }

    uxTasksRunningNow = ( UBaseType_t ) uxTaskGetNumberOfTasks();

    if( uxTasksRunningNow < uxTasksRunningAtStart ) {
        xReturn = pdFALSE;
    } else if( ( uxTasksRunningNow - uxTasksRunningAtStart ) > uxMaxNumberOfExtraTasksRunning ) {
        xReturn = pdFALSE;
    } else {
        /* Everything is okay. */
    }

    return xReturn;
}
예제 #9
0
void vCreateSuicidalTasks( UBaseType_t uxPriority )
{
	xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) NULL, uxPriority, NULL );

	/* Record the number of tasks that are running now so we know if any of the
	suicidal tasks have failed to be killed. */
	uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();

	/* FreeRTOS.org versions before V3.0 started the idle-task as the very
	first task. The idle task was then already included in uxTasksRunningAtStart.
	From FreeRTOS V3.0 on, the idle task is started when the scheduler is
	started. Therefore the idle task is not yet accounted for. We correct
	this by increasing uxTasksRunningAtStart by 1. */
	uxTasksRunningAtStart++;

	/* From FreeRTOS version 7.0.0 can optionally create a timer service task.
	If this is done, then uxTasksRunningAtStart needs incrementing again as that
	too is created when the scheduler is started. */
	#if configUSE_TIMERS == 1
	{
		uxTasksRunningAtStart++;
	}
	#endif
}
예제 #10
0
extern "C" void vApplicationTickHook()
{
	static unsigned portLONG ulTicksSinceLastDisplay = 0;

	// Called from every tick interrupt. Have enough ticks passed to make it
	// time to perform our health status check again?
	ulTicksSinceLastDisplay++;
	if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
	{
		ulTicksSinceLastDisplay = 0;

		WDT_Feed();

#if configGENERATE_RUN_TIME_STATS == 1
		unsigned long long uptime_usec = ullTaskGetSchedulerUptime();

#if 1
		struct timeval tp;
		int t = gettimeofday(&tp, NULL);
		printf("timeofday = %ld seconds %ld microseconds (code %d)\n", (long)tp.tv_sec, (long)tp.tv_usec, t);
#endif

		printf("Uptime: %u.%06u seconds\n", (unsigned int)(uptime_usec / 1000000), (unsigned int)(uptime_usec % 1000000));

		int8_t *taskListBuffer = (int8_t *)malloc(40 * uxTaskGetNumberOfTasks());
		if (taskListBuffer != NULL)
		{
			vTaskGetRunTimeStats((int8_t *)taskListBuffer);
			puts((const char *)taskListBuffer);
			free(taskListBuffer);
		}
#endif

		// Has an error been found in any task?
		int allGood = 1;
#if 0
		if( xAreBlockingQueuesStillRunning() != pdTRUE )
		{
			printf("ERROR - BLOCKQ\n");
			allGood = 0;
		}

		if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
		{
			printf("ERROR - BLOCKTIM\n");
			allGood = 0;
		}

		if( xAreGenericQueueTasksStillRunning() != pdTRUE )
		{
			printf("ERROR - GENQ\n");
			allGood = 0;
		}

		if( xAreQueuePeekTasksStillRunning() != pdTRUE )
		{
			printf("ERROR - PEEKQ\n");
			allGood = 0;
		}

		if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
		{
			printf("ERROR - DYNAMIC\n");
			allGood = 0;
		}
#endif
		if (allGood == 1)
		{
			printf("All Good.\n");
		}
		fflush(stdout);
	}
}
예제 #11
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;
}
예제 #12
0
static uint8_t PrintStatus( Shell_ConstStdIO_t *io )
{
#if configUSE_TRACE_FACILITY || configGENERATE_RUN_TIME_STATS /* FreeRTOS trace feature enabled */
#if configFRTOS_MEMORY_SCHEME==1 /* this scheme does not allow deallocation of memory */
    static unsigned char *taskListBufferP=NULL; /* allocated only once, never deallocated! */
#else
    unsigned char *taskListBufferP;
#endif
    size_t bufSize;
#endif
    uint8_t buf[16];

    Shell_SendStatusStr((unsigned char*) "rtos", (unsigned char*) "\r\n", io->stdOut);
#if 0 && configUSE_TRACE_FACILITY /* FreeRTOS trace feature enabled */
    Shell_SendStr((unsigned char*)"TASK LIST:\r\n", io->stdOut);
    buf[0] = '\0';
    strcatPad(buf, sizeof(buf), (const unsigned char*)"Name", ' ', configMAX_TASK_NAME_LEN);
    Shell_SendStr(buf, io->stdOut);
    Shell_SendStr((unsigned char*)"\tState\tPrio\tStack\tTCB#\r\n", io->stdOut);
    Shell_SendStr((unsigned char*)CLS1_DASH_LINE, io->stdOut);
    Shell_SendStr((unsigned char*)"\r\n", io->stdOut);
    /* task list and status */
    bufSize = 40*uxTaskGetNumberOfTasks(); /* about 40 bytes for a task should be enough */
#if configFRTOS_MEMORY_SCHEME==1 /* this scheme does not allow deallocation of memory */
    if (taskListBufferP==NULL) { /* only if not allocated yet */
        taskListBufferP = FRTOS1_pvPortMalloc(bufSize); /* about 40 bytes for a task should be enough */
    }
#else
    taskListBufferP = FRTOS1_pvPortMalloc(bufSize); /* about 40 bytes for a task should be enough */
#endif
    if (taskListBufferP != NULL) {
        vTaskList((char*)taskListBufferP, bufSize);
        Shell_SendStr(taskListBufferP, io->stdOut);
#if configFRTOS_MEMORY_SCHEME!=1 /* this scheme does not allow deallocation of memory */
        vPortFree(taskListBufferP);
#endif
    } else {
        Shell_SendStr((unsigned char*)"\r\n*** out of heap! ***\r\n", io->stdErr);
    }
#endif
#if ((configGENERATE_RUN_TIME_STATS==1) && (configUSE_STATS_FORMATTING_FUNCTIONS==1))
    Shell_SendStr((unsigned char*)CLS1_DASH_LINE, io->stdOut);
    Shell_SendStr((unsigned char*)"\r\nRTOS RUN-TIME STATISTICS:\r\n", io->stdOut);
    buf[0] = '\0';
    custom_strcatPad(buf, sizeof(buf), (const unsigned char*)"Name", ' ', configMAX_TASK_NAME_LEN);
    Shell_SendStr(buf, io->stdOut);
    Shell_SendStr((unsigned char*)"\tTime\t\t%Time\r\n", io->stdOut);
    Shell_SendStr((unsigned char*)CLS1_DASH_LINE, io->stdOut);
    Shell_SendStr((unsigned char*)"\r\n", io->stdOut);
    /* task list and status */
    bufSize = 40*uxTaskGetNumberOfTasks(); /* about 40 bytes for a task should be enough */
#if configFRTOS_MEMORY_SCHEME==1 /* this scheme does not allow deallocation of memory */
    if (taskListBufferP==NULL) { /* only if not allocated yet */
        taskListBufferP = FRTOS1_pvPortMalloc(bufSize);
    }
#else
    taskListBufferP = FRTOS1_pvPortMalloc(bufSize);
#endif
    if (taskListBufferP != NULL) {
        FRTOS1_vTaskGetRunTimeStats((char*)taskListBufferP, bufSize);
        Shell_SendStr(taskListBufferP, io->stdOut);
#if configFRTOS_MEMORY_SCHEME!=1 /* this scheme does not allow deallocation of memory */
        FRTOS1_vPortFree(taskListBufferP);
#endif
    } else {
        Shell_SendStr((unsigned char*)"\r\n*** out of heap! ***\r\n", io->stdErr);
    }
#endif
    Shell_SendStatusStr((unsigned char*) "  RTOS ticks", (const unsigned char*) "", io->stdOut);
    num16sToStr(buf, sizeof(buf), configTICK_RATE_HZ);
    Shell_SendStr(buf, io->stdOut);
    Shell_SendStr((unsigned char*) " Hz, ", io->stdOut);
    num16sToStr(buf, sizeof(buf), 1000 / configTICK_RATE_HZ);
    Shell_SendStr(buf, io->stdOut);
    Shell_SendStr((unsigned char*) " ms\r\n", io->stdOut);
#if configFRTOS_MEMORY_SCHEME!=3 /* wrapper to malloc() does not have xPortGetFreeHeapSize() */
    Shell_SendStatusStr((unsigned char*) "  Free heap", (const unsigned char*) "", io->stdOut);
    num32uToStr(buf, sizeof(buf), xPortGetFreeHeapSize());
    Shell_SendStr(buf, io->stdOut);
    Shell_SendStr((unsigned char*) " bytes\r\n", io->stdOut);
#endif
    return ERR_OK;
}
예제 #13
0
int csp_sys_tasklist_size(void) {
	return 40 * uxTaskGetNumberOfTasks();
}
예제 #14
0
static portTASK_FUNCTION( vComRxTask, pvParameters )		{
signed char cExpectedByte, cByteRxed;
portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
portBASE_TYPE xGotChar;
int ch, mm=0;
char s[30];

	/* Just to stop compiler warnings. */
	( void ) pvParameters;
	vTaskDelay(1);
	
	//vSerialPutString(xPort, "mulakan\r\n", 9);
	
	init_banner();
	//set_env_default();
	baca_konfig_rom();					// hardware/iap.c
	//load_data_rtc();
	
	cmd_shell();
	st_hw.init++;
	
	#ifdef PAKAI_RTC
		//init_RTC_sh();
		start_uptime();
	#endif
	
	#ifdef PAKAI_SDCARD
		st_hw.sdc = 0;
		//disk_initialize(SDC);
		disk_initialize(0);
		set_fs_mount();
		cek_fs_free();
		//mount_disk(0);		// 0: SDCARD
		//uprintf("Cek Memori SDCARD: ...");
		//cek_free_cluster();
		st_hw.sdc = 1;
	#endif
	
	#ifdef configUSE_IDLE_HOOK
		st_hw.init++;
	#endif

	do	{
		vTaskDelay(100);
	} while (st_hw.init != uxTaskGetNumberOfTasks());
	
	//vTaskDelay(100);
	#ifdef PAKAI_SDCARD
	//uprintf("Cek Memori SDCARD: ...");
	//cek_free_cluster();
	#endif
	vTaskDelay(100);
	sprintf(s, "%s$ ", PROMPT);
	
	
	#ifdef PAKAI_FREERTOS_CLI		// gak jadi pake FreeRTOS-CLI
	uprintf(s);
	vRegisterCLICommands();
	
	for(;;)	{
		//uprintf("Merdeka!!!\r\n");
		//vSerialPutString(xPort, "tes\r\n", 5);
		xGotChar = xSerialGetChar( xPort, &ch, 10 );
		if( xGotChar == pdTRUE )		{
			//if( xSerialGetChar( xPort, &ch, comRX_BLOCK_TIME ) )		{ // comRX_BLOCK_TIME = 0xffff
			//tinysh_char_in((unsigned char) ch);
			toogle_led_utama();
			if ((uchr) ch=='\r')	{
				sprintf(s, "\r\n%s$ ", PROMPT);
				uprintf(s);
			}
		}
		vTaskDelay(10);
	}
	#endif
	
	#ifdef PAKAI_TINYSH
	tinysh_set_prompt(s);
	tinysh_char_in('\r');
	vTaskDelay(500);
	for( ;; )	{
		//vTaskDelay(10);
		//printf("testing\r\n");
		xGotChar = xSerialGetChar( xPort, &ch, 10 );
		
		if( xGotChar == pdTRUE )		{
			tinysh_char_in((unsigned char) ch);
			toogle_led_utama();
		}
		if (st_hw.mm>=120)	{			// cron tiap 1 menit
		//if (st_hw.mm >= 10)	{			// cron tiap 10detik
		//if (st_hw.mm>=2)		{			// cron tiap 1 detik
			st_hw.mm = 0;
			st_hw.uuwaktu++;
			#ifdef PAKAI_FILE_SIMPAN
			simpan_file_data();
			#endif
		}
		
		qrprintf(0);
	}
	#endif	
	
	for( ;; )	{
		vTaskDelay(10);
	}
}
예제 #15
0
#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "unity.h"

static void task_delete_self(void *param)
{
    printf("Task %p running on core %d. Deleting shortly...\n", xTaskGetCurrentTaskHandle(), xPortGetCoreID());
    vTaskDelay(5);
    vTaskDelete(NULL);
}

TEST_CASE("FreeRTOS Delete Tasks", "[freertos]")
{
    uint32_t before_count = uxTaskGetNumberOfTasks();

    xTaskCreatePinnedToCore(task_delete_self, "tsk_self_a", 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0);
    xTaskCreatePinnedToCore(task_delete_self, "tsk_self_a", 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0);
    TEST_ASSERT_EQUAL(before_count + 2, uxTaskGetNumberOfTasks());
    vTaskDelay(200 / portTICK_PERIOD_MS);
    TEST_ASSERT_EQUAL(before_count, uxTaskGetNumberOfTasks());
}
예제 #16
0
static void tsk_extern_del(void *param)
{
    vTaskDelay(portMAX_DELAY);  //Await external deletion
}

static void tsk_self_del_us_delay(void *param)
{
    uint32_t delay = (uint32_t)param;
    ets_delay_us(delay);
    vTaskDelete(NULL);
}

TEST_CASE("FreeRTOS Delete Tasks", "[freertos]")
{
/* -------------- Test vTaskDelete() on currently running tasks ----------------*/
    uint32_t before_count = uxTaskGetNumberOfTasks();
    uint32_t before_heap = heap_caps_get_free_size(HEAP_CAPS);
    for(int i = 0; i < portNUM_PROCESSORS; i++){
        for(int j = 0; j < NO_OF_TSKS; j++){
            TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(tsk_self_del, "tsk_self", 1024, NULL, configMAX_PRIORITIES - 1, NULL, i));
        }
    }
    vTaskDelay(DELAY_TICKS);    //Minimal delay to see if Idle task cleans up all tasks awaiting deletion in a single tick
    TEST_ASSERT_EQUAL(before_count, uxTaskGetNumberOfTasks());
    TEST_ASSERT_EQUAL(before_heap, heap_caps_get_free_size(HEAP_CAPS));

/* ------------- Test vTaskDelete() on not currently running tasks ------------ */
    TaskHandle_t handles[NO_OF_TSKS];
    before_heap = heap_caps_get_free_size(HEAP_CAPS);
    //Create task pinned to the same core that will not run during task deletion
    for(int j = 0 ; j < NO_OF_TSKS; j++){
예제 #17
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
}