コード例 #1
0
void vApplicationIdleHook( void )
{
volatile size_t xFreeStackSpace;

	/* This function is called on each cycle of the idle task.  In this case it
	does nothing useful, other than report the amount of FreeRTOS heap that
	remains unallocated. */
	xFreeStackSpace = xPortGetFreeHeapSize();

	if( xFreeStackSpace > 100 )
	{
		/* By now, the kernel has allocated everything it is going to, so
		if there is a lot of heap remaining unallocated then
		the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
		reduced accordingly. */
	}
}
コード例 #2
0
ファイル: esplisp.c プロジェクト: f0086/esp-lisp
void user_init(void) {
    lastTick = xTaskGetTickCount();
    startMem = lastMem = xPortGetFreeHeapSize();

    sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
    
    setbuf(stdin, NULL);
    setbuf(stdout, NULL);

    // this doesn't have enough stack!
    //lispTask(NULL); return;

    // for now run in a task, in order to allocate a bigger stack
    // 1024 --> (fibo 13)
    // 2048 --> (fibo 30) ???
    xTaskCreate(lispTask, (signed char *)"lispTask", 2048, NULL, 2, NULL);
}
コード例 #3
0
ファイル: main.c プロジェクト: Eclo/FreeRTOS
void vApplicationIdleHook( void )
{
volatile size_t xFreeHeapSpace, xMinimumEverFreeHeapSpace;

	/* This is just a trivial example of an idle hook.  It is called on each
	cycle of the idle task.  It must *NOT* attempt to block.  In this case the
	idle task just queries the amount of FreeRTOS heap that remains.  See the
	memory management section on the http://www.FreeRTOS.org web site for memory
	management options.  If there is a lot of heap memory free then the
	configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
	RAM. */
	xFreeHeapSpace = xPortGetFreeHeapSize();
	xMinimumEverFreeHeapSpace = xPortGetMinimumEverFreeHeapSize();

	/* Remove compiler warning about xFreeHeapSpace being set but never used. */
	( void ) xFreeHeapSpace;
	( void ) xMinimumEverFreeHeapSpace;
}
コード例 #4
0
ファイル: main.c プロジェクト: BuiChien/FreeRTOS-TM4C123GXL
void vApplicationIdleHook( void )
{
volatile size_t xFreeHeapSpace;

	/* This is just a trivial example of an idle hook.  It is called on each
	cycle of the idle task.  It must *NOT* attempt to block.  In this case the
	idle task just queries the amount of FreeRTOS heap that remains.  See the
	memory management section on the http://www.FreeRTOS.org web site for memory
	management options.  If there is a lot of heap memory free then the
	configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
	RAM. */
	xFreeHeapSpace = xPortGetFreeHeapSize();

	/* Remove compiler warning about xFreeHeapSpace being set but never used. */
	( void ) xFreeHeapSpace;

	#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1
	{
		/* If the file system is only going to be accessed from one task then
		F_FS_THREAD_AWARE can be set to 0 and the set of example files is
		created before the RTOS scheduler is started.  If the file system is
		going to be	access from more than one task then F_FS_THREAD_AWARE must
		be set to 1 and the set of sample files are created from the idle task
		hook function. */
		#if F_FS_THREAD_AWARE == 1
		{
			static portBASE_TYPE xCreatedSampleFiles = pdFALSE;

			/* Initialise the drive and file system, then create a few example
			files.  The output from this function just goes to the stdout window,
			allowing the output to be viewed when the UDP command console is not
			connected. */
			if( xCreatedSampleFiles == pdFALSE )
			{
				vCreateAndVerifySampleFiles();
				xCreatedSampleFiles = pdTRUE;
			}
		}
		#endif
	}
	#endif
}
コード例 #5
0
ファイル: debug.c プロジェクト: yangk/FreeRTOS_BOARD_DEMO
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;
}
コード例 #6
0
ファイル: eeprom.c プロジェクト: jlaica/ESP8266-WebRadio
ICACHE_FLASH_ATTR struct shoutcast_info* getStation(uint8_t position) {
	if (position > NBSTATIONS-1) {printf("getStation fails position=%d\n",position); return NULL;}
	uint8_t* buffer = malloc(256);
	while (buffer== NULL)
	{
		buffer = malloc(256);
        if ( buffer == NULL ){
			int i = 0;
			do { 
			i++;		
			printf ("Heap size: %d\n",xPortGetFreeHeapSize( ));
			vTaskDelay(10);
			printf("getstation malloc fails for %d\n",256 );
			}
			while (i<10);
			if (i >=10) { /*free(string);*/ return NULL;}
		} 		
	}
	eeGetData((position+1)*256, buffer, 256);
	return (struct shoutcast_info*)buffer;
}
コード例 #7
0
ファイル: systemmod.c プロジェクト: abdulparis1/OpenPilot
/**
 * Called periodically to update the system stats
 */
static void updateStats()
{
	static portTickType lastTickCount = 0;
	SystemStatsData stats;

	// Get stats and update
	SystemStatsGet(&stats);
	stats.FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
	// POSIX port of FreeRTOS doesn't have xPortGetFreeHeapSize()
	stats.HeapRemaining = 10240;
#else
	stats.HeapRemaining = xPortGetFreeHeapSize();
#endif

	// Get Irq stack status
	stats.IRQStackRemaining = GetFreeIrqStackSize();

	// When idleCounterClear was not reset by the idle-task, it means the idle-task did not run
	if (idleCounterClear) {
		idleCounter = 0;
	}

	portTickType now = xTaskGetTickCount();
	if (now > lastTickCount) {
		uint32_t dT = (xTaskGetTickCount() - lastTickCount) * portTICK_RATE_MS;	// in ms
		stats.CPULoad =
			100 - (uint8_t) round(100.0 * ((float)idleCounter / ((float)dT / 1000.0)) / (float)IDLE_COUNTS_PER_SEC_AT_NO_LOAD);
	} //else: TickCount has wrapped, do not calc now
	lastTickCount = now;
	idleCounterClear = 1;
	
#if defined(PIOS_INCLUDE_ADC) && defined(PIOS_ADC_USE_TEMP_SENSOR)
	float temp_voltage = 3.3 * PIOS_ADC_PinGet(0) / ((1 << 12) - 1);
	const float STM32_TEMP_V25 = 1.43; /* V */
	const float STM32_TEMP_AVG_SLOPE = 4.3; /* mV/C */
	stats.CPUTemp = (temp_voltage-STM32_TEMP_V25) * 1000 / STM32_TEMP_AVG_SLOPE + 25;
#endif
	SystemStatsSet(&stats);
}
コード例 #8
0
ファイル: main.c プロジェクト: code-constructor/openbeacon
static void serial_task(void *handle)
{
	int i;
	(void) handle;
	portCHAR data;

	vTasksRunning = TRUE;

	i = 0;
	for (;;)
	{
		debug_printf("%04i: Hello Task! (%04i bytes free heap memory)\n", i++,
				xPortGetFreeHeapSize());

		GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		vTaskDelay(10 / portTICK_RATE_MS);
		GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);

		while (vUSBRecvByte(&data, sizeof(data), 990))
			UARTSendChar(data);
	}
}
コード例 #9
0
STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
    // FreeRTOS info
    {
        printf("---------------------------------------------\n");
        printf("FreeRTOS\n");
        printf("---------------------------------------------\n");
        printf("Total heap: %u\n", configTOTAL_HEAP_SIZE);
        printf("Free heap: %u\n", xPortGetFreeHeapSize());
        printf("MpTask min free stack: %u\n", (unsigned int)uxTaskGetStackHighWaterMark((TaskHandle_t)mpTaskHandle));
        printf("ServersTask min free stack: %u\n", (unsigned int)uxTaskGetStackHighWaterMark((TaskHandle_t)svTaskHandle));
        printf("SlTask min free stack: %u\n", (unsigned int)uxTaskGetStackHighWaterMark(xSimpleLinkSpawnTaskHndl));
        printf("IdleTask min free stack: %u\n", (unsigned int)uxTaskGetStackHighWaterMark(xTaskGetIdleTaskHandle()));

        uint32_t *pstack = (uint32_t *)&_stack;
        while (*pstack == 0x55555555) {
            pstack++;
        }
        printf("MAIN min free stack: %u\n", pstack - ((uint32_t *)&_stack));
        printf("---------------------------------------------\n");
    }

    return mp_const_none;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: boutboutnico/femtin
int main(int argc, char* argv[])
{
	// At this stage the system clock should have already been configured
	// at high speed.

#if !USE_WRAPPER
	xTaskCreate(task_led4, (const char * ) "Led4", configMINIMAL_STACK_SIZE, NULL, TASK_LED4_PRIO,
			NULL);

	xTaskCreate(task_led3, (const char * ) "Led3", configMINIMAL_STACK_SIZE, NULL, TASK_LED3_PRIO,
			&handle_led3);

#else
	static TSK_T1 tsk_t1;
	static TSK_T2 tsk_t2;

	tsk_t1.link(tsk_t2);

#endif

	volatile size_t size = xPortGetFreeHeapSize();

	vTaskStartScheduler();    // should never return
}
コード例 #11
0
ファイル: main.c プロジェクト: peterliu2/FreeRTOS
static void prvLCDTask( void *pvParameters )
{
    xQueueMessage xReceivedMessage;
    long lLine = Line1;
    const long lFontHeight = (((sFONT *)LCD_GetFont())->Height);

    /* Buffer into which strings are formatted and placed ready for display on the
    LCD.  Note this is a static variable to prevent it being allocated on the task
    stack, which is too small to hold such a variable.  The stack size is configured
    when the task is created. */
    static char cBuffer[ 512 ];

    /* This function is the only function that uses printf().  If printf() is
    used from any other function then some sort of mutual exclusion on stdout
    will be necessary.

    This is also the only function that is permitted to access the LCD.

    First print out the number of bytes that remain in the FreeRTOS heap.  This
    can be viewed in the terminal IO window within the IAR Embedded Workbench. */
    printf( "%d bytes of heap space remain unallocated\n", xPortGetFreeHeapSize() );

    for( ;; ) {
        /* Wait for a message to be received.  Using portMAX_DELAY as the block
        time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
        set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
        function return value and the function will only return when a value
        has been received. */
        xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

        /* Clear the LCD if no room remains for any more text output. */
        if( lLine > Line9 ) {
            LCD_Clear( Blue );
            lLine = 0;
        }

        /* What is this message?  What does it contain? */
        switch( xReceivedMessage.cMessageID ) {
            case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
                sprintf( cBuffer, "Button up = %d", xReceivedMessage.lMessageValue );
                break;

            case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button was pressed.
												Generate a table of task run time
												statistics and output this to
												the terminal IO window in the IAR
												embedded workbench. */
                printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );
                vTaskGetRunTimeStats( cBuffer );
                printf( cBuffer );

                /* Also print out a message to
                the LCD - in this case the
                pointer to the string to print
                is sent directly in the
                lMessageValue member of the
                message.  This just demonstrates
                a different communication
                technique. */
                sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.lMessageValue );
                break;

            case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
                prvGenerateStatusMessage( cBuffer, xReceivedMessage.lMessageValue );
                break;

            default							:
                sprintf( cBuffer, "Unknown message" );
                break;
        }

        /* Output the message that was placed into the cBuffer array within the
        switch statement above. */
        LCD_DisplayStringLine( lLine, ( uint8_t * ) cBuffer );

        /* Move onto the next LCD line, ready for the next iteration of this
        loop. */
        lLine += lFontHeight;
    }
}
コード例 #12
0
static void prvLCDTask( void *pvParameters )
{
    xQueueMessage xReceivedMessage;

    /* Buffer into which strings are formatted and placed ready for display on the
    LCD.  Note this is a static variable to prevent it being allocated on the task
    stack, which is too small to hold such a variable.  The stack size is configured
    when the task is created. */
    static char cBuffer[ 512 ];
    unsigned char ucLine = 1;


    /* This function is the only function that uses printf().  If printf() is
    used from any other function then some sort of mutual exclusion on stdout
    will be necessary.

    This is also the only function that is permitted to access the LCD.

    First print out the number of bytes that remain in the FreeRTOS heap.  This
    can be viewed in the terminal IO window within the IAR Embedded Workbench. */
    printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() );

    /* Just as a test of the port, and for no functional reason, check the task
    parameter contains its expected value. */
    if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
    {
        halLcdPrintLine( "Invalid parameter", ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }

    for( ;; )
    {
        /* Wait for a message to be received.  Using portMAX_DELAY as the block
        time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
        set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
        function return value and the function will only return when a value
        has been received. */
        xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

        /* Clear the LCD if no room remains for any more text output. */
        if( ucLine > mainMAX_LCD_LINES )
        {
            halLcdClearScreen();
            ucLine = 0;
        }

        /* What is this message?  What does it contain? */
        switch( xReceivedMessage.cMessageID )
        {
        case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
            sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button was pressed.
												Generate a table of task run time
												statistics and output this to
												the terminal IO window in the IAR
												embedded workbench. */
            printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );
            vTaskGetRunTimeStats( ( signed char * ) cBuffer );
            printf( cBuffer );

            /* Also print out a message to
            the LCD - in this case the
            pointer to the string to print
            is sent directly in the
            ulMessageValue member of the
            message.  This just demonstrates
            a different communication
            technique. */
            sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
            break;

        case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
            prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
            break;

        default							:
            sprintf( cBuffer, "Unknown message" );
            break;
        }

        /* Output the message that was placed into the cBuffer array within the
        switch statement above, then move onto the next line ready for the next
        message to arrive on the queue. */
        halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
        ucLine++;
    }
}
コード例 #13
0
ファイル: rs485.c プロジェクト: FlameN/STM32RUNO
void vRs485Task(void *pvParameters)
{
	int bufsize = 512;
	uint8 buffer[bufsize];
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	uart3Init(9600/2);

	//xComPortHandle porthandle =  xSerialPortInitMinimal(9600,1024);
	buffer[0]='W';
	buffer[1]='A';
	buffer[2]='R';
	buffer[3]='E';
	buffer[4]='F';
	GPIO_ResetBits(GPIOB, GPIO_Pin_14);
int heapSize = 0;
		while (1)
			{

			heapSize = xPortGetFreeHeapSize();
			heapSize +=0;

			if (AskConunter())
			    {
			    vTaskDelay(10);

			    }
			else
			    {

			    rs485size = iecProcExitPacket(rs485buf);
			    GPIO_SetBits(GPIOB, GPIO_Pin_14);
			    vTaskDelay(1);
			    processBuffer8to7(rs485buf,rs485size);
			    uart3Write ((uint8*) rs485buf, rs485size);
			    vTaskDelay(300);
			    vTaskDelay(20);
			    }
			}

		/*
		signed char bufvar = 0;
		  while (1)
		    {
				  int cnt = uart3Read(buffer,bufsize);
				  vTaskDelay(10);
				  GPIO_SetBits(GPIOB, GPIO_Pin_14);
				  vTaskDelay(2);
				  if(cnt>0)
				  {
					 uart3Write(buffer,cnt);
					 //vTaskDelay(10);
					 //uart3Write(&buffer[1],1);
					 //uart3Write(&buffer[2],1);
				  }
				  vTaskDelay(5);
				  GPIO_ResetBits(GPIOB, GPIO_Pin_14);
				  vTaskDelay(10);
		    }
*/
}
コード例 #14
0
	static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
	{
		/* Remove compile time warnings about unused parameters, and check the
		write buffer is not NULL.  NOTE - for simplicity, this example assumes the
		write buffer length is adequate, so does not check for buffer overflows. */
		( void ) pcCommandString;
		( void ) xWriteBufferLen;
		configASSERT( pcWriteBuffer );

		sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );

		/* There is no more data to return after this single string, so return
		pdFALSE. */
		return pdFALSE;
	}
コード例 #15
0
ファイル: mm.c プロジェクト: gabrielrezzonico/canopus
static retval_t cmd_get_telemetry_beacon(const subsystem_t *self, frame_t * iframe, frame_t * oframe) {
	frame_put_u32(oframe, xPortGetFreeHeapSize());
    FUTURE_HOOK_2(mm_cmd_get_telemetry_beacon, iframe, oframe);

	return RV_SUCCESS;
}
コード例 #16
0
ファイル: commands.c プロジェクト: ilikecake/network-analyzer
		resp = ReadBootVersion(tempVal);
		if(resp == IAP_CMD_SUCCESS)
		{
			printf("Boot Code Version: %u.%u\r\n", (uint8_t)((tempVal[0]>>8)&0xFF), (uint8_t)(tempVal[0]&0xFF));
		}

		printf("----------------------------\r\n");
		printf("Task Name\tStack Usage\r\n");
		printf("----------------------------\r\n");
		printf("vTaskLed1\t%u/64\r\n", 64-uxTaskGetStackHighWaterMark(TaskList[0]));
		printf("vConsole\t%u/300\r\n", 300-uxTaskGetStackHighWaterMark(TaskList[1]));
		printf("vOLEDTask\t%u/200\r\n", 200-uxTaskGetStackHighWaterMark(TaskList[2]));
		printf("vTimer\t\t%u/150\r\n", 150-uxTaskGetStackHighWaterMark(TaskList[3]));
		printf("----------------------------\r\n");
		printf("Free Heap Space: %u\r\n", xPortGetFreeHeapSize());

		printf("Compile Time: %s, %s\r\n", __DATE__, __TIME__);
	}

	return 0;
}


//i2cscan
static int _F3_Handler (void)
{
	i2c_probe_slaves(I2C0);
	return 0;
}
コード例 #17
0
void systemTask(void *arg)
{
  bool pass = true;

  ledInit();
  ledSet(CHG_LED, 1);

#ifdef DEBUG_QUEUE_MONITOR
  queueMonitorInit();
#endif

  uartInit();
#ifdef ENABLE_UART1
  uart1Init();
#endif
#ifdef ENABLE_UART2
  uart2Init();
#endif

  //Init the high-levels modules
  systemInit();

#ifndef USE_RADIOLINK_CRTP
#ifdef UART_OUTPUT_TRACE_DATA
  //debugInitTrace();
#endif
#ifdef ENABLE_UART
//  uartInit();
#endif
#endif //ndef USE_RADIOLINK_CRTP

  commInit();
  commanderAdvancedInit();
  stabilizerInit();
#ifdef PLATFORM_CF2
  deckInit();
  #endif
  soundInit();
  memInit();

#ifdef PROXIMITY_ENABLED
  proximityInit();
#endif

  //Test the modules
  pass &= systemTest();
  pass &= configblockTest();
  pass &= commTest();
  pass &= commanderAdvancedTest();
  pass &= stabilizerTest();
#ifdef PLATFORM_CF2
  pass &= deckTest();
  #endif
  pass &= soundTest();
  pass &= memTest();
  pass &= watchdogNormalStartTest();

  //Start the firmware
  if(pass)
  {
    selftestPassed = 1;
    systemStart();
    soundSetEffect(SND_STARTUP);
    ledseqRun(SYS_LED, seq_alive);
    ledseqRun(LINK_LED, seq_testPassed);
  }
  else
  {
    selftestPassed = 0;
    if (systemTest())
    {
      while(1)
      {
        ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed!
        vTaskDelay(M2T(2000));
        // System can be forced to start by setting the param to 1 from the cfclient
        if (selftestPassed)
        {
	        DEBUG_PRINT("Start forced.\n");
          systemStart();
          break;
        }
      }
    }
    else
    {
      ledInit();
      ledSet(SYS_LED, true);
    }
  }
  DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize());

  workerLoop();

  //Should never reach this point!
  while(1)
    vTaskDelay(portMAX_DELAY);
}
コード例 #18
0
 void onAccept()
 {
     os_printf("Accept, port:%d!\n", port);
     uint16_t remainingHeap = xPortGetFreeHeapSize();
     os_printf("on accept: remaining heap: %dB!\n", remainingHeap / 10);
 }
コード例 #19
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;
}
コード例 #20
0
ファイル: ml-http2.c プロジェクト: iamblue/ml-http2
        nghttp2_session_del(connection.session);

        mbedtls_ssl_close_notify( &(pclient->ssl) );
        mbedtls_net_free( &pclient->fd );
        mbedtls_x509_crt_free( &(ssl_config->verify_source.cacertl) );
        mbedtls_ssl_free( &(pclient->ssl) );
        mbedtls_ssl_config_free( &(ssl_config->conf) );
        mbedtls_ctr_drbg_free(&ctr_drbg);
        mbedtls_entropy_free(&entropy);

        request_free(&req);
        return 0;

    }
    printf("nghttp2client_test_entry begin!\r\n");
    mfs = xPortGetFreeHeapSize();
    printf("mfs 1 =%d\r\n", mfs);

    memset(&ssl, 0, sizeof(http2_ssl_custom_conf_t));

    parse_uri(&uri, url_buffer);

    ret = nghttp2client_connect(&client, url_buffer, HTTPS_PORT, &ssl, &uri);

    mfs = xPortGetFreeHeapSize();
    printf("mfs 2 =%d\r\n", mfs);

    if(ret != 0)
    {

        void http11client_test_entry(char* url_path)
コード例 #21
0
ファイル: main_full.c プロジェクト: AlexShiLucky/freertos
static void prvCheckTask( void *pvParameters )
{
TickType_t xNextWakeTime;
const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );

	/* Just to remove compiler warning. */
	( void ) pvParameters;

	/* Initialise xNextWakeTime - this only needs to be done once. */
	xNextWakeTime = xTaskGetTickCount();

	for( ;; )
	{
		/* Place this task in the blocked state until it is time to run again. */
		vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );

		/* Check the standard demo tasks are running without error. */
		#if( configUSE_PREEMPTION != 0 )
		{
			/* These tasks are only created when preemption is used. */
			if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
			{
				pcStatusMessage = "Error: TimerDemo";
			}
		}
		#endif

		if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error:  Notification";
		}

		if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: IntSem";
		}
		else if( xAreEventGroupTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: EventGroup";
		}
		else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: IntMath";
		}
		else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: GenQueue";
		}
		else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: QueuePeek";
		}
		else if( xAreBlockingQueuesStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: BlockQueue";
		}
		else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: SemTest";
		}
		else if( xArePollingQueuesStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: PollQueue";
		}
		else if( xAreMathsTaskStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Flop";
		}
		else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: RecMutex";
		}
		else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: CountSem";
		}
		else if( xIsCreateTaskStillRunning() != pdTRUE )
		{
			pcStatusMessage = "Error: Death";
		}
		else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Dynamic";
		}
		else if( xAreQueueSetTasksStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Queue set";
		}
		else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Queue overwrite";
		}
		else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Queue set polling";
		}
		else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Block time";
		}
		else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
		{
			pcStatusMessage = "Error: Abort delay";
		}

		#if( configSUPPORT_STATIC_ALLOCATION == 1 )
			else if( xAreStaticAllocationTasksStillRunning() != pdPASS )
			{
				pcStatusMessage = "Error: Static allocation";
			}
		#endif /* configSUPPORT_STATIC_ALLOCATION */

		/* This is the only task that uses stdout so its ok to call printf()
		directly. */
		printf( "%s - tick count %d - free heap %d - min free heap %d\r\n", pcStatusMessage,
																			xTaskGetTickCount(),
																			xPortGetFreeHeapSize(),
																			xPortGetMinimumEverFreeHeapSize() );
	}
}
コード例 #22
0
void systemTask(void *arg)
{
  bool pass = true;
  
  ledInit();
  ledSet(CHG_LED, 1);

  uartInit();
  //Init the high-levels modules
  systemInit();

#ifndef USE_RADIOLINK_CRTP
#ifdef UART_OUTPUT_TRACE_DATA
  //debugInitTrace();
#endif
#ifdef ENABLE_UART
//  uartInit();
#endif
#endif //ndef USE_RADIOLINK_CRTP

  commInit();

  DEBUG_PRINT("----------------------------\n");
  DEBUG_PRINT("Crazyflie is up and running!\n");
  DEBUG_PRINT("Build %s:%s (%s) %s\n", V_SLOCAL_REVISION,
              V_SREVISION, V_STAG, (V_MODIFIED)?"MODIFIED":"CLEAN");
  DEBUG_PRINT("I am 0x%X%X%X and I have %dKB of flash!\n",
              *((int*)(MCU_ID_ADDRESS+8)), *((int*)(MCU_ID_ADDRESS+4)),
              *((int*)(MCU_ID_ADDRESS+0)), *((short*)(MCU_FLASH_SIZE_ADDRESS)));

  commanderInit();
  stabilizerInit();
  expbrdInit();
  memInit();
  
  //Test the modules
  pass &= systemTest();
  pass &= configblockTest();
  pass &= commTest();
  pass &= commanderTest();
  pass &= stabilizerTest();
  pass &= expbrdTest();
  pass &= memTest();
  
  //Start the firmware
  if(pass)
  {
    selftestPassed = 1;
    systemStart();
    ledseqRun(SYS_LED, seq_alive);
    ledseqRun(LINK_LED, seq_testPassed);
  }
  else
  {
    selftestPassed = 0;
    if (systemTest())
    {
      while(1)
      {
        ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed!
        vTaskDelay(M2T(2000));
        // System can be forced to start by setting the param to 1 from the cfclient
        if (selftestPassed)
        {
	        DEBUG_PRINT("Start forced.\n");
          systemStart();
          break;
        }
      }
    }
    else
    {
      ledInit();
      ledSet(SYS_LED, true);
    }
  }
  DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize());
  
  workerLoop();
  
  //Should never reach this point!
  while(1)
    vTaskDelay(portMAX_DELAY);
}
コード例 #23
0
#include "wear_levelling.h"
#include "test_utils.h"
#include "freertos/FreeRTOS.h"
#include "freertos/portable.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp32/clk.h"
#include "soc/cpu.h"

TEST_CASE("wl_unmount doesn't leak memory", "[wear_levelling]")
{
    const esp_partition_t *partition = get_test_data_partition();
    wl_handle_t handle;
    // dummy unmount is needed to initialize static lock in WL
    wl_unmount(WL_INVALID_HANDLE);
    size_t size_before = xPortGetFreeHeapSize();
    TEST_ESP_OK(wl_mount(partition, &handle));
    wl_unmount(handle);
    size_t size_after = xPortGetFreeHeapSize();

    // Original code:
    //TEST_ASSERT_EQUAL_HEX32(size_before, size_after);
    // Workaround for problem with heap size calculation:
    ptrdiff_t stack_diff = size_before - size_after; 
    stack_diff = abs(stack_diff);
    if (stack_diff > 8) TEST_ASSERT_EQUAL(0, stack_diff);
}

TEST_CASE("wl_mount check partition parameters", "[wear_levelling][ignore]")
{
    const esp_partition_t *test_partition = get_test_data_partition();
コード例 #24
0
void systemTask(void *arg)
{
  bool pass = true;

  ledInit();
  ledSet(CHG_LED, 1);

#ifdef DEBUG_QUEUE_MONITOR
  queueMonitorInit();
#endif

#ifdef ENABLE_UART1
  uart1Init();
#endif
#ifdef ENABLE_UART2
  uart2Init();
#endif

  //Init the high-levels modules
  systemInit();
  commInit();
  commanderInit();

  StateEstimatorType estimator = anyEstimator;
  deckInit();
  estimator = deckGetRequiredEstimator();
  stabilizerInit(estimator);
  if (deckGetRequiredLowInterferenceRadioMode())
  {
    platformSetLowInterferenceRadioMode();
  }
  soundInit();
  memInit();

#ifdef PROXIMITY_ENABLED
  proximityInit();
#endif

  //Test the modules
  pass &= systemTest();
  pass &= configblockTest();
  pass &= commTest();
  pass &= commanderTest();
  pass &= stabilizerTest();
  pass &= deckTest();
  pass &= soundTest();
  pass &= memTest();
  pass &= watchdogNormalStartTest();

  //Start the firmware
  if(pass)
  {
    selftestPassed = 1;
    systemStart();
    soundSetEffect(SND_STARTUP);
    ledseqRun(SYS_LED, seq_alive);
    ledseqRun(LINK_LED, seq_testPassed);
  }
  else
  {
    selftestPassed = 0;
    if (systemTest())
    {
      while(1)
      {
        ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed!
        vTaskDelay(M2T(2000));
        // System can be forced to start by setting the param to 1 from the cfclient
        if (selftestPassed)
        {
	        DEBUG_PRINT("Start forced.\n");
          systemStart();
          break;
        }
      }
    }
    else
    {
      ledInit();
      ledSet(SYS_LED, true);
    }
  }
  DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize());

  workerLoop();

  //Should never reach this point!
  while(1)
    vTaskDelay(portMAX_DELAY);
}
コード例 #25
0
ファイル: main.c プロジェクト: testing-ishita/test2
/*****************************************************************************
 * c_entry: this is our main() function, called from boot_prot.S
 *
 * RETURNS: None
 */
__attribute__((regparm(0))) void c_entry (void)
{
	xTaskHandle xHandle;
	UINT8   	i=0,bFlag = 0;
    UINT16		port, baud = 0;
    NV_RW_Data	nvdata;
#ifdef INCLUDE_DEBUG_VGA
    char achBuffer[80];
#endif
    

#if 0 /* Not used, HAL no longer present */

	/*
	 * Register the local service provider now, as code will be using BIT
	 * services for PCI accesses.
	 */

	cctRegisterServiceProvider (cctServiceProvider);
#endif

	/*
	 * Key sub-system initialisation
	 */

	sysMmuInitialize ();				/* Initialise the local page table management */
	sysInitMalloc (K_HEAP, U_HEAP);		/* Initialise the heap management */

#ifdef INCLUDE_EXCEPTION_DEBUG
	dbgInstallExceptionHandlers();
#endif

#ifdef INCLUDE_DBGLOG	
	dbgLogInit();
#endif

	/*Initialise the mutexes so that we can start using the public functions*/
	for(i=0; i < MAX_CUTEBIT_MUTEX; i++)
	{
		globalMutexPool[i]=xSemaphoreCreateMutex();

		if( globalMutexPool[i] == NULL )
		{
			/*We should not get here, die...*/
			while(1);
		}
	}

	/*
	 * Search and parse BIOS_INFO and  EXTENDED_INFO structures
	 */
	board_service(SERVICE__BRD_GET_BIOS_INFO,     NULL, &dBiosInfo_addr);
	board_service(SERVICE__BRD_GET_EXTENDED_INFO, NULL, NULL);


	/*
	 * Open/close the debug channel and sign-on - we can't use vDebugWrite() this
	 * early, so make direct calls to sysDebug...
	 */
	if(bStartupDebugMode())
	{
		sysDebugWriteString ("\n[Debugging Enabled]\n");
		
		if(sysIsDebugopen())
		{
			if(board_service(SERVICE__BRD_GET_FORCE_DEBUG_OFF, NULL, NULL) == E__OK)
			{	
				sysDebugWriteString ("[Debugging Forced Off]\n");
				sysDebugClose();
			}
		}
	}
	else if( board_service(SERVICE__BRD_GET_FORCE_DEBUG_ON, NULL, NULL) == E__OK )
	{
		sysDebugWriteString ("[Debugging Forced On]\n");
		bForceStartupDebugMode();
		sysDebugOpen();
	}
	
	sysDebugFlush ();
	
#ifdef INCLUDE_DEBUG_VGA
	vgaDisplayInit();
	vgaSetCursor( CURSOR_OFF );
#endif

	sysDebugWriteString ("Starting HW Initialization\n");
	board_service(SERVICE__BRD_HARDWARE_INIT, NULL, NULL); /* board-specific H/W initialisation */

	if(board_service(SERVICE__BRD_GET_CONSOLE_PORT, NULL, &port) == E__OK)
	{
		baud = bGetBaudRate();
		//baud = 0; //hard coded by Rajan. Need to remove after debug
		sysSccInit (port, baud);
		
#ifdef INCLUDE_DEBUG_VGA
		sprintf( achBuffer, "Console open, port: 0x%x baud: %u\n", port, baud );
		vgaPutsXY( 0, startLine++, achBuffer );
		
#endif
	}

	if(board_service(SERVICE__BRD_GET_DEBUG_PORT, NULL, &port) == E__OK)
	{

//#ifdef commented by Rajan. Need to uncomment after debug
//#ifdef INCLUDE_DEBUG_PORT_INIT
			baud = bGetBaudRate();
            baud = 0; //hard coded by Rajan. Need to remove after debug
			sysSccInit (port, baud);
//#endif

#ifdef INCLUDE_DEBUG_VGA			
			sprintf( achBuffer, "Debug %s,   port: 0x%x baud: %u\n", 
						(sysIsDebugopen()? "open":"closed"), port, baud );
			vgaPutsXY( 0, startLine++, achBuffer );
#endif		
	}


#ifdef INCLUDE_MAIN_DEBUG
	{	
		UINT32 temp = 0;
		
		board_service(SERVICE__BRD_GET_MAX_DRAM_BELOW_4GB, NULL, &temp);
		DBLOG( "Max DRAM below 4GB: 0x%08x\n", temp );
	}
#endif

#if	defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE)
	#if defined(VPX)
		vpxPreInit();
	#endif

	#if defined(CPCI)
		board_service(SERVICE__BRD_CHECK_CPCI_IS_SYSCON,NULL,&bFlag);
		cpciPreInit(bFlag);
	#endif

	board_service(SERVICE__BRD_CONFIGURE_VXS_NT_PORTS, NULL, NULL);
#endif

#if defined (SRIO)

	sysDebugWriteString ("Initializing: SRIO\n");
	
	for (i = 1 ; i < MAX_TSI721_DEVS; i++)
	{
	   srioPreInit (i);
	}

#endif

#ifndef CPCI
	if (!bFlag)
		vDelay(2000);// delay added, so pmc160 will show up!
#endif

	sysDebugWriteString ("Initializing: PCI\n");
	sysPciInitialize ();		/* (re)scan PCI and allocate resources */

	sysDebugWriteString ("Rajan--> Step1\n");


#if	defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE)
	#if defined (VME) && defined (INCLUDE_LWIP_SMC)
		// pci bus enumeration must have been run
		InitialiseVMEDevice();
	#endif
#endif

	sysDebugWriteString ("Rajan--> Step2\n");


#ifdef INCLUDE_DEBUG_VGA
	vgaPutsXY( 0, startLine, "FreeRTOS starting....\n\n" );
	startLine += 2;
#endif

	board_service(SERVICE__BRD_POST_SCAN_INIT, NULL, NULL); // post scan H/W initialisations
	board_service(SERVICE__BRD_ENABLE_SMIC_LPC_IOWINDOW, NULL, NULL); /* board-specific smic Initialization */
	/*
	 * Having got this far, clear the load error that we've been holding in CMOS
	 */
	nvdata.dNvToken = NV__TEST_NUMBER;
	nvdata.dData    = 0;
	board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata);

	nvdata.dNvToken = NV__ERROR_CODE;
	nvdata.dData    = E__BOARD_HANG;
	board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata);

	
#ifdef INCLUDE_MAIN_DEBUG
	DBLOG( "CUTE/BIT Kernel heap: 0x%08x-0x%08x\n", (UINT32)K_HEAP, ((UINT32)K_HEAP + HEAP_SIZE - 1) );
	DBLOG( "CUTE/BIT User heap  : 0x%08x-0x%08x\n", (UINT32)U_HEAP, ((UINT32)U_HEAP + HEAP_SIZE - 1) );
	
	xPortGetFreeHeapSize();
#endif

	
	/* Initialise task data */
	vTaskDataInit( bCpuCount );
	
	/* Initialise PCI shared interrupt handling */
	pciIntInit();

#ifdef INCLUDE_MAIN_DEBUG	
	pciListDevs( 0 );
#endif
	
	/* Create and start the network */
	sysDebugWriteString ("Initializing: Network\n");
	networkInit();

#if defined(SRIO)
	sysDebugWriteString ("Initializing: TSI721\n");
	
	for (i = 1 ; i < MAX_TSI721_DEVS; i++)
	{
		tsi721_init(i);
	}

	rio_init_mports();
	
#endif

	// some boards may not reset the RTC cleanly
	board_service(SERVICE__BRD_INIT_RTC, NULL, NULL);

#ifdef INCLUDE_DEMO_TASKS
	
	randMutex = xSemaphoreCreateMutex();
	if (randMutex == NULL)
	{
		sysDebugWriteString ("Error - Failed to create rand mutex\n");
	}
	else
	{
		for (i = 0; i < bCpuConfigured; i++)
		{
			tParam[i].taskNum = i + 1;
			sprintf( tParam[i].taskName, "Demo%u", tParam[i].taskNum );
			xTaskCreate( i, vTaskCodePeriodic, tParam[i].taskName, mainDEMO_STACK_SIZE, 
						&tParam[i],	mainDEMO_TASK_PRIORITY, &xHandle );
		}
		
		tParam[i].taskNum = i + 1;
		sprintf( tParam[i].taskName, "BKGRD" );	
		xTaskCreate( 0, vTaskCodeBackground, tParam[i].taskName, mainDEMO_STACK_SIZE, 
						&tParam[i],	mainDEMO_TASK_PRIORITY+1, &xHandle );
	}						
#endif

	sysDebugWriteString ("Creating CUTE task\n");
	xTaskCreate( 0, startCuteBit, "CuteBitTask", mainCUTEBIT_TASK_STACKSIZE,
			NULL, mainCUTEBIT_TASK_PRIORITY, &xHandle );

#ifdef INCLUDE_MAIN_DEBUG
	sysDebugWriteString ("\n[Starting FreeRtos Scheduler]\n");
	sysDebugFlush ();
#endif


	sysInvalidateTLB();

	/* Start the FreeRTOS Scheduler, does not return */
	vTaskStartScheduler();

} /* c_entry () */
コード例 #26
0
ファイル: system_tasks.c プロジェクト: xuezhongbo/gateway
/*******************************************************************************
  Function:
    void _SYS_Tasks ( void )

  Summary:
    Maintains state machines of system modules.
*/
static void _SYS_Tasks ( void)
{
    TIMEOUT_THREAD_0_START;
    while(1)
    {
        /* Maintain system services */
        SYS_DEVCON_Tasks(sysObj.sysDevcon);
        /* Maintain the file system state machine. */
        SYS_FS_Tasks();
        SYS_CONSOLE_Tasks(sysObj.sysConsole0);
        /* SYS_COMMAND layer tasks routine */ 
        SYS_CMD_Tasks();
        /* SYS_TMR Device layer tasks routine */ 
        SYS_TMR_Tasks(sysObj.sysTmr);

        /* Maintain Device Drivers */
        DRV_SST25VF064C_Tasks(sysObj.drvSst25vf064c0);
        DRV_SDCARD_Tasks(sysObj.drvSDCard);

        /* Maintain Middleware */
        NET_PRES_Tasks(sysObj.netPres);
        /* Maintain the TCP/IP Stack*/

        wdt_arm_thread_0();
        wdt_kick();
        if(TIMEOUT_THREAD_0(10))
        {
            TIMEOUT_THREAD_0_START;
            SYS_DEBUG(SYS_ERROR_INFO, "MON: SYS Stack size: %d\r\n",uxTaskGetStackHighWaterMark(NULL));
            size_t libc_heap_usage_total = TrackHeap_TotalUsage();
            size_t libc_heap_usage_max = TrackHeap_MaxUsage();
            SYS_DEBUG(SYS_ERROR_INFO, "MON: heap usage: %dKB (%dKB), free: %dKB\r\n", libc_heap_usage_total / 1024, libc_heap_usage_max / 1024,xPortGetFreeHeapSize() / 1024);
        }
        /* Task Delay */
        vTaskDelay(1 / portTICK_PERIOD_MS);
    }
}
コード例 #27
0
ファイル: main.c プロジェクト: rballis/up4dar-os
static void vServiceTask( void *pvParameters )
{
	
	int last_backlight = -1;
	int last_contrast = -1;
	char last_repeater_mode = 0;
	char last_parrot_mode = 0;
	char dcs_boot_timer = 8;
	// bool update = true;
	bool last_rmu_enabled = false;

	for (;;)
	{	
		
		vTaskDelay(500); 
		
		// gpio_toggle_pin(AVR32_PIN_PB28);
		//gpio_toggle_pin(AVR32_PIN_PB18);
			
		// x_counter ++;
			
		
		// rtclock_disp_xy(84, 0, x_counter & 0x02, 1);
		rtclock_disp_xy(84, 0, 2, 1);
			
			
			
		vdisp_i2s( tmp_buf, 5, 10, 0, voltage);
		tmp_buf[3] = tmp_buf[2];
		tmp_buf[2] = '.';
		tmp_buf[4] = 'V';
		tmp_buf[5] = 0;
			
			
		vdisp_prints_xy( 55, 0, VDISP_FONT_4x6, 0, tmp_buf );
			
		// vdisp_i2s( tmp_buf, 5, 10, 0, serial_rx_error );
		// vd_prints_xy(VDISP_DEBUG_LAYER, 108, 28, VDISP_FONT_4x6, 0, tmp_buf );
		vdisp_i2s( tmp_buf, 5, 10, 0, serial_rx_ok );
		vd_prints_xy(VDISP_DEBUG_LAYER, 108, 34, VDISP_FONT_4x6, 0, tmp_buf );	
		// vdisp_i2s( tmp_buf, 5, 10, 0, serial_timeout_error );
		vdisp_i2s( tmp_buf, 5, 10, 0, dstar_pos_not_correct );
		vd_prints_xy(VDISP_DEBUG_LAYER, 108, 40, VDISP_FONT_4x6, 0, tmp_buf );
		vdisp_i2s( tmp_buf, 5, 10, 0, serial_putc_q_full );
		vd_prints_xy(VDISP_DEBUG_LAYER, 108, 46, VDISP_FONT_4x6, 0, tmp_buf );
		vdisp_i2s( tmp_buf, 5, 10, 0, initialHeapSize );
		vd_prints_xy(VDISP_DEBUG_LAYER, 108, 52, VDISP_FONT_4x6, 0, tmp_buf );
		vdisp_i2s( tmp_buf, 5, 10, 0, xPortGetFreeHeapSize() );
		vd_prints_xy(VDISP_DEBUG_LAYER, 108, 58, VDISP_FONT_4x6, 0, tmp_buf );
		
		
		int v = 0;
			
		switch (eth_autoneg_state)
		{
			case 0:
			if (SETTING_BOOL(B_ONLY_TEN_MBIT))
			{
				AVR32_MACB.man = 0x50920061; // write register 0x04, advertise only 10MBit/s for autoneg
			}
			eth_autoneg_state = 1;
			break;
			
			case 1:
			AVR32_MACB.man = 0x50821200; // write register 0x00, power on, autoneg, restart autoneg
			eth_autoneg_state = 2;
			break;
			
			case 2:
			AVR32_MACB.man = 0x60C20000; // read register 0x10
			eth_autoneg_state = 3;
			break;
			
			case 3:
			v = AVR32_MACB.MAN.data; // read data from previously read register 0x10
			AVR32_MACB.man = 0x60C20000; // read register 0x10
			break;
		}
		
		dvset();
		nodeinfo_print();
				
		if (last_rmu_enabled != rmu_enabled)
		{
			rmuset_print();
			last_rmu_enabled = rmu_enabled;
		}

			
		const char * net_status = "     ";
			
		dhcp_set_link_state( v & 1 );
			
		if (v & 1)  // Ethernet link is active
		{
			v = ((v >> 1) & 0x03) ^ 0x01;
				
			switch (v)
			{
				case 0:
					net_status = " 10HD";
					break;
				case 1:
					net_status = "100HD";
					break;
				case 2:
					net_status = " 10FD";
					break;
				case 3:
					net_status = "100FD";
					break;
			}
				
			AVR32_MACB.ncfgr = 0x00000800 | v;  // SPD, FD, CLK = MCK / 32 -> 1.875 MHz
				
			vdisp_prints_xy( 28, 0, VDISP_FONT_4x6, 
				(dhcp_is_ready() != 0) ? 0 : 1, net_status );
		}
		else
		{
コード例 #28
0
ファイル: example_uvc.c プロジェクト: alex1818/rtk-8711af
                          RtlUpSema(&rtsp_ctx->start_rtp_sema);
                    }


		}
out:
                rtsp_ctx->state = RTSP_INIT;
                close(client_socket);                               
            }

	}               
exit:
        if((rtsp_ctx->is_rtp_start) == 1){
               RtlUpSema(&rtsp_ctx->start_rtp_sema); 
        }
	printf("\n\rrtsp -> Available heap 0x%x\n\r", xPortGetFreeHeapSize());
        close(client_socket);
        close(rtsp_ctx->connect_ctx.socket_id);
        if(request_header != NULL)
        free(request_header);
        /*wait until rtp task being destroyed*/
        while((rtsp_ctx->is_rtp_start))
        {
                vTaskDelay(100);
        }
        rtsp_context_free(rtsp_ctx);
        if(rtsp_ctx != NULL)
                free(rtsp_ctx);
        RTSP_ERROR("\n\rkill rtsp server thread!");
        //printf("Available heap 0x%x\n", xPortGetFreeHeapSize());
	//thread must be killed after server socket is terminated
コード例 #29
0
static void prvLCDTask( void *pvParameters )
{
xQueueMessage xReceivedMessage;

/* Buffer into which strings are formatted and placed ready for display on the
LCD.  Note this is a static variable to prevent it being allocated on the task
stack, which is too small to hold such a variable.  The stack size is configured
when the task is created. */
static char cBuffer[ 50 ];
unsigned char ucLine = 1;

	/* Now the scheduler has been started (it must have been for this task to
	be running), start the check timer too.  The call to xTimerStart() will
	block until the command has been accepted. */
	if( xCheckTimer != NULL )
	{
		xTimerStart( xCheckTimer, portMAX_DELAY );
	}

	/* This is the only function that is permitted to access the LCD.
	
	First print out the number of bytes that remain in the FreeRTOS heap.  This
	is done after a short delay to ensure all the demo tasks have created all
	the objects they are going to use.  */
	vTaskDelay( mainTIMER_TEST_PERIOD * 10 );
	sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );
	halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
	ucLine++;
	
	/* Just as a test of the port, and for no functional reason, check the task
	parameter contains its expected value. */
	if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
	{
		halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );
		ucLine++;		
	}

	for( ;; )
	{
		/* Wait for a message to be received.  Using portMAX_DELAY as the block
		time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
		set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
		function return value and the function will only return when a value
		has been received. */
		xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );

		/* Clear the LCD if no room remains for any more text output. */
		if( ucLine > mainMAX_LCD_LINES )
		{
			halLcdClearScreen();
			ucLine = 0;
		}
		
		/* What is this message?  What does it contain? */
		switch( xReceivedMessage.cMessageID )
		{
			case mainMESSAGE_BUTTON_UP		:	/* The button poll task has just
												informed this task that the up
												button on the joystick input has
												been pressed or released. */
												sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
												break;

			case mainMESSAGE_BUTTON_SEL		:	/* The select button interrupt
												just informed this task that the
												select button has been pressed.
												In this case the pointer to the 
												string to print is sent directly 
												in the ulMessageValue member of 
												the	message.  This just 
												demonstrates a different 
												communication technique. */
												sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
												break;
												
			case mainMESSAGE_STATUS			:	/* The tick interrupt hook
												function has just informed this
												task of the system status.
												Generate a string in accordance
												with the status value. */
												prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
												break;
												
			default							:	sprintf( cBuffer, "Unknown message" );
												break;
		}
		
		/* Output the message that was placed into the cBuffer array within the
		switch statement above, then move onto the next line ready for the next
		message to arrive on the queue. */
		halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );
		ucLine++;
	}
}
コード例 #30
0
void http_get_task(void *pvParameters)
{
    int successes = 0, failures = 0, ret;
    printf("HTTP get task starting...\n");

    uint32_t flags;
    unsigned char buf[1024];
    const char *pers = "ssl_client1";

    mbedtls_entropy_context entropy;
    mbedtls_ctr_drbg_context ctr_drbg;
    mbedtls_ssl_context ssl;
    mbedtls_x509_crt cacert;
    mbedtls_ssl_config conf;
    mbedtls_net_context server_fd;

    /*
     * 0. Initialize the RNG and the session data
     */
    mbedtls_ssl_init(&ssl);
    mbedtls_x509_crt_init(&cacert);
    mbedtls_ctr_drbg_init(&ctr_drbg);
    printf("\n  . Seeding the random number generator...");

    mbedtls_ssl_config_init(&conf);

    mbedtls_entropy_init(&entropy);
    if((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
                                    (const unsigned char *) pers,
                                    strlen(pers))) != 0)
    {
        printf(" failed\n  ! mbedtls_ctr_drbg_seed returned %d\n", ret);
        abort();
    }

    printf(" ok\n");

    /*
     * 0. Initialize certificates
     */
    printf("  . Loading the CA root certificate ...");

    ret = mbedtls_x509_crt_parse(&cacert, (uint8_t*)server_root_cert, strlen(server_root_cert)+1);
    if(ret < 0)
    {
        printf(" failed\n  !  mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
        abort();
    }

    printf(" ok (%d skipped)\n", ret);

    /* Hostname set here should match CN in server certificate */
    if((ret = mbedtls_ssl_set_hostname(&ssl, WEB_SERVER)) != 0)
    {
        printf(" failed\n  ! mbedtls_ssl_set_hostname returned %d\n\n", ret);
        abort();
    }

    /*
     * 2. Setup stuff
     */
    printf("  . Setting up the SSL/TLS structure...");

    if((ret = mbedtls_ssl_config_defaults(&conf,
                                          MBEDTLS_SSL_IS_CLIENT,
                                          MBEDTLS_SSL_TRANSPORT_STREAM,
                                          MBEDTLS_SSL_PRESET_DEFAULT)) != 0)
    {
        printf(" failed\n  ! mbedtls_ssl_config_defaults returned %d\n\n", ret);
        goto exit;
    }

    printf(" ok\n");

    /* OPTIONAL is not optimal for security, in this example it will print
       a warning if CA verification fails but it will continue to connect.
    */
    mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
    mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL);
    mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
#ifdef MBEDTLS_DEBUG_C
    mbedtls_debug_set_threshold(DEBUG_LEVEL);
    mbedtls_ssl_conf_dbg(&conf, my_debug, stdout);
#endif

    if((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0)
    {
        printf(" failed\n  ! mbedtls_ssl_setup returned %d\n\n", ret);
        goto exit;
    }

    /* Wait until we can resolve the DNS for the server, as an indication
       our network is probably working...
    */
    printf("Waiting for server DNS to resolve... ");
    err_t dns_err;
    ip_addr_t host_ip;
    do {
        vTaskDelay(500 / portTICK_PERIOD_MS);
        dns_err = netconn_gethostbyname(WEB_SERVER, &host_ip);
    } while(dns_err != ERR_OK);
    printf("done.\n");

    while(1) {
        mbedtls_net_init(&server_fd);
        printf("top of loop, free heap = %u\n", xPortGetFreeHeapSize());
        /*
         * 1. Start the connection
         */
        printf("  . Connecting to %s:%s...", WEB_SERVER, WEB_PORT);

        if((ret = mbedtls_net_connect(&server_fd, WEB_SERVER,
                                      WEB_PORT, MBEDTLS_NET_PROTO_TCP)) != 0)
        {
            printf(" failed\n  ! mbedtls_net_connect returned %d\n\n", ret);
            goto exit;
        }

        printf(" ok\n");

        mbedtls_ssl_set_bio(&ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);

        /*
         * 4. Handshake
         */
        printf("  . Performing the SSL/TLS handshake...");

        while((ret = mbedtls_ssl_handshake(&ssl)) != 0)
        {
            if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
            {
                printf(" failed\n  ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret);
                goto exit;
            }
        }

        printf(" ok\n");

        /*
         * 5. Verify the server certificate
         */
        printf("  . Verifying peer X.509 certificate...");

        /* In real life, we probably want to bail out when ret != 0 */
        if((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0)
        {
            char vrfy_buf[512];

            printf(" failed\n");

            mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "  ! ", flags);

            printf("%s\n", vrfy_buf);
        }
        else
            printf(" ok\n");

        /*
         * 3. Write the GET request
         */
        printf("  > Write to server:");

        int len = sprintf((char *) buf, GET_REQUEST);

        while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
        {
            if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
            {
                printf(" failed\n  ! mbedtls_ssl_write returned %d\n\n", ret);
                goto exit;
            }
        }

        len = ret;
        printf(" %d bytes written\n\n%s", len, (char *) buf);

        /*
         * 7. Read the HTTP response
         */
        printf("  < Read from server:");

        do
        {
            len = sizeof(buf) - 1;
            memset(buf, 0, sizeof(buf));
            ret = mbedtls_ssl_read(&ssl, buf, len);

            if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)
                continue;

            if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
                ret = 0;
                break;
            }

            if(ret < 0)
            {
                printf("failed\n  ! mbedtls_ssl_read returned %d\n\n", ret);
                break;
            }

            if(ret == 0)
            {
                printf("\n\nEOF\n\n");
                break;
            }

            len = ret;
            printf(" %d bytes read\n\n%s", len, (char *) buf);
        } while(1);

        mbedtls_ssl_close_notify(&ssl);

    exit:
        mbedtls_ssl_session_reset(&ssl);
        mbedtls_net_free(&server_fd);

        if(ret != 0)
        {
            char error_buf[100];
            mbedtls_strerror(ret, error_buf, 100);
            printf("\n\nLast error was: %d - %s\n\n", ret, error_buf);
            failures++;
        } else {
            successes++;
        }

        printf("\n\nsuccesses = %d failures = %d\n", successes, failures);
        for(int countdown = successes ? 10 : 5; countdown >= 0; countdown--) {
            printf("%d... ", countdown);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
        }
        printf("\nStarting again!\n");
    }
}