| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- #include "FreeRTOS.h"
- #include "board.h"
- #include "sysinfo.h"
- #include "chip.h"
- static uint32_t chip_hversion = CHIP_HVER_NONE;
- static const char* abort_status[][2]=
- {
- // IFSR status , DFSR status
- {"Unknown(reserved status)", "Unknown(reserved status)" },//0
- {"Unknown(reserved status)", "Alignment Fault" },//1
- {"Debug Event", "Debug Event" },//2
- {"Access flag - section", "Access flag - section" },//3
- {"Unknown(reserved status)", "Instruction cache maintenance" },//4
- {"Translation fault - section", "Translation fault - section" },//5
- {"Access flag - Page", "Access flag - Page" },//6
- {"Translation fault -Page", "Translation fault -Page" },//7
- {"Synchronous external abort", "Synchronous external abort, nontranslation" },//8
- {"Domain fault - Section", "Domain fault - Section" },//9
- {"Unknown(reserved status)", "Unknown(reserved status)" },//10
- {"Domain fault - Page", "Domain fault - Page" },//11
- {"Synchronous external abort - L1 Translation", "Synchronous external abort - L1 Translation" },//12
- {"Permission fault - Section", "Permission fault - Section" },//13
- {"Synchronous external abort - L2 Translation", "Synchronous external abort - L2 Translation" },//14
- {"Permission fault - Page", "Permission fault - Page" },//15
- {"Unknown(reserved status)", "Unknown(reserved status)" },//16
- {"Unknown(reserved status)", "Unknown(reserved status)" },//17
- {"Unknown(reserved status)", "Unknown(reserved status)" },//18
- {"Unknown(reserved status)", "Unknown(reserved status)" },//19
- {"Unknown(reserved status)", "Unknown(reserved status)" },//20
- {"Unknown(reserved status)", "Unknown(reserved status)" },//21
- {"Unknown(reserved status)", "Asynchronous external abort"}
- };
- void LowLevelInit( void )
- {
- }
- void Abort_C_Handler( void)
- {
- uint32_t v1,v2, dfsr, lr;
- v1= 0;
- v2= 0;
- lr = 0;
- asm("mov %0,lr" : : "r"(lr));
- printf("abort lr=0x%x.\n", lr);
- asm("mrc p15, 0, %0, c5, c0, 0" : : "r"(v1));
- asm("mrc p15, 0, %0, c6, c0, 0" : : "r"(v2));
- dfsr = ((v1 >> 4) & 0x0F);
- printf("\n\r######################################################################\n\r");
- printf("Data Abort occured in %x domain\n\r", (unsigned int)dfsr);
- dfsr = (((v1 & 0x400) >> 6) | (v1 & 0x0F));
- printf("Data abort fault reason is: %s\n\r", (char*)abort_status[dfsr][1]);
- printf("Data fault occured at Address = 0x%08x\n\n\r",(unsigned int)v2);
- printf("-[Info]-Data fault status register value = 0x%x\n\r",(unsigned int)v1);
- while(1);
- }
- void Prefetch_C_Handler( void)
- {
- uint32_t v1,v2, ifsr;
- v1= 0;
- v2= 0;
- asm("mrc p15, 0, %0, c5, c0, 1" : : "r"(v1));
- asm("mrc p15, 0, %0, c6, c0, 2" : : "r"(v2));
- ifsr = (((v1 & 0x400) >> 6) | (v1 & 0x0F));
- printf("\n\r######################################################################\n\r");
- printf("Instruction prefetch abort reason is: %s\n\r", (char*)abort_status[ifsr][0]);
- printf("Instruction prefetch Fault occured at Address = 0x%08x\n\n\r",(unsigned int)v2);
- printf("-[INFO]- Prefetch Fault status register value by = 0x%x\n\r",(unsigned int)v1);
- while(1);
- }
- void Undefined_C_Handler( void)
- {
- printf("Undefined abort \n\r");
- while(1);
- }
- /*-----------------------------------------------------------*/
- 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;
- ( void ) pcFile;
- ( void ) ulLine;
- printf("crash %s : %d", 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 )
- {
- GIC_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;
- }
- uint32_t GetChipHWVeriosn(void)
- {
- ChipInfo *info = (ChipInfo *)(0x8000 - sizeof(ChipInfo));
- if (chip_hversion != CHIP_HVER_NONE)
- return chip_hversion;
- chip_hversion = CHIP_HVER_0; //default chip version is CHIP_HVER_0.
- if (info->crc == xcrc32((void*)info, sizeof(ChipInfo) - 4, 0xffffffff, HARD_CALC_CRC)) {
- if (info->hver >= CHIP_HVER_COUNT) {
- printf("Invalie chip version info.\n");
- return chip_hversion;
- }
- chip_hversion = info->hver;
- return chip_hversion;
- }
- printf("chip version info invalid.\n");
- return chip_hversion;
- }
|