int main( void ) { sysInit(); /* USB Power dinyalakan supaya memory USB bisa dipakai */ PCONP |= 0x80000000; FIO0DIR = LED_UTAMA; FIO0CLR = LED_UTAMA; FIO1DIR = 0xFFFFFFFF; #ifdef PAKAI_SERIAL_3 /* PCONP enable UART3 */ PCONP |= BIT(25); /* PCLK UART3, PCLK = CCLK */ PCLKSEL1 &= ~(BIT(18) | BIT(19)); PCLKSEL1 |= BIT(18); /* init TX3, RX3 */ PINSEL1 &= ~(BIT(18) | BIT(19) | BIT(20) | BIT(21)); PINSEL1 |= (BIT(18) | BIT(19)); PINSEL1 |= (BIT(20) | BIT(21)); PINSEL1 &= ~(BIT(16) | BIT(17)); /* TXDE di highkan */ FIO0DIR |= TXDE; //FIO0SET = TXDE; // on ---> bisa kirim //FIO0SET &= ~TXDE; // off ---> gak bisa kirim //FIO0CLR = TXDE; FIO0SET = TXDE; FIO0DIR |= RXDE; FIO0SET = RXDE; #endif #ifdef PAKAI_SERIAL_2 /* PCONP enable UART2 */ PCONP |= BIT(24); /* PCLK UART2, PCLK = CCLK */ PCLKSEL1 &= ~(BIT(16) | BIT(17)); PCLKSEL1 |= BIT(16); /* init TX2, RX2 */ PINSEL0 |= (BIT(20) | BIT(22)); #endif /* untuk cek blinking saat system boot */ #ifdef CEK_BLINK int t=0; while(t<5) { dele(1000000); FIO0CLR = LED_UTAMA; dele(1000000); FIO0SET = LED_UTAMA; t++; } #endif xSerialPortInitMinimal( BAUD_RATE, configMINIMAL_STACK_SIZE ); #ifdef PAKAI_SERIAL_2 serial2_init( BAUD_PM, (1 * configMINIMAL_STACK_SIZE) ); #endif #ifdef PAKAI_SERIAL_3 serial3_init( BAUD_PM, (1 * configMINIMAL_STACK_SIZE) ); #endif #ifdef PAKAI_ADC init_gpio_adc(); init_gpio_mmc(); init_spi_mmc(0); // untuk adc dan mmc #endif #ifdef jalankan init_led_utama(); start_ether(); #if (defined(PAKAI_PM) && defined(AMBIL_PM)) //init_task_pm(); #endif init_shell(); vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the idle task. */ return 0; #endif
void InitCmdHandlerTask(void) { xComPort = xSerialPortInitMinimal(57600, 1024); xTaskCreate(vCmdHandlerTask, "CmdHandlerTask", configMINIMAL_STACK_SIZE, NULL, 1, NULL); }
void main_full( void ) { /* The baud rate setting here has no effect, hence it is set to 0 to make that obvious. */ xSerialPortInitMinimal( 0, mainUART_QUEUE_LENGTHS ); /* 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 are 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 vApplicationIdleHook() - which is defined in this file. */ #if ( mainINCLUDE_FAT_SL_DEMO == 1 )&& ( F_FS_THREAD_AWARE == 0 ) { /* 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. */ vCreateAndVerifySampleFiles(); } #endif /* Start all the other standard demo/test tasks. The have not particular functionality, but do demonstrate how to use the FreeRTOS API and test the kernel port. */ vStartDynamicPriorityTasks(); vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); vCreateBlockTimeTasks(); vStartCountingSemaphoreTasks(); vStartGenericQueueTasks( tskIDLE_PRIORITY ); vStartRecursiveMutexTasks(); vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); vStartMathTasks( mainFLOP_TASK_PRIORITY ); vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); #if mainINCLUDE_FAT_SL_DEMO == 1 { /* Start the tasks that implements the command console on the UART, as described above. */ vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY ); /* Register both the standard and file system related CLI commands. */ vRegisterSampleCLICommands(); vRegisterFileSystemCLICommands(); } #else { /* The COM test tasks can use the UART if the CLI is not used by the FAT SL demo. The COM test tasks require a UART connector to be fitted to the UART port. */ vAltStartComTestTasks( mainCOM_TEST_TASK_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED ); } #endif /* Create the register check tasks, as described at the top of this file */ xTaskCreate( prvRegTestTaskEntry1, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvRegTestTaskEntry2, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL ); /* Create the task that performs the 'check' functionality, as described at the top of this file. */ xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); /* The set of tasks created by the following function call have to be created last as they keep account of the number of tasks they expect to see running. */ vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); /* Start the scheduler. */ vTaskStartScheduler(); /* If all is well, the scheduler will now be running, and the following line will never be reached. If the following line does execute, then there was either insufficient FreeRTOS heap memory available for the idle and/or timer tasks to be created, or vTaskStartScheduler() was called from User mode. See the memory management section on the FreeRTOS web site for more details on the FreeRTOS heap http://www.freertos.org/a00111.html. The mode from which main() is called is set in the C start up code and must be a privileged mode (not user mode). */ for( ;; ); }
static void prvUARTCommandConsoleTask( void *pvParameters ) { signed char cRxedChar; uint8_t ucInputIndex = 0; char *pcOutputString; static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ]; portBASE_TYPE 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, 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, 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, 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, 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 ); } } }