Esempio n. 1
0
static void vCommsRxCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
static char cRxedChar, cExpectedChar = mainFIRST_TX_CHAR;
portBASE_TYPE xResult;

	crSTART( xHandle );

	for( ;; )
	{
		/* Wait for a character to be received. */
		crQUEUE_RECEIVE( xHandle, xCommsQueue, ( void * ) &cRxedChar, mainCOMMS_RX_DELAY, &xResult );

		/* Was the character recived (if any) the expected character. */
		if( ( cRxedChar != cExpectedChar ) || ( xResult != pdPASS ) )
		{
			/* Got an unexpected character.  This can sometimes occur when
			reseting the system using the debugger leaving characters already
			in the UART regsters. */
			uxErrorStatus = pdFAIL;

			/* Resync by waiting for the end of the current string. */
			while( cRxedChar != mainLAST_TX_CHAR )
			{
				crQUEUE_RECEIVE( xHandle, xCommsQueue, ( void * ) &cRxedChar, mainCOMMS_RX_DELAY, &xResult );
			}

			/* The next expected character is the start of the string again. */
			cExpectedChar = mainFIRST_TX_CHAR;
		}
		else
		{
			if( cExpectedChar == mainLAST_TX_CHAR )
			{
				/* We have reached the end of the string - we now expect to 
				receive the first character in the string again.   The LED is 
				toggled to indicate that the entire string was received without
				error. */
				vParTestToggleLED( mainCOMMS_RX_LED );
				cExpectedChar = mainFIRST_TX_CHAR;
			}
			else
			{
				/* We got the expected character, we now expect to receive the
				next character in the string. */
				cExpectedChar++;
			}
		}
	}

	crEND();
}
Esempio n. 2
0
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
{
    /* Even though this is a co-routine the variable do not need to be
    static as we do not need it to maintain their state between blocks. */
    signed portBASE_TYPE xResult;
    unsigned portBASE_TYPE uxLEDToFlash;

    /* Co-routines MUST start with a call to crSTART. */
    crSTART( xHandle );
    ( void ) uxIndex;

    for( ;; ) {
        /* Block to wait for the number of the LED to flash. */
        crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );

        if( xResult != pdPASS ) {
            /* We would not expect to wake unless we received something. */
            uxCoRoutineFlashStatus = pdFAIL;
        } else {
            /* We received the number of an LED to flash - flash it! */
            /* Added by MPi, PDR00_Offset is added in order to make the
            vParTestToggleLED() work. */
            vParTestToggleLED( uxLEDToFlash +  PDR00_Offset );
        }
    }

    /* Co-routines MUST end with a call to crEND. */
    crEND();
}
Esempio n. 3
0
static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
{
static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
BaseType_t xResult;

	/* Each co-routine MUST start with a call to crSTART(); */
	crSTART( xHandle );

	for( ;; )
	{
		/* Wait to receive a value from the tick hook. */
		xResult = pdFAIL;
		crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );

		/* There is no reason why we should not have received something on
		the queue. */
		if( xResult != pdPASS )
		{
			xCoRoutineErrorDetected = pdTRUE;
		}

		/* Send the same number back to the idle hook so it can verify it. */
		xResult = pdFAIL;
		crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult );
		if( xResult != pdPASS )
		{
			/* There is no reason why we should not have been able to post to 
			the queue. */
			xCoRoutineErrorDetected = pdTRUE;
		}
	}

	/* Each co-routine MUST end with a call to crEND(). */
	crEND();
}
Esempio n. 4
0
static void vI2CCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
portTickType xADCResult;
static portBASE_TYPE xResult = 0, xMilliSecs, xLED;

	crSTART( xHandle );

	for( ;; )
	{
		/* Start the I2C off to read the ADC. */
		uxState = mainI2C_READ_1;
		I2CMasterSlaveAddrSet( I2C_MASTER_BASE, mainI2CAddress, pdTRUE );		
		I2CMasterControl( I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START );

		/* Wait to receive the conversion result. */
		crQUEUE_RECEIVE( xHandle, xADCQueue, &xADCResult, portMAX_DELAY, &xResult );

		/* Scale the result to give a useful range of values for a visual 
		demo. */
		xADCResult >>= 2;
		xMilliSecs = xADCResult / portTICK_RATE_MS;

		/* The delay is split between the four co-routines so they remain in
		synch. */
		uxDelay = xMilliSecs / ( mainNUM_LEDs + 1 );

		/* Trigger each of the flash co-routines. */
		for( xLED = 0; xLED < mainNUM_LEDs; xLED++ )
		{
			crQUEUE_SEND( xHandle, xDelayQueue, &xLED, 0, &xResult );
		}

		/* Wait for the full delay time then start again.  This delay is long 
		enough to ensure the flash co-routines have done their thing and gone
		back to sleep. */
		crDELAY( xHandle, xMilliSecs );
	}

	crEND();
}
Esempio n. 5
0
static void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
portBASE_TYPE xResult, xNothing;

	crSTART( xHandle );

	for( ;; )
	{
		/* Wait for start of next round. */
		crQUEUE_RECEIVE( xHandle, xDelayQueue, &xNothing, portMAX_DELAY, &xResult );

		/* Wait until it is this co-routines turn to flash. */
		crDELAY( xHandle, uxDelay * uxIndex );

		/* Turn on the LED for a fixed period. */
		vParTestSetLED( uxIndex, pdTRUE );
		crDELAY( xHandle, uxDelay );
		vParTestSetLED( uxIndex, pdFALSE );

		/* Go back and wait for the next round. */
	}

	crEND();
}
Esempio n. 6
0
void crUsbIo( xCoRoutineHandle xHandle, 
              unsigned portBASE_TYPE uxIndex )
{
    static uint8_t data;
    static portBASE_TYPE rcTo;
    static uint8_t state = STATE_CMD;
    static uint8_t size = 0;
    static uint8_t bufferIndex = 0;
    static uint32_t stateResetTimeout = 0;
    
    crSTART( xHandle );

    for ( ;; )
    {
        if ( !g_usbInitialized )
        {
            initUsbIo();
            // USB setup.
            Set_USBClock();
            USB_Interrupts_Config();
            USB_Init();

            g_usbInitialized = 1;
        }

        /*if ( !g_usbInitialized )
        {
            // Data for gpioEn.
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
   
            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 2;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Data for gpioConfig
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 2;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 255;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 255;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 0x48;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
   
            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 3;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Data for gpio.
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 5;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
 
            g_usbInitialized = 1;
        }*/
        // Receive data from USB and place to an execution buffer.
        crQUEUE_RECEIVE( xHandle, g_toMcu, &data, 0, &rcTo );
        if ( rcTo == pdPASS )
        {
            // Analyze data and put it into execution buffer.
            switch ( state )
            {
                case STATE_CMD:
                    //setRed( 1 );
                    //setGreen( 0 );
                    // Reset timer.
                    stateResetTimeout = STATE_RESET_TIMEOUT;
                    if ( data == CMD_DATA )
                    {
                        state = STATE_SIZE;
                    }
                    else if ( data == CMD_FUNC )
                    {
                        state = STATE_FUNC;
                    }
                    break;
                case STATE_SIZE:
                    size = data;
                    state = STATE_DATA;
                    break;
                case STATE_DATA:
                    g_buffer[ bufferIndex++ ] = data;
                    size--;
                    if ( size == 0 )
                        state = STATE_CMD;
                    break;
                case STATE_FUNC:
                    //setRed( 0 );
                    //setGreen( 1 );
                    // Function invocation.
                    invokeFunc( data );
                    // And state back to STATE_CMD
                    state = STATE_CMD;
                    bufferIndex = 0;
                    break;
            }
        }
        else
        {
            if ( stateResetTimeout > 0 )
                stateResetTimeout--;
            else
            {
                state = STATE_CMD;
                bufferIndex = 0;
            }
        }
        crDELAY( xHandle, 1 );

        // Debugging.
        //static uint8_t a = 'a';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
        /*a = 'b';
        crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        if ( rcFrom == pdPASS )
            setRed( ( red() ) ? 0 : 1 );*/
        //a = '\r';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
        //a = '\n';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
    
        /*taskENTER_CRITICAL();
        USB_Send_Data( 'a' );
        USB_Send_Data( '\r' );
        USB_Send_Data( '\n' );
        taskEXIT_CRITICAL();*/
        //crDELAY( xHandle, 20 );

    }

    crEND();
}