| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- /*
- * FreeRTOS V202104.00
- * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
- /******************************************************************************
- * This project provides two demo applications. A simple blinky style project,
- * and a more comprehensive test and demo application. The
- * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
- * select between the two. The simply blinky demo is implemented and described
- * in main_blinky.c. The more comprehensive test and demo application is
- * implemented and described in main_full.c.
- *
- * This file implements the code that is not demo specific, including the
- * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
- * by the RTOS after interrupt entry (including nesting) has been taken care of.
- *
- * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
- * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
- * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
- *
- */
- /* Scheduler include files. */
- #include "FreeRTOS.h"
- #include "task.h"
- #include "semphr.h"
- /* Standard demo includes. */
- #include "partest.h"
- #include "TimerDemo.h"
- #include "QueueOverwrite.h"
- #include "EventGroupsDemo.h"
- /* Library includes. */
- #include "board.h"
- #include "chip.h"
- #ifdef ADC_TOUCH
- #include "touch.h"
- #endif
- #ifdef ADC_KEY
- #include "keypad.h"
- #endif
- //#define mainCREATE_SIMPLE_BLINKY_DEMO
- #ifdef VG_ONLY
- #define mainCREATE_OPENVG_DEMO
- #else
- #define mainCREATE_LVGL_DEMO
- #endif
- #if defined(mainCREATE_LVGL_DEMO)
- extern int main_lvgl(void);
- #elif defined(mainCREATE_OPENVG_DEMO)
- extern void main_openvg( void );
- #elif defined(mainCREATE_SIMPLE_BLINKY_DEMO)
- extern void main_blinky( void );
- #endif
- /*-----------------------------------------------------------*/
- /*
- * Configure the hardware as necessary to run this demo.
- */
- static void prvSetupHardware( void );
- /* Prototypes for the standard FreeRTOS callback/hook functions implemented
- within this file. */
- void vApplicationMallocFailedHook( size_t size );
- void vApplicationIdleHook( void );
- void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
- void vApplicationTickHook( void );
- /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
- layer. */
- void vApplicationIRQHandler( void );
- static void prvBoardLateInitTask( void *pvParameters )
- {
- ark_lcd_enable(1);
- #ifdef SDMMC_SUPPORT
- mmcsd_core_init();
- mmc_init();
- #endif
-
- #ifdef ADC_TOUCH
- adc_channel_enable(ADC_CH_TP);
- /* tp enable */
- vSysctlConfigure(SYS_ANA1_CFG, 26, 1, 1);
- if (LoadTouchConfigure()) {
- AdjustTouch();
- }
- #endif
- #ifdef ADC_KEY
- KeypadInit();
- #endif
- #ifdef AUDIO_REPLAY
- extern int sound_init(void);
- sound_init();
- #endif
- #ifdef USB_SUPPORT
- extern int ark_usb_init(void);
- ark_usb_init();
- #endif
- /* you'd better init the rtc driver at last */
- #ifdef RTC_SUPPORT
- rtc_init();
- SystemTime_t tm;
- iGetLocalTime(&tm);
- printf("Time: %d-%.2d-%.2d %.2d:%.2d:%.2d.\n", tm.tm_year, tm.tm_mon,
- tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- #endif
- for (;;) {
- vTaskDelay(portMAX_DELAY);
- }
- }
- /*-----------------------------------------------------------*/
- int main( void )
- {
- /* Configure the hardware ready to run the demo. */
- prvSetupHardware();
- /* lateinit the hardware which needs call task funcs */
- xTaskCreate(prvBoardLateInitTask, "lateinit", configMINIMAL_STACK_SIZE * 10, NULL,
- configMAX_PRIORITIES - 1, NULL);
- #if defined(mainCREATE_LVGL_DEMO) && LCD_INTERFACE_TYPE != LCD_INTERFACE_CPU
- main_lvgl();
- #elif defined(mainCREATE_OPENVG_DEMO)
- main_openvg();
- #elif defined(mainCREATE_SIMPLE_BLINKY_DEMO)
- main_blinky();
- #endif
- /* Start the tasks and timer running. */
- 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 insufficient FreeRTOS heap memory available for the idle and/or
- timer tasks to be created. See the memory management section on the
- FreeRTOS web site for more details. */
- for( ;; );
- }
- /*-----------------------------------------------------------*/
- #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
- #pragma data_alignment=16*1024
- static uint32_t MMUTable[4*1024];
- #else
- static uint32_t MMUTable[4*1024] __attribute__((aligned(16*1024)));
- #endif
- static void prvSetupHardware( void )
- {
- /* Disable watchdog */
- //WDT_Disable( WDT );
- /* Setup pinctrl */
- vPinctrlSetup();
- /* Setup clock */
- vClkInit();
- /* Configure a timer for delay */
- vInitialiseTimerForDelay();
- /* Initialize interrupt contorller */
- AIC_Initialize();
- /* Initialize Debug Uart */
- vDebugConsoleInitialise();
- printf("\r\ncpu_clk=%d, ddr_clk=%d, ahb_clk=%d, apb_clk=%d.\n", ulClkGetRate(CLK_CPU),
- ulClkGetRate(CLK_DDR), ulClkGetRate(CLK_AHB), ulClkGetRate(CLK_APB));
- /* Configure ports used by LEDs. */
- //vParTestInitialise();
- /* enable cache */
- MMU_Initialize(MMUTable);
- CP15_EnableMMU();
- CP15_EnableDcache();
- CP15_EnableIcache();
- dma_init();
- spi_init();
- i2c_init();
- wdt_init();
- jpegdec_init();
- itu_init();
- pxp_init();
- VideoDisplayBufInit();
- adc_init();
- #if LCD_INTERFACE_TYPE == LCD_INTERFACE_CPU
- Cpulcd_Init();
- #else
- lcd_init();
- #endif
- #ifdef ADC_TOUCH
- TouchInit();
- #endif
- }
- /*-----------------------------------------------------------*/
- void vApplicationMallocFailedHook( size_t size )
- {
- /* Called if a call to pvPortMalloc() fails because there is insufficient
- free memory available in the FreeRTOS heap. pvPortMalloc() is called
- internally by FreeRTOS API functions that create tasks, queues, software
- timers, and semaphores. The size of the FreeRTOS heap is set by the
- configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
- HeapStats_t heapStat;
- vPortGetHeapStats(&heapStat);
- printf("ERROR! Malloc %d bytes fail.\n", size);
- printf("xAvailableHeapSpaceInBytes %d.\n", heapStat.xAvailableHeapSpaceInBytes);
- printf("xSizeOfLargestFreeBlockInBytes %d.\n", heapStat.xSizeOfLargestFreeBlockInBytes);
- configASSERT( ( volatile void * ) NULL );
- }
- /*-----------------------------------------------------------*/
- void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
- {
- ( void ) pcTaskName;
- ( void ) pxTask;
- /* Run time stack overflow checking is performed if
- configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
- function is called if a stack overflow is detected. */
- printf("ERROR! task %s stack over flow.\n", pcTaskName);
- /* Force an assert. */
- configASSERT( ( volatile void * ) NULL );
- }
- /*-----------------------------------------------------------*/
- void vApplicationIdleHook( void )
- {
- static uint32_t idletick = 0;
- volatile size_t xFreeHeapSpace;
- /* This is just a trivial example of an idle hook. It is called on each
- cycle of the idle task. It must *NOT* attempt to block. In this case the
- idle task just queries the amount of FreeRTOS heap that remains. See the
- memory management section on the http://www.FreeRTOS.org web site for memory
- management options. If there is a lot of heap memory free then the
- configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
- RAM. */
- xFreeHeapSpace = xPortGetFreeHeapSize();
- /* Remove compiler warning about xFreeHeapSpace being set but never used. */
- ( void ) xFreeHeapSpace;
- if (xTaskGetTickCount() - idletick > configTICK_RATE_HZ * 10) {
- printf("Memory free: %d bytes.\n", xFreeHeapSpace);
- idletick = xTaskGetTickCount();
- }
- }
- /*-----------------------------------------------------------*/
- void vAssertCalled( const char * pcFile, unsigned long ulLine )
- {
- volatile unsigned long ul = 0;
- printf("vAssertCalled %s %d.\n", pcFile, ulLine);
- taskENTER_CRITICAL();
- {
- /* Set ul to a non-zero value using the debugger to step out of this
- function. */
- while( ul == 0 )
- {
- portNOP();
- }
- }
- taskEXIT_CRITICAL();
- }
- /*-----------------------------------------------------------*/
- void vApplicationTickHook( void )
- {
- }
- /*-----------------------------------------------------------*/
- /* The function called by the RTOS port layer after it has managed interrupt
- entry. */
- void vApplicationIRQHandler( void )
- {
- AIC_IrqHandler();
- __DSB();
- __ISB();
- }
- /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
- implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
- used by the Idle task. */
- void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
- {
- /* If the buffers to be provided to the Idle task are declared inside this
- function then they must be declared static - otherwise they will be allocated on
- the stack and so not exists after this function exits. */
- static StaticTask_t xIdleTaskTCB;
- static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
- /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
- state will be stored. */
- *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
- /* Pass out the array that will be used as the Idle task's stack. */
- *ppxIdleTaskStackBuffer = uxIdleTaskStack;
- /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configMINIMAL_STACK_SIZE is specified in words, not bytes. */
- *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
- }
- /*-----------------------------------------------------------*/
- /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
- application must provide an implementation of vApplicationGetTimerTaskMemory()
- to provide the memory that is used by the Timer service task. */
- void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
- {
- /* If the buffers to be provided to the Timer task are declared inside this
- function then they must be declared static - otherwise they will be allocated on
- the stack and so not exists after this function exits. */
- static StaticTask_t xTimerTaskTCB;
- static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
- /* Pass out a pointer to the StaticTask_t structure in which the Timer
- task's state will be stored. */
- *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
- /* Pass out the array that will be used as the Timer task's stack. */
- *ppxTimerTaskStackBuffer = uxTimerTaskStack;
- /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configMINIMAL_STACK_SIZE is specified in words, not bytes. */
- *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
- }
|