static void prvCANWriteTask( void *pvParameters ) { static Peripheral_Descriptor_t xCAN = NULL; portTickType xLastWakeTime; const portTickType xFrequency = 100; xLastWakeTime = xTaskGetTickCount (); uint64_t cTxedChar=0xC3C3C3C3C3C3; uint64_t cRxedChar=0; uint32_t *id=(void *)0x00012340; uint8_t *frame_type=0; uint8_t *frame_length=6; uint8_t *use_irq=1; ( void ) pvParameters; xCAN=FreeRTOS_open( boardCAN, ( uint32_t ) cmdPARAMTER_NOT_USED ); FreeRTOS_ioctl( xCAN,ioctlSET_CAN_FRAME_TYPE ,(void *)frame_type); FreeRTOS_ioctl( xCAN,ioctlSET_CAN_FRAME_LENGTH,(void *)frame_length); FreeRTOS_write(xCAN, &cTxedChar,sizeof(cTxedChar)); //FreeRTOS_ioctl( xCAN,ioctlUSE_INTERRUPTS,(void *)use_irq); //FreeRTOS_read( xCAN, &cRxedChar,sizeof(cRxedChar)); for( ;; ) { vTaskDelayUntil( &xLastWakeTime, xFrequency ); FreeRTOS_ioctl( xCAN,ioctlSET_CAN_EXT_ID,(void *)id); FreeRTOS_write(xCAN, &cTxedChar,sizeof(cTxedChar)); } }
void vI2C_Initialize( void ) { /* Open the I2C port used for writing to both the OLED and the EEPROM. The second parameter (ulFlags) is not used in this case. The port is opened in polling mode. It is changed to interrupt driven mode later in this function. */ xI2CPort = FreeRTOS_open(board_I2C_PORT, (uint32_t) i2cPARAMETER_NOT_USED); configASSERT( xI2CPort ); /* Switch to interrupt driven zero copy Tx mode and interrupt driven circular buffer Rx mode (with a limited time out). */ FreeRTOS_ioctl(xI2CPort, ioctlUSE_ZERO_COPY_TX, i2cPARAMETER_NOT_USED); FreeRTOS_ioctl(xI2CPort, ioctlUSE_CIRCULAR_BUFFER_RX, i2cCIRCULAR_BUFFER_SIZE); FreeRTOS_ioctl(xI2CPort, ioctlSET_RX_TIMEOUT, i2c200MS_TIMEOUT); /* By default, the I2C interrupt priority will have been set to the lowest possible. It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority using a FreeRTOS_ioctl() call with the ioctlSET_INTERRUPT_PRIORITY command. */ FreeRTOS_ioctl(xI2CPort, ioctlSET_INTERRUPT_PRIORITY, (void *) configI2C_INTERRUPT_PRIORITY); xOLEDMutex = xSemaphoreCreateMutex(); }
void prvUARTReceiver( void * prvParameters ) { int8_t cRxedChar, cInputIndex = 0; static int8_t cInputString[ pwmctrlMAX_INPUT_SIZE ]; portBASE_TYPE xReturned; ( void ) prvParameters; /* Open the UART port used for console input. The second parameter (ulFlags) is not used in this case. The default board rate is set by the boardDEFAULT_UART_BAUD parameter. The baud rate can be changed using a FreeRTOS_ioctl() call with the ioctlSET_SPEED command. */ xUART3 = FreeRTOS_open( boardUART3, ( uint32_t ) pwmctrlPARAMETER_NOT_USED ); configASSERT( xUART3 ); /* Change the Tx usage model from straight polled mode to use zero copy buffers with interrupts. In this mode, the UART will transmit characters directly from the buffer passed to the FreeRTOS_write() function. */ xReturned = FreeRTOS_ioctl( xUART3, ioctlUSE_ZERO_COPY_TX, pwmctrlPARAMETER_NOT_USED ); configASSERT( xReturned ); /* Change the Rx usage model from straight polled mode to use a character queue. Character queue reception is appropriate in this case as characters can only be received as quickly as they can be typed, and need to be parsed character by character. */ xReturned = FreeRTOS_ioctl( xUART3, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) pwmctrlMAX_INPUT_SIZE ); configASSERT( xReturned ); /* By default, the UART interrupt priority will have been set to the lowest possible. It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority using a FreeRTOS_ioctl() call with the ioctlSET_INTERRUPT_PRIORITY command. */ xReturned = FreeRTOS_ioctl( xUART3, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) ); configASSERT( xReturned ); for(;;) { /* Only interested in reading one character at a time (for now). */ FreeRTOS_read( xUART3, &cRxedChar, sizeof( cRxedChar ) ); /* For debugging purposes, echo back each character received to the terminal */ #if pwmctrlDEBUG if( FreeRTOS_ioctl( xUART3, ioctlOBTAIN_WRITE_MUTEX, pwmctrl50ms ) == pdPASS ) { FreeRTOS_write( xUART3, &cRxedChar, sizeof( cRxedChar ) ); } #endif /* If we receive the STOP character, stop taking input and begin parsing the command. */ if ( cRxedChar == pwmctrlSTOP ) { /* Again, for debugging we're just adding a carriage return to make the output look nice. */ #if pwmctrlDEBUG if( FreeRTOS_ioctl( xUART3, ioctlOBTAIN_WRITE_MUTEX, pwmctrl50ms ) == pdPASS ) { FreeRTOS_write( xUART3, "\r", 1 ); } #endif /* Run the method to parse the input received over UART, then reset cInputString to be ready for the next command */ prvParseCommand( cInputString ); cInputIndex = 0; memset( cInputString, 0x00, pwmctrlMAX_INPUT_SIZE ); /* Otherwise, increment the cInputIndex and continue receiving bytes */ } else { if( cInputIndex < pwmctrlMAX_INPUT_SIZE ) { cInputString[ cInputIndex ] = cRxedChar; cInputIndex++; } } } }
// // // //lecture - many features are from FREERTOS+CLI subsystem - explore related headers and // source files as needed ??? // //lecture - several calls are to FREERTOS+IO subsystems - explore related headers and // source files as needed ??? // // // // // static void prvUARTCommandConsoleTask( void *pvParameters ) { int8_t cRxedChar, cInputIndex = 0, *pcOutputString; static int8_t 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(); /* Open the UART port used for console input. The second parameter (ulFlags) is not used in this case. The default board rate is set by the boardDEFAULT_UART_BAUD parameter. The baud rate can be changed using a FreeRTOS_ioctl() call with the ioctlSET_SPEED command. */ //lecture - UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_open() api // - UART - refer to LPCXpresso17xx-base-board.h for // boardCOMMAND_CONSOLE_UART - it is UART3 of the four UARTs // // //lecture - UART - we will receive NULL, if there is a failure // // xConsoleUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) cmdPARAMTER_NOT_USED ); configASSERT( xConsoleUART ); // //lecture - UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api // // #if 1 /* Change the Tx usage model from straight polled mode to use zero copy buffers with interrupts. In this mode, the UART will transmit characters directly from the buffer passed to the FreeRTOS_write() function. */ // xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_ZERO_COPY_TX, cmdPARAMTER_NOT_USED ); //configASSERT( xReturned ); xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_TASKNOTIFICATION_TX, uartstCIRCULAR_BUFFER_SIZE ); configASSERT( xReturned ); #endif #if 1 //xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CIRCULAR_BUFFER_RX, uartstCIRCULAR_BUFFER_SIZE ); //configASSERT( xReturned ); xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_TASKNOTIFICATION_RX, uartstCIRCULAR_BUFFER_SIZE ); configASSERT( xReturned ); #endif // // // //lecture -UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api // // /* Change the Rx usage model from straight polled mode to use a character queue. Character queue reception is appropriate in this case as characters can only be received as quickly as they can be typed, and need to be parsed character by character. */ //xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) cmdMAX_INPUT_SIZE ); //configASSERT( xReturned ); // //lecture - UART - refer to refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api - // eventually, invokes the uart specific ioctl method and respective setting // //lecture - UART - may set different priorities and check ??? // /* By default, the UART interrupt priority will have been set to the lowest possible. It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority using a FreeRTOS_ioctl() call with the ioctlSET_INTERRUPT_PRIORITY command. */ xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) ); configASSERT( xReturned ); // // // //lecture - UART - as per zero copy tx mode, we must first acquire the mutex, before we can // initiate a write on the device instance - in this case, it is uart // //lecture - UART - refer to FreeRTOS_DriverInterface.c for code and details of FreeRTOS_ioctl() // // #if 1 // /* Send the welcome message. */ // if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS ) { FreeRTOS_write( xConsoleUART, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) ); } #endif #if 0 if(FreeRTOS_ioctl( xConsoleUART, ioctlRELEASE_WRITE_MUTEX, cmd50ms ) == pdPASS ) { printf("mutex released\n"); } #endif //FreeRTOS_write( xConsoleUART, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) ); //for(;;); //aaa-zzz : for testing for( ;; ) { xReturned = FreeRTOS_read( xConsoleUART, &cRxedChar, sizeof( cRxedChar ) ); configASSERT( xReturned ); //printf("LSR=%d",) /* Echo the character back. */ if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS ) { FreeRTOS_write( xConsoleUART, &cRxedChar, sizeof( cRxedChar ) ); } if( cRxedChar == '\n' ) { /* The input command string is complete. Ensure the previous UART transmission has finished before sending any more data. This task will be held in the Blocked state while the Tx completes, if it has not already done so, so no CPU time will be wasted by polling. */ // if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS ) { /* Start to transmit a line separator, just to make the output easier to read. */ FreeRTOS_write( xConsoleUART, pcNewLine, strlen( ( char * ) pcNewLine ) ); } /* See if the command is empty, indicating that the last command is to be executed again. */ if( cInputIndex == 0 ) { strcpy( ( char * ) cInputString, ( char * ) cLastInputString ); } /* Pass the received command to the command interpreter. The command interpreter is called repeatedly until it returns pdFALSE as it might generate more than one string. */ do { /* Once again, just check to ensure the UART has completed sending whatever it was sending last. This task will be held in the Blocked state while the Tx completes, if it has not already done so, so no CPU time is wasted polling. */ xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ); if( xReturned == pdPASS ) { /* Get the string to write to the UART from the command interpreter. */ xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE ); /* Write the generated string to the UART. */ FreeRTOS_write( xConsoleUART, 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 ); /* Ensure the last string to be transmitted has completed. */ if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS ) { /* Start to transmit a line separator, just to make the output easier to read. */ FreeRTOS_write( xConsoleUART, pcEndOfCommandOutputString, strlen( ( char * ) pcEndOfCommandOutputString ) ); } } 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++; } } } } } }
static void prvUARTTxOperationModesTestTask( void *pvParameters ) { portBASE_TYPE xReturned, xTestLoops; portTickType xTimeBefore, xTimeAfter; ( void ) pvParameters; /* Open the UART port used for console input. The second parameter (ulFlags) is not used in this case. */ xTestUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) uarttstPARAMTER_NOT_USED ); prvCheckTestResult( ( xTestUART != NULL ), __LINE__ ); /************************************************************************* * Test 1. Polling Tx and polling Rx. *************************************************************************/ /* When this task starts, the Rx task will already have started as the Rx task has the higher priority. The Rx task should have placed itself into the Suspended state to wait for the Tx task to be ready. */ xReturned = xTaskIsTaskSuspended( xRxTaskHandle ); prvCheckTestResult( xReturned, __LINE__ ); /* Resume the Rx task. It will start polling for received characters, but put itself in the Blocked state when no characters are present to ensure this task does not get starved of CPU time. */ vTaskResume( xRxTaskHandle ); /* The UART has been opened, but not yet configured. It will use the default configuration, which is to poll rather than use interrupts, and to use 115200 baud. Try writing out a message a few times to check the default functionality. */ for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ ) { xReturned = FreeRTOS_write( xTestUART, pcTestMessage1, strlen( ( char * ) pcTestMessage1 ) ); prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage1 ) ), __LINE__ ); } for( ;; ) { /* Allow the Rx task to complete previous test. */ while( xTaskIsTaskSuspended( xRxTaskHandle ) != pdTRUE ) { vTaskDelay( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME ); } /********************************************************************** * Test 2. Interrupt driven, zero copy Tx, ring buffer Rx. **********************************************************************/ /* Now the UART configuration is going to change. First set the baud rate to 115200 - which it is already as that is the default so this is just for test purposes. Setting it to any other value would require the terminal baud rate to change too. As the UART is still in polled mode there is no need to wait for it to be free. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_SPEED, ( void * ) boardDEFAULT_UART_BAUD ); prvCheckTestResult( xReturned, __LINE__ ); /* Next, change the Tx usage model from straight polled mode to use zero copy buffers with interrupts. In this mode, the UART will transmit characters directly from the buffer passed to the FreeRTOS_write() function. This call will cause UART interrupts to be enabled and the interrupt priority to be set to the minimum possible. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_ZERO_COPY_TX, uarttstPARAMTER_NOT_USED ); prvCheckTestResult( xReturned, __LINE__ ); /* Change the Rx usage model from polled to instead use a ring buffer. The Rx driver created the circular buffer itself. This call will cause UART interrupts to be enabled and the interrupt priority to be set to the minimum possible. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CIRCULAR_BUFFER_RX, uartstCIRCULAR_BUFFER_SIZE ); prvCheckTestResult( xReturned, __LINE__ ); /* By default, the UART interrupt priority will have been set to the lowest possible. It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) configMAX_LIBRARY_INTERRUPT_PRIORITY ); prvCheckTestResult( xReturned, __LINE__ ); /* Zero copy transmit requires a task to obtain exclusive access to the peripheral before attempting a FreeRTOS_write() call. A mutex is by the FreeRTOS+IO code to grant access. Attempting a write here, without first obtaining the mutex, should result in no bytes being transmitted. Only attempt this if configASSERT() is not defined, otherwise attempting a write without first holding the mutex will cause an assertion. */ /* _RB_ Test this path. */ #ifndef configASSERT { xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) ); prvCheckTestResult( ( xReturned == 0U ), __LINE__ ); } #endif /* configASSERT(). */ /* Unsuspend the Rx task ready for this test. */ vTaskResume( xRxTaskHandle ); for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ ) { /* Try writing a string again, this time using a zero copy interrupt driven mode. First obtain exclusive write access to the UART. Obtaining write access not only ensure mutually exclusive access, it also ensures any previous transmit activity has been completed (important when using zero copy buffers to ensure a buffer being that is still being transmitted is not overwritten). This task will wait indefinitely in the Blocked state while waiting for UART access to be granted, so no CPU time is wasted polling. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME ); prvCheckTestResult( xReturned, __LINE__ ); /* Write the string. The write access mutex will be returned by the UART ISR once the entire string has been transmitted. */ xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) ); prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage2 ) ), __LINE__ ); } /* Send the same string another uartstNUM_TEST_TRANSACTIONS times. This time the Rx task will receive the characters one by one. */ for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ ) { xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME ); prvCheckTestResult( xReturned, __LINE__ ); xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) ); prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage2 ) ), __LINE__ ); } /* Take the write mutex again. This will only be obtainable when the UART has completed transmitting the last string sent to it in the loop above. Normally the write mutex is released again by the UART ISR when it has completed transmitting a string sent to it by a call to FreeRTOS_write(). In this case it is not going to be released, as it will be deleted when the UART mode is switched in the next part of this test anyway. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME ); prvCheckTestResult( xReturned, __LINE__ ); /* Allow the Rx task to complete test 2. */ while( xTaskIsTaskSuspended( xRxTaskHandle ) != pdTRUE ) { vTaskDelay( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME ); } /************************************************************************* * Test 3. Character queue Rx/Tx *************************************************************************/ /* Change the Tx usage model from zero copy with interrupts to use a character by character queue. Real applications should not change interrupt usage modes in this manner! It is done here purely for test purposes. Character by character Tx queues are a convenient and easy transmit method. They can, however, be inefficient if a lot of data is being transmitted quickly. This command will always result in UART interrupts becoming enabled, with the interrupt priority set to the minimum possible. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CHARACTER_QUEUE_TX, uartstQUEUE_LENGTH ); prvCheckTestResult( xReturned, __LINE__ ); /* Set a maximum transmit block time to ensure tasks that perform a FreeRTOS_write() on a peripheral that is using an interrupt driven character queue transfer mode do not block indefinitely if their requested number of characters cannot be written to the queue. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_TX_TIMEOUT, uartstVERY_LONG_BLOCK_TIME ); prvCheckTestResult( xReturned, __LINE__ ); /* Likewise, change the Rx usage model from circular buffer, to use a character by character queue. Character by character Rx queue are a convenient receive method. They can, however, be inefficient if a lot of data is being received quickly. This command will always result in UART interrupts becoming enabled, with the interrupt priority set to the minimum possible. The Rx block time was set when the reception was set to use the circular buffer transfer mode. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CHARACTER_QUEUE_RX, uartstQUEUE_LENGTH ); prvCheckTestResult( xReturned, __LINE__ ); /* By default, the UART interrupt priority will have been reset to the lowest possible when the usage mode was changed. It must be at or kept below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority again. */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) configMAX_LIBRARY_INTERRUPT_PRIORITY ); prvCheckTestResult( xReturned, __LINE__ ); /* Unsuspend the Rx task ready for this test. */ vTaskResume( xRxTaskHandle ); for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ ) { /* Try writing a string again, this time using a character by character Tx queue, still with interrupts enabled. */ xReturned = FreeRTOS_write( xTestUART, pcTestMessage3, strlen( ( char * ) pcTestMessage3 ) ); prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage3 ) ), __LINE__ ); } /************************************************************************* * Test 4. Character queue Rx/Tx block times *************************************************************************/ /* Writing characters to a Tx queue has a block time. This is the total time spent trying to write the characters to the Tx queue if the queue is already full. If the task finds the queue full then it is held in the Blocked state until space becomes available, so no CPU time is wasted polling. If the block time expires before all the characters have been written to the queue then the FreeRTOS_write() call returns the number of characters that were successfully sent (as normal). */ xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_TX_TIMEOUT, uartstVERY_SHORT_TX_BLOCK_TIME ); prvCheckTestResult( xReturned, __LINE__ ); for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ ) { /* Try writing a string again, still using the character by character queue, but this time using a very short block time so not all the characters will make it into the queue. */ xTimeBefore = xTaskGetTickCount(); xReturned = FreeRTOS_write( xTestUART, pcTestMessage4, strlen( ( char * ) pcTestMessage4 ) ); xTimeAfter = xTaskGetTickCount(); prvCheckTestResult( ( xReturned != ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage4 ) ), __LINE__ ); prvCheckTestResult( ( ( xTimeAfter - xTimeBefore ) < ( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME + ( portTickType ) 2 ) ), __LINE__ ); FreeRTOS_write( xTestUART, "\r\n", strlen( ( char * ) "\r\n" ) ); } } }
static void prvI2CTask( void *pvParameters ) { Peripheral_Descriptor_t xI2CPort; const uint32_t ulMaxDelay = 500UL / portTICK_RATE_MS; ( void ) pvParameters; /* Open the I2C port used for writing to both the OLED and the EEPROM. The second parameter (ulFlags) is not used in this case. The port is opened in polling mode. It is changed to interrupt driven mode later in this function. */ xI2CPort = FreeRTOS_open( boardOLED_I2C_PORT, ( uint32_t ) i2cPARAMETER_NOT_USED ); configASSERT( xI2CPort ); /* The OLED must be initialised before it is used. */ vI2C_OLEDInitialise( xI2CPort ); /* Write and read-back operations are to be performed on the EEPROM while the I2C bus is in polling mode. Indicate this on the OLED. */ vOLEDPutString( 0U, ( uint8_t * ) "Testing EEPROM", OLED_COLOR_WHITE, OLED_COLOR_BLACK ); vOLEDPutString( oledCHARACTER_HEIGHT, ( uint8_t * ) "in polling mode", OLED_COLOR_WHITE, OLED_COLOR_BLACK ); vOLEDRefreshDisplay(); /* Perform the polling mode EEPROM tests/examples. */ vI2C_EEPROMTest( xI2CPort ); /* Perform the polling mode OLED write example. */ vI2C_OLEDTest( xI2CPort, ( uint8_t * ) "in polling mode" ); /* Switch to interrupt driven zero copy Tx mode and interrupt driven circular buffer Rx mode (with a limited time out). */ FreeRTOS_ioctl( xI2CPort, ioctlUSE_ZERO_COPY_TX, i2cPARAMETER_NOT_USED ); FreeRTOS_ioctl( xI2CPort, ioctlUSE_CIRCULAR_BUFFER_RX, i2cCIRCULAR_BUFFER_SIZE ); FreeRTOS_ioctl( xI2CPort, ioctlSET_RX_TIMEOUT, i2c200MS_TIMEOUT ); /* By default, the I2C interrupt priority will have been set to the lowest possible. It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its default priority using a FreeRTOS_ioctl() call with the ioctlSET_INTERRUPT_PRIORITY command. */ FreeRTOS_ioctl( xI2CPort, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) ); /* Write and read-back operations are to be performed on the EEPROM while the I2C bus is in interrupt driven zero copy Tx, and interrupt driven circular buffer Rx mode. Indicate this on the OLED. */ vOLEDPutString( 0U, ( uint8_t * ) "Testing EEPROM", OLED_COLOR_WHITE, OLED_COLOR_BLACK ); vOLEDPutString( oledCHARACTER_HEIGHT, ( uint8_t * ) "in intrpt mode", OLED_COLOR_WHITE, OLED_COLOR_BLACK ); /* Using zero copy Tx mode means the write mutex must be obtained prior to calling vOLEDRefreshDisplay(). The write mutex is retained when vOLEDRefreshDisplay() returns. */ FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay ); vOLEDRefreshDisplay(); /* Perform the interrupt driven mode EEPROM tests/examples. */ vI2C_EEPROMTest( xI2CPort ); /* Finish off by just continuously writing a scrolling message to the OLED. */ for( ;; ) { vI2C_OLEDTest( xI2CPort, ( uint8_t * ) "in intrpt mode" ); } }