-// See LICENSE for license details.\r
+/*\r
+ * FreeRTOS Kernel V10.1.1\r
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
\r
+/* FreeRTOS kernel includes. */\r
#include <FreeRTOS.h>\r
#include <task.h>\r
\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include "platform.h"\r
-#include <string.h>\r
-#include "plic/plic_driver.h"\r
-#include "encoding.h"\r
-#include <unistd.h>\r
-#include "stdatomic.h"\r
-\r
+/******************************************************************************\r
+ * This project provides two demo applications. A simple blinky style project,\r
+ * and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
+ * select between the two. The simply blinky demo is implemented and described\r
+ * in main_blinky.c. The more comprehensive test and demo application is\r
+ * implemented and described in main_full.c.\r
+ *\r
+ * This file implements the code that is not demo specific, including the\r
+ * hardware setup and standard FreeRTOS hook functions.\r
+ *\r
+ * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
+ * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
+ * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
+ *\r
+ */\r
\r
+/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
+or 0 to run the more comprehensive test and demo application. */\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0\r
\r
/*\r
- * FreeRTOS hook for when malloc fails, enable in FreeRTOSConfig.\r
+ * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
*/\r
+#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
+ extern void main_blinky( void );\r
+#else\r
+ extern void main_full( void );\r
+#endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
+\r
+/* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
+within this file. See https://www.freertos.org/a00016.html */\r
void vApplicationMallocFailedHook( void );\r
-\r
-/*\r
- * FreeRTOS hook for when FreeRtos is idling, enable in FreeRTOSConfig.\r
- */\r
void vApplicationIdleHook( void );\r
-\r
-/*\r
- * FreeRTOS hook for when a stack overflow occurs, enable in FreeRTOSConfig.\r
- */\r
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
+void vApplicationTickHook( void );\r
\r
-\r
-\r
-void vRegTest1Task( void *pvParameters );\r
-void vRegTest2Task( void *pvParameters );\r
-\r
-\r
-const char * const pcStartMessage = "FreeRTOS demo\r\n";\r
-volatile uint32_t ulRegTest1LoopCounter = 0, ulRegTest2LoopCounter = 0;\r
-static void prvCheckTask( void *pvParameters );\r
-plic_instance_t g_plic;\r
-uint32_t bitbang_mask = 0;\r
+/*-----------------------------------------------------------*/\r
\r
int main( void )\r
{\r
- #ifdef HAS_BOARD_BUTTONS\r
- GPIO_REG(GPIO_OUTPUT_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));\r
- GPIO_REG(GPIO_PULLUP_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));\r
- GPIO_REG(GPIO_INPUT_EN) |= ((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));\r
- #endif\r
-\r
- GPIO_REG(GPIO_INPUT_EN) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;\r
- GPIO_REG(GPIO_OUTPUT_EN) |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;\r
- GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ;\r
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ;\r
-\r
- /* For Bit-banging with Atomics demo. */\r
- #ifdef _SIFIVE_HIFIVE1_H\r
- bitbang_mask = (1 << PIN_19_OFFSET);\r
+ /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
+ of this file. */\r
+ #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
+ {\r
+ main_blinky();\r
+ }\r
#else\r
- #ifdef _SIFIVE_COREPLEXIP_ARTY_H\r
- bitbang_mask = (0x1 << JA_0_OFFSET);\r
- #endif\r
- #endif\r
-\r
- GPIO_REG(GPIO_OUTPUT_EN) |= bitbang_mask;\r
-\r
-// xTaskCreate( vRegTest1Task, "RegTest1", 1000, NULL, tskIDLE_PRIORITY, NULL );\r
-// xTaskCreate( vRegTest2Task, "RegTest2", 1000, NULL, tskIDLE_PRIORITY, NULL );\r
- xTaskCreate( prvCheckTask, "Check", 1000, NULL, configMAX_PRIORITIES - 1, NULL );\r
-\r
- vTaskStartScheduler();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvCheckTask( void *pvParameters )\r
-{\r
-const char *pcMessage = "PASS\r\n";\r
-const TickType_t xCheckPeriod = pdMS_TO_TICKS( 3000UL );\r
-uint32_t ulLastRegTest1LoopCounter = 0, ulLastRegTest2LoopCounter = 0;\r
-volatile uintptr_t mstatus;\r
-\r
-volatile uint32_t ulx;\r
-__asm volatile ("csrr %0, mstatus" : "=r"(mstatus));\r
-portENABLE_INTERRUPTS();\r
-__asm volatile ("csrr %0, mstatus" : "=r"(mstatus));\r
-for( ;; )\r
-{\r
-// for( ulx = 0; ulx < 0xffff; ulx++ ) __asm volatile( "NOP" );\r
-// vPortSetupTimerInterrupt();\r
- vTaskDelay( xCheckPeriod );\r
- write( STDOUT_FILENO, "Blip\r\n", strlen( "Blip\r\n" ) );\r
-}\r
-#if 0\r
- for( ;; )\r
{\r
- vTaskDelay( xCheckPeriod );\r
-\r
- if( ulLastRegTest1LoopCounter == ulRegTest1LoopCounter )\r
- {\r
- /* The RegTest1 loop counter is no longer incrementing, indicating\r
- the task failed its self check. */\r
- pcMessage = "FAIL: RegTest1\r\n";\r
- }\r
- else\r
- {\r
- ulLastRegTest1LoopCounter = ulRegTest1LoopCounter;\r
- }\r
-\r
- if( ulLastRegTest2LoopCounter == ulRegTest2LoopCounter )\r
- {\r
- /* The RegTest1 loop counter is no longer incrementing, indicating\r
- the task failed its self check. */\r
- pcMessage = "FAIL: RegTest2\r\n";\r
- }\r
- else\r
- {\r
- ulLastRegTest2LoopCounter = ulRegTest2LoopCounter;\r
- }\r
-\r
- vUARTWriteString( pcMessage );\r
+ main_full();\r
}\r
-#endif\r
+ #endif\r
}\r
/*-----------------------------------------------------------*/\r
\r
to query the size of free heap space that remains (although it does not\r
provide information on how the remaining heap might be fragmented). */\r
taskDISABLE_INTERRUPTS();\r
+// __asm volatile( "ebreak" );\r
for( ;; );\r
}\r
/*-----------------------------------------------------------*/\r
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
function is called if a stack overflow is detected. */\r
taskDISABLE_INTERRUPTS();\r
+// __asm volatile( "ebreak" );\r
for( ;; );\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#define mainINTERRUPT_BIT_SET 0x80000000UL\r
-#define mainENVIRONMENT_CALL 11UL\r
-#define mainEXTERNAL_INTERRRUPT ( mainINTERRUPT_BIT_SET | 11UL )\r
-#define mainTIMER_INTERRUPT ( mainINTERRUPT_BIT_SET | 7UL )\r
-#define mainSOFTWARE_INTERRUPT ( mainINTERRUPT_BIT_SET | 3UL )\r
-\r
-extern void Timer_IRQHandler( void );\r
-\r
-uint32_t ulPortTrapHandler( uint32_t mcause, uint32_t mepc )\r
+void vApplicationTickHook( void )\r
{\r
- if( mcause == mainENVIRONMENT_CALL )\r
+ /* The tests in the full demo expect some interaction with interrupts. */\r
+ #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )\r
{\r
- vTaskSwitchContext();\r
-\r
- /* Ensure not to return to the instruction that generated the exception. */\r
- mepc += 4;\r
- }\r
- else if( mcause == mainEXTERNAL_INTERRRUPT )\r
- {\r
- for( ;; );\r
- }\r
- else if( mcause == mainTIMER_INTERRUPT )\r
- {\r
- Timer_IRQHandler();\r
- }\r
- else if( mcause == mainSOFTWARE_INTERRUPT )\r
- {\r
- for( ;; );\r
+ extern void vFullDemoTickHook( void );\r
+ vFullDemoTickHook();\r
}\r
+ #endif\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
- return mepc;\r
+void vAssertCalled( void )\r
+{\r
+ taskDISABLE_INTERRUPTS();\r
+// __asm volatile( "ebreak" );\r
+ for( ;; );\r
}\r