示例#1
0
/**
 * Add a network interface
 */
void apps_init( void )
{
	vSerialPutString("INIT\n");
	vSerialPutString("...\n");
	if( sys_thread_new( "demo-apps", vDemoAppsTask, NULL, 1024, (tskIDLE_PRIORITY + 1) ) == NULL )
		printf( "apps_init: create task failed!\n");

	vSerialPutString("OK\n");
}
/*
 * Just keep counting the shared variable up.  The control task will suspend
 * this task when it wants.
 */
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
{
unsigned long *pulCounter;
unsigned portBASE_TYPE uxOurPriority;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Take a pointer to the shared variable from the parameters passed into
	the task. */
	pulCounter = ( unsigned long * ) pvParameters;

	/* Query our priority so we can raise it when exclusive access to the 
	shared variable is required. */
	uxOurPriority = uxTaskPriorityGet( NULL );

	for( ;; )
	{
		/* Raise our priority above the controller task to ensure a context
		switch does not occur while we are accessing this variable. */
		vTaskPrioritySet( NULL, uxOurPriority + 1 );
			( *pulCounter )++;		
		vTaskPrioritySet( NULL, uxOurPriority );
	}
}
/* Called to check that all the created tasks are still running without error. */
portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )
{
/* Keep a history of the check variables so we know if it has been incremented 
since the last call. */
static unsigned short usLastTaskCheck = ( unsigned short ) 0;
portBASE_TYPE xReturn = pdTRUE;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Check the tasks are still running by ensuring the check variable
	is still incrementing. */

	if( usCheckVariable == usLastTaskCheck )
	{
		/* The check has not incremented so an error exists. */
		xReturn = pdFALSE;
	}

	if( xSuspendedQueueSendError == pdTRUE )
	{
		xReturn = pdFALSE;
	}

	if( xSuspendedQueueReceiveError == pdTRUE )
	{
		xReturn = pdFALSE;
	}

	usLastTaskCheck = usCheckVariable;
	return xReturn;
}
static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )
{
static unsigned long ulValueToSend = ( unsigned long ) 0;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Just to stop warning messages. */
	( void ) pvParameters;

	for( ;; )
	{
		vTaskSuspendAll();
		{
			/* We must not block while the scheduler is suspended! */
			if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
			{
				xSuspendedQueueSendError = pdTRUE;
			}
		}
		xTaskResumeAll();

		vTaskDelay( priSLEEP_TIME );

		++ulValueToSend;
	}
}
/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
{
portBASE_TYPE xReturn = pdTRUE;
short sTask;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Check the maths tasks are still running by ensuring their check variables
	are still being set to true. */
	for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
	{
		if( xTaskCheck[ sTask ] == pdFALSE )
		{
			/* The check has not incremented so an error exists. */
			xReturn = pdFALSE;
		}

		/* Reset the check variable so we can tell if it has been set by
		the next time around. */
		xTaskCheck[ sTask ] = pdFALSE;
	}

	return xReturn;
}
/*
 * Just loops around incrementing the shared variable until the limit has been
 * reached.  Once the limit has been reached it suspends itself. 
 */
static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )
{
unsigned long *pulCounter;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Take a pointer to the shared variable from the parameters passed into
	the task. */
	pulCounter = ( unsigned long * ) pvParameters;

	/* This will run before the control task, so the first thing it does is
	suspend - the control task will resume it when ready. */
	vTaskSuspend( NULL );

	for( ;; )
	{
		/* Just count up to a value then suspend. */
		( *pulCounter )++;	
		
		if( *pulCounter >= priMAX_COUNT )
		{
			vTaskSuspend( NULL );
		} 	
	}
}
示例#7
0
/*
 * main
 */
int main( void ) {
    uint8_t myDataToSend[100];
    prvSetupHardware();

    enableSerial0();

    xSerialPortInitMinimal(0, 115200, 250 );
    vSerialPutString(0, "Starting up LPC23xx with FreeRTOS\n\r", 50);

    SCS |= 1; //Configure FIO

    // Initialize I2C0
    I2Cinit(I2C0);

    xTaskCreate( i2ceepromtask, 
            ( signed portCHAR * ) "i2ceepromtask", 
            I2CTEST_STACK_SIZE, NULL, 
            mainCHECK_TASK_PRIORITY - 1, 
            NULL );


    /* Start the scheduler. */
    vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle
       task. */
    return 0; 
}
示例#8
0
static void vComTxTask( void *pvParameters )
{
const char * const pcTaskStartMsg = "COM Tx task started.\r\n";
portTickType xTimeToWait;

	/* Stop warnings. */
	( void ) pvParameters;

	/* Queue a message for printing to say the task has started. */
	vPrintDisplayMessage( &pcTaskStartMsg );

	for( ;; )
	{
		/* Send the string to the serial port. */
		vSerialPutString( xPort, pcMessageToExchange, strlen( pcMessageToExchange ) );

		/* We have posted all the characters in the string - increment the variable 
		used to check that this task is still running, then wait before re-sending 
		the string. */
		sTxCount++;

		xTimeToWait = xTaskGetTickCount();

		/* Make sure we don't wait too long... */
		xTimeToWait %= comTX_MAX_BLOCK_TIME;

		/* ...but we do want to wait. */
		if( xTimeToWait < comTX_MIN_BLOCK_TIME )
		{
			xTimeToWait = comTX_MIN_BLOCK_TIME;
		}

		vTaskDelay( xTimeToWait );
	}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
示例#9
0
static void prvComTxTimerCallback( xTimerHandle xTimer )
{
portTickType xTimeToWait;

	/* The parameter is not used in this case. */
	( void ) xTimer;

	/* Send the string.  How this is actually performed depends on the
	sample driver provided with this demo.  However - as this is a timer,
	it executes in the context of the timer task and therefore must not
	block. */
	vSerialPutString( xPort, ( const signed char * const ) comTRANSACTED_STRING, xStringLength );

	/* Toggle an LED to give a visible indication that another transmission
	has been performed. */
	vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );

	/* Wait a pseudo random time before sending the string again. */
	xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;

	/* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
	xTimeToWait %= comTX_MAX_BLOCK_TIME;

	/* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
	if( xTimeToWait < comTX_MIN_BLOCK_TIME )
	{
		xTimeToWait = comTX_MIN_BLOCK_TIME;
	}

	/* Reset the timer to run again xTimeToWait ticks from now.  This function
	is called from the context of the timer task, so the block time must not
	be anything other than zero. */
	xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
}
portBASE_TYPE xAreBlockTimeTestTasksStillRunning( void )
{
static portBASE_TYPE xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
portBASE_TYPE xReturn = pdPASS;

    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );
	/* Have both tasks performed at least one cycle since this function was
	last called? */
	if( xPrimaryCycles == xLastPrimaryCycleCount )
	{
		xReturn = pdFAIL;
	}

	if( xSecondaryCycles == xLastSecondaryCycleCount )
	{
		xReturn = pdFAIL;
	}

	if( xErrorOccurred == pdTRUE )
	{
		xReturn = pdFAIL;
	}

	xLastSecondaryCycleCount = xSecondaryCycles;
	xLastPrimaryCycleCount = xPrimaryCycles;

	return xReturn;
}
/* Function required in order to link UARTCommandConsole.c - which is used by
multiple different demo application. */
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
{
    /* Just mapped to vSerialPutString() so the block time is not used. */
    ( void ) xBlockTime;

    vSerialPutString( pxPort, &cOutChar, sizeof( cOutChar ) );
    return pdPASS;
}
示例#12
0
void vOutputString( const char * const pcMessage )
{
    if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
    {
        vSerialPutString( xPort, ( signed char * ) pcMessage, ( unsigned short ) strlen( pcMessage ) );
        xSemaphoreGive( xTxMutex );
    }
}
void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
{
short sTask;

	for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
	{
		xTaskCreate( vCompeteingIntMathTask, ( signed char * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
	}
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );
}
示例#14
0
/* Prints on serial line a string */
int print(char* string)
{
	int len;

	len = strlen(string);
	if(uartHandle){
		vSerialPutString(uartHandle, (const signed char*)string, len);
		return len;
	}
	else{
		return -1;
	}
}
示例#15
0
static void vDemoAppsTask( void *pvParameters )
{
	struct ip_addr  xIpAddr, xNetMast, xGateway;
	static struct netif ftmac100_if;

	vSerialPutString("TASK\n");
	/* The parameters are not used in this function. */
	( void ) pvParameters;

#if 1
	/* Init lwip library */
	tcpip_init( NULL, NULL );

	/* Create and configure the EMAC interface. */
	IP4_ADDR( &xIpAddr, 192, 168, 68, 70 );
	IP4_ADDR( &xNetMast, 255, 255, 255, 0 );
	IP4_ADDR( &xGateway, 192, 168, 68, 66 );
	netif_add( &ftmac100_if, &xIpAddr, &xNetMast, &xGateway, NULL, ftMac100_init, tcpip_input );

	/* make it the default interface */
	netif_set_default( &ftmac100_if );

	/* bring it up */
	netif_set_up( &ftmac100_if );

	/* link is up */
	netif_set_link_up( &ftmac100_if );
#endif
//	if( sys_thread_new( "httpd", http_server_netconn_thread, NULL, 16384, ( tskIDLE_PRIORITY + 2 ) ) == NULL )
//		simple_printf( "apps_init: create task failed!\n");
	vSerialPutString("loop\n");
	for ( ;; )
	{
		/* do nothing, delay very long time, let other tasks
		   to run */
		vTaskDelay( 0xffff );
	}
}
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
{
static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;
portBASE_TYPE xGotValue;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	/* Just to stop warning messages. */
	( void ) pvParameters;

	for( ;; )
	{
		do
		{
			/* Suspending the scheduler here is fairly pointless and 
			undesirable for a normal application.  It is done here purely
			to test the scheduler.  The inner xTaskResumeAll() should
			never return pdTRUE as the scheduler is still locked by the
			outer call. */
			vTaskSuspendAll();
			{
				vTaskSuspendAll();
				{
					xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
				}
				if( xTaskResumeAll() )
				{
					xSuspendedQueueReceiveError = pdTRUE;
				}
			}
			xTaskResumeAll();

			#if configUSE_PREEMPTION == 0
			{
				taskYIELD();
			}
			#endif

		} while( xGotValue == pdFALSE );

		if( ulReceivedValue != ulExpectedValue )
		{
			xSuspendedQueueReceiveError = pdTRUE;
		}

		++ulExpectedValue;
	}
}
示例#17
0
int printf2 (const char *fmt, ...)
{
   va_list args;
   uint i;

   va_start (args, fmt);

   /* For this to work, printbuffer must be larger than
    * anything we ever want to print.
    */
   i = vsprintf (printbuffer, fmt, args);
   va_end (args);

   /* Print the string */
   vSerialPutString(1, printbuffer);
   return 0;
} 
示例#18
0
void uprintf(char *fmt, ...) {
#ifdef PAKAI_SHELL
//#if 1
	
	int lg=0;
    va_list args;
    va_start(args, fmt);
    lg = vsprintf(str_buffer, fmt, args);
    va_end(args);
    if( xSemSer0 != NULL )    {
		if( xSemaphoreTake( xSemSer0, ( portTickType ) 10 ) == pdTRUE )	{
			vSerialPutString(xPort, str_buffer, 0xffff);
			xSemaphoreGive( xSemSer0 );
		}
	}
	vTaskDelay(10);
#endif
}
示例#19
0
// qrprintf : custom printf yg dapat mengambil data dari queue
void qrprintf(portTickType w) {
	//char *str_buffer;
	if( xSemSer0 != NULL )    {
        // See if we can obtain the semaphore.  If the semaphore is not available
        // wait 10 ticks to see if it becomes free.	
        if( xSemaphoreTake( xSemSer0, ( portTickType ) 10 ) == pdTRUE )	{
			char str_buffer[128];
			if (xPrintQueue != 0)	{
				if (xQueueReceive( xPrintQueue, &str_buffer, w ))	{
					//uprintf("PrintQueue: %d/%d__%s\r\n", xPrintQueue, strlen(str_buffer), str_buffer);
					//uprintf("%d__%s\r\n", strlen(str_buffer), str_buffer);
					vSerialPutString(xPort, str_buffer, strlen(str_buffer));
				}
			}
			xSemaphoreGive( xSemSer0 );
		}
	}
	//vTaskDelay(5);
}
示例#20
0
int printf0 (const char *fmt, ...)		{
	va_list args;
	int i;
	//char printbuffer[256];
	va_start (args, fmt);

	i = vsprintf (str_buffer, fmt, args);
	va_end (args);

	/* Print the string */
	if( xSemSer0 != NULL )    {
		if( xSemaphoreTake( xSemSer0, ( portTickType ) 10 ) == pdTRUE )	{
			vSerialPutString(xPort, str_buffer, 0xffff);
			xSemaphoreGive( xSemSer0 );
		}
	}
	vTaskDelay(1);
	return 0;
} 
void vCreateBlockTimeTasks( void )
{
	/* Create the queue on which the two tasks block. */
    xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );

	/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
	in use.  The queue registry is provided as a means for kernel aware
	debuggers to locate queues and has no purpose if a kernel aware debugger
	is not being used.  The call to vQueueAddToRegistry() will be removed
	by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
	defined to be less than 1. */
	vQueueAddToRegistry( xTestQueue, ( signed char * ) "Block_Time_Queue" );

	/* Create the two test tasks. */
	xTaskCreate( vPrimaryBlockTimeTestTask, ( signed char * )"BTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
	xTaskCreate( vSecondaryBlockTimeTestTask, ( signed char * )"BTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );
}
/*
 * Start the three tasks as described at the top of the file.
 * Note that the limited count task is given a higher priority.
 */
void vStartDynamicPriorityTasks( void )
{
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );
	xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );

	/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
	in use.  The queue registry is provided as a means for kernel aware 
	debuggers to locate queues and has no purpose if a kernel aware debugger
	is not being used.  The call to vQueueAddToRegistry() will be removed
	by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is 
	defined to be less than 1. */
	vQueueAddToRegistry( xSuspendedTestQueue, ( signed char * ) "Suspended_Test_Queue" );

	xTaskCreate( vContinuousIncrementTask, ( signed char * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinousIncrementHandle );
	xTaskCreate( vLimitedIncrementTask, ( signed char * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
	xTaskCreate( vCounterControlTask, ( signed char * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
	xTaskCreate( vQueueSendWhenSuspendedTask, ( signed char * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
	xTaskCreate( vQueueReceiveWhenSuspendedTask, ( signed char * ) "SUSP_RX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
示例#23
0
void printd(int prio, const char *format, ...)	{
	va_list arg;
	int lg=0;
	
	struct t_env *st_env;
	st_env = ALMT_ENV;
	
	char str_buffer[128];
	//if (prio>0)	{
	if (prio>=st_env->prioDebug)	{
		if( xSemSer0 != NULL )    {
			if( xSemaphoreTake( xSemSer0, ( portTickType ) 10 ) == pdTRUE )	{
				va_start (arg, format);
				lg = vsprintf (str_buffer, format, arg);	
				va_end (arg);
				vSerialPutString(xPort, format, lg);
				xSemaphoreGive( xSemSer0 );
			}
		}
		vTaskDelay(5);
	}
}
示例#24
0
ssize_t
write( int fd, const void *buf, size_t nbytes )
{
    ssize_t res = nbytes;
    extern xComPortHandle xSTDComPort;
    switch ( fd )
    {
        case STDERR_FILENO:
            vSerialPutStringNOISR( xSTDComPort,
                                   ( const signed char * const )buf,
                                   ( unsigned short )nbytes );
            break;
        case STDOUT_FILENO:
            vSerialPutString( xSTDComPort,
                              ( const signed char * const)buf,
                              ( unsigned short )nbytes );
            break;
        default:
            errno = EIO;
            res = -1;
            break;
    }
    return res;
}
示例#25
0
static void prvUARTCommandConsoleTask( void *pvParameters )
{
    signed char cRxedChar;
    uint8_t ucInputIndex = 0;
    char *pcOutputString;
    static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
    BaseType_t xReturned;
    xComPortHandle xPort;

    ( void ) pvParameters;

    /* Obtain the address of the output buffer.  Note there is no mutual
    exclusion on this buffer as it is assumed only one command console interface
    will be used at any one time. */
    pcOutputString = FreeRTOS_CLIGetOutputBuffer();

    /* Initialise the UART. */
    xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH );

    /* Send the welcome message. */
    vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );

    for( ;; )
    {
        /* Wait for the next character.  The while loop is used in case
        INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
        be a genuine block time rather than an infinite block time. */
        while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS );

        /* Ensure exclusive access to the UART Tx. */
        if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
        {
            /* Echo the character back. */
            xSerialPutChar( xPort, cRxedChar, portMAX_DELAY );

            /* Was it the end of the line? */
            if( cRxedChar == '\n' || cRxedChar == '\r' )
            {
                /* Just to space the output from the input. */
                vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) );

                /* See if the command is empty, indicating that the last command
                is to be executed again. */
                if( ucInputIndex == 0 )
                {
                    /* Copy the last command back into the input string. */
                    strcpy( cInputString, cLastInputString );
                }

                /* Pass the received command to the command interpreter.  The
                command interpreter is called repeatedly until it returns
                pdFALSE	(indicating there is no more output) as it might
                generate more than one string. */
                do
                {
                    /* Get the next output string from the command interpreter. */
                    xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

                    /* Write the generated string to the UART. */
                    vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) );

                } while( xReturned != pdFALSE );

                /* All the strings generated by the input command have been
                sent.  Clear the input string ready to receive the next command.
                Remember the command that was just processed first in case it is
                to be processed again. */
                strcpy( cLastInputString, cInputString );
                ucInputIndex = 0;
                memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );

                vSerialPutString( xPort, ( signed char * ) pcEndOfOutputMessage, ( unsigned short ) strlen( pcEndOfOutputMessage ) );
            }
            else
            {
                if( cRxedChar == '\r' )
                {
                    /* Ignore the character. */
                }
                else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
                {
                    /* Backspace was pressed.  Erase the last character in the
                    string - if any. */
                    if( ucInputIndex > 0 )
                    {
                        ucInputIndex--;
                        cInputString[ ucInputIndex ] = '\0';
                    }
                }
                else
                {
                    /* A character was entered.  Add it to the string entered so
                    far.  When a \n is entered the complete	string will be
                    passed to the command interpreter. */
                    if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
                    {
                        if( ucInputIndex < cmdMAX_INPUT_SIZE )
                        {
                            cInputString[ ucInputIndex ] = cRxedChar;
                            ucInputIndex++;
                        }
                    }
                }
            }

            /* Must ensure to give the mutex back. */
            xSemaphoreGive( xTxMutex );
        }
    }
}
示例#26
0
static void prvUARTCommandConsoleTask( void *pvParameters )
{
char cRxedChar, cInputIndex = 0, *pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
portBASE_TYPE xReturned;

	( void ) pvParameters;

	/* Obtain the address of the output buffer.  Note there is no mutual
	exclusion on this buffer as it is assumed only one command console
	interface will be used at any one time. */
	pcOutputString = FreeRTOS_CLIGetOutputBuffer();

	/* Send the welcome message. */
	vSerialPutString( NULL, ( const signed char * ) pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );

	for( ;; )
	{
		/* Only interested in reading one character at a time. */
		while( xSerialGetChar( NULL, ( signed char * ) &cRxedChar, portMAX_DELAY ) == pdFALSE );

		/* Echo the character back. */
		xSerialPutChar( NULL, cRxedChar, portMAX_DELAY );

		/* Was it the end of the line? */
		if( cRxedChar == '\n' || cRxedChar == '\r' )
		{
			/* Just to space the output from the input. */
			vSerialPutString( NULL, ( const signed char * ) pcNewLine, strlen( ( char * ) pcNewLine ) );

			/* See if the command is empty, indicating that the last command is
			to be executed again. */
			if( cInputIndex == 0 )
			{
				/* Copy the last command back into the input string. */
				strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
			}

			/* Pass the received command to the command interpreter.  The
			command interpreter is called repeatedly until it returns pdFALSE
			(indicating there is no more output) as it might generate more than
			one string. */
			do
			{
				/* Get the next output string from the command interpreter. */
				xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

				/* Write the generated string to the UART. */
				vSerialPutString( NULL, ( const signed char * ) pcOutputString, strlen( ( char * ) pcOutputString ) );

			} while( xReturned != pdFALSE );

			/* All the strings generated by the input command have been sent.
			Clear the input	string ready to receive the next command.  Remember
			the command that was just processed first in case it is to be
			processed again. */
			strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
			cInputIndex = 0;
			memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
			vSerialPutString( NULL, ( const signed char * ) pcEndOfOutputMessage, strlen( ( char * ) pcEndOfOutputMessage ) );
		}
		else
		{
			if( cRxedChar == '\r' )
			{
				/* Ignore the character. */
			}
			else if( cRxedChar == '\b' )
			{
				/* Backspace was pressed.  Erase the last character in the
				string - if any. */
				if( cInputIndex > 0 )
				{
					cInputIndex--;
					cInputString[ cInputIndex ] = '\0';
				}
			}
			else
			{
				/* A character was entered.  Add it to the string
				entered so far.  When a \n is entered the complete
				string will be passed to the command interpreter. */
				if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
				{
					if( cInputIndex < cmdMAX_INPUT_SIZE )
					{
						cInputString[ cInputIndex ] = cRxedChar;
						cInputIndex++;
					}
				}
			}
		}
	}
}
示例#27
0
portTASK_FUNCTION(ambilcepat, pvParameters )	{
    vTaskDelay(500);

    int loopambil=0;

#ifdef PAKAI_SHELL
    printf(" Monita : Ambil cepat init !!\r\n");
#endif

#if defined(PAKAI_I2C) && defined(PAKAI_TSC)
    unsigned char st_tsc=0;
    char a;
    int i;
    int c=0;

    if (setup_fma())	printf(" NO ack !\r\n");
    else	{
        printf("Init TSC OK ack !!!\r\n");
        st_tsc = 1;
    }
#endif

#ifdef PAKAI_GPS
    int hasil_gpsnya;
    awal_gps();
#endif

#ifdef PAKAI_ADC
    extern unsigned char status_adcnya;
#endif

#ifdef PAKAI_GPIO_DIMMER
    //init_remang();
#endif

#ifdef PAKAI_PM
    int almtSumber=0;
    int sPM=0;

#ifdef AMBIL_PM
    printf("Init ambil PM ..-ambilcepat-..!!!\r\n");
    vTaskDelay(3000);
#endif
#endif

    int waktunya=0;
    char dataserial[50];

    vTaskDelay(50);
    for(;;) {
        vTaskDelay(1);

#ifdef DATA_RANDOM
        data_f[loopambil%10] = (float) ((rand() % 100));
        //printf("%d: data: %.1f\r\n", loopambil%10, data_f[loopambil%10]);
#endif

        loopambil++;
#ifdef PAKAI_GPS
        if (serPollGPS())
        {
            hasil_gpsnya = proses_gps();
#if 0
            info_gps(hasilGPS);
#endif
        }
#endif

#ifdef PAKAI_PM
#ifdef AMBIL_PM			// AMBIL_PM
        sedot_pm();
#endif
#endif

#ifdef PAKAI_ADC
        if (status_adcnya) {
            proses_data_adc();
            //printf("proses adc ... %d !!\r\n", status_adcnya);

#ifdef BOARD_KOMON_420_SAJA
            hitung_datanya();
#endif

            simpan_ke_data_f();
        }
#endif

#ifdef BOARD_KOMON_KONTER
        if (loopambil%20==0) {		// 5x20 = 100
            hitung_rpm();
        }
        data_frek_rpm();
#endif

#ifdef BOARD_KOMON_KONTER_3_0
        if (loopambil%20==0) {		// 5x20 = 100
            hitung_rpm();
            data_frek_rpm();
        }
#endif

#ifdef PAKAI_I2C
#if 0
        if (st_tsc) {
            if (loopambil%500==0) {	// 2*250: 500ms = 0.5 detik
                printf("__detik: %3d\r\n", c++);
                //baca_register_tsc();

#if 1
                if (int_berganti() == 0)
                {
                    printf("disentuh\r\n");
                }
                else
                    printf("HIGH\r\n");
                //vSerialPutString(0, "HIGH\r\n");
#endif
            }
        }
#endif
#if 0
        if (st_tsc) {
            if (xSerialGetChar(1, &c, 0xFFFF ) == pdTRUE)
            {
                vSerialPutString(0, "Tombol ditekan = ");
                xSerialPutChar(	0, (char ) c);
                vSerialPutString(0, " \r\n");

                if ( (char) c == 's')
                {
                    printf(" Set\r\n");
                    /*
                    if (i2c_set_register(0x68, 1, 8))
                    {
                    	out(" NO ACK !!\r\n");
                    }
                    else
                    	out(" OK\r\n");
                    */

                    if (setup_fma())
                    {
                        printf(" NO ack !\r\n");
                    }
                    else
                        printf(" OK ack !\r\n");


                }
                else
                {
                    printf("====\r\n");
                    for (i=0; i<16; i++)
                    {
                        if (i == 8) printf("****\r\n");

                        if (i2c_read_register(0x68, (0x50 + i), &a))
                        {
                            printf(" Read failed !\r\n");
                        }
                        else
                        {
                            printf(" Read OK =");
                            a = a + '0';
                            printf("%c", (char) a);
                            printf(" \r\n");
                        }
                    }

                    printf("KEY \r\n");
                    if (i2c_read_register(0x68, 0x68, &a))
                    {
                        printf(" Read failed !\r\n");
                    }
                    else
                    {
                        printf(" Read OK =");
                        a = a + '0';
                        printf("%c", (char) a);
                        printf(" \r\n");
                    }
                    //a = read_key();
                    //a = a + '0';
                    //xSerialPutChar(	0, (char ) a);
                }
            }
        }
#endif

#endif


#ifdef PAKAI_GPIO_DIMMER
        //remangkan();
        /*
        loop_pwm++;

        #ifdef DEBUG_PWM_GPIO
        if (loop_pwm>500) {
        	loop_pwm=0;
        	blink_pwm=1-blink_pwm;
        	if (blink_pwm) {
        		FIO1SET = BIT(30);
        	} else {
        		FIO1CLR = BIT(30);
        	}
        }
        #endif
        //*/
#endif
    }

#ifdef PAKAI_GPS
    deinit_gps();
#endif
}
static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
{
/* These variables are all effectively set to constants so they are volatile to
ensure the compiler does not just get rid of them. */
volatile long lValue;
short sError = pdFALSE;
volatile signed portBASE_TYPE *pxTaskHasExecuted;

	/* Set a pointer to the variable we are going to set to true each
	iteration.  This is also a good test of the parameter passing mechanism
	within each port. */
	pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );


	/* Keep performing a calculation and checking the result against a constant. */
	for( ;; )
	{
		/* Perform the calculation.  This will store partial value in
		registers, resulting in a good test of the context switch mechanism. */
		lValue = intgCONST1;
		lValue += intgCONST2;

		/* Yield in case cooperative scheduling is being used. */
		#if configUSE_PREEMPTION == 0
		{
			taskYIELD();
		}
		#endif

		/* Finish off the calculation. */
		lValue *= intgCONST3;

		lValue /= intgCONST4;

		/* If the calculation is found to be incorrect we stop setting the
		TaskHasExecuted variable so the check task can see an error has
		occurred. */
		if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
		{
			sError = pdTRUE;
		}

		if( sError == pdFALSE )
		{
			/* We have not encountered any errors, so set the flag that show
			we are still executing.  This will be periodically cleared by
			the check task. */
#if 0
            char str[64];
            sprintf( str, "[%s]: %s\r\n", __func__, "portENTER_CRITICAL()\n" );
            vSerialPutString(configUART_PORT, str, strlen(str) );
#endif
			portENTER_CRITICAL();
				*pxTaskHasExecuted = pdTRUE;
			portEXIT_CRITICAL();
#if 0
            sprintf( str, "[%s]: %s\r\n", __func__, "portEXIT_CRITICAL()\n" );
            vSerialPutString(configUART_PORT, str, strlen(str) );
#endif
		}

		/* Yield in case cooperative scheduling is being used. */
		#if configUSE_PREEMPTION == 0
		{
			taskYIELD();
		}
		#endif
	}
}
static void vPrimaryBlockTimeTestTask( void *pvParameters )
{
portBASE_TYPE xItem, xData;
portTickType xTimeWhenBlocking;
portTickType xTimeToBlock, xBlockedTime;

	( void ) pvParameters;

	for( ;; )
	{
		/*********************************************************************
        Test 1

        Simple block time wakeup test on queue receives. */
		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			/* The queue is empty. Attempt to read from the queue using a block
			time.  When we wake, ensure the delta in time is as expected. */
			xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;

			xTimeWhenBlocking = xTaskGetTickCount();

			/* We should unblock after xTimeToBlock having not received
			anything on the queue. */
			if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
			{
				xErrorOccurred = pdTRUE;
			}

			/* How long were we blocked for? */
			xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;

			if( xBlockedTime < xTimeToBlock )
			{
				/* Should not have blocked for less than we requested. */
				xErrorOccurred = pdTRUE;
			}

			if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
			{
				/* Should not have blocked for longer than we requested,
				although we would not necessarily run as soon as we were
				unblocked so a margin is allowed. */
				xErrorOccurred = pdTRUE;
			}
            char str[64];
            sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
            vSerialPutString(configUART_PORT, str, strlen(str) );
		}

		/*********************************************************************
        Test 2

        Simple block time wakeup test on queue sends.

		First fill the queue.  It should be empty so all sends should pass. */
		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}

            char str[64];
            sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
            vSerialPutString(configUART_PORT, str, strlen(str) );

			#if configUSE_PREEMPTION == 0
				taskYIELD();
			#endif
		}

		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			/* The queue is full. Attempt to write to the queue using a block
			time.  When we wake, ensure the delta in time is as expected. */
			xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;

			xTimeWhenBlocking = xTaskGetTickCount();

			/* We should unblock after xTimeToBlock having not received
			anything on the queue. */
			if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
			{
				xErrorOccurred = pdTRUE;
			}

			/* How long were we blocked for? */
			xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;

			if( xBlockedTime < xTimeToBlock )
			{
				/* Should not have blocked for less than we requested. */
				xErrorOccurred = pdTRUE;
			}

			if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
			{
				/* Should not have blocked for longer than we requested,
				although we would not necessarily run as soon as we were
				unblocked so a margin is allowed. */
				xErrorOccurred = pdTRUE;
			}
            char str[64];
            sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
            vSerialPutString(configUART_PORT, str, strlen(str) );
		}

		/*********************************************************************
        Test 3

		Wake the other task, it will block attempting to post to the queue.
		When we read from the queue the other task will wake, but before it
		can run we will post to the queue again.  When the other task runs it
		will find the queue still full, even though it was woken.  It should
		recognise that its block time has not expired and return to block for
		the remains of its block time.

		Wake the other task so it blocks attempting to post to the already
		full queue. */
		xRunIndicator = 0;
		vTaskResume( xSecondary );

		/* We need to wait a little to ensure the other task executes. */
		while( xRunIndicator != bktRUN_INDICATOR )
		{
			/* The other task has not yet executed. */
			vTaskDelay( bktSHORT_WAIT );
		}
		/* Make sure the other task is blocked on the queue. */
		vTaskDelay( bktSHORT_WAIT );
		xRunIndicator = 0;

		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			/* Now when we make space on the queue the other task should wake
			but not execute as this task has higher priority. */
			if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}

			/* Now fill the queue again before the other task gets a chance to
			execute.  If the other task had executed we would find the queue
			full ourselves, and the other task have set xRunIndicator. */
			if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}

			if( xRunIndicator == bktRUN_INDICATOR )
			{
				/* The other task should not have executed. */
				xErrorOccurred = pdTRUE;
			}

			/* Raise the priority of the other task so it executes and blocks
			on the queue again. */
			vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );

			/* The other task should now have re-blocked without exiting the
			queue function. */
			if( xRunIndicator == bktRUN_INDICATOR )
			{
				/* The other task should not have executed outside of the
				queue function. */
				xErrorOccurred = pdTRUE;
			}

			/* Set the priority back down. */
			vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
		}

		/* Let the other task timeout.  When it unblockes it will check that it
		unblocked at the correct time, then suspend itself. */
		while( xRunIndicator != bktRUN_INDICATOR )
		{
			vTaskDelay( bktSHORT_WAIT );
		}
		vTaskDelay( bktSHORT_WAIT );
		xRunIndicator = 0;


		/*********************************************************************
        Test 4

		As per test 3 - but with the send and receive the other way around.
		The other task blocks attempting to read from the queue.

		Empty the queue.  We should find that it is full. */
		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}
		}

		/* Wake the other task so it blocks attempting to read from  the
		already	empty queue. */
		vTaskResume( xSecondary );

		/* We need to wait a little to ensure the other task executes. */
		while( xRunIndicator != bktRUN_INDICATOR )
		{
			vTaskDelay( bktSHORT_WAIT );
		}
		vTaskDelay( bktSHORT_WAIT );
		xRunIndicator = 0;

		for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
		{
			/* Now when we place an item on the queue the other task should
			wake but not execute as this task has higher priority. */
			if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}

			/* Now empty the queue again before the other task gets a chance to
			execute.  If the other task had executed we would find the queue
			empty ourselves, and the other task would be suspended. */
			if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
			{
				xErrorOccurred = pdTRUE;
			}

			if( xRunIndicator == bktRUN_INDICATOR )
			{
				/* The other task should not have executed. */
				xErrorOccurred = pdTRUE;
			}

			/* Raise the priority of the other task so it executes and blocks
			on the queue again. */
			vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );

			/* The other task should now have re-blocked without exiting the
			queue function. */
			if( xRunIndicator == bktRUN_INDICATOR )
			{
				/* The other task should not have executed outside of the
				queue function. */
				xErrorOccurred = pdTRUE;
			}
			vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
		}

		/* Let the other task timeout.  When it unblockes it will check that it
		unblocked at the correct time, then suspend itself. */
		while( xRunIndicator != bktRUN_INDICATOR )
		{
			vTaskDelay( bktSHORT_WAIT );
		}
		vTaskDelay( bktSHORT_WAIT );

		xPrimaryCycles++;
	}
}
static void vSecondaryBlockTimeTestTask( void *pvParameters )
{
portTickType xTimeWhenBlocking, xBlockedTime;
portBASE_TYPE xData;

	( void ) pvParameters;
    char str[64];
    sprintf( str, "[%s]: %d\r\n", __func__, __LINE__ );
    vSerialPutString(configUART_PORT, str, strlen(str) );

	for( ;; )
	{
		/*********************************************************************
        Test 1 and 2

		This task does does not participate in these tests. */
		vTaskSuspend( NULL );

		/*********************************************************************
        Test 3

		The first thing we do is attempt to read from the queue.  It should be
		full so we block.  Note the time before we block so we can check the
		wake time is as per that expected. */
		xTimeWhenBlocking = xTaskGetTickCount();

		/* We should unblock after bktTIME_TO_BLOCK having not sent
		anything to the queue. */
		xData = 0;
		xRunIndicator = bktRUN_INDICATOR;
		if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
		{
			xErrorOccurred = pdTRUE;
		}

		/* How long were we inside the send function? */
		xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;

		/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
		if( xBlockedTime < bktTIME_TO_BLOCK )
		{
			xErrorOccurred = pdTRUE;
		}

		/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
		either.  A margin is permitted as we would not necessarily run as
		soon as we unblocked. */
		if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
		{
			xErrorOccurred = pdTRUE;
		}

		/* Suspend ready for test 3. */
		xRunIndicator = bktRUN_INDICATOR;
		vTaskSuspend( NULL );

		/*********************************************************************
        Test 4

		As per test three, but with the send and receive reversed. */
		xTimeWhenBlocking = xTaskGetTickCount();

		/* We should unblock after bktTIME_TO_BLOCK having not received
		anything on the queue. */
		xRunIndicator = bktRUN_INDICATOR;
		if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
		{
			xErrorOccurred = pdTRUE;
		}

		xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;

		/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
		if( xBlockedTime < bktTIME_TO_BLOCK )
		{
			xErrorOccurred = pdTRUE;
		}

		/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
		either.  A margin is permitted as we would not necessarily run as soon
		as we unblocked. */
		if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
		{
			xErrorOccurred = pdTRUE;
		}

		xRunIndicator = bktRUN_INDICATOR;

		xSecondaryCycles++;
	}
}