mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-29 22:48:37 -04:00
Backup checking of the Freedom Studio RISC-V project - still a work in progress.
This commit is contained in:
parent
65f7a2dc19
commit
4b9dd38d1c
8 changed files with 801 additions and 277 deletions
|
@ -1,126 +1,87 @@
|
|||
// See LICENSE for license details.
|
||||
/*
|
||||
* FreeRTOS Kernel V10.1.1
|
||||
* Copyright (C) 2018 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!
|
||||
*/
|
||||
|
||||
/* FreeRTOS kernel includes. */
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "platform.h"
|
||||
#include <string.h>
|
||||
#include "plic/plic_driver.h"
|
||||
#include "encoding.h"
|
||||
#include <unistd.h>
|
||||
#include "stdatomic.h"
|
||||
|
||||
/******************************************************************************
|
||||
* 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 and standard FreeRTOS hook functions.
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
*/
|
||||
|
||||
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
|
||||
or 0 to run the more comprehensive test and demo application. */
|
||||
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
|
||||
|
||||
/*
|
||||
* FreeRTOS hook for when malloc fails, enable in FreeRTOSConfig.
|
||||
* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
|
||||
* main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
|
||||
*/
|
||||
#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
|
||||
extern void main_blinky( void );
|
||||
#else
|
||||
extern void main_full( void );
|
||||
#endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
|
||||
|
||||
/* Prototypes for the standard FreeRTOS callback/hook functions implemented
|
||||
within this file. See https://www.freertos.org/a00016.html */
|
||||
void vApplicationMallocFailedHook( void );
|
||||
|
||||
/*
|
||||
* FreeRTOS hook for when FreeRtos is idling, enable in FreeRTOSConfig.
|
||||
*/
|
||||
void vApplicationIdleHook( void );
|
||||
|
||||
/*
|
||||
* FreeRTOS hook for when a stack overflow occurs, enable in FreeRTOSConfig.
|
||||
*/
|
||||
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
|
||||
void vApplicationTickHook( void );
|
||||
|
||||
|
||||
|
||||
void vRegTest1Task( void *pvParameters );
|
||||
void vRegTest2Task( void *pvParameters );
|
||||
|
||||
|
||||
const char * const pcStartMessage = "FreeRTOS demo\r\n";
|
||||
volatile uint32_t ulRegTest1LoopCounter = 0, ulRegTest2LoopCounter = 0;
|
||||
static void prvCheckTask( void *pvParameters );
|
||||
plic_instance_t g_plic;
|
||||
uint32_t bitbang_mask = 0;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int main( void )
|
||||
{
|
||||
#ifdef HAS_BOARD_BUTTONS
|
||||
GPIO_REG(GPIO_OUTPUT_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));
|
||||
GPIO_REG(GPIO_PULLUP_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));
|
||||
GPIO_REG(GPIO_INPUT_EN) |= ((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));
|
||||
#endif
|
||||
|
||||
GPIO_REG(GPIO_INPUT_EN) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
|
||||
GPIO_REG(GPIO_OUTPUT_EN) |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
|
||||
GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ;
|
||||
GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ;
|
||||
|
||||
/* For Bit-banging with Atomics demo. */
|
||||
#ifdef _SIFIVE_HIFIVE1_H
|
||||
bitbang_mask = (1 << PIN_19_OFFSET);
|
||||
#else
|
||||
#ifdef _SIFIVE_COREPLEXIP_ARTY_H
|
||||
bitbang_mask = (0x1 << JA_0_OFFSET);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GPIO_REG(GPIO_OUTPUT_EN) |= bitbang_mask;
|
||||
|
||||
// xTaskCreate( vRegTest1Task, "RegTest1", 1000, NULL, tskIDLE_PRIORITY, NULL );
|
||||
// xTaskCreate( vRegTest2Task, "RegTest2", 1000, NULL, tskIDLE_PRIORITY, NULL );
|
||||
xTaskCreate( prvCheckTask, "Check", 1000, NULL, configMAX_PRIORITIES - 1, NULL );
|
||||
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckTask( void *pvParameters )
|
||||
{
|
||||
const char *pcMessage = "PASS\r\n";
|
||||
const TickType_t xCheckPeriod = pdMS_TO_TICKS( 3000UL );
|
||||
uint32_t ulLastRegTest1LoopCounter = 0, ulLastRegTest2LoopCounter = 0;
|
||||
volatile uintptr_t mstatus;
|
||||
|
||||
volatile uint32_t ulx;
|
||||
__asm volatile ("csrr %0, mstatus" : "=r"(mstatus));
|
||||
portENABLE_INTERRUPTS();
|
||||
__asm volatile ("csrr %0, mstatus" : "=r"(mstatus));
|
||||
for( ;; )
|
||||
{
|
||||
// for( ulx = 0; ulx < 0xffff; ulx++ ) __asm volatile( "NOP" );
|
||||
// vPortSetupTimerInterrupt();
|
||||
vTaskDelay( xCheckPeriod );
|
||||
write( STDOUT_FILENO, "Blip\r\n", strlen( "Blip\r\n" ) );
|
||||
}
|
||||
#if 0
|
||||
for( ;; )
|
||||
/* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
|
||||
of this file. */
|
||||
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
|
||||
{
|
||||
vTaskDelay( xCheckPeriod );
|
||||
|
||||
if( ulLastRegTest1LoopCounter == ulRegTest1LoopCounter )
|
||||
{
|
||||
/* The RegTest1 loop counter is no longer incrementing, indicating
|
||||
the task failed its self check. */
|
||||
pcMessage = "FAIL: RegTest1\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ulLastRegTest1LoopCounter = ulRegTest1LoopCounter;
|
||||
}
|
||||
|
||||
if( ulLastRegTest2LoopCounter == ulRegTest2LoopCounter )
|
||||
{
|
||||
/* The RegTest1 loop counter is no longer incrementing, indicating
|
||||
the task failed its self check. */
|
||||
pcMessage = "FAIL: RegTest2\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ulLastRegTest2LoopCounter = ulRegTest2LoopCounter;
|
||||
}
|
||||
|
||||
vUARTWriteString( pcMessage );
|
||||
main_blinky();
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
{
|
||||
main_full();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
@ -137,6 +98,7 @@ void vApplicationMallocFailedHook( void )
|
|||
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();
|
||||
// __asm volatile( "ebreak" );
|
||||
for( ;; );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -164,39 +126,26 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
|
|||
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
|
||||
function is called if a stack overflow is detected. */
|
||||
taskDISABLE_INTERRUPTS();
|
||||
// __asm volatile( "ebreak" );
|
||||
for( ;; );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#define mainINTERRUPT_BIT_SET 0x80000000UL
|
||||
#define mainENVIRONMENT_CALL 11UL
|
||||
#define mainEXTERNAL_INTERRRUPT ( mainINTERRUPT_BIT_SET | 11UL )
|
||||
#define mainTIMER_INTERRUPT ( mainINTERRUPT_BIT_SET | 7UL )
|
||||
#define mainSOFTWARE_INTERRUPT ( mainINTERRUPT_BIT_SET | 3UL )
|
||||
|
||||
extern void Timer_IRQHandler( void );
|
||||
|
||||
uint32_t ulPortTrapHandler( uint32_t mcause, uint32_t mepc )
|
||||
void vApplicationTickHook( void )
|
||||
{
|
||||
if( mcause == mainENVIRONMENT_CALL )
|
||||
/* The tests in the full demo expect some interaction with interrupts. */
|
||||
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
|
||||
{
|
||||
vTaskSwitchContext();
|
||||
|
||||
/* Ensure not to return to the instruction that generated the exception. */
|
||||
mepc += 4;
|
||||
extern void vFullDemoTickHook( void );
|
||||
vFullDemoTickHook();
|
||||
}
|
||||
else if( mcause == mainEXTERNAL_INTERRRUPT )
|
||||
{
|
||||
for( ;; );
|
||||
}
|
||||
else if( mcause == mainTIMER_INTERRUPT )
|
||||
{
|
||||
Timer_IRQHandler();
|
||||
}
|
||||
else if( mcause == mainSOFTWARE_INTERRUPT )
|
||||
{
|
||||
for( ;; );
|
||||
}
|
||||
|
||||
return mepc;
|
||||
#endif
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vAssertCalled( void )
|
||||
{
|
||||
taskDISABLE_INTERRUPTS();
|
||||
// __asm volatile( "ebreak" );
|
||||
for( ;; );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue