Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/05 - Steps to work with FreeRTOS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1) clone the repository
2) Inside /esh clone the freeRTOS kernel source code : https://github.com/FreeRTOS/FreeRTOS-Kernel
3) Disable the configAssert of port.c in freeRTOS kernel Code (For the given example of GCC/ARM3/port.c Line 370)
4) make
5) make run

This will start two tasks concurrently one to run shell and other to periodically print a statement
189 changes: 189 additions & 0 deletions examples/emulation/freertos/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* FreeRTOS V202212.01
* 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.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configUSE_TRACE_FACILITY 0
#define configGENERATE_RUN_TIME_STATS 0

#define configUSE_TICKLESS_IDLE 0
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 1
#define configCPU_CLOCK_HZ ( ( unsigned long ) 25000000 )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 80 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 60 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_QUEUE_SETS 1
#define configUSE_COUNTING_SEMAPHORES 1

#define configMAX_PRIORITIES ( 9UL )
#define configQUEUE_REGISTRY_SIZE 10
#define configSUPPORT_STATIC_ALLOCATION 1

/* Timer related defines. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 4 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )

#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1

/* This demo makes use of one or more example stats formatting functions. These
format the raw data provided by the uxTaskGetSystemState() function in to human
readable ASCII form. See the notes in the implementation of vTaskList() within
FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 0

#define configKERNEL_INTERRUPT_PRIORITY ( 255 ) /* All eight bits as QEMU doesn't model the priority bits. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( 191 )

/* Use the Cortex-M3 optimised task selection rather than the generic C code
version. */
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1

/* The Win32 target is capable of running all the tests tasks at the same
* time. */
#define configRUN_ADDITIONAL_TESTS 1

/* The test that checks the trigger level on stream buffers requires an
allowable margin of error on slower processors (slower than the Win32
machine on which the test is developed). */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 4

#ifndef __IASMARM__ /* Prevent C code being included in IAR asm files. */
void vAssertCalled( const char *pcFileName, uint32_t ulLine );
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ );
#endif

#define intqHIGHER_PRIORITY ( configMAX_PRIORITIES - 5 )
#define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 )
#define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 )

#endif /* FREERTOS_CONFIG_H */

// #define configUSE_MALLOC_FAILED_HOOK 0
// #define configUSE_MUTEXES 1
// #define configUSE_RECURSIVE_MUTEXES 1
// #define configUSE_TIMERS 1
// #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )

// #define INCLUDE_vTaskPrioritySet 1
// #define INCLUDE_uxTaskPriorityGet 1
// #define INCLUDE_vTaskDelete 1
// #define INCLUDE_vTaskCleanUpResources 0
// #define INCLUDE_vTaskSuspend 1
// #define INCLUDE_vTaskDelayUntil 1
// #define INCLUDE_vTaskDelay 1
// #define INCLUDE_uxTaskGetStackHighWaterMark 1
// #define INCLUDE_uxTaskGetStackHighWaterMark2 1
// #define INCLUDE_xTaskGetSchedulerState 1
// #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
// #define INCLUDE_xTaskGetIdleTaskHandle 1
// #define INCLUDE_xTaskGetHandle 1
// #define INCLUDE_eTaskGetState 1
// #define INCLUDE_xSemaphoreGetMutexHolder 1
// #define INCLUDE_xTimerPendFunctionCall 1
// #define INCLUDE_xTaskAbortDelay 1

// #define projCOVERAGE_TEST 0
// #define configKERNEL_INTERRUPT_PRIORITY 255
// #define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xa0, or priority 5. */
// #define configMAC_INTERRUPT_PRIORITY 5


// #define configASSERT_DEFINED 1
// extern void vAssertCalled( void );
// #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()
// #define configQUEUE_REGISTRY_SIZE 20

// #define configUSE_PREEMPTION 1
// #define configUSE_TIME_SLICING 0
// #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0

// #define configUSE_IDLE_HOOK 0
// #define configUSE_TICK_HOOK 0
// #define configUSE_DAEMON_TASK_STARTUP_HOOK 0
// #define configCPU_CLOCK_HZ ( ( unsigned long ) 25000000 )
// #define configTICK_RATE_HZ ( ( TickType_t ) 10000 )
// #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 2000 )
// #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 80 * 1024 ) )
// #define configMAX_TASK_NAME_LEN ( 10 )
// #define configUSE_TRACE_FACILITY 1
// #define configUSE_16_BIT_TICKS 0
// #define configIDLE_SHOULD_YIELD 1

// #define configMAX_PRIORITIES ( 10 )
// #define configTIMER_QUEUE_LENGTH 20
// #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
// #define configUSE_COUNTING_SEMAPHORES 1
// #define configSUPPORT_DYNAMIC_ALLOCATION 1
// #define configSUPPORT_STATIC_ALLOCATION 0
// #define configNUM_TX_DESCRIPTORS 15
// #define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 2
79 changes: 79 additions & 0 deletions examples/emulation/freertos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# NOTE: the toolchain can be installed using -
# sudo apt install -y gcc-arm-none-eabi

TOOLCHAIN_PREFIX ?= arm-none-eabi-
OPTIMIZATION = g

EXTERN_SRC = ../../../../FreeRTOS-Kernel
SRC_C += ../../../../FreeRTOS-Kernel/portable/GCC/ARM_CM3/port.c
SRC_C += ../../../../FreeRTOS-Kernel/portable/MemMang/heap_4.c
IGNORE_SRC_PATH += ../../../../FreeRTOS-Kernel/examples
IGNORE_SRC_PATH += ../../../../FreeRTOS-Kernel/portable
IGNORE_HEADER_PATH += ../../../../FreeRTOS-Kernel/portable
IGNORE_HEADER_PATH += ../../../../FreeRTOS-Kernel/examples
INCLUDES += -I../../../../FreeRTOS-Kernel/include
INCLUDES += -I../../../../FreeRTOS-Kernel/portable/GCC/ARM_CM3/
TOOLCHAIN_VERSION := $(shell $(TOOLCHAIN_PREFIX)gcc -dumpversion)
LIB_GCC_PATH = /usr/lib/gcc/arm-none-eabi/$(TOOLCHAIN_VERSION)/thumb/v7-m/nofp/

DEFINES = -mcpu=cortex-m3 -mthumb
ASM_FLAGS = -march=armv7-m
LD_FLAGS = -lgcc -L$(LIB_GCC_PATH)

STARTUP = cortex-m

# MANDATORY:
# These 3 parameters are needed for every port
# Provide all values in hex
ROM_BASE_PHYSICAL = 0x00000000
ROM_SIZE = 0x3FFFF

RAM_BASE_PHYSICAL = 0x20000000
RAM_SIZE = 0x7FFFFF

# to reduce binary size, set to 1
# SHELL_LITE = 0

# setting the stack start manually for m class processors
DEFINES += -DSTACK_START=0x0003FFFF
DEFINES += -DSHELL_NO_PRINTF_LL

# MANDATORY:
# Provide relative path to shell/ from current directory
# Only Variable should be set above this line
SHELL_ROOT=../../../shell
-include $(SHELL_ROOT)/Makefile
# ^^ Do not move the above line. All user targets to be defined below this line!

# ------------------------ User targets below this line ------------------------
### run: Launches QEMU and loads the project binary on it
run: $(PROJECT).elf
@echo "Use Ctrl+A X to exit Qemu"
@qemu-system-arm -M mps2-an385 -cpu cortex-m3 -nographic \
-kernel $(PROJECT).elf
### debug: Qemu with GDB server. To be executed before 'make gdb'
debug:
@echo Please use \"make gdb\" in another terminal to attach gdb.
@echo Use \"cltr+a,x\" to quit qemu debug
@qemu-system-arm -S -M mps2-an385 -cpu cortex-m3 -nographic -kernel \
$(PROJECT).elf -gdb tcp::1234

### gdb: Launches GDB and connects to qemu. To be executed after 'make debug'
gdb:
@gdb-multiarch shell.elf -ex "target remote localhost:1234"
41 changes: 41 additions & 0 deletions examples/emulation/freertos/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

/*
* This is a mandatory include.
* This has the ADD_CMD() macro
*/
#include "shell.h"

/*
* There can be one or many function with same prototype, exposed as
* a command on the shell. They can be in same or multiple files.
*/
int hello(int argc, char** argv) {
for (int i = 0; i < argc; i++) {
printf(argv[i]);
printf(" ");
}

printf("\nPress ctrl + a, x to exit !\n");
return 0;
}

/*
* One or many such can exist per file.
* Description: ADD_CMD(command, help string, function to be exposed)
*/
ADD_CMD(hello, "Echoes the commandline\n\tusage: hello <any string>", hello);
Loading