- /*************************************************************************//**
- * [url=home.php?mod=space&uid=288409]@file[/url] main.c
- * [url=home.php?mod=space&uid=895143]@version[/url] V1.00
- * [url=home.php?mod=space&uid=247401]@brief[/url] A uIP httpd sample for M451 MCU and DM9051 with FreeRTOS.
- *
- *
- * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2019 Nuvoton Technology Corp. All rights reserved.
- *****************************************************************************/
- /* Standard includes. */
- #include <stdio.h>
- /* Scheduler includes. */
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "M451Series.h"
- #include "uIP_Task.h"
- /* Task function*/
- static void vLEDTask(void *pvParameters);
- /* Sys init function*/
- static void prvSetupHardware(void);
- void SYS_Init(void);
- void UART0_Init(void);
- int Web_LED_FLASH = 1; // Default set 1 use freertos task control led, if set 0 web control
- int main(void)
- {
- /* Init System */
- prvSetupHardware();
- /* create task */
- xTaskCreate(vuIP_Task, "uIP", configMINIMAL_STACK_SIZE * 3, NULL, tskIDLE_PRIORITY + 4, NULL);
- xTaskCreate(vLEDTask, "LED", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
- printf("FreeRTOS is starting ...\n");
- /* start OS */
- vTaskStartScheduler();
- for (;;);
- }
- /*-----------------------------------------------------------*/
- void vLEDTask(void *pvParameters)
- {
- /* Set LED */
- GPIO_EnableInt(PC, 9, GPIO_INT_FALLING);
- GPIO_SetMode(PC, BIT9, GPIO_MODE_OUTPUT);
- for (;;)
- {
- if (Web_LED_FLASH == 1)
- {
- PC9 = 1;
- vTaskDelay(500 / portTICK_RATE_MS);
- PC9 = 0;
- vTaskDelay(500 / portTICK_RATE_MS);
- }
- }
- }
- /*-----------------------------------------------------------*/
- static void prvSetupHardware(void)
- {
- SYS_Init();
- UART0_Init();
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init NUC_M451 System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- void SYS_Init(void)
- {
- /* Unlock protected registers */
- SYS_UnlockReg();
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Enable HIRC clock (Internal RC 22.1184MHz) */
- CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
- /* Wait for HIRC clock ready */
- CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
- /* Select HCLK clock source as HIRC and and HCLK source divider as 1 */
- CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
- /* Enable HXT clock (external XTAL 12MHz) */
- CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
- /* Wait for HXT clock ready */
- CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
- /* Set core clock as PLL_CLOCK from PLL */
- CLK_SetCoreClock(FREQ_72MHZ);
- CLK_EnableModuleClock(TMR0_MODULE);
- /* Update System Core Clock */
- /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
- SystemCoreClockUpdate();
- /* Lock protected registers */
- SYS_LockReg();
- }
- /*-----------------------------------------------------------*/
- void UART0_Init(void)
- {
- /* Enable UART0 Module clock */
- CLK_EnableModuleClock(UART0_MODULE);
- /* UART0 module clock from EXT */
- CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init I/O Multi-function */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Configure multi-function pins for UART0 RXD and TXD */
- SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
- SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
- /* Configure UART0 and set UART0 Baud-rate */
- UART_Open(UART0, 115200);
- }
- void vApplicationMallocFailedHook(void)
- {
- /* vApplicationMallocFailedHook() will only be called if
- configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
- function that will get called if a call to pvPortMalloc() fails.
- pvPortMalloc() is called internally by the kernel whenever a task, queue,
- timer or semaphore is created. It is also called by various parts of the
- demo application. If heap_1.c or heap_2.c are used, then the size of the
- heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
- FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
- to query the size of free heap space that remains (although it does not
- provide information on how the remaining heap might be fragmented). */
- //taskDISABLE_INTERRUPTS();
- //for(;;);
- }
- void vApplicationTickHook(void)
- {
- /* This function will be called by each tick interrupt if
- configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
- added here, but the tick hook is called from an interrupt context, so
- code must not attempt to block, and only the interrupt safe FreeRTOS API
- functions can be used (those that end in FromISR()). */
- #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
- {
- /* In this case the tick hook is used as part of the queue set test. */
- //vQueueSetAccessQueueSetFromISR();
- }
- #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */
- }
- void vApplicationIdleHook(void)
- {
- /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
- to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
- task. It is essential that code added to this hook function never attempts
- to block in any way (for example, call xQueueReceive() with a block time
- specified, or call vTaskDelay()). If the application makes use of the
- vTaskDelete() API function (as this demo application does) then it is also
- important that vApplicationIdleHook() is permitted to return to its calling
- function, because it is the responsibility of the idle task to clean up
- memory allocated by the kernel to any task that has since been deleted. */
- }
- /*** (C) COPYRIGHT 2019 Nuvoton Technology Corp. ***/
|