├── .dbuild ├── pretty │ ├── rl.py │ ├── test.py │ ├── prettychmod.py │ ├── prettymd.py │ ├── prettylinux.py │ ├── todo.py │ ├── pretty.py │ ├── prettify.py │ ├── prettyformat.py │ ├── prettycp.py │ └── prettysamba.py ├── module.mk ├── asm-objects.mk ├── clean.mk ├── verbosity.mk ├── subdirs.mk ├── pretty.mk ├── cpp-objects.mk ├── module-link.mk ├── c-objects.mk ├── dbuild.mk └── rbuild.mk ├── dbuild.config.mk ├── Demo ├── Drivers │ ├── irq.h │ ├── irq.c │ ├── gpio.h │ ├── bcm2835_intc.h │ └── gpio.c ├── main.c ├── FreeRTOSConfig.h └── startup.s ├── objects.mk ├── README.md ├── Makefile ├── raspberrypi.ld └── FreeRTOS └── Source ├── include ├── projdefs.h ├── FreeRTOSConfig.h ├── mpu_wrappers.h ├── StackMacros.h ├── portable.h └── list.h ├── portable ├── MemMang │ ├── heap_3.c │ ├── heap_1.c │ ├── heap_2.c │ └── heap_4.c └── GCC │ └── RaspberryPi │ ├── port.c │ ├── portisr.c │ └── portmacro.h ├── list.c └── croutine.c /.dbuild/pretty/rl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import prettyformat 4 | import sys 5 | 6 | for line in prettyformat.readline(sys.stdin): 7 | print line 8 | -------------------------------------------------------------------------------- /.dbuild/module.mk: -------------------------------------------------------------------------------- 1 | include $(BASE).dbuild/c-objects.mk 2 | include $(BASE).dbuild/cpp-objects.mk 3 | include $(BASE).dbuild/module-link.mk 4 | include $(BASE).dbuild/clean.mk 5 | -------------------------------------------------------------------------------- /.dbuild/pretty/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import time 4 | 5 | print "This is the first line" 6 | 7 | time.sleep(1) 8 | 9 | print "This is the second line" 10 | -------------------------------------------------------------------------------- /.dbuild/asm-objects.mk: -------------------------------------------------------------------------------- 1 | 2 | $(BUILD_DIR)%.o: $(BASE)%.s 3 | $(Q)$(PRETTY) --dbuild "AS" $(MODULE_NAME) $(notdir $@) 4 | @mkdir -p $(dir $@) 5 | $(Q)$(AS) $(ASFLAGS) $< -o $@ 6 | 7 | 8 | -------------------------------------------------------------------------------- /dbuild.config.mk: -------------------------------------------------------------------------------- 1 | 2 | CFLAGS += -march=armv6z -g -Wall -Wextra 3 | CFLAGS += -I $(BASE)FreeRTOS/Source/portable/GCC/RaspberryPi/ 4 | CFLAGS += -I $(BASE)FreeRTOS/Source/include/ 5 | CFLAGS += -I $(BASE)Demo/Drivers/ 6 | 7 | TOOLCHAIN=arm-none-eabi- 8 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettychmod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | action = "CHMOD" 8 | module = sys.argv[1] 9 | 10 | for line in sys.stdin: 11 | description = line.split("\n")[0] 12 | prettyformat.pretty(action, module, description) 13 | 14 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettymd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | action = "MKDIR" 8 | module = sys.argv[1] 9 | 10 | for line in sys.stdin: 11 | description = line.split("\n")[0] 12 | prettyformat.pretty(action, module, description, False) 13 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettylinux.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | module = sys.argv[1] 8 | 9 | line = sys.stdin.readline() 10 | while(line): 11 | action = line.strip().split(" ")[0] 12 | newline = line.strip().split("\n")[0] 13 | newline = newline.split(" ", 1)[1].strip(); 14 | description = newline 15 | prettyformat.pretty(action, module, description, False) 16 | line = sys.stdin.readline() 17 | 18 | -------------------------------------------------------------------------------- /.dbuild/pretty/todo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | import prettyformat 5 | 6 | if(len(sys.argv) != 3): 7 | sys.exit(0) 8 | 9 | myfile = open(sys.argv[1], "a") 10 | 11 | for line in sys.stdin: 12 | splits = line.split(":", 2) 13 | filename = splits[0] 14 | lineno = splits[1] 15 | description = splits[2].strip() 16 | info = "%-25s : %-5s : %-15s : %s" % (filename, lineno, sys.argv[2][:15], description) 17 | prettyformat.pretty("TODO", sys.argv[2], info); 18 | myfile.write(info + "\n") 19 | 20 | myfile.close() 21 | -------------------------------------------------------------------------------- /.dbuild/pretty/pretty.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import prettyformat 5 | 6 | bCustom = True 7 | opcode = "??" 8 | module = "Unknown" 9 | description = "Please fix this somebody!" 10 | offset = 0 11 | 12 | if(sys.argv[1] == "--dbuild"): 13 | bCustom = False 14 | offset = 1; 15 | 16 | if(len(sys.argv) > 1+offset): 17 | opcode = sys.argv[1+offset] 18 | 19 | if(len(sys.argv) > 2+offset): 20 | module = sys.argv[2+offset] 21 | 22 | if(len(sys.argv) > 3+offset): 23 | description = sys.argv[3+offset] 24 | 25 | prettyformat.pretty(opcode, module, description, bCustom) 26 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | bCustom = True 8 | opcode = "??" 9 | module = "Unknown" 10 | description = "Somebody please fix this!" 11 | offset = 0 12 | 13 | if(sys.argv[1] == "--rbuild"): 14 | bCustom = False 15 | offset = 1; 16 | 17 | if(len(sys.argv) > 1+offset): 18 | opcode = sys.argv[1+offset] 19 | 20 | if(len(sys.argv) > 2+offset): 21 | module = sys.argv[2+offset] 22 | 23 | if(len(sys.argv) > 3+offset): 24 | description = sys.argv[3+offset] 25 | 26 | for line in sys.stdin: 27 | prettyformat.pretty(opcode, module, line.split("\n")[0], bCustom) 28 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettyformat.py: -------------------------------------------------------------------------------- 1 | def pretty(command = "??", module="Unknown", description="Somebody please fix this!!", bCustom=True): 2 | if bCustom: 3 | pretty_command = "*[%s]" % (command[:5]) 4 | else: 5 | pretty_command = " [%s]" % (command[:5]) 6 | 7 | pretty_module = "[%s]" % (module[:15]) 8 | if("/" in module): 9 | mods = module.split("/") 10 | tail = mods[len(mods)-1] 11 | mod = tail 12 | pretty_module = "[%s]" % mod[:10] 13 | 14 | print(" %-8s %-17s %s" % (pretty_command, pretty_module, description)); 15 | 16 | 17 | def readline(finput): 18 | line = "" 19 | c = finput.read(1) 20 | print(c) 21 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettycp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | command = "CP" 8 | module = "Unknown" 9 | description = "Please fix this somebody!" 10 | bCustom = True 11 | offset = 0 12 | 13 | if(len(sys.argv) >= 2): 14 | if(sys.argv[1] == "--rbuild"): 15 | offset = 1 16 | bCustom = False 17 | 18 | if(len(sys.argv) >= 2+offset): 19 | command = sys.argv[1+offset] 20 | 21 | if(len(sys.argv) >= 3+offset): 22 | module = sys.argv[2+offset] 23 | 24 | for line in sys.stdin: 25 | source = line.split("`")[1].split("'")[0] 26 | dest = line.split("`")[2].split("'")[0] 27 | prettyformat.pretty(command, module, source + " -> " + dest, bCustom) 28 | -------------------------------------------------------------------------------- /Demo/Drivers/irq.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tiny Interrupt Manager 3 | * 4 | * @author James Walmsley 5 | * This code is licensed under the GNU GPLv3 license. 6 | **/ 7 | 8 | #ifndef _INTERRUPTS_H_ 9 | #define _INTERRUPTS_H_ 10 | 11 | typedef void (*FN_INTERRUPT_HANDLER) (unsigned int irq, void *pParam); 12 | 13 | typedef struct { 14 | FN_INTERRUPT_HANDLER pfnHandler; ///< Function that handles this IRQn 15 | void *pParam; ///< A special parameter that the use can pass to the IRQ. 16 | } INTERRUPT_VECTOR; 17 | 18 | void irqRegister (const unsigned int irq, FN_INTERRUPT_HANDLER pfnHandler, void *pParam); 19 | void irqEnable (const unsigned int irq); 20 | void irqDisable (const unsigned int irq); 21 | void irqBlock (void); 22 | void irqUnblock (void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /.dbuild/clean.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Default Clean Process. 3 | # 4 | 5 | 6 | clean: 7 | ifeq ($(strip $(OBJECTS)),) 8 | else 9 | $(Q)rm $(PRM_FLAGS) $(NEW_OBJECTS) $(PRM_PIPE) 10 | $(Q)rm $(PRM_FLAGS) $(OBJECTS) $(PRM_PIPE) 11 | endif 12 | ifeq ($(strip $(CPPOBJECTS)),) 13 | else 14 | $(Q)rm $(PRM_FLAGS) $(CPPOBJECTS) $(PRM_PIPE) 15 | endif 16 | ifeq ($(strip $(ARCHIVES)),) 17 | else 18 | $(Q)rm $(PRM_FLAGS) $(ARCHIVES) $(PRM_PIPE) 19 | endif 20 | ifeq ($(strip $(OBJECTS:.o=.d)),) 21 | else 22 | $(Q)rm $(PRM_FLAGS) $(OBJECTS:.o=.d) $(PRM_PIPE) 23 | endif 24 | ifeq ($(strip $(MODULE_TARGET)),) 25 | else 26 | $(Q)rm $(PRM_FLAGS) $(MODULE_TARGET) $(PRM_PIPE) 27 | endif 28 | ifeq ($(strip $(TARGETS)),) 29 | else 30 | $(Q)rm $(PRM_FLAGS) $(TARGETS) $(PRM_PIPE) 31 | endif 32 | ifeq ($(CLEAN_EXTRAS), 1) 33 | $(Q)rm $(PRM_FLAGS) $(CLEAN_LIST) $(PRM_PIPE) 34 | endif 35 | -------------------------------------------------------------------------------- /.dbuild/verbosity.mk: -------------------------------------------------------------------------------- 1 | V=0 2 | 3 | # Set the default verbosity FLAGS. 4 | VERBOSE_DEPS_PRETTY=0 5 | VERBOSE_OBJECTS=0 6 | VERBOSE_LINK=0 7 | 8 | DBUILD_VERBOSE_DEPS=0 9 | DBUILD_VERBOSE_CMD=0 10 | 11 | # If a verbosity level has been specified, then we switch the verbosity flags. 12 | ifeq ($(V), -1) 13 | DBUILD_VERBOSE_CMD=1 14 | endif 15 | 16 | ifeq ($(V), 1) 17 | DBUILD_VERBOSE_DEPS=1 18 | endif 19 | 20 | ifeq ($(V), 2) 21 | DBUILD_VERBOSE_CMD=1 22 | endif 23 | 24 | ifeq ($(V), 3) 25 | DBUILD_VERBOSE_DEPS=1 26 | DBUILD_VERBOSE_CMD=1 27 | endif 28 | 29 | # 30 | # Make Command Verbosity Control! 31 | # Here we prefix all commands with $(Q) instead of @ to make them silent. 32 | # 33 | # Then we can control the command printing dynamically using the V (verbosity) variable. 34 | # 35 | Q=@ 36 | ifeq ($(V), 2) 37 | Q= 38 | endif 39 | ifeq ($(V), 3) 40 | Q= 41 | endif 42 | -------------------------------------------------------------------------------- /.dbuild/pretty/prettysamba.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os, sys 4 | import prettyformat 5 | import fileinput 6 | 7 | action = sys.argv[1] 8 | module = sys.argv[2] 9 | 10 | line = sys.stdin.readline() 11 | while(line): 12 | if("Compiling " in line): 13 | action = "CC" 14 | elif("Linking " in line): 15 | action = "LN" 16 | elif("checking " in line): 17 | action = "CHECK" 18 | elif("Building " in line): 19 | action = "BUILD" 20 | else: 21 | action = "CONF" 22 | 23 | newline = line.split("\n")[0] 24 | if(action == "CC"): 25 | newline = newline.split("Compiling ")[1] 26 | elif(action == "LN"): 27 | newline = newline.split("Linking ")[1] 28 | elif(action == "BUILD"): 29 | newline = newline.split("Building ")[1] 30 | 31 | prettyformat.pretty(action, module, newline, False) 32 | line = sys.stdin.readline() 33 | 34 | -------------------------------------------------------------------------------- /.dbuild/subdirs.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Riegl Builder - Subdirectory handling. 3 | # 4 | # @author James Walmsley 5 | # 6 | 7 | .PHONY:$(SUBDIRS) 8 | 9 | # 10 | # Each listed item in the SUBDIRS variable shall be executed in parralel. 11 | # We must therefore take care to provide a make job server. 12 | # Hence the +make command. 13 | # 14 | 15 | include $(addsuffix objects.mk, $(SUB_OBJDIRS)) 16 | 17 | $(SUBDIRS): 18 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 19 | $(Q)$(PRETTY) --dbuild "BUILD" $(MODULE_NAME) "Building $@" 20 | endif 21 | $(Q)$(MAKE) -C $@ DBUILD_SPLASHED=1 $(SUBDIR_PARAMS) 22 | 23 | 24 | # 25 | # Sub-dir Clean targets. (Creates $SUBDIR.clean). 26 | # 27 | $(SUBDIRS:%=%.clean): 28 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 29 | $(Q)$(PRETTY) --dbuild "CLDIR" $(MODULE_NAME) "$(@:%.clean=%)" 30 | endif 31 | $(Q)$(MAKE) -C $(@:%.clean=%) DBUILD_SPLASHED=1 $(SUBDIR_PARAMS) clean 32 | 33 | 34 | # 35 | # Hook sub-dir cleaning to the main clean method. 36 | # 37 | clean.subdirs: $(SUBDIRS:%=%.clean) 38 | @: 39 | clean: clean.subdirs 40 | -------------------------------------------------------------------------------- /objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # FreeRTOS portable layer for RaspberryPi 3 | # 4 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/portable/GCC/RaspberryPi/port.o 5 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/portable/GCC/RaspberryPi/portisr.o 6 | 7 | # 8 | # FreeRTOS Core 9 | # 10 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/croutine.o 11 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/list.o 12 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/queue.o 13 | OBJECTS += $(BUILD_DIR)FreeRTOS/Source/tasks.o 14 | 15 | # 16 | # Interrupt Manager & GPIO Drivers 17 | # 18 | OBJECTS += $(BUILD_DIR)Demo/Drivers/irq.o 19 | OBJECTS += $(BUILD_DIR)Demo/Drivers/gpio.o 20 | 21 | $(BUILD_DIR)FreeRTOS/Source/portable/GCC/RaspberryPi/port.o: CFLAGS += -I $(BASE)Demo/ 22 | 23 | # 24 | # Selected HEAP implementation for FreeRTOS. 25 | # 26 | OBJECTS += $(BUILD_DIR)/FreeRTOS/Source/portable/MemMang/heap_4.o 27 | 28 | # 29 | # Startup and platform initialisation code. 30 | # 31 | OBJECTS += $(BUILD_DIR)Demo/startup.o 32 | 33 | 34 | # 35 | # Main Test Program 36 | # 37 | OBJECTS += $(BUILD_DIR)Demo/main.o 38 | -------------------------------------------------------------------------------- /.dbuild/pretty.mk: -------------------------------------------------------------------------------- 1 | PRETTY = $(BASE).dbuild/pretty/pretty.py 2 | PRETTIFY = $(BASE).dbuild/pretty/prettify.py 3 | PCP = $(BASE).dbuild/pretty/prettycp.py --rbuild "CP" 4 | PMD = $(BASE).dbuild/pretty/prettymd.py 5 | PRM = $(PRETTIFY) --rbuild "RM" 6 | PCHMOD = $(BASE).dbuild/pretty/prettychmod.py 7 | PRETTYSAMBA = $(BASE).dbuild/pretty/prettysamba.py 8 | PRETTYLINUX = $(BASE).dbuild/pretty/prettylinux.py 9 | PTODO = $(BASE).dbuild/pretty/todo.py 10 | 11 | ifeq ($(DBUILD_VERBOSE_CMD), 1) 12 | #PRETTY=@ # 13 | endif 14 | 15 | # 16 | # PRM (Pretty Remove) flags 17 | # 18 | PRM_PIPE= 19 | PRM_FLAGS=-rf 20 | 21 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 22 | PRM_PIPE=| $(PRM) $(MODULE_NAME) 23 | PRM_FLAGS=-rvf 24 | endif 25 | 26 | # 27 | # PCP Flags 28 | # 29 | PCP_PIPE= 30 | PCP_FLAGS=-r 31 | 32 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 33 | PCP_PIPE=| $(PCP) $(MODULE_NAME) 34 | PCP_FLAGS=-vr 35 | endif 36 | 37 | # 38 | # PMD Flags 39 | # 40 | PMD_FLAGS=-p 41 | PMD_PIPE= 42 | 43 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 44 | PMD_FLAGS=-pv 45 | PMD_PIPE=| $(PMD) $(MODULE_NAME) 46 | endif 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FreeRTOS Ported to Raspberry Pi 2 | 3 | This provides a very basic port of FreeRTOS to Raspberry pi. 4 | 5 | ## Howto Build 6 | 7 | Type make! -- If you get an error then: 8 | 9 | $ cd .dbuild/pretty 10 | $ chmod +x *.py 11 | 12 | Currently the makefile expect an arm-none-eabi- toolchain in the path. Either export the path to yours or 13 | modify the TOOLCHAIN variable in dbuild.config.mk file. 14 | 15 | You may also need to modify the library locations in the Makefile: 16 | 17 | kernel.elf: LDFLAGS += -L"c:/yagarto/lib/gcc/arm-none-eabi/4.7.1/" -lgcc 18 | kernel.elf: LDFLAGS += -L"c:/yagarto/arm-none-eabi/lib/" -lc 19 | 20 | The build system also expects find your python interpreter by using /usr/bin/env python, 21 | if this doesn't work you will get problems. 22 | 23 | To resolve this, modify the #! lines in the .dbuild/pretty/*.py files. 24 | 25 | Hope this helps. 26 | 27 | I'm currently porting my BitThunder project to the Pi, which is a OS based on FreeRTOS 28 | but with a comprehensive driver model, and file-systems etc. 29 | 30 | http://github.com/jameswalmsley/bitthunder/ 31 | 32 | James 33 | 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for FreeRTOS demo on Raspberry Pi 3 | # 4 | BASE=$(shell pwd)/ 5 | BUILD_DIR=$(shell pwd)/build/ 6 | 7 | MODULE_NAME="RaspberryPi BSP" 8 | 9 | TARGETS=kernel.img kernel.list kernel.syms kernel.elf 10 | LINKER_SCRIPT=raspberrypi.ld 11 | 12 | -include .dbuild/dbuild.mk 13 | 14 | 15 | all: kernel.list kernel.img kernel.syms 16 | @$(SIZE) kernel.elf 17 | 18 | kernel.img: kernel.elf 19 | $(Q)$(PRETTY) IMAGE $(MODULE_NAME) $@ 20 | $(Q)$(OBJCOPY) kernel.elf -O binary $@ 21 | 22 | kernel.list: kernel.elf 23 | $(Q)$(PRETTY) LIST $(MODULE_NAME) $@ 24 | $(Q)$(OBJDUMP) -D -S kernel.elf > $@ 25 | 26 | kernel.syms: kernel.elf 27 | $(Q)$(PRETTY) SYMS $(MODULE_NAME) $@ 28 | $(Q)$(OBJDUMP) -t kernel.elf > $@ 29 | 30 | #kernel.elf: LDFLAGS += -L "/opt/Xilinx/14.2/ISE_DS/EDK/gnu/arm/lin64/lib/gcc/arm-xilinx-eabi/4.6.1/" -lgcc 31 | #kernel.elf: LDFLAGS += -L "/opt/Xilinx/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-eabi/lib/" -lc 32 | kernel.elf: LDFLAGS += -L "/usr/lib/gcc/arm-none-eabi/4.7.4" -lgcc 33 | kernel.elf: LDFLAGS += -L "/usr/arm-none-eabi/lib" -lc 34 | kernel.elf: $(OBJECTS) 35 | $(Q)$(LD) $(OBJECTS) -Map kernel.map -o $@ -T $(LINKER_SCRIPT) $(LDFLAGS) 36 | -------------------------------------------------------------------------------- /.dbuild/cpp-objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Here we define the RBUILD default implicit C object build rule. 3 | # 4 | # This overrides Make's default implicit rule for C objects. 5 | # 6 | 7 | -include $(OBJECTS:.o=.d) # Include all dependency information for all objects. (Prefixing - means if they exist). 8 | 9 | ifeq ($(V), 3) 10 | qd= 11 | else 12 | qd=@ 13 | endif 14 | 15 | %.o : %.cpp 16 | ifeq ($(RBUILD_VERBOSE_CMD), 0) # Pretty print on successful compile, but still display errors when they occur. 17 | $(Q)$(PRETTY) --rbuild "CXX" $(MODULE_NAME) $*.o 18 | endif # Full verbose output for debugging (make V=1). 19 | $(Q)$(CXX) -MD -MP $(CXXFLAGS) $(CFLAGS) $*.cpp -o $*.o 20 | $(POST_CC) 21 | 22 | ifeq ($(RBUILD_VERBOSE_DEPS), 1) 23 | # $(Q)$(PRETTY) --rbuild "DEP" $(MODULE_NAME) $*.d 24 | endif 25 | # http://scottmcpeak.com/autodepend/autodepend.html # Autogenerate Dependencies for object. 26 | # $(qd)$(CXX) -MM $(CXXFLAGS) $(CFLAGS) $*.cpp -MF $*.d 27 | # # Fix the GCC dep file output format. 28 | # $(qd)mv -f $*.d $*.d.tmp 29 | # $(qd)sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d 30 | # $(qd)sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ 31 | # sed -e 's/^ *//' -e 's/$$/:/' >> $*.d 32 | # $(qd)rm -f $*.d.tmp 33 | -------------------------------------------------------------------------------- /.dbuild/module-link.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Standard module linker 3 | # 4 | 5 | # 6 | # Here we filter out "archive" targets, because they are special! 7 | # 8 | AR_TARGETS=$(filter %.a, $(TARGETS)) 9 | 10 | $(AR_TARGETS): 11 | ifeq ($(DBUILD_VERBOSE_CMD), 0) 12 | $(Q)$(PRETTY) --dbuild "AR" $(MODULE_NAME) $@ 13 | endif 14 | $(Q)$(AR) rvs $@ $(OBJECTS) 1> /dev/null 2> /dev/null 15 | 16 | # 17 | # RI Targets are the standard targets with the AR_TARGETS filtered out. 18 | # 19 | 20 | 21 | TEMP_TARGETS=$(filter-out $(AR_TARGETS), $(TARGETS)) 22 | KERN_TARGETS=$(filter-out *.img, $(TEMP_TARGETS)) 23 | 24 | RI_TARGETS=$(filter-out $(KERN_TARGETS), $(TEMP_TARGETS)) 25 | 26 | 27 | $(RI_TARGETS): 28 | ifeq ($(RBUILD_VERBOSE_CMD), 0) 29 | $(Q)$(PRETTY) --rbuild "LD" $(MODULE_NAME) $@ 30 | endif 31 | $(Q)$(CXX) $(OBJECTS) $(ARCHIVES) $(LDFLAGS) $(LDLIBS) -o $@ 32 | 33 | 34 | %: %.c 35 | ifeq ($(RBUILD_VERBOSE_CMD), 0) 36 | $(Q)$(PRETTY) --rbuild "CC|LD" $(MODULE_NAME) $@ 37 | endif 38 | $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $< -o $@ 39 | 40 | output/%: source/%.c 41 | ifeq ($(RBUILD_VERBOSE_CMD), 0) 42 | $(Q)$(PRETTY) --rbuild "CC|LD" $(MODULE_NAME) $@ 43 | endif 44 | $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $< -o $@ 45 | 46 | output/%: source/%.o 47 | ifeq ($(RBUILD_VERBOSE_CMD), 0) 48 | $(Q)$(PRETTY) --rbuild "LD" $(MODULE_NAME) $@ 49 | endif 50 | $(Q)$(CC) $(LDFLAGS) $(LDLIBS) $< -o $@ 51 | 52 | -------------------------------------------------------------------------------- /raspberrypi.ld: -------------------------------------------------------------------------------- 1 | /** 2 | * BlueThunder Linker Script for the raspberry Pi! 3 | * 4 | * 5 | * 6 | **/ 7 | MEMORY 8 | { 9 | RESERVED (r) : ORIGIN = 0x00000000, LENGTH = 32K 10 | INIT_RAM (rwx) : ORIGIN = 0x00008000, LENGTH = 32K 11 | RAM (rwx) : ORIGIN = 0x00010000, LENGTH = 128M 12 | } 13 | 14 | ENTRY(_start) 15 | 16 | SECTIONS { 17 | /* 18 | * Our init section allows us to place the bootstrap code at address 0x8000 19 | * 20 | * This is where the Graphics processor forces the ARM to start execution. 21 | * However the interrupt vector code remains at 0x0000, and so we must copy the correct 22 | * branch instructions to 0x0000 - 0x001C in order to get the processor to handle interrupts. 23 | * 24 | */ 25 | .init : { 26 | KEEP(*(.init)) 27 | } > INIT_RAM = 0 28 | 29 | .module_entries : { 30 | __module_entries_start = .; 31 | KEEP(*(.module_entries)) 32 | KEEP(*(.module_entries.*)) 33 | __module_entries_end = .; 34 | __module_entries_size = SIZEOF(.module_entries); 35 | } > INIT_RAM 36 | 37 | 38 | /** 39 | * This is the main code section, it is essentially of unlimited size. (128Mb). 40 | * 41 | **/ 42 | .text : { 43 | *(.text) 44 | } > RAM 45 | 46 | /* 47 | * Next we put the data. 48 | */ 49 | .data : { 50 | *(.data) 51 | } > RAM 52 | 53 | .bss : 54 | { 55 | __bss_start = .; 56 | *(.bss) 57 | *(.bss.*) 58 | __bss_end = .; 59 | } > RAM 60 | 61 | /** 62 | * Place HEAP here??? 63 | **/ 64 | 65 | /** 66 | * Stack starts at the top of the RAM, and moves down! 67 | **/ 68 | _estack = ORIGIN(RAM) + LENGTH(RAM); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /.dbuild/c-objects.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Here we define the RBUILD default implicit C object build rule. 3 | # 4 | # This overrides Make's default implicit rule for C objects. 5 | # 6 | 7 | # 8 | # Include all object dependencies. 9 | # 10 | -include $(OBJECTS:.o=.d) 11 | 12 | NEW_OBJECTS = $(addprefix $(BUILD_DIR),$(OBJECTS)) 13 | 14 | #NEW_OBJECTS = $(subst $(BASE),$(BUILD_DIR),$(OBJECTS)) 15 | 16 | ifeq ($(V), 3) 17 | qd= 18 | else 19 | qd=@ 20 | endif 21 | 22 | 23 | $(BUILD_DIR)%.o: $(BASE)%.c 24 | ifeq ($(DBUILD_VERBOSE_CMD), 0) # Pretty print on successful compile, but still display errors when they occur. 25 | $(Q)$(PRETTY) --dbuild "CC" $(MODULE_NAME) $(notdir $@) 26 | endif 27 | @mkdir -p $(dir $@) 28 | $(Q)$(CC) -MD -MP $(CFLAGS) $< -o $@ 29 | 30 | # @echo $($@:$(BASE)="jim")#$(BASE), "JIM", $(dir $@)) 31 | 32 | # $(patsubst $(BASE), "", $(BUILD_ROOT)$@) 33 | $(POST_CC) 34 | 35 | #ifeq ($(DBUILD_VERBOSE_DEPS), 1) 36 | # $(Q)$(PRETTY) --dbuild "DEP" $(MODULE_NAME) $*.d 37 | #endif 38 | ## http://scottmcpeak.com/autodepend/autodepend.html # Autogenerate Dependencies for object. 39 | # $(qd)$(CC) -MD -MP $(CFLAGS) $*.c 40 | 41 | 42 | 43 | # # Fix the GCC dep file output format. 44 | # $(qd)mv -f $*.d $*.d.tmp 45 | # $(qd)sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d 46 | # $(qd)sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ 47 | # sed -e 's/^ *//' -e 's/$$/:/' >> $*.d 48 | # $(qd)rm -f $*.d.tmp 49 | 50 | $(OBJECTS): $(dir $(BUILD_ROOT)$($@:$(BASE)="")) 51 | 52 | $(dir $(BUILD_ROOT)$($@:$(BASE)="")): 53 | mkdir -p $@ 54 | 55 | 56 | test: 57 | echo $(BASE) 58 | echo $(BUILD_DIR) 59 | echo $(OBJECTS) 60 | echo $(NEW_OBJECTS) 61 | 62 | -------------------------------------------------------------------------------- /.dbuild/dbuild.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Dark Builder - Designed and Created by James Walmsley 3 | # 4 | # Dark Builder attempts to provide a clean framework for creating organised 5 | # and "pretty" builds with minimal effort. 6 | # 7 | # Dark Builder is based upon the vebuild as found in the FullFAT project 8 | # in the .vebuild directory. 9 | # 10 | # @see github.com/FullFAT/FullFAT/ 11 | # @author James Walmsley 12 | # 13 | # @version 1.0.0 (Armstrong) 14 | # 15 | 16 | DBUILD_VERSION_MAJOR=1 17 | DBUILD_VERSION_MINOR=0 18 | DBUILD_VERSION_REVISION=0 19 | 20 | DBUILD_VERSION_NAME=Armstrong 21 | DBUILD_VERSION_DATE=October 2010 22 | 23 | # 24 | # Let's ensure we have a pure make environment. 25 | # (Delete all rules and variables). 26 | # 27 | MAKEFLAGS += -rR --no-print-directory 28 | 29 | # 30 | # Optional Include directive, blue build attempts to build using lists of objects, 31 | # targets and subdirs as found in objects.mk and subdirs.mk 32 | # 33 | -include objects.mk 34 | -include targets.mk 35 | -include subdirs.mk 36 | 37 | # 38 | # A top-level configureation file can be found in the project root dir. 39 | # 40 | -include $(BASE)dbuild.config.mk 41 | 42 | # 43 | # A config file can be overidden or extended in any sub-directory 44 | # 45 | -include dbuild.config.mk 46 | -include $(BUILD_ROOT)dbuild.config.mk 47 | 48 | # 49 | # Defaults for compile/build toolchain 50 | # 51 | override TOOLCHAIN ?= 52 | override AR = $(TOOLCHAIN)ar 53 | override AS = $(TOOLCHAIN)as 54 | override CC = $(TOOLCHAIN)gcc 55 | override CXX = $(TOOLCHAIN)g++ 56 | override LD = $(TOOLCHAIN)ld 57 | override OBJCOPY = $(TOOLCHAIN)objcopy 58 | override OBJDUMP = $(TOOLCHAIN)objdump 59 | override SIZE = $(TOOLCHAIN)size 60 | 61 | CFLAGS += -c 62 | 63 | # 64 | # Provide a default target named all, 65 | # This is dependent on $(TARGETS) and $(SUBDIRS) 66 | # 67 | # All is finally dependent on silent, to keep make silent when it has 68 | # nothing to do. 69 | # 70 | 71 | dbuild_entry: dbuild_splash | all 72 | all: $(TARGETS) $(SUBDIRS) $(MODULE_TARGET) | silent 73 | 74 | 75 | include $(BASE).dbuild/verbosity.mk 76 | include $(BASE).dbuild/pretty.mk 77 | include $(BASE).dbuild/subdirs.mk 78 | include $(BASE).dbuild/clean.mk 79 | include $(BASE).dbuild/module-link.mk 80 | include $(BASE).dbuild/c-objects.mk 81 | include $(BASE).dbuild/cpp-objects.mk 82 | include $(BASE).dbuild/asm-objects.mk 83 | 84 | # 85 | # DBuild Splash 86 | # 87 | .PHONY: dbuild_splash 88 | dbuild_splash: 89 | ifeq ($(DBUILD_SPLASHED), 1) 90 | else 91 | @echo " Dark Builder - Unified Build Environment" 92 | @echo " Version ($(DBUILD_VERSION_MAJOR).$(DBUILD_VERSION_MINOR).$(DBUILD_VERSION_REVISION) - $(DBUILD_VERSION_NAME))" 93 | endif 94 | 95 | # 96 | # Finally provide an implementation of the silent target. 97 | # 98 | silent: 99 | @: 100 | -------------------------------------------------------------------------------- /.dbuild/rbuild.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Riegl Builder - Designed and Created by James Walmsley 3 | # 4 | # Riegl Builder attempts to provide a clean framework for creating organised 5 | # and "pretty" builds with minimal effort. 6 | # 7 | # Riegl Builder is based upon the vebuild as found in the FullFAT project 8 | # in the .vebuild directory. 9 | # 10 | # @see github.com/FullFAT/FullFAT/ 11 | # @author James Walmsley 12 | # 13 | # @version 1.0.0 (Armstrong) - 14 | # 15 | 16 | RBUILD_VERSION_MAJOR=1 17 | RBUILD_VERSION_MINOR=0 18 | RBUILD_VERSION_REVISION=0 19 | 20 | RBUILD_VERSION_NAME=Armstrong 21 | RBUILD_VERSION_DATA=May 2012 22 | 23 | # 24 | # Let's ensure we have a well purified MAKE environment, and make its output less 25 | # redundant. 26 | # 27 | MAKEFLAGS += -rR --no-print-directory 28 | 29 | # 30 | # Optional Include directive, rbuild attempts to build using lists of objects, 31 | # targets and subdirs as found in objects.mk and subdirs.mk 32 | # 33 | -include objects.mk 34 | -include targets.mk 35 | -include subdirs.mk 36 | 37 | # 38 | # A top-level configuration file can be found in the project root file. 39 | # 40 | -include $(BASE).rbuild.config.mk 41 | 42 | # 43 | # This config file can be overridden or extended in any sub-directory 44 | # 45 | -include .rbuild.config.mk 46 | 47 | # 48 | # Provide a default target named all, 49 | # This is dependent on $(TARGETS) and $(SUBDIRS) 50 | # 51 | # All is finally dependent on silent, to keep make silent when it has 52 | # nothing more to do. 53 | # 54 | rbuild_entry: rbuild_splash | all 55 | all: $(TARGETS) $(SUBDIRS) $(MODULE_TARGET) | silent 56 | 57 | # 58 | # Defaults for compile/build toolchain environments. 59 | # 60 | CC = gcc 61 | CXX = g++ 62 | CFLAGS += -c 63 | 64 | # 65 | # Over-time we can provide some simple macros to force certain kinds 66 | # of build, without having to modify any make files. 67 | # 68 | # Assuming that no sub-project overrides our CFLAGS. 69 | # 70 | ifeq ($(CONFIG_i386), 1) 71 | CFLAGS += -m32 72 | LDFLAGS += -m32 73 | endif 74 | 75 | ifeq ($(RBUILD_TODO), 1) 76 | RBUILD_TODOSTRINGS="(TODO|FIXME|TOFIX|FINISHME|BROKEN)" 77 | POST_CC = $(Q)-grep -EHn $(RBUILD_TODOSTRINGS) $< | $(PTODO) $(BASE)rbuild.todo $(MODULE_NAME) 78 | endif 79 | 80 | # 81 | # Include the different rbuild modules 82 | # 83 | include $(BASE).rbuild/verbosity.mk 84 | include $(BASE).rbuild/pretty.mk 85 | include $(BASE).rbuild/subdirs.mk 86 | include $(BASE).rbuild/clean.mk 87 | include $(BASE).rbuild/module-link.mk 88 | include $(BASE).rbuild/c-objects.mk 89 | include $(BASE).rbuild/cpp-objects.mk 90 | 91 | # 92 | # Rbuild Splash 93 | # 94 | .PHONY: rbuild_splash 95 | rbuild_splash: 96 | ifeq ($(RBUILD_SPLASHED), 1) 97 | else 98 | @echo " Riegl Builder - Unified Build Environment" 99 | @echo " Version ($(RBUILD_VERSION_MAJOR).$(RBUILD_VERSION_MINOR).$(RBUILD_VERSION_REVISION) - $(RBUILD_VERSION_NAME))" 100 | ifeq ($(RBUILD_TODO), 1) 101 | @rm -rf $(BASE)rbuild.todo 102 | @touch $(BASE)rbuild.todo 103 | @echo "Filename : Line : Module : TODO message" >> $(BASE)rbuild.todo 104 | @echo "===============================================================================" >> $(BASE)rbuild.todo 105 | endif 106 | endif 107 | 108 | # 109 | # Finally provide an implementation of the silent target. 110 | # 111 | silent: 112 | @: 113 | -------------------------------------------------------------------------------- /Demo/Drivers/irq.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Integrated Interrupt Controller for RaspberryPi. 3 | * @author James Walmsley 4 | **/ 5 | 6 | #include "irq.h" 7 | #include "bcm2835_intc.h" 8 | 9 | static INTERRUPT_VECTOR g_VectorTable[BCM2835_INTC_TOTAL_IRQ]; 10 | 11 | 12 | typedef struct { 13 | unsigned long IRQBasic; // Pending 0 14 | unsigned long Pending1; 15 | unsigned long Pending2; 16 | unsigned long FIQCtrl; 17 | unsigned long Enable1; 18 | unsigned long Enable2; 19 | unsigned long EnableBasic; 20 | unsigned long Disable1; 21 | unsigned long Disable2; 22 | unsigned long DisableBasic; 23 | } BCM2835_INTC_REGS; 24 | 25 | static volatile BCM2835_INTC_REGS * const pRegs = (BCM2835_INTC_REGS *) (BCM2835_BASE_INTC); 26 | 27 | // Remember which interrupts have been enabled: 28 | static unsigned long enabled[3]; 29 | 30 | static void handleRange (unsigned long pending, const unsigned int base) 31 | { 32 | while (pending) 33 | { 34 | // Get index of first set bit: 35 | unsigned int bit = 31 - __builtin_clz(pending); 36 | 37 | // Map to IRQ number: 38 | unsigned int irq = base + bit; 39 | 40 | // Call interrupt handler, if enabled: 41 | if (g_VectorTable[irq].pfnHandler) 42 | g_VectorTable[irq].pfnHandler(irq, g_VectorTable[irq].pParam); 43 | 44 | // Clear bit in bitfield: 45 | pending &= ~(1UL << bit); 46 | } 47 | } 48 | 49 | /** 50 | * This is the global IRQ handler on this platform! 51 | * It is based on the assembler code found in the Broadcom datasheet. 52 | * 53 | **/ 54 | void irqHandler (void) 55 | { 56 | register unsigned long ulMaskedStatus = pRegs->IRQBasic; 57 | 58 | // Bit 8 in IRQBasic indicates interrupts in Pending1 (interrupts 31-0): 59 | if (ulMaskedStatus & (1UL << 8)) 60 | handleRange(pRegs->Pending1 & enabled[0], 0); 61 | 62 | // Bit 9 in IRQBasic indicates interrupts in Pending2 (interrupts 63-32): 63 | if (ulMaskedStatus & (1UL << 9)) 64 | handleRange(pRegs->Pending2 & enabled[1], 32); 65 | 66 | // Bits 7 through 0 in IRQBasic represent interrupts 64-71: 67 | if (ulMaskedStatus & 0xFF) 68 | handleRange(ulMaskedStatus & 0xFF & enabled[2], 64); 69 | } 70 | 71 | void irqUnblock (void) 72 | { 73 | asm volatile ("cpsie i" ::: "memory"); 74 | } 75 | 76 | void irqBlock (void) 77 | { 78 | asm volatile ("cpsid i" ::: "memory"); 79 | } 80 | 81 | void irqRegister (const unsigned int irq, FN_INTERRUPT_HANDLER pfnHandler, void *pParam) 82 | { 83 | if (irq < BCM2835_INTC_TOTAL_IRQ) { 84 | irqBlock(); 85 | g_VectorTable[irq].pfnHandler = pfnHandler; 86 | g_VectorTable[irq].pParam = pParam; 87 | irqUnblock(); 88 | } 89 | } 90 | 91 | void irqEnable (const unsigned int irq) 92 | { 93 | unsigned long mask = 1UL << (irq % 32); 94 | 95 | if (irq <= 31) { 96 | pRegs->Enable1 = mask; 97 | enabled[0] |= mask; 98 | } 99 | else if (irq <= 63) { 100 | pRegs->Enable2 = mask; 101 | enabled[1] |= mask; 102 | } 103 | else if (irq < BCM2835_INTC_TOTAL_IRQ) { 104 | pRegs->EnableBasic = mask; 105 | enabled[2] |= mask; 106 | } 107 | } 108 | 109 | void irqDisable (const unsigned int irq) 110 | { 111 | unsigned long mask = 1UL << (irq % 32); 112 | 113 | if (irq <= 31) { 114 | pRegs->Disable1 = mask; 115 | enabled[0] &= ~mask; 116 | } 117 | else if (irq <= 63) { 118 | pRegs->Disable2 = mask; 119 | enabled[1] &= ~mask; 120 | } 121 | else if (irq < BCM2835_INTC_TOTAL_IRQ) { 122 | pRegs->DisableBasic = mask; 123 | enabled[2] &= ~mask; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/projdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef PROJDEFS_H 68 | #define PROJDEFS_H 69 | 70 | /* Defines the prototype to which task functions must conform. */ 71 | typedef void (*pdTASK_CODE)( void * ); 72 | 73 | #define pdTRUE ( 1 ) 74 | #define pdFALSE ( 0 ) 75 | 76 | #define pdPASS ( 1 ) 77 | #define pdFAIL ( 0 ) 78 | #define errQUEUE_EMPTY ( 0 ) 79 | #define errQUEUE_FULL ( 0 ) 80 | 81 | /* Error definitions. */ 82 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) 83 | #define errNO_TASK_TO_RUN ( -2 ) 84 | #define errQUEUE_BLOCKED ( -4 ) 85 | #define errQUEUE_YIELD ( -5 ) 86 | 87 | #endif /* PROJDEFS_H */ 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Demo/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | 68 | #include 69 | #include 70 | 71 | #include "Drivers/irq.h" 72 | #include "Drivers/gpio.h" 73 | 74 | void task1(void *pParam) { 75 | 76 | int i = 0; 77 | while(1) { 78 | i++; 79 | SetGpio(16, 1); 80 | vTaskDelay(200); 81 | } 82 | } 83 | 84 | void task2(void *pParam) { 85 | 86 | int i = 0; 87 | while(1) { 88 | i++; 89 | vTaskDelay(100); 90 | SetGpio(16, 0); 91 | vTaskDelay(100); 92 | } 93 | } 94 | 95 | 96 | /** 97 | * This is the systems main entry, some call it a boot thread. 98 | * 99 | * -- Absolutely nothing wrong with this being called main(), just it doesn't have 100 | * -- the same prototype as you'd see in a linux program. 101 | **/ 102 | void main (void) 103 | { 104 | SetGpioFunction(16, 1); // RDY led 105 | 106 | xTaskCreate(task1, "LED_0", 128, NULL, 0, NULL); 107 | xTaskCreate(task2, "LED_1", 128, NULL, 0, NULL); 108 | 109 | vTaskStartScheduler(); 110 | 111 | /* 112 | * We should never get here, but just in case something goes wrong, 113 | * we'll place the CPU into a safe loop. 114 | */ 115 | while(1) { 116 | ; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Demo/Drivers/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef _GPIO_H_ 68 | #define _GPIO_H_ 69 | 70 | /* GPIO event detect types */ 71 | enum DETECT_TYPE { 72 | DETECT_NONE, 73 | DETECT_RISING, 74 | DETECT_FALLING, 75 | DETECT_HIGH, 76 | DETECT_LOW, 77 | DETECT_RISING_ASYNC, 78 | DETECT_FALLING_ASYNC 79 | }; 80 | 81 | /* GPIO pull up or down states */ 82 | enum PULL_STATE { 83 | PULL_DISABLE, 84 | PULL_UP, 85 | PULL_DOWN, 86 | PULL_RESERVED 87 | }; 88 | 89 | /* Pin data direction */ 90 | enum GPIO_DIR { 91 | GPIO_IN, 92 | GPIO_OUT 93 | }; 94 | 95 | /* GPIO pin setup */ 96 | void SetGpioFunction (unsigned int pinNum, unsigned int funcNum); 97 | /* A simple wrapper around SetGpioFunction */ 98 | void SetGpioDirection (unsigned int pinNum, enum GPIO_DIR dir); 99 | 100 | /* Set GPIO output level */ 101 | void SetGpio (unsigned int pinNum, unsigned int pinVal); 102 | 103 | /* Read GPIO pin level */ 104 | int ReadGpio (unsigned int pinNum); 105 | 106 | /* GPIO pull up/down resistor control function (NOT YET IMPLEMENTED) */ 107 | int PudGpio (unsigned int pinNum, enum PULL_STATE state); 108 | 109 | /* Interrupt related functions */ 110 | void EnableGpioDetect (unsigned int pinNum, enum DETECT_TYPE type); 111 | void DisableGpioDetect (unsigned int pinNum, enum DETECT_TYPE type); 112 | void ClearGpioInterrupt (unsigned int pinNum); 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /Demo/Drivers/bcm2835_intc.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | 68 | #ifndef _BCM2835_INTC_H_ 69 | #define _BCM2835_INTC_H_ 70 | 71 | //#include "bcm2835.h" 72 | 73 | #define BCM2835_INTC_TOTAL_IRQ 64 + 8 74 | 75 | #define BCM2835_BASE_INTC (0x2000B200) 76 | #define BCM2835_INTC_IRQ_BASIC (BCM2835_BASE_INTC + 0x00) 77 | #define BCM2835_IRQ_PENDING1 (BCM2835_BASE_INTC + 0x04) 78 | #define BCM2835_IRQ_PENDING2 (BCM2835_BASE_INTC + 0x08) 79 | #define BCM2835_IRQ_FIQ_CTRL (BCM2835_BASE_INTC + 0x0C) 80 | #define BCM2835_IRQ_ENABLE1 (BCM2835_BASE_INTC + 0x10) 81 | #define BCM2835_IRQ_ENABLE2 (BCM2835_BASE_INTC + 0x14) 82 | #define BCM2835_IRQ_ENABLE_BASIC (BCM2835_BASE_INTC + 0x18) 83 | #define BCM2835_IRQ_DISABLE1 (BCM2835_BASE_INTC + 0x1C) 84 | #define BCM2835_IRQ_DISABLE2 (BCM2835_BASE_INTC + 0x20) 85 | #define BCM2835_IRQ_DISABLE_BASIC (BCM2835_BASE_INTC + 0x24) 86 | 87 | 88 | 89 | 90 | #define BCM2835_IRQ_ID_AUX 29 91 | #define BCM2835_IRQ_ID_SPI_SLAVE 43 92 | #define BCM2835_IRQ_ID_PWA0 45 93 | #define BCM2835_IRQ_ID_PWA1 46 94 | #define BCM2835_IRQ_ID_SMI 48 95 | #define BCM2835_IRQ_ID_GPIO_0 49 96 | #define BCM2835_IRQ_ID_GPIO_1 50 97 | #define BCM2835_IRQ_ID_GPIO_2 51 98 | #define BCM2835_IRQ_ID_GPIO_3 52 99 | #define BCM2835_IRQ_ID_I2C 53 100 | #define BCM2835_IRQ_ID_SPI 54 101 | #define BCM2835_IRQ_ID_PCM 55 102 | #define BCM2835_IRQ_ID_UART 57 103 | 104 | 105 | #define BCM2835_IRQ_ID_TIMER_0 64 106 | #define BCM2835_IRQ_ID_MAILBOX_0 65 107 | #define BCM2835_IRQ_ID_DOORBELL_0 66 108 | #define BCM2835_IRQ_ID_DOORBELL_1 67 109 | #define BCM2835_IRQ_ID_GPU0_HALTED 68 110 | 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/MemMang/heap_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | 68 | /* 69 | * Implementation of pvPortMalloc() and vPortFree() that relies on the 70 | * compilers own malloc() and free() implementations. 71 | * 72 | * This file can only be used if the linker is configured to to generate 73 | * a heap memory area. 74 | * 75 | * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the 76 | * memory management pages of http://www.FreeRTOS.org for more information. 77 | */ 78 | 79 | #include 80 | 81 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 82 | all the API functions to use the MPU wrappers. That should only be done when 83 | task.h is included from an application file. */ 84 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 85 | 86 | #include "FreeRTOS.h" 87 | #include "task.h" 88 | 89 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 90 | 91 | /*-----------------------------------------------------------*/ 92 | 93 | void *pvPortMalloc( size_t xWantedSize ) 94 | { 95 | void *pvReturn; 96 | 97 | vTaskSuspendAll(); 98 | { 99 | pvReturn = malloc( xWantedSize ); 100 | } 101 | xTaskResumeAll(); 102 | 103 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 104 | { 105 | if( pvReturn == NULL ) 106 | { 107 | extern void vApplicationMallocFailedHook( void ); 108 | vApplicationMallocFailedHook(); 109 | } 110 | } 111 | #endif 112 | 113 | return pvReturn; 114 | } 115 | /*-----------------------------------------------------------*/ 116 | 117 | void vPortFree( void *pv ) 118 | { 119 | if( pv ) 120 | { 121 | vTaskSuspendAll(); 122 | { 123 | free( pv ); 124 | } 125 | xTaskResumeAll(); 126 | } 127 | } 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /Demo/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef FREERTOS_CONFIG_H 68 | #define FREERTOS_CONFIG_H 69 | 70 | /*----------------------------------------------------------- 71 | * Application specific definitions. 72 | * 73 | * These definitions should be adjusted for your particular hardware and 74 | * application requirements. 75 | * 76 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 77 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 78 | * 79 | * See http://www.freertos.org/a00110.html. 80 | *----------------------------------------------------------*/ 81 | 82 | #define configUSE_PREEMPTION 1 83 | #define configUSE_IDLE_HOOK 0 84 | #define configUSE_TICK_HOOK 0 85 | #define configCPU_CLOCK_HZ ( ( unsigned long ) 24000000 ) 86 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 87 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 ) 88 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) 89 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 4096 ) ) 90 | #define configMAX_TASK_NAME_LEN ( 16 ) 91 | #define configUSE_TRACE_FACILITY 0 92 | #define configUSE_16_BIT_TICKS 0 93 | #define configIDLE_SHOULD_YIELD 1 94 | #define configUSE_APPLICATION_TASK_TAG 1 95 | 96 | /* Co-routine definitions. */ 97 | #define configUSE_CO_ROUTINES 0 98 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 99 | 100 | /* Set the following definitions to 1 to include the API function, or zero 101 | to exclude the API function. */ 102 | 103 | #define INCLUDE_vTaskPrioritySet 1 104 | #define INCLUDE_uxTaskPriorityGet 1 105 | #define INCLUDE_vTaskDelete 1 106 | #define INCLUDE_vTaskCleanUpResources 0 107 | #define INCLUDE_vTaskSuspend 1 108 | #define INCLUDE_vTaskDelayUntil 1 109 | #define INCLUDE_vTaskDelay 1 110 | 111 | /* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 112 | (lowest) to 0 (1?) (highest). */ 113 | #define configKERNEL_INTERRUPT_PRIORITY 255 114 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 115 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 116 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xb0, or priority 11. */ 117 | 118 | 119 | /* This is the value being used as per the ST library which permits 16 120 | priority values, 0 to 15. This must correspond to the 121 | configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest 122 | NVIC value of 255. */ 123 | #define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 124 | 125 | #endif /* FREERTOS_CONFIG_H */ 126 | 127 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef FREERTOS_CONFIG_H 68 | #define FREERTOS_CONFIG_H 69 | 70 | /*----------------------------------------------------------- 71 | * Application specific definitions. 72 | * 73 | * These definitions should be adjusted for your particular hardware and 74 | * application requirements. 75 | * 76 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 77 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 78 | * 79 | * See http://www.freertos.org/a00110.html. 80 | *----------------------------------------------------------*/ 81 | 82 | #define configUSE_PREEMPTION 1 83 | #define configUSE_IDLE_HOOK 0 84 | #define configUSE_TICK_HOOK 0 85 | #define configCPU_CLOCK_HZ ( ( unsigned long ) 24000000 ) 86 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 87 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 ) 88 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) 89 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 4096 ) ) 90 | #define configMAX_TASK_NAME_LEN ( 16 ) 91 | #define configUSE_TRACE_FACILITY 0 92 | #define configUSE_16_BIT_TICKS 0 93 | #define configIDLE_SHOULD_YIELD 1 94 | #define configUSE_APPLICATION_TASK_TAG 1 95 | 96 | /* Co-routine definitions. */ 97 | #define configUSE_CO_ROUTINES 0 98 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 99 | 100 | /* Set the following definitions to 1 to include the API function, or zero 101 | to exclude the API function. */ 102 | 103 | #define INCLUDE_vTaskPrioritySet 1 104 | #define INCLUDE_uxTaskPriorityGet 1 105 | #define INCLUDE_vTaskDelete 1 106 | #define INCLUDE_vTaskCleanUpResources 0 107 | #define INCLUDE_vTaskSuspend 1 108 | #define INCLUDE_vTaskDelayUntil 1 109 | #define INCLUDE_vTaskDelay 1 110 | 111 | /* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 112 | (lowest) to 0 (1?) (highest). */ 113 | #define configKERNEL_INTERRUPT_PRIORITY 255 114 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 115 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 116 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xb0, or priority 11. */ 117 | 118 | 119 | /* This is the value being used as per the ST library which permits 16 120 | priority values, 0 to 15. This must correspond to the 121 | configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest 122 | NVIC value of 255. */ 123 | #define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 124 | 125 | #endif /* FREERTOS_CONFIG_H */ 126 | 127 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/MemMang/heap_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | 68 | /* 69 | * The simplest possible implementation of pvPortMalloc(). Note that this 70 | * implementation does NOT allow allocated memory to be freed again. 71 | * 72 | * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the 73 | * memory management pages of http://www.FreeRTOS.org for more information. 74 | */ 75 | #include 76 | 77 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 78 | all the API functions to use the MPU wrappers. That should only be done when 79 | task.h is included from an application file. */ 80 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 81 | 82 | #include "FreeRTOS.h" 83 | #include "task.h" 84 | 85 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 86 | 87 | /* Allocate the memory for the heap. The struct is used to force byte 88 | alignment without using any non-portable code. */ 89 | static union xRTOS_HEAP 90 | { 91 | #if portBYTE_ALIGNMENT == 8 92 | volatile portDOUBLE dDummy; 93 | #else 94 | volatile unsigned long ulDummy; 95 | #endif 96 | unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; 97 | } xHeap; 98 | 99 | static size_t xNextFreeByte = ( size_t ) 0; 100 | /*-----------------------------------------------------------*/ 101 | 102 | void *pvPortMalloc( size_t xWantedSize ) 103 | { 104 | void *pvReturn = NULL; 105 | 106 | /* Ensure that blocks are always aligned to the required number of bytes. */ 107 | #if portBYTE_ALIGNMENT != 1 108 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 109 | { 110 | /* Byte alignment required. */ 111 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 112 | } 113 | #endif 114 | 115 | vTaskSuspendAll(); 116 | { 117 | /* Check there is enough room left for the allocation. */ 118 | if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) && 119 | ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ 120 | { 121 | /* Return the next free byte then increment the index past this 122 | block. */ 123 | pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] ); 124 | xNextFreeByte += xWantedSize; 125 | } 126 | } 127 | xTaskResumeAll(); 128 | 129 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 130 | { 131 | if( pvReturn == NULL ) 132 | { 133 | extern void vApplicationMallocFailedHook( void ); 134 | vApplicationMallocFailedHook(); 135 | } 136 | } 137 | #endif 138 | 139 | return pvReturn; 140 | } 141 | /*-----------------------------------------------------------*/ 142 | 143 | void vPortFree( void *pv ) 144 | { 145 | /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and 146 | heap_4.c for alternative implementations, and the memory management pages of 147 | http://www.FreeRTOS.org for more information. */ 148 | ( void ) pv; 149 | 150 | /* Force an assert as it is invalid to call this function. */ 151 | configASSERT( pv == NULL ); 152 | } 153 | /*-----------------------------------------------------------*/ 154 | 155 | void vPortInitialiseBlocks( void ) 156 | { 157 | /* Only required when static memory is not cleared. */ 158 | xNextFreeByte = ( size_t ) 0; 159 | } 160 | /*-----------------------------------------------------------*/ 161 | 162 | size_t xPortGetFreeHeapSize( void ) 163 | { 164 | return ( configTOTAL_HEAP_SIZE - xNextFreeByte ); 165 | } 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /Demo/startup.s: -------------------------------------------------------------------------------- 1 | ;/* 2 | ; FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | ; 4 | ; 5 | ; *************************************************************************** 6 | ; * * 7 | ; * FreeRTOS tutorial books are available in pdf and paperback. * 8 | ; * Complete, revised, and edited pdf reference manuals are also * 9 | ; * available. * 10 | ; * * 11 | ; * Purchasing FreeRTOS documentation will not only help you, by * 12 | ; * ensuring you get running as quickly as possible and with an * 13 | ; * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | ; * the FreeRTOS project to continue with its mission of providing * 15 | ; * professional grade, cross platform, de facto standard solutions * 16 | ; * for microcontrollers - completely free of charge! * 17 | ; * * 18 | ; * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | ; * * 20 | ; * Thank you for using FreeRTOS, and thank you for your support! * 21 | ; * * 22 | ; *************************************************************************** 23 | ; 24 | ; 25 | ; This file is part of the FreeRTOS distribution. 26 | ; 27 | ; FreeRTOS is free software; you can redistribute it and/or modify it under 28 | ; the terms of the GNU General Public License (version 2) as published by the 29 | ; Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | ; >>>NOTE<<< The modification to the GPL is included to allow you to 31 | ; distribute a combined work that includes FreeRTOS without being obliged to 32 | ; provide the source code for proprietary components outside of the FreeRTOS 33 | ; kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | ; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | ; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | ; more details. You should have received a copy of the GNU General Public 37 | ; License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | ; can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | ; by writing to Richard Barry, contact details for whom are available on the 40 | ; FreeRTOS WEB site. 41 | ; 42 | ; 1 tab == 4 spaces! 43 | ; 44 | ; *************************************************************************** 45 | ; * * 46 | ; * Having a problem? Start by reading the FAQ "My application does * 47 | ; * not run, what could be wrong? * 48 | ; * * 49 | ; * http://www.FreeRTOS.org/FAQHelp.html * 50 | ; * * 51 | ; *************************************************************************** 52 | ; 53 | ; 54 | ; http://www.FreeRTOS.org - Documentation, training, latest information, 55 | ; license and contact details. 56 | ; 57 | ; http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | ; including FreeRTOS+Trace - an indispensable productivity tool. 59 | ; 60 | ; Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | ; the code with commercial support, indemnification, and middleware, under 62 | ; the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | ; provide a safety engineered and independently SIL3 certified version under 64 | ; the SafeRTOS brand: http://www.SafeRTOS.com. 65 | ;*/ 66 | 67 | 68 | .extern system_init 69 | .extern __bss_start 70 | .extern __bss_end 71 | .extern vFreeRTOS_ISR 72 | .extern vPortYieldProcessor 73 | .extern irqBlock 74 | .extern main 75 | .section .init 76 | .globl _start 77 | ;; 78 | _start: 79 | ;@ All the following instruction should be read as: 80 | ;@ Load the address at symbol into the program counter. 81 | 82 | ldr pc,reset_handler ;@ Processor Reset handler -- we will have to force this on the raspi! 83 | ;@ Because this is the first instruction executed, of cause it causes an immediate branch into reset! 84 | 85 | ldr pc,undefined_handler ;@ Undefined instruction handler -- processors that don't have thumb can emulate thumb! 86 | ldr pc,swi_handler ;@ Software interrupt / TRAP (SVC) -- system SVC handler for switching to kernel mode. 87 | ldr pc,prefetch_handler ;@ Prefetch/abort handler. 88 | ldr pc,data_handler ;@ Data abort handler/ 89 | ldr pc,unused_handler ;@ -- Historical from 26-bit addressing ARMs -- was invalid address handler. 90 | ldr pc,irq_handler ;@ IRQ handler 91 | ldr pc,fiq_handler ;@ Fast interrupt handler. 92 | 93 | ;@ Here we create an exception address table! This means that reset/hang/irq can be absolute addresses 94 | reset_handler: .word reset 95 | undefined_handler: .word undefined_instruction 96 | swi_handler: .word vPortYieldProcessor 97 | prefetch_handler: .word prefetch_abort 98 | data_handler: .word data_abort 99 | unused_handler: .word unused 100 | irq_handler: .word vFreeRTOS_ISR 101 | fiq_handler: .word fiq 102 | 103 | reset: 104 | ;@ In the reset handler, we need to copy our interrupt vector table to 0x0000, its currently at 0x8000 105 | 106 | mov r0,#0x8000 ;@ Store the source pointer 107 | mov r1,#0x0000 ;@ Store the destination pointer. 108 | 109 | ;@ Here we copy the branching instructions 110 | ldmia r0!,{r2,r3,r4,r5,r6,r7,r8,r9} ;@ Load multiple values from indexed address. ; Auto-increment R0 111 | stmia r1!,{r2,r3,r4,r5,r6,r7,r8,r9} ;@ Store multiple values from the indexed address. ; Auto-increment R1 112 | 113 | ;@ So the branches get the correct address we also need to copy our vector table! 114 | ldmia r0!,{r2,r3,r4,r5,r6,r7,r8,r9} ;@ Load from 4*n of regs (8) as R0 is now incremented. 115 | stmia r1!,{r2,r3,r4,r5,r6,r7,r8,r9} ;@ Store this extra set of data. 116 | 117 | 118 | ;@ Set up the various STACK pointers for different CPU modes 119 | ;@ (PSR_IRQ_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS) 120 | mov r0,#0xD2 121 | msr cpsr_c,r0 122 | mov sp,#0x8000 123 | 124 | ;@ (PSR_FIQ_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS) 125 | mov r0,#0xD1 126 | msr cpsr_c,r0 127 | mov sp,#0x4000 128 | 129 | ;@ (PSR_SVC_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS) 130 | mov r0,#0xD3 131 | msr cpsr_c,r0 132 | mov sp,#0x8000000 133 | 134 | ldr r0, =__bss_start 135 | ldr r1, =__bss_end 136 | 137 | mov r2, #0 138 | 139 | zero_loop: 140 | cmp r0,r1 141 | it lt 142 | strlt r2,[r0], #4 143 | blt zero_loop 144 | 145 | bl irqBlock 146 | 147 | 148 | ;@ mov sp,#0x1000000 149 | b main ;@ We're ready?? Lets start main execution! 150 | .section .text 151 | 152 | undefined_instruction: 153 | b undefined_instruction 154 | 155 | prefetch_abort: 156 | b prefetch_abort 157 | 158 | data_abort: 159 | b data_abort 160 | 161 | unused: 162 | b unused 163 | 164 | fiq: 165 | b fiq 166 | 167 | hang: 168 | b hang 169 | 170 | -------------------------------------------------------------------------------- /Demo/Drivers/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | /** 68 | * Quick and very Dirty GPIO API. 69 | * 70 | **/ 71 | 72 | #include "gpio.h" 73 | 74 | typedef struct { 75 | unsigned long GPFSEL[6]; ///< Function selection registers. 76 | unsigned long Reserved_1; 77 | unsigned long GPSET[2]; 78 | unsigned long Reserved_2; 79 | unsigned long GPCLR[2]; 80 | unsigned long Reserved_3; 81 | unsigned long GPLEV[2]; 82 | unsigned long Reserved_4; 83 | unsigned long GPEDS[2]; 84 | unsigned long Reserved_5; 85 | unsigned long GPREN[2]; 86 | unsigned long Reserved_6; 87 | unsigned long GPFEN[2]; 88 | unsigned long Reserved_7; 89 | unsigned long GPHEN[2]; 90 | unsigned long Reserved_8; 91 | unsigned long GPLEN[2]; 92 | unsigned long Reserved_9; 93 | unsigned long GPAREN[2]; 94 | unsigned long Reserved_A; 95 | unsigned long GPAFEN[2]; 96 | unsigned long Reserved_B; 97 | unsigned long GPPUD[1]; 98 | unsigned long GPPUDCLK[2]; 99 | //Ignoring the reserved and test bytes 100 | } BCM2835_GPIO_REGS; 101 | 102 | volatile BCM2835_GPIO_REGS * const pRegs = (BCM2835_GPIO_REGS *) (0x20200000); 103 | 104 | 105 | void SetGpioFunction(unsigned int pinNum, unsigned int funcNum) { 106 | 107 | int offset = pinNum / 10; 108 | 109 | unsigned long val = pRegs->GPFSEL[offset]; // Read in the original register value. 110 | 111 | int item = pinNum % 10; 112 | val &= ~(0x7 << (item * 3)); 113 | val |= ((funcNum & 0x7) << (item * 3)); 114 | pRegs->GPFSEL[offset] = val; 115 | } 116 | 117 | void SetGpioDirection(unsigned int pinNum, enum GPIO_DIR dir) { 118 | SetGpioFunction(pinNum,dir); 119 | } 120 | 121 | void SetGpio(unsigned int pinNum, unsigned int pinVal) { 122 | unsigned long offset=pinNum/32; 123 | unsigned long mask=(1<<(pinNum%32)); 124 | 125 | if(pinVal) { 126 | pRegs->GPSET[offset]|=mask; 127 | } else { 128 | pRegs->GPCLR[offset]|=mask; 129 | } 130 | } 131 | 132 | int ReadGpio(unsigned int pinNum) { 133 | return ((pRegs->GPLEV[pinNum/32])>>(pinNum%32))&1; 134 | } 135 | 136 | void EnableGpioDetect(unsigned int pinNum, enum DETECT_TYPE type) 137 | { 138 | unsigned long mask=(1<GPREN[offset]|=mask; 144 | break; 145 | case DETECT_FALLING: 146 | pRegs->GPFEN[offset]|=mask; 147 | break; 148 | case DETECT_HIGH: 149 | pRegs->GPHEN[offset]|=mask; 150 | break; 151 | case DETECT_LOW: 152 | pRegs->GPLEN[offset]|=mask; 153 | break; 154 | case DETECT_RISING_ASYNC: 155 | pRegs->GPAREN[offset]|=mask; 156 | break; 157 | case DETECT_FALLING_ASYNC: 158 | pRegs->GPAFEN[offset]|=mask; 159 | break; 160 | case DETECT_NONE: 161 | break; 162 | } 163 | } 164 | 165 | void DisableGpioDetect(unsigned int pinNum, enum DETECT_TYPE type) 166 | { 167 | unsigned long mask=~(1<<(pinNum%32)); 168 | unsigned long offset=pinNum/32; 169 | 170 | switch(type) { 171 | case DETECT_RISING: 172 | pRegs->GPREN[offset]&=mask; 173 | break; 174 | case DETECT_FALLING: 175 | pRegs->GPFEN[offset]&=mask; 176 | break; 177 | case DETECT_HIGH: 178 | pRegs->GPHEN[offset]&=mask; 179 | break; 180 | case DETECT_LOW: 181 | pRegs->GPLEN[offset]&=mask; 182 | break; 183 | case DETECT_RISING_ASYNC: 184 | pRegs->GPAREN[offset]&=mask; 185 | break; 186 | case DETECT_FALLING_ASYNC: 187 | pRegs->GPAFEN[offset]&=mask; 188 | break; 189 | case DETECT_NONE: 190 | break; 191 | } 192 | } 193 | 194 | void ClearGpioInterrupt(unsigned int pinNum) 195 | { 196 | unsigned long mask=(1<<(pinNum%32)); 197 | unsigned long offset=pinNum/32; 198 | 199 | pRegs->GPEDS[offset]=mask; 200 | } 201 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/mpu_wrappers.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef MPU_WRAPPERS_H 68 | #define MPU_WRAPPERS_H 69 | 70 | /* This file redefines API functions to be called through a wrapper macro, but 71 | only for ports that are using the MPU. */ 72 | #ifdef portUSING_MPU_WRAPPERS 73 | 74 | /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is 75 | included from queue.c or task.c to prevent it from having an effect within 76 | those files. */ 77 | #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 78 | 79 | #define xTaskGenericCreate MPU_xTaskGenericCreate 80 | #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions 81 | #define vTaskDelete MPU_vTaskDelete 82 | #define vTaskDelayUntil MPU_vTaskDelayUntil 83 | #define vTaskDelay MPU_vTaskDelay 84 | #define uxTaskPriorityGet MPU_uxTaskPriorityGet 85 | #define vTaskPrioritySet MPU_vTaskPrioritySet 86 | #define vTaskSuspend MPU_vTaskSuspend 87 | #define xTaskIsTaskSuspended MPU_xTaskIsTaskSuspended 88 | #define vTaskResume MPU_vTaskResume 89 | #define vTaskSuspendAll MPU_vTaskSuspendAll 90 | #define xTaskResumeAll MPU_xTaskResumeAll 91 | #define xTaskGetTickCount MPU_xTaskGetTickCount 92 | #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks 93 | #define vTaskList MPU_vTaskList 94 | #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats 95 | #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag 96 | #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag 97 | #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook 98 | #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark 99 | #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle 100 | #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState 101 | 102 | #define xQueueGenericCreate MPU_xQueueGenericCreate 103 | #define xQueueCreateMutex MPU_xQueueCreateMutex 104 | #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive 105 | #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive 106 | #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore 107 | #define xQueueGenericSend MPU_xQueueGenericSend 108 | #define xQueueAltGenericSend MPU_xQueueAltGenericSend 109 | #define xQueueAltGenericReceive MPU_xQueueAltGenericReceive 110 | #define xQueueGenericReceive MPU_xQueueGenericReceive 111 | #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting 112 | #define vQueueDelete MPU_vQueueDelete 113 | 114 | #define pvPortMalloc MPU_pvPortMalloc 115 | #define vPortFree MPU_vPortFree 116 | #define xPortGetFreeHeapSize MPU_xPortGetFreeHeapSize 117 | #define vPortInitialiseBlocks MPU_vPortInitialiseBlocks 118 | 119 | #if configQUEUE_REGISTRY_SIZE > 0 120 | #define vQueueAddToRegistry MPU_vQueueAddToRegistry 121 | #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue 122 | #endif 123 | 124 | /* Remove the privileged function macro. */ 125 | #define PRIVILEGED_FUNCTION 126 | 127 | #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 128 | 129 | /* Ensure API functions go in the privileged execution section. */ 130 | #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions"))) 131 | #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) 132 | //#define PRIVILEGED_DATA 133 | 134 | #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 135 | 136 | #else /* portUSING_MPU_WRAPPERS */ 137 | 138 | #define PRIVILEGED_FUNCTION 139 | #define PRIVILEGED_DATA 140 | #define portUSING_MPU_WRAPPERS 0 141 | 142 | #endif /* portUSING_MPU_WRAPPERS */ 143 | 144 | 145 | #endif /* MPU_WRAPPERS_H */ 146 | 147 | -------------------------------------------------------------------------------- /FreeRTOS/Source/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | 68 | #include 69 | #include "FreeRTOS.h" 70 | #include "list.h" 71 | 72 | /*----------------------------------------------------------- 73 | * PUBLIC LIST API documented in list.h 74 | *----------------------------------------------------------*/ 75 | 76 | void vListInitialise( xList *pxList ) 77 | { 78 | /* The list structure contains a list item which is used to mark the 79 | end of the list. To initialise the list the list end is inserted 80 | as the only list entry. */ 81 | pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd ); 82 | 83 | /* The list end value is the highest possible value in the list to 84 | ensure it remains at the end of the list. */ 85 | pxList->xListEnd.xItemValue = portMAX_DELAY; 86 | 87 | /* The list end next and previous pointers point to itself so we know 88 | when the list is empty. */ 89 | pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd ); 90 | pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd ); 91 | 92 | pxList->uxNumberOfItems = ( unsigned portBASE_TYPE ) 0U; 93 | } 94 | /*-----------------------------------------------------------*/ 95 | 96 | void vListInitialiseItem( xListItem *pxItem ) 97 | { 98 | /* Make sure the list item is not recorded as being on a list. */ 99 | pxItem->pvContainer = NULL; 100 | } 101 | /*-----------------------------------------------------------*/ 102 | 103 | void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ) 104 | { 105 | volatile xListItem * pxIndex; 106 | 107 | /* Insert a new list item into pxList, but rather than sort the list, 108 | makes the new list item the last item to be removed by a call to 109 | pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by 110 | the pxIndex member. */ 111 | pxIndex = pxList->pxIndex; 112 | 113 | pxNewListItem->pxNext = pxIndex->pxNext; 114 | pxNewListItem->pxPrevious = pxList->pxIndex; 115 | pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; 116 | pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem; 117 | pxList->pxIndex = ( volatile xListItem * ) pxNewListItem; 118 | 119 | /* Remember which list the item is in. */ 120 | pxNewListItem->pvContainer = ( void * ) pxList; 121 | 122 | ( pxList->uxNumberOfItems )++; 123 | } 124 | /*-----------------------------------------------------------*/ 125 | 126 | void vListInsert( xList *pxList, xListItem *pxNewListItem ) 127 | { 128 | volatile xListItem *pxIterator; 129 | portTickType xValueOfInsertion; 130 | 131 | /* Insert the new list item into the list, sorted in ulListItem order. */ 132 | xValueOfInsertion = pxNewListItem->xItemValue; 133 | 134 | /* If the list already contains a list item with the same item value then 135 | the new list item should be placed after it. This ensures that TCB's which 136 | are stored in ready lists (all of which have the same ulListItem value) 137 | get an equal share of the CPU. However, if the xItemValue is the same as 138 | the back marker the iteration loop below will not end. This means we need 139 | to guard against this by checking the value first and modifying the 140 | algorithm slightly if necessary. */ 141 | if( xValueOfInsertion == portMAX_DELAY ) 142 | { 143 | pxIterator = pxList->xListEnd.pxPrevious; 144 | } 145 | else 146 | { 147 | /* *** NOTE *********************************************************** 148 | If you find your application is crashing here then likely causes are: 149 | 1) Stack overflow - 150 | see http://www.freertos.org/Stacks-and-stack-overflow-checking.html 151 | 2) Incorrect interrupt priority assignment, especially on Cortex-M3 152 | parts where numerically high priority values denote low actual 153 | interrupt priories, which can seem counter intuitive. See 154 | configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html 155 | 3) Calling an API function from within a critical section or when 156 | the scheduler is suspended. 157 | 4) Using a queue or semaphore before it has been initialised or 158 | before the scheduler has been started (are interrupts firing 159 | before vTaskStartScheduler() has been called?). 160 | See http://www.freertos.org/FAQHelp.html for more tips. 161 | **********************************************************************/ 162 | 163 | for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) 164 | { 165 | /* There is nothing to do here, we are just iterating to the 166 | wanted insertion position. */ 167 | } 168 | } 169 | 170 | pxNewListItem->pxNext = pxIterator->pxNext; 171 | pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; 172 | pxNewListItem->pxPrevious = pxIterator; 173 | pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem; 174 | 175 | /* Remember which list the item is in. This allows fast removal of the 176 | item later. */ 177 | pxNewListItem->pvContainer = ( void * ) pxList; 178 | 179 | ( pxList->uxNumberOfItems )++; 180 | } 181 | /*-----------------------------------------------------------*/ 182 | 183 | void vListRemove( xListItem *pxItemToRemove ) 184 | { 185 | xList * pxList; 186 | 187 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; 188 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; 189 | 190 | /* The list item knows which list it is in. Obtain the list from the list 191 | item. */ 192 | pxList = ( xList * ) pxItemToRemove->pvContainer; 193 | 194 | /* Make sure the index is left pointing to a valid item. */ 195 | if( pxList->pxIndex == pxItemToRemove ) 196 | { 197 | pxList->pxIndex = pxItemToRemove->pxPrevious; 198 | } 199 | 200 | pxItemToRemove->pvContainer = NULL; 201 | ( pxList->uxNumberOfItems )--; 202 | } 203 | /*-----------------------------------------------------------*/ 204 | 205 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef STACK_MACROS_H 68 | #define STACK_MACROS_H 69 | 70 | /* 71 | * Call the stack overflow hook function if the stack of the task being swapped 72 | * out is currently overflowed, or looks like it might have overflowed in the 73 | * past. 74 | * 75 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 76 | * the current stack state only - comparing the current top of stack value to 77 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 78 | * will also cause the last few stack bytes to be checked to ensure the value 79 | * to which the bytes were set when the task was created have not been 80 | * overwritten. Note this second test does not guarantee that an overflowed 81 | * stack will always be recognised. 82 | */ 83 | 84 | /*-----------------------------------------------------------*/ 85 | 86 | #if( configCHECK_FOR_STACK_OVERFLOW == 0 ) 87 | 88 | /* FreeRTOSConfig.h is not set to check for stack overflows. */ 89 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() 90 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 91 | 92 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ 93 | /*-----------------------------------------------------------*/ 94 | 95 | #if( configCHECK_FOR_STACK_OVERFLOW == 1 ) 96 | 97 | /* FreeRTOSConfig.h is only set to use the first method of 98 | overflow checking. */ 99 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 100 | 101 | #endif 102 | /*-----------------------------------------------------------*/ 103 | 104 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) 105 | 106 | /* Only the current stack state is to be checked. */ 107 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 108 | { \ 109 | /* Is the currently saved stack pointer within the stack limit? */ \ 110 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 111 | { \ 112 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 113 | } \ 114 | } 115 | 116 | #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */ 117 | /*-----------------------------------------------------------*/ 118 | 119 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) 120 | 121 | /* Only the current stack state is to be checked. */ 122 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 123 | { \ 124 | \ 125 | /* Is the currently saved stack pointer within the stack limit? */ \ 126 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 127 | { \ 128 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 129 | } \ 130 | } 131 | 132 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 133 | /*-----------------------------------------------------------*/ 134 | 135 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 136 | 137 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 138 | { \ 139 | static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 140 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 141 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 142 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 143 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 144 | \ 145 | \ 146 | /* Has the extremity of the task stack ever been written over? */ \ 147 | if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 148 | { \ 149 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 150 | } \ 151 | } 152 | 153 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 154 | /*-----------------------------------------------------------*/ 155 | 156 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 157 | 158 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 159 | { \ 160 | char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \ 161 | static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 162 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 163 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 164 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 165 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 166 | \ 167 | \ 168 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 169 | \ 170 | /* Has the extremity of the task stack ever been written over? */ \ 171 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 172 | { \ 173 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 174 | } \ 175 | } 176 | 177 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 178 | /*-----------------------------------------------------------*/ 179 | 180 | #endif /* STACK_MACROS_H */ 181 | 182 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/GCC/RaspberryPi/port.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | * 66 | * 67 | * Raspberry Pi Porting layer for FreeRTOS. 68 | */ 69 | 70 | #include "FreeRTOS.h" 71 | #include "task.h" 72 | #include 73 | 74 | /* Constants required to setup the task context. */ 75 | #define portINITIAL_SPSR ( ( portSTACK_TYPE ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */ 76 | #define portTHUMB_MODE_BIT ( ( portSTACK_TYPE ) 0x20 ) 77 | #define portINSTRUCTION_SIZE ( ( portSTACK_TYPE ) 4 ) 78 | #define portNO_CRITICAL_SECTION_NESTING ( ( portSTACK_TYPE ) 0 ) 79 | 80 | #define portTIMER_PRESCALE ( ( unsigned long ) 0xF9 ) 81 | 82 | 83 | /* Constants required to setup the VIC for the tick ISR. */ 84 | #define portTIMER_BASE ( (unsigned long ) 0x2000B400 ) 85 | 86 | typedef struct _BCM2835_TIMER_REGS { 87 | unsigned long LOD; 88 | unsigned long VAL; 89 | unsigned long CTL; 90 | unsigned long CLI; 91 | unsigned long RIS; 92 | unsigned long MIS; 93 | unsigned long RLD; 94 | unsigned long DIV; 95 | unsigned long CNT; 96 | } BCM2835_TIMER_REGS; 97 | 98 | static volatile BCM2835_TIMER_REGS * const pRegs = (BCM2835_TIMER_REGS *) (portTIMER_BASE); 99 | 100 | /*-----------------------------------------------------------*/ 101 | 102 | /* Setup the timer to generate the tick interrupts. */ 103 | static void prvSetupTimerInterrupt( void ); 104 | 105 | /* 106 | * The scheduler can only be started from ARM mode, so 107 | * vPortISRStartFirstSTask() is defined in portISR.c. 108 | */ 109 | extern void vPortISRStartFirstTask( void ); 110 | 111 | /*-----------------------------------------------------------*/ 112 | 113 | /* 114 | * Initialise the stack of a task to look exactly as if a call to 115 | * portSAVE_CONTEXT had been called. 116 | * 117 | * See header file for description. 118 | */ 119 | portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) 120 | { 121 | portSTACK_TYPE *pxOriginalTOS; 122 | 123 | pxOriginalTOS = pxTopOfStack; 124 | 125 | /* To ensure asserts in tasks.c don't fail, although in this case the assert 126 | is not really required. */ 127 | pxTopOfStack--; 128 | 129 | /* Setup the initial stack of the task. The stack is set exactly as 130 | expected by the portRESTORE_CONTEXT() macro. */ 131 | 132 | /* First on the stack is the return address - which in this case is the 133 | start of the task. The offset is added to make the return address appear 134 | as it would within an IRQ ISR. */ 135 | *pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE; 136 | pxTopOfStack--; 137 | 138 | *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaaaaaa; /* R14 */ 139 | pxTopOfStack--; 140 | *pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */ 141 | pxTopOfStack--; 142 | *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212; /* R12 */ 143 | pxTopOfStack--; 144 | *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111; /* R11 */ 145 | pxTopOfStack--; 146 | *pxTopOfStack = ( portSTACK_TYPE ) 0x10101010; /* R10 */ 147 | pxTopOfStack--; 148 | *pxTopOfStack = ( portSTACK_TYPE ) 0x09090909; /* R9 */ 149 | pxTopOfStack--; 150 | *pxTopOfStack = ( portSTACK_TYPE ) 0x08080808; /* R8 */ 151 | pxTopOfStack--; 152 | *pxTopOfStack = ( portSTACK_TYPE ) 0x07070707; /* R7 */ 153 | pxTopOfStack--; 154 | *pxTopOfStack = ( portSTACK_TYPE ) 0x06060606; /* R6 */ 155 | pxTopOfStack--; 156 | *pxTopOfStack = ( portSTACK_TYPE ) 0x05050505; /* R5 */ 157 | pxTopOfStack--; 158 | *pxTopOfStack = ( portSTACK_TYPE ) 0x04040404; /* R4 */ 159 | pxTopOfStack--; 160 | *pxTopOfStack = ( portSTACK_TYPE ) 0x03030303; /* R3 */ 161 | pxTopOfStack--; 162 | *pxTopOfStack = ( portSTACK_TYPE ) 0x02020202; /* R2 */ 163 | pxTopOfStack--; 164 | *pxTopOfStack = ( portSTACK_TYPE ) 0x01010101; /* R1 */ 165 | pxTopOfStack--; 166 | 167 | /* When the task starts it will expect to find the function parameter in 168 | R0. */ 169 | *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ 170 | pxTopOfStack--; 171 | 172 | /* The last thing onto the stack is the status register, which is set for 173 | system mode, with interrupts enabled. */ 174 | *pxTopOfStack = ( portSTACK_TYPE ) portINITIAL_SPSR; 175 | 176 | if( ( ( unsigned long ) pxCode & 0x01UL ) != 0x00 ) 177 | { 178 | /* We want the task to start in thumb mode. */ 179 | *pxTopOfStack |= portTHUMB_MODE_BIT; 180 | } 181 | 182 | pxTopOfStack--; 183 | 184 | /* Some optimisation levels use the stack differently to others. This 185 | means the interrupt flags cannot always be stored on the stack and will 186 | instead be stored in a variable, which is then saved as part of the 187 | tasks context. */ 188 | *pxTopOfStack = portNO_CRITICAL_SECTION_NESTING; 189 | 190 | return pxTopOfStack; 191 | } 192 | /*-----------------------------------------------------------*/ 193 | 194 | portBASE_TYPE xPortStartScheduler( void ) 195 | { 196 | /* Start the timer that generates the tick ISR. Interrupts are disabled 197 | here already. */ 198 | prvSetupTimerInterrupt(); 199 | 200 | /* Start the first task. */ 201 | vPortISRStartFirstTask(); 202 | 203 | /* Should not get here! */ 204 | return 0; 205 | } 206 | /*-----------------------------------------------------------*/ 207 | 208 | void vPortEndScheduler( void ) 209 | { 210 | /* It is unlikely that the ARM port will require this function as there 211 | is nothing to return to. */ 212 | } 213 | /*-----------------------------------------------------------*/ 214 | 215 | /* 216 | * This is the TICK interrupt service routine, note. no SAVE/RESTORE_CONTEXT here 217 | * as thats done in the bottom-half of the ISR. 218 | * 219 | * See bt_interrupts.c in the RaspberryPi Drivers folder. 220 | */ 221 | void vTickISR (unsigned int nIRQ, void *pParam) 222 | { 223 | vTaskIncrementTick(); 224 | 225 | #if configUSE_PREEMPTION == 1 226 | vTaskSwitchContext(); 227 | #endif 228 | 229 | pRegs->CLI = 0; // Acknowledge the timer interrupt. 230 | } 231 | 232 | /* 233 | * Setup the timer 0 to generate the tick interrupts at the required frequency. 234 | */ 235 | static void prvSetupTimerInterrupt( void ) 236 | { 237 | unsigned long ulCompareMatch; 238 | 239 | 240 | /* Calculate the match value required for our wanted tick rate. */ 241 | ulCompareMatch = 1000000 / configTICK_RATE_HZ; 242 | 243 | /* Protect against divide by zero. Using an if() statement still results 244 | in a warning - hence the #if. */ 245 | #if portPRESCALE_VALUE != 0 246 | { 247 | ulCompareMatch /= ( portPRESCALE_VALUE + 1 ); 248 | } 249 | #endif 250 | 251 | irqBlock(); 252 | 253 | pRegs->CTL = 0x003E0000; 254 | pRegs->LOD = 1000 - 1; 255 | pRegs->RLD = 1000 - 1; 256 | pRegs->DIV = portTIMER_PRESCALE; 257 | pRegs->CLI = 0; 258 | pRegs->CTL = 0x003E00A2; 259 | 260 | irqRegister(64, vTickISR, NULL); 261 | 262 | irqEnable(64); 263 | 264 | irqUnblock(); 265 | } 266 | /*-----------------------------------------------------------*/ 267 | 268 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/GCC/RaspberryPi/portisr.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | 66 | 67 | *----------------------------------------------------------- 68 | * Components that can be compiled to either ARM or THUMB mode are 69 | * contained in port.c The ISR routines, which can only be compiled 70 | * to ARM mode, are contained in this file. 71 | *----------------------------------------------------------*/ 72 | 73 | /* 74 | Changes from V2.5.2 75 | 76 | + The critical section management functions have been changed. These no 77 | longer modify the stack and are safe to use at all optimisation levels. 78 | The functions are now also the same for both ARM and THUMB modes. 79 | 80 | Changes from V2.6.0 81 | 82 | + Removed the 'static' from the definition of vNonPreemptiveTick() to 83 | allow the demo to link when using the cooperative scheduler. 84 | 85 | Changes from V3.2.4 86 | 87 | + The assembler statements are now included in a single asm block rather 88 | than each line having its own asm block. 89 | */ 90 | 91 | 92 | /* Scheduler includes. */ 93 | #include "FreeRTOS.h" 94 | 95 | /* Constants required to handle interrupts. */ 96 | #define portTIMER_MATCH_ISR_BIT ( ( unsigned char ) 0x01 ) 97 | #define portCLEAR_VIC_INTERRUPT ( ( unsigned long ) 0 ) 98 | 99 | /* Constants required to handle critical sections. */ 100 | #define portNO_CRITICAL_NESTING ( ( unsigned long ) 0 ) 101 | volatile unsigned long ulCriticalNesting = 9999UL; 102 | 103 | /*-----------------------------------------------------------*/ 104 | 105 | /* ISR to handle manual context switches (from a call to taskYIELD()). */ 106 | void vPortYieldProcessor( void ) __attribute__((interrupt("SWI"), naked)); 107 | 108 | /* 109 | * The scheduler can only be started from ARM mode, hence the inclusion of this 110 | * function here. 111 | */ 112 | void vPortISRStartFirstTask( void ); 113 | /*-----------------------------------------------------------*/ 114 | 115 | int g_bStarted = 0; 116 | 117 | void vPortISRStartFirstTask( void ) 118 | { 119 | 120 | /* 121 | * Change from System to IRQ mode. 122 | * 123 | * 124 | */ 125 | 126 | g_bStarted++; 127 | 128 | __asm volatile("mrs r0,cpsr"); // Read in the cpsr register. 129 | __asm volatile("bic r0,r0,#0x80"); // Clear bit 8, (0x80) -- Causes IRQs to be enabled 130 | __asm volatile("msr cpsr_c, r0"); // Write it back to the CPSR register 131 | // __asm volatile("swi 0"); // Force a task switch with SWI! 132 | // __asm volatile("nop"); 133 | 134 | /* Simply start the scheduler. This is included here as it can only be 135 | called from ARM mode. */ 136 | portRESTORE_CONTEXT(); 137 | __asm volatile ( 138 | "LDMFD SP!, {LR} \n" 139 | "SUB LR, LR, #4 \n" 140 | 141 | "BX LR \n" 142 | ); 143 | } 144 | /*-----------------------------------------------------------*/ 145 | 146 | /* 147 | * Called by portYIELD() or taskYIELD() to manually force a context switch. 148 | * 149 | * When a context switch is performed from the task level the saved task 150 | * context is made to look as if it occurred from within the tick ISR. This 151 | * way the same restore context function can be used when restoring the context 152 | * saved from the ISR or that saved from a call to vPortYieldProcessor. 153 | */ 154 | 155 | 156 | void vPortYieldProcessor( void ) 157 | { 158 | /* Within an IRQ ISR the link register has an offset from the true return 159 | address, but an SWI ISR does not. Add the offset manually so the same 160 | ISR return code can be used in both cases. */ 161 | __asm volatile ( "ADD LR, LR, #4" ); 162 | 163 | /* Perform the context switch. First save the context of the current task. */ 164 | portSAVE_CONTEXT(); 165 | 166 | /* Find the highest priority task that is ready to run. */ 167 | __asm volatile ( "bl vTaskSwitchContext" ); 168 | 169 | /* Restore the context of the new task. */ 170 | portRESTORE_CONTEXT(); 171 | } 172 | /*-----------------------------------------------------------*/ 173 | 174 | /* 175 | * The ISR used for the scheduler tick. 176 | */ 177 | 178 | /*-----------------------------------------------------------*/ 179 | 180 | 181 | /** 182 | * This is the KERNEL's true entry point into an ISR. 183 | * 184 | * We use the FreeRTOS to save context before entering the BitThunder 185 | * vectorising ISR, and emitting the true ISR event. 186 | * 187 | * On return from the BitThunder ISR we simply restore the context :D 188 | **/ 189 | 190 | extern void irqHandler(void); 191 | 192 | void vFreeRTOS_ISR( void ) __attribute__((naked)); 193 | void vFreeRTOS_ISR( void ) { 194 | portSAVE_CONTEXT(); 195 | irqHandler(); 196 | portRESTORE_CONTEXT(); 197 | } 198 | 199 | /* 200 | * The interrupt management utilities can only be called from ARM mode. When 201 | * THUMB_INTERWORK is defined the utilities are defined as functions here to 202 | * ensure a switch to ARM mode. When THUMB_INTERWORK is not defined then 203 | * the utilities are defined as macros in portmacro.h - as per other ports. 204 | */ 205 | #ifdef THUMB_INTERWORK 206 | 207 | void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked)); 208 | void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked)); 209 | 210 | void vPortDisableInterruptsFromThumb( void ) 211 | { 212 | __asm volatile ( 213 | "STMDB SP!, {R0} \n\t" /* Push R0. */ 214 | "MRS R0, CPSR \n\t" /* Get CPSR. */ 215 | "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ 216 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ 217 | "LDMIA SP!, {R0} \n\t" /* Pop R0. */ 218 | "BX R14" ); /* Return back to thumb. */ 219 | } 220 | 221 | void vPortEnableInterruptsFromThumb( void ) 222 | { 223 | __asm volatile ( 224 | "STMDB SP!, {R0} \n\t" /* Push R0. */ 225 | "MRS R0, CPSR \n\t" /* Get CPSR. */ 226 | "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ 227 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ 228 | "LDMIA SP!, {R0} \n\t" /* Pop R0. */ 229 | "BX R14" ); /* Return back to thumb. */ 230 | } 231 | 232 | #endif /* THUMB_INTERWORK */ 233 | 234 | /* The code generated by the GCC compiler uses the stack in different ways at 235 | different optimisation levels. The interrupt flags can therefore not always 236 | be saved to the stack. Instead the critical section nesting level is stored 237 | in a variable, which is then saved as part of the stack context. */ 238 | void vPortEnterCritical( void ) 239 | { 240 | /* Disable interrupts as per portDISABLE_INTERRUPTS(); */ 241 | __asm volatile ( 242 | "STMDB SP!, {R0} \n\t" /* Push R0. */ 243 | "MRS R0, CPSR \n\t" /* Get CPSR. */ 244 | "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ 245 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ 246 | "LDMIA SP!, {R0}" ); /* Pop R0. */ 247 | 248 | /* Now interrupts are disabled ulCriticalNesting can be accessed 249 | directly. Increment ulCriticalNesting to keep a count of how many times 250 | portENTER_CRITICAL() has been called. */ 251 | ulCriticalNesting++; 252 | } 253 | 254 | void vPortExitCritical( void ) 255 | { 256 | if( ulCriticalNesting > portNO_CRITICAL_NESTING ) 257 | { 258 | /* Decrement the nesting count as we are leaving a critical section. */ 259 | ulCriticalNesting--; 260 | 261 | /* If the nesting level has reached zero then interrupts should be 262 | re-enabled. */ 263 | if( ulCriticalNesting == portNO_CRITICAL_NESTING ) 264 | { 265 | /* Enable interrupts as per portEXIT_CRITICAL(). */ 266 | __asm volatile ( 267 | "STMDB SP!, {R0} \n\t" /* Push R0. */ 268 | "MRS R0, CPSR \n\t" /* Get CPSR. */ 269 | "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ 270 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ 271 | "LDMIA SP!, {R0}" ); /* Pop R0. */ 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/GCC/RaspberryPi/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #ifndef PORTMACRO_H 68 | #define PORTMACRO_H 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | /*----------------------------------------------------------- 75 | * Port specific definitions. 76 | * 77 | * The settings in this file configure FreeRTOS correctly for the 78 | * given hardware and compiler. 79 | * 80 | * These settings should not be altered. 81 | *----------------------------------------------------------- 82 | */ 83 | 84 | /* Type definitions. */ 85 | #define portCHAR char 86 | #define portFLOAT float 87 | #define portDOUBLE double 88 | #define portLONG long 89 | #define portSHORT short 90 | #define portSTACK_TYPE unsigned portLONG 91 | #define portBASE_TYPE portLONG 92 | 93 | #if( configUSE_16_BIT_TICKS == 1 ) 94 | typedef unsigned portSHORT portTickType; 95 | #define portMAX_DELAY ( portTickType ) 0xffff 96 | #else 97 | typedef unsigned portLONG portTickType; 98 | #define portMAX_DELAY ( portTickType ) 0xffffffff 99 | #endif 100 | /*-----------------------------------------------------------*/ 101 | 102 | /* Architecture specifics. */ 103 | #define portSTACK_GROWTH ( -1 ) 104 | #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) 105 | #define portBYTE_ALIGNMENT 8 106 | #define portNOP() __asm volatile ( "NOP" ); 107 | /*-----------------------------------------------------------*/ 108 | 109 | 110 | /* Scheduler utilities. */ 111 | 112 | /* 113 | * portSAVE_CONTEXT, portRESTORE_CONTEXT, portENTER_SWITCHING_ISR 114 | * and portEXIT_SWITCHING_ISR can only be called from ARM mode, but 115 | * are included here for efficiency. An attempt to call one from 116 | * THUMB mode code will result in a compile time error. 117 | */ 118 | 119 | #define portRESTORE_CONTEXT() \ 120 | { \ 121 | extern volatile void * volatile pxCurrentTCB; \ 122 | extern volatile unsigned portLONG ulCriticalNesting; \ 123 | \ 124 | /* Set the LR to the task stack. */ \ 125 | __asm volatile ( \ 126 | /* Put the address of the current TCB into R1. */ \ 127 | "LDR R0, =pxCurrentTCB \n\t" \ 128 | /* Load the 32-bit value stored at the address in R1. */ \ 129 | /* First item in the TCB is the top of the stack for the current TCB. */ \ 130 | "LDR R0, [R0] \n\t" \ 131 | \ 132 | /* Move the value into the Link Register! */ \ 133 | "LDR LR, [R0] \n\t" \ 134 | \ 135 | /* The critical nesting depth is the first item on the stack. */ \ 136 | /* Load it into the ulCriticalNesting variable. */ \ 137 | "LDR R0, =ulCriticalNesting \n\t" \ 138 | "LDMFD LR!, {R1} \n\t" \ 139 | "STR R1, [R0] \n\t" \ 140 | \ 141 | /* Get the SPSR from the stack. */ \ 142 | "LDMFD LR!, {R0} \n\t" \ 143 | "MSR SPSR_cxsf, R0 \n\t" \ 144 | \ 145 | /* Restore all system mode registers for the task. */ \ 146 | "LDMFD LR, {R0-R14}^ \n\t" \ 147 | "NOP \n\t" \ 148 | \ 149 | /* Restore the return address. */ \ 150 | "LDR LR, [LR, #+60] \n\t" \ 151 | \ 152 | /* And return - correcting the offset in the LR to obtain the */ \ 153 | /* correct address. */ \ 154 | "SUBS PC, LR, #4 \n\t" \ 155 | "NOP \n\t" \ 156 | "NOP \n\t" \ 157 | ); \ 158 | ( void ) ulCriticalNesting; \ 159 | ( void ) pxCurrentTCB; \ 160 | } 161 | /*-----------------------------------------------------------*/ 162 | 163 | #define portSAVE_CONTEXT() \ 164 | { \ 165 | extern volatile void * volatile pxCurrentTCB; \ 166 | extern volatile unsigned portLONG ulCriticalNesting; \ 167 | \ 168 | /* Push R0 as we are going to use the register. */ \ 169 | __asm volatile ( \ 170 | "STMDB SP!, {R0} \n\t" \ 171 | \ 172 | /* Set R0 to point to the task stack pointer. */ \ 173 | "STMDB SP,{SP}^ \n\t" /* ^ means get the user mode SP value. */ \ 174 | /*"NOP \n\t" */ \ 175 | "SUB SP, SP, #4 \n\t" \ 176 | "LDMIA SP!,{R0} \n\t" \ 177 | \ 178 | /* Push the return address onto the stack. */ \ 179 | "STMDB R0!, {LR} \n\t" \ 180 | \ 181 | /* Now we have saved LR we can use it instead of R0. */ \ 182 | "MOV LR, R0 \n\t" \ 183 | \ 184 | /* Pop R0 so we can save it onto the system mode stack. */ \ 185 | "LDMIA SP!, {R0} \n\t" \ 186 | \ 187 | /* Push all the system mode registers onto the task stack. */ \ 188 | "STMDB LR,{R0-LR}^ \n\t" \ 189 | "NOP \n\t" \ 190 | "SUB LR, LR, #60 \n\t" \ 191 | \ 192 | /* Push the SPSR onto the task stack. */ \ 193 | "MRS R0, SPSR \n\t" \ 194 | "STMDB LR!, {R0} \n\t" \ 195 | \ 196 | "LDR R0, =ulCriticalNesting \n\t" \ 197 | "LDR R0, [R0] \n\t" \ 198 | "STMDB LR!, {R0} \n\t" \ 199 | \ 200 | /* Store the new top of stack for the task. */ \ 201 | "LDR R0, =pxCurrentTCB \n\t" \ 202 | "LDR R0, [R0] \n\t" \ 203 | "STR LR, [R0] \n\t" \ 204 | ); \ 205 | ( void ) ulCriticalNesting; \ 206 | ( void ) pxCurrentTCB; \ 207 | } 208 | 209 | extern void vTaskSwitchContext( void ); 210 | #define portYIELD_FROM_ISR() vTaskSwitchContext() 211 | #define portYIELD() __asm volatile ( "SWI 0" ) 212 | /*-----------------------------------------------------------*/ 213 | 214 | 215 | /* Critical section management. */ 216 | 217 | /* 218 | * The interrupt management utilities can only be called from ARM mode. When 219 | * THUMB_INTERWORK is defined the utilities are defined as functions in 220 | * portISR.c to ensure a switch to ARM mode. When THUMB_INTERWORK is not 221 | * defined then the utilities are defined as macros here - as per other ports. 222 | */ 223 | 224 | #ifdef THUMB_INTERWORK 225 | 226 | extern void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked)); 227 | extern void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked)); 228 | 229 | #define portDISABLE_INTERRUPTS() vPortDisableInterruptsFromThumb() 230 | #define portENABLE_INTERRUPTS() vPortEnableInterruptsFromThumb() 231 | 232 | #else 233 | 234 | #define portDISABLE_INTERRUPTS() \ 235 | __asm volatile ( \ 236 | "STMDB SP!, {R0} \n\t" /* Push R0. */ \ 237 | "MRS R0, CPSR \n\t" /* Get CPSR. */ \ 238 | "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ \ 239 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ \ 240 | "LDMIA SP!, {R0} " ) /* Pop R0. */ 241 | 242 | #define portENABLE_INTERRUPTS() \ 243 | __asm volatile ( \ 244 | "STMDB SP!, {R0} \n\t" /* Push R0. */ \ 245 | "MRS R0, CPSR \n\t" /* Get CPSR. */ \ 246 | "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ \ 247 | "MSR CPSR, R0 \n\t" /* Write back modified value. */ \ 248 | "LDMIA SP!, {R0} " ) /* Pop R0. */ 249 | 250 | #endif /* THUMB_INTERWORK */ 251 | 252 | extern void vPortEnterCritical( void ); 253 | extern void vPortExitCritical( void ); 254 | 255 | #define portENTER_CRITICAL() vPortEnterCritical(); 256 | #define portEXIT_CRITICAL() vPortExitCritical(); 257 | /*-----------------------------------------------------------*/ 258 | 259 | /* Task function macros as described on the FreeRTOS.org WEB site. */ 260 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 261 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 262 | 263 | #ifdef __cplusplus 264 | } 265 | #endif 266 | 267 | #endif /* PORTMACRO_H */ 268 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/MemMang/heap_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | /* 68 | * A sample implementation of pvPortMalloc() and vPortFree() that permits 69 | * allocated blocks to be freed, but does not combine adjacent free blocks 70 | * into a single larger block (and so will fragment memory). See heap_4.c for 71 | * an aquivalent that does combine adjacent blocks into single larger blocks. 72 | * 73 | * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the 74 | * memory management pages of http://www.FreeRTOS.org for more information. 75 | */ 76 | #include 77 | 78 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 79 | all the API functions to use the MPU wrappers. That should only be done when 80 | task.h is included from an application file. */ 81 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 82 | 83 | #include "FreeRTOS.h" 84 | #include "task.h" 85 | 86 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 87 | 88 | /* Allocate the memory for the heap. The struct is used to force byte 89 | alignment without using any non-portable code. */ 90 | static union xRTOS_HEAP 91 | { 92 | #if portBYTE_ALIGNMENT == 8 93 | volatile portDOUBLE dDummy; 94 | #else 95 | volatile unsigned long ulDummy; 96 | #endif 97 | unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; 98 | } xHeap; 99 | 100 | /* Define the linked list structure. This is used to link free blocks in order 101 | of their size. */ 102 | typedef struct A_BLOCK_LINK 103 | { 104 | struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ 105 | size_t xBlockSize; /*<< The size of the free block. */ 106 | } xBlockLink; 107 | 108 | 109 | static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); 110 | #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) 111 | 112 | /* Create a couple of list links to mark the start and end of the list. */ 113 | static xBlockLink xStart, xEnd; 114 | 115 | /* Keeps track of the number of free bytes remaining, but says nothing about 116 | fragmentation. */ 117 | static size_t xFreeBytesRemaining = configTOTAL_HEAP_SIZE; 118 | 119 | /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ 120 | 121 | /* 122 | * Insert a block into the list of free blocks - which is ordered by size of 123 | * the block. Small blocks at the start of the list and large blocks at the end 124 | * of the list. 125 | */ 126 | #define prvInsertBlockIntoFreeList( pxBlockToInsert ) \ 127 | { \ 128 | xBlockLink *pxIterator; \ 129 | size_t xBlockSize; \ 130 | \ 131 | xBlockSize = pxBlockToInsert->xBlockSize; \ 132 | \ 133 | /* Iterate through the list until a block is found that has a larger size */ \ 134 | /* than the block we are inserting. */ \ 135 | for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \ 136 | { \ 137 | /* There is nothing to do here - just iterate to the correct position. */ \ 138 | } \ 139 | \ 140 | /* Update the list to include the block being inserted in the correct */ \ 141 | /* position. */ \ 142 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \ 143 | pxIterator->pxNextFreeBlock = pxBlockToInsert; \ 144 | } 145 | /*-----------------------------------------------------------*/ 146 | 147 | #define prvHeapInit() \ 148 | { \ 149 | xBlockLink *pxFirstFreeBlock; \ 150 | \ 151 | /* xStart is used to hold a pointer to the first item in the list of free */ \ 152 | /* blocks. The void cast is used to prevent compiler warnings. */ \ 153 | xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; \ 154 | xStart.xBlockSize = ( size_t ) 0; \ 155 | \ 156 | /* xEnd is used to mark the end of the list of free blocks. */ \ 157 | xEnd.xBlockSize = configTOTAL_HEAP_SIZE; \ 158 | xEnd.pxNextFreeBlock = NULL; \ 159 | \ 160 | /* To start with there is a single free block that is sized to take up the \ 161 | entire heap space. */ \ 162 | pxFirstFreeBlock = ( void * ) xHeap.ucHeap; \ 163 | pxFirstFreeBlock->xBlockSize = configTOTAL_HEAP_SIZE; \ 164 | pxFirstFreeBlock->pxNextFreeBlock = &xEnd; \ 165 | } 166 | /*-----------------------------------------------------------*/ 167 | 168 | void *pvPortMalloc( size_t xWantedSize ) 169 | { 170 | xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; 171 | static portBASE_TYPE xHeapHasBeenInitialised = pdFALSE; 172 | void *pvReturn = NULL; 173 | 174 | vTaskSuspendAll(); 175 | { 176 | /* If this is the first call to malloc then the heap will require 177 | initialisation to setup the list of free blocks. */ 178 | if( xHeapHasBeenInitialised == pdFALSE ) 179 | { 180 | prvHeapInit(); 181 | xHeapHasBeenInitialised = pdTRUE; 182 | } 183 | 184 | /* The wanted size is increased so it can contain a xBlockLink 185 | structure in addition to the requested amount of bytes. */ 186 | if( xWantedSize > 0 ) 187 | { 188 | xWantedSize += heapSTRUCT_SIZE; 189 | 190 | /* Ensure that blocks are always aligned to the required number of bytes. */ 191 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 192 | { 193 | /* Byte alignment required. */ 194 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 195 | } 196 | } 197 | 198 | if( ( xWantedSize > 0 ) && ( xWantedSize < configTOTAL_HEAP_SIZE ) ) 199 | { 200 | /* Blocks are stored in byte order - traverse the list from the start 201 | (smallest) block until one of adequate size is found. */ 202 | pxPreviousBlock = &xStart; 203 | pxBlock = xStart.pxNextFreeBlock; 204 | while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) 205 | { 206 | pxPreviousBlock = pxBlock; 207 | pxBlock = pxBlock->pxNextFreeBlock; 208 | } 209 | 210 | /* If we found the end marker then a block of adequate size was not found. */ 211 | if( pxBlock != &xEnd ) 212 | { 213 | /* Return the memory space - jumping over the xBlockLink structure 214 | at its start. */ 215 | pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); 216 | 217 | /* This block is being returned for use so must be taken out of the 218 | list of free blocks. */ 219 | pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; 220 | 221 | /* If the block is larger than required it can be split into two. */ 222 | if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) 223 | { 224 | /* This block is to be split into two. Create a new block 225 | following the number of bytes requested. The void cast is 226 | used to prevent byte alignment warnings from the compiler. */ 227 | pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); 228 | 229 | /* Calculate the sizes of two blocks split from the single 230 | block. */ 231 | pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; 232 | pxBlock->xBlockSize = xWantedSize; 233 | 234 | /* Insert the new block into the list of free blocks. */ 235 | prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); 236 | } 237 | 238 | xFreeBytesRemaining -= pxBlock->xBlockSize; 239 | } 240 | } 241 | } 242 | xTaskResumeAll(); 243 | 244 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 245 | { 246 | if( pvReturn == NULL ) 247 | { 248 | extern void vApplicationMallocFailedHook( void ); 249 | vApplicationMallocFailedHook(); 250 | } 251 | } 252 | #endif 253 | 254 | return pvReturn; 255 | } 256 | /*-----------------------------------------------------------*/ 257 | 258 | void vPortFree( void *pv ) 259 | { 260 | unsigned char *puc = ( unsigned char * ) pv; 261 | xBlockLink *pxLink; 262 | 263 | if( pv != NULL ) 264 | { 265 | /* The memory being freed will have an xBlockLink structure immediately 266 | before it. */ 267 | puc -= heapSTRUCT_SIZE; 268 | 269 | /* This casting is to keep the compiler from issuing warnings. */ 270 | pxLink = ( void * ) puc; 271 | 272 | vTaskSuspendAll(); 273 | { 274 | /* Add this block to the list of free blocks. */ 275 | prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); 276 | xFreeBytesRemaining += pxLink->xBlockSize; 277 | } 278 | xTaskResumeAll(); 279 | } 280 | } 281 | /*-----------------------------------------------------------*/ 282 | 283 | size_t xPortGetFreeHeapSize( void ) 284 | { 285 | return xFreeBytesRemaining; 286 | } 287 | /*-----------------------------------------------------------*/ 288 | 289 | void vPortInitialiseBlocks( void ) 290 | { 291 | /* This just exists to keep the linker quiet. */ 292 | } 293 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/portable.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | /*----------------------------------------------------------- 68 | * Portable layer API. Each function must be defined for each port. 69 | *----------------------------------------------------------*/ 70 | 71 | #ifndef PORTABLE_H 72 | #define PORTABLE_H 73 | 74 | /* Include the macro file relevant to the port being used. */ 75 | 76 | #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT 77 | #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" 78 | typedef void ( __interrupt __far *pxISR )(); 79 | #endif 80 | 81 | #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT 82 | #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" 83 | typedef void ( __interrupt __far *pxISR )(); 84 | #endif 85 | 86 | #ifdef GCC_MEGA_AVR 87 | #include "../portable/GCC/ATMega323/portmacro.h" 88 | #endif 89 | 90 | #ifdef IAR_MEGA_AVR 91 | #include "../portable/IAR/ATMega323/portmacro.h" 92 | #endif 93 | 94 | #ifdef MPLAB_PIC24_PORT 95 | #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" 96 | #endif 97 | 98 | #ifdef MPLAB_DSPIC_PORT 99 | #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" 100 | #endif 101 | 102 | #ifdef MPLAB_PIC18F_PORT 103 | #include "..\..\Source\portable\MPLAB\PIC18F\portmacro.h" 104 | #endif 105 | 106 | #ifdef MPLAB_PIC32MX_PORT 107 | #include "..\..\Source\portable\MPLAB\PIC32MX\portmacro.h" 108 | #endif 109 | 110 | #ifdef _FEDPICC 111 | #include "libFreeRTOS/Include/portmacro.h" 112 | #endif 113 | 114 | #ifdef SDCC_CYGNAL 115 | #include "../../Source/portable/SDCC/Cygnal/portmacro.h" 116 | #endif 117 | 118 | #ifdef GCC_ARM7 119 | #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" 120 | #endif 121 | 122 | #ifdef GCC_ARM7_ECLIPSE 123 | #include "portmacro.h" 124 | #endif 125 | 126 | #ifdef ROWLEY_LPC23xx 127 | #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" 128 | #endif 129 | 130 | #ifdef IAR_MSP430 131 | #include "..\..\Source\portable\IAR\MSP430\portmacro.h" 132 | #endif 133 | 134 | #ifdef GCC_MSP430 135 | #include "../../Source/portable/GCC/MSP430F449/portmacro.h" 136 | #endif 137 | 138 | #ifdef ROWLEY_MSP430 139 | #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" 140 | #endif 141 | 142 | #ifdef ARM7_LPC21xx_KEIL_RVDS 143 | #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" 144 | #endif 145 | 146 | #ifdef SAM7_GCC 147 | #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" 148 | #endif 149 | 150 | #ifdef SAM7_IAR 151 | #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" 152 | #endif 153 | 154 | #ifdef SAM9XE_IAR 155 | #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" 156 | #endif 157 | 158 | #ifdef LPC2000_IAR 159 | #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" 160 | #endif 161 | 162 | #ifdef STR71X_IAR 163 | #include "..\..\Source\portable\IAR\STR71x\portmacro.h" 164 | #endif 165 | 166 | #ifdef STR75X_IAR 167 | #include "..\..\Source\portable\IAR\STR75x\portmacro.h" 168 | #endif 169 | 170 | #ifdef STR75X_GCC 171 | #include "..\..\Source\portable\GCC\STR75x\portmacro.h" 172 | #endif 173 | 174 | #ifdef STR91X_IAR 175 | #include "..\..\Source\portable\IAR\STR91x\portmacro.h" 176 | #endif 177 | 178 | #ifdef GCC_H8S 179 | #include "../../Source/portable/GCC/H8S2329/portmacro.h" 180 | #endif 181 | 182 | #ifdef GCC_AT91FR40008 183 | #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" 184 | #endif 185 | 186 | #ifdef RVDS_ARMCM3_LM3S102 187 | #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" 188 | #endif 189 | 190 | #ifdef GCC_ARMCM3_LM3S102 191 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 192 | #endif 193 | 194 | #ifdef GCC_ARMCM3 195 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 196 | #endif 197 | 198 | #ifdef IAR_ARM_CM3 199 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 200 | #endif 201 | 202 | #ifdef IAR_ARMCM3_LM 203 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 204 | #endif 205 | 206 | #ifdef HCS12_CODE_WARRIOR 207 | #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" 208 | #endif 209 | 210 | #ifdef MICROBLAZE_GCC 211 | #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" 212 | #endif 213 | 214 | #ifdef TERN_EE 215 | #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" 216 | #endif 217 | 218 | #ifdef GCC_HCS12 219 | #include "../../Source/portable/GCC/HCS12/portmacro.h" 220 | #endif 221 | 222 | #ifdef GCC_MCF5235 223 | #include "../../Source/portable/GCC/MCF5235/portmacro.h" 224 | #endif 225 | 226 | #ifdef COLDFIRE_V2_GCC 227 | #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" 228 | #endif 229 | 230 | #ifdef COLDFIRE_V2_CODEWARRIOR 231 | #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" 232 | #endif 233 | 234 | #ifdef GCC_PPC405 235 | #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" 236 | #endif 237 | 238 | #ifdef GCC_PPC440 239 | #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" 240 | #endif 241 | 242 | #ifdef _16FX_SOFTUNE 243 | #include "..\..\Source\portable\Softune\MB96340\portmacro.h" 244 | #endif 245 | 246 | #ifdef BCC_INDUSTRIAL_PC_PORT 247 | /* A short file name has to be used in place of the normal 248 | FreeRTOSConfig.h when using the Borland compiler. */ 249 | #include "frconfig.h" 250 | #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" 251 | typedef void ( __interrupt __far *pxISR )(); 252 | #endif 253 | 254 | #ifdef BCC_FLASH_LITE_186_PORT 255 | /* A short file name has to be used in place of the normal 256 | FreeRTOSConfig.h when using the Borland compiler. */ 257 | #include "frconfig.h" 258 | #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" 259 | typedef void ( __interrupt __far *pxISR )(); 260 | #endif 261 | 262 | #ifdef __GNUC__ 263 | #ifdef __AVR32_AVR32A__ 264 | #include "portmacro.h" 265 | #endif 266 | #endif 267 | 268 | #ifdef __ICCAVR32__ 269 | #ifdef __CORE__ 270 | #if __CORE__ == __AVR32A__ 271 | #include "portmacro.h" 272 | #endif 273 | #endif 274 | #endif 275 | 276 | #ifdef __91467D 277 | #include "portmacro.h" 278 | #endif 279 | 280 | #ifdef __96340 281 | #include "portmacro.h" 282 | #endif 283 | 284 | 285 | #ifdef __IAR_V850ES_Fx3__ 286 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 287 | #endif 288 | 289 | #ifdef __IAR_V850ES_Jx3__ 290 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 291 | #endif 292 | 293 | #ifdef __IAR_V850ES_Jx3_L__ 294 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 295 | #endif 296 | 297 | #ifdef __IAR_V850ES_Jx2__ 298 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 299 | #endif 300 | 301 | #ifdef __IAR_V850ES_Hx2__ 302 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 303 | #endif 304 | 305 | #ifdef __IAR_78K0R_Kx3__ 306 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 307 | #endif 308 | 309 | #ifdef __IAR_78K0R_Kx3L__ 310 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 311 | #endif 312 | 313 | /* Catch all to ensure portmacro.h is included in the build. Newer demos 314 | have the path as part of the project options, rather than as relative from 315 | the project location. If portENTER_CRITICAL() has not been defined then 316 | portmacro.h has not yet been included - as every portmacro.h provides a 317 | portENTER_CRITICAL() definition. Check the demo application for your demo 318 | to find the path to the correct portmacro.h file. */ 319 | #ifndef portENTER_CRITICAL 320 | #include "portmacro.h" 321 | #endif 322 | 323 | #if portBYTE_ALIGNMENT == 8 324 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 325 | #endif 326 | 327 | #if portBYTE_ALIGNMENT == 4 328 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 329 | #endif 330 | 331 | #if portBYTE_ALIGNMENT == 2 332 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 333 | #endif 334 | 335 | #if portBYTE_ALIGNMENT == 1 336 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 337 | #endif 338 | 339 | #ifndef portBYTE_ALIGNMENT_MASK 340 | #error "Invalid portBYTE_ALIGNMENT definition" 341 | #endif 342 | 343 | #ifndef portNUM_CONFIGURABLE_REGIONS 344 | #define portNUM_CONFIGURABLE_REGIONS 1 345 | #endif 346 | 347 | #ifdef __cplusplus 348 | extern "C" { 349 | #endif 350 | 351 | #include "mpu_wrappers.h" 352 | 353 | /* 354 | * Setup the stack of a new task so it is ready to be placed under the 355 | * scheduler control. The registers have to be placed on the stack in 356 | * the order that the port expects to find them. 357 | * 358 | */ 359 | #if( portUSING_MPU_WRAPPERS == 1 ) 360 | portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters, portBASE_TYPE xRunPrivileged ) PRIVILEGED_FUNCTION; 361 | #else 362 | portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ); 363 | #endif 364 | 365 | /* 366 | * Map to the memory management routines required for the port. 367 | */ 368 | void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; 369 | void vPortFree( void *pv ) PRIVILEGED_FUNCTION; 370 | void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; 371 | size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; 372 | 373 | /* 374 | * Setup the hardware ready for the scheduler to take control. This generally 375 | * sets up a tick interrupt and sets timers for the correct tick frequency. 376 | */ 377 | portBASE_TYPE xPortStartScheduler( void ) PRIVILEGED_FUNCTION; 378 | 379 | /* 380 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 381 | * the hardware is left in its original condition after the scheduler stops 382 | * executing. 383 | */ 384 | void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; 385 | 386 | /* 387 | * The structures and methods of manipulating the MPU are contained within the 388 | * port layer. 389 | * 390 | * Fills the xMPUSettings structure with the memory region information 391 | * contained in xRegions. 392 | */ 393 | #if( portUSING_MPU_WRAPPERS == 1 ) 394 | struct xMEMORY_REGION; 395 | void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, portSTACK_TYPE *pxBottomOfStack, unsigned short usStackDepth ) PRIVILEGED_FUNCTION; 396 | #endif 397 | 398 | #ifdef __cplusplus 399 | } 400 | #endif 401 | 402 | #endif /* PORTABLE_H */ 403 | 404 | -------------------------------------------------------------------------------- /FreeRTOS/Source/portable/MemMang/heap_4.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | /* 68 | * A sample implementation of pvPortMalloc() and vPortFree() that combines 69 | * (coalescences) adjacent memory blocks as they are freed, and in so doing 70 | * limits memory fragmentation. 71 | * 72 | * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the 73 | * memory management pages of http://www.FreeRTOS.org for more information. 74 | */ 75 | #include 76 | 77 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 78 | all the API functions to use the MPU wrappers. That should only be done when 79 | task.h is included from an application file. */ 80 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 81 | 82 | #include "FreeRTOS.h" 83 | #include "task.h" 84 | 85 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 86 | 87 | /* Block sizes must not get too small. */ 88 | #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) 89 | 90 | /* Allocate the memory for the heap. The struct is used to force byte 91 | alignment without using any non-portable code. */ 92 | static union xRTOS_HEAP 93 | { 94 | #if portBYTE_ALIGNMENT == 8 95 | volatile portDOUBLE dDummy; 96 | #else 97 | volatile unsigned long ulDummy; 98 | #endif 99 | unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; 100 | } xHeap; 101 | 102 | /* Define the linked list structure. This is used to link free blocks in order 103 | of their memory address. */ 104 | typedef struct A_BLOCK_LINK 105 | { 106 | struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ 107 | size_t xBlockSize; /*<< The size of the free block. */ 108 | } xBlockLink; 109 | 110 | /*-----------------------------------------------------------*/ 111 | 112 | /* 113 | * Inserts a block of memory that is being freed into the correct position in 114 | * the list of free memory blocks. The block being freed will be merged with 115 | * the block in front it and/or the block behind it if the memory blocks are 116 | * adjacent to each other. 117 | */ 118 | static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ); 119 | 120 | /* 121 | * Called automatically to setup the required heap structures the first time 122 | * pvPortMalloc() is called. 123 | */ 124 | static void prvHeapInit( void ); 125 | 126 | /*-----------------------------------------------------------*/ 127 | 128 | /* The size of the structure placed at the beginning of each allocated memory 129 | block must by correctly byte aligned. */ 130 | static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); 131 | 132 | /* Ensure the pxEnd pointer will end up on the correct byte alignment. */ 133 | static const size_t xTotalHeapSize = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); 134 | 135 | /* Create a couple of list links to mark the start and end of the list. */ 136 | static xBlockLink xStart, *pxEnd = NULL; 137 | 138 | /* Keeps track of the number of free bytes remaining, but says nothing about 139 | fragmentation. */ 140 | static size_t xFreeBytesRemaining = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); 141 | 142 | /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ 143 | 144 | /*-----------------------------------------------------------*/ 145 | size_t allocated = 0; 146 | void *pvPortMalloc( size_t xWantedSize ) 147 | { 148 | xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; 149 | void *pvReturn = NULL; 150 | 151 | vTaskSuspendAll(); 152 | { 153 | /* If this is the first call to malloc then the heap will require 154 | initialisation to setup the list of free blocks. */ 155 | if( pxEnd == NULL ) 156 | { 157 | prvHeapInit(); 158 | } 159 | 160 | /* The wanted size is increased so it can contain a xBlockLink 161 | structure in addition to the requested amount of bytes. */ 162 | if( xWantedSize > 0 ) 163 | { 164 | xWantedSize += heapSTRUCT_SIZE; 165 | 166 | /* Ensure that blocks are always aligned to the required number of 167 | bytes. */ 168 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 169 | { 170 | /* Byte alignment required. */ 171 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 172 | } 173 | } 174 | 175 | if( ( xWantedSize > 0 ) && ( xWantedSize < xTotalHeapSize ) ) 176 | { 177 | /* Traverse the list from the start (lowest address) block until one 178 | of adequate size is found. */ 179 | pxPreviousBlock = &xStart; 180 | pxBlock = xStart.pxNextFreeBlock; 181 | while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) 182 | { 183 | pxPreviousBlock = pxBlock; 184 | pxBlock = pxBlock->pxNextFreeBlock; 185 | } 186 | 187 | /* If the end marker was reached then a block of adequate size was 188 | not found. */ 189 | if( pxBlock != pxEnd ) 190 | { 191 | /* Return the memory space - jumping over the xBlockLink structure 192 | at its start. */ 193 | pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); 194 | 195 | /* This block is being returned for use so must be taken out of 196 | the list of free blocks. */ 197 | pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; 198 | 199 | /* If the block is larger than required it can be split into two. */ 200 | if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) 201 | { 202 | /* This block is to be split into two. Create a new block 203 | following the number of bytes requested. The void cast is 204 | used to prevent byte alignment warnings from the compiler. */ 205 | pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); 206 | 207 | /* Calculate the sizes of two blocks split from the single 208 | block. */ 209 | pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; 210 | pxBlock->xBlockSize = xWantedSize; 211 | 212 | /* Insert the new block into the list of free blocks. */ 213 | prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); 214 | } 215 | 216 | xFreeBytesRemaining -= pxBlock->xBlockSize; 217 | } 218 | } 219 | } 220 | xTaskResumeAll(); 221 | 222 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 223 | { 224 | if( pvReturn == NULL ) 225 | { 226 | extern void vApplicationMallocFailedHook( void ); 227 | vApplicationMallocFailedHook(); 228 | } 229 | } 230 | #endif 231 | 232 | allocated += xWantedSize; 233 | 234 | return pvReturn; 235 | } 236 | /*-----------------------------------------------------------*/ 237 | 238 | void vPortFree( void *pv ) 239 | { 240 | unsigned char *puc = ( unsigned char * ) pv; 241 | xBlockLink *pxLink; 242 | 243 | if( pv != NULL ) 244 | { 245 | /* The memory being freed will have an xBlockLink structure immediately 246 | before it. */ 247 | puc -= heapSTRUCT_SIZE; 248 | 249 | /* This casting is to keep the compiler from issuing warnings. */ 250 | pxLink = ( void * ) puc; 251 | 252 | vTaskSuspendAll(); 253 | { 254 | /* Add this block to the list of free blocks. */ 255 | xFreeBytesRemaining += pxLink->xBlockSize; 256 | prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); 257 | } 258 | xTaskResumeAll(); 259 | } 260 | } 261 | /*-----------------------------------------------------------*/ 262 | 263 | size_t xPortGetFreeHeapSize( void ) 264 | { 265 | return xFreeBytesRemaining; 266 | } 267 | /*-----------------------------------------------------------*/ 268 | 269 | void vPortInitialiseBlocks( void ) 270 | { 271 | /* This just exists to keep the linker quiet. */ 272 | } 273 | /*-----------------------------------------------------------*/ 274 | 275 | static void prvHeapInit( void ) 276 | { 277 | xBlockLink *pxFirstFreeBlock; 278 | unsigned char *pucHeapEnd; 279 | 280 | /* Ensure the start of the heap is aligned. */ 281 | configASSERT( ( ( ( unsigned long ) xHeap.ucHeap ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); 282 | 283 | /* xStart is used to hold a pointer to the first item in the list of free 284 | blocks. The void cast is used to prevent compiler warnings. */ 285 | xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; 286 | xStart.xBlockSize = ( size_t ) 0; 287 | 288 | /* pxEnd is used to mark the end of the list of free blocks and is inserted 289 | at the end of the heap space. */ 290 | pucHeapEnd = xHeap.ucHeap + xTotalHeapSize; 291 | pucHeapEnd -= heapSTRUCT_SIZE; 292 | pxEnd = ( void * ) pucHeapEnd; 293 | configASSERT( ( ( ( unsigned long ) pxEnd ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); 294 | pxEnd->xBlockSize = 0; 295 | pxEnd->pxNextFreeBlock = NULL; 296 | 297 | /* To start with there is a single free block that is sized to take up the 298 | entire heap space, minus the space taken by pxEnd. */ 299 | pxFirstFreeBlock = ( void * ) xHeap.ucHeap; 300 | pxFirstFreeBlock->xBlockSize = xTotalHeapSize - heapSTRUCT_SIZE; 301 | pxFirstFreeBlock->pxNextFreeBlock = pxEnd; 302 | 303 | /* The heap now contains pxEnd. */ 304 | xFreeBytesRemaining -= heapSTRUCT_SIZE; 305 | } 306 | /*-----------------------------------------------------------*/ 307 | 308 | static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) 309 | { 310 | xBlockLink *pxIterator; 311 | unsigned char *puc; 312 | 313 | /* Iterate through the list until a block is found that has a higher address 314 | than the block being inserted. */ 315 | for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) 316 | { 317 | /* Nothing to do here, just iterate to the right position. */ 318 | } 319 | 320 | /* Do the block being inserted, and the block it is being inserted after 321 | make a contiguous block of memory? */ 322 | puc = ( unsigned char * ) pxIterator; 323 | if( ( puc + pxIterator->xBlockSize ) == ( unsigned char * ) pxBlockToInsert ) 324 | { 325 | pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; 326 | pxBlockToInsert = pxIterator; 327 | } 328 | 329 | /* Do the block being inserted, and the block it is being inserted before 330 | make a contiguous block of memory? */ 331 | puc = ( unsigned char * ) pxBlockToInsert; 332 | if( ( puc + pxBlockToInsert->xBlockSize ) == ( unsigned char * ) pxIterator->pxNextFreeBlock ) 333 | { 334 | if( pxIterator->pxNextFreeBlock != pxEnd ) 335 | { 336 | /* Form one big block from the two blocks. */ 337 | pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; 338 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; 339 | } 340 | else 341 | { 342 | pxBlockToInsert->pxNextFreeBlock = pxEnd; 343 | } 344 | } 345 | else 346 | { 347 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; 348 | } 349 | 350 | /* If the block being inserted plugged a gab, so was merged with the block 351 | before and the block after, then it's pxNextFreeBlock pointer will have 352 | already been set, and should not be set here as that would make it point 353 | to itself. */ 354 | if( pxIterator != pxBlockToInsert ) 355 | { 356 | pxIterator->pxNextFreeBlock = pxBlockToInsert; 357 | } 358 | } 359 | 360 | -------------------------------------------------------------------------------- /FreeRTOS/Source/include/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | /* 68 | * This is the list implementation used by the scheduler. While it is tailored 69 | * heavily for the schedulers needs, it is also available for use by 70 | * application code. 71 | * 72 | * xLists can only store pointers to xListItems. Each xListItem contains a 73 | * numeric value (xItemValue). Most of the time the lists are sorted in 74 | * descending item value order. 75 | * 76 | * Lists are created already containing one list item. The value of this 77 | * item is the maximum possible that can be stored, it is therefore always at 78 | * the end of the list and acts as a marker. The list member pxHead always 79 | * points to this marker - even though it is at the tail of the list. This 80 | * is because the tail contains a wrap back pointer to the true head of 81 | * the list. 82 | * 83 | * In addition to it's value, each list item contains a pointer to the next 84 | * item in the list (pxNext), a pointer to the list it is in (pxContainer) 85 | * and a pointer to back to the object that contains it. These later two 86 | * pointers are included for efficiency of list manipulation. There is 87 | * effectively a two way link between the object containing the list item and 88 | * the list item itself. 89 | * 90 | * 91 | * \page ListIntroduction List Implementation 92 | * \ingroup FreeRTOSIntro 93 | */ 94 | 95 | 96 | #ifndef LIST_H 97 | #define LIST_H 98 | 99 | #ifdef __cplusplus 100 | extern "C" { 101 | #endif 102 | /* 103 | * Definition of the only type of object that a list can contain. 104 | */ 105 | struct xLIST_ITEM 106 | { 107 | portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ 108 | volatile struct xLIST_ITEM * pxNext; /*< Pointer to the next xListItem in the list. */ 109 | volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */ 110 | void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */ 111 | void * pvContainer; /*< Pointer to the list in which this list item is placed (if any). */ 112 | }; 113 | typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */ 114 | 115 | struct xMINI_LIST_ITEM 116 | { 117 | portTickType xItemValue; 118 | volatile struct xLIST_ITEM *pxNext; 119 | volatile struct xLIST_ITEM *pxPrevious; 120 | }; 121 | typedef struct xMINI_LIST_ITEM xMiniListItem; 122 | 123 | /* 124 | * Definition of the type of queue used by the scheduler. 125 | */ 126 | typedef struct xLIST 127 | { 128 | volatile unsigned portBASE_TYPE uxNumberOfItems; 129 | volatile xListItem * pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */ 130 | volatile xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */ 131 | } xList; 132 | 133 | /* 134 | * Access macro to set the owner of a list item. The owner of a list item 135 | * is the object (usually a TCB) that contains the list item. 136 | * 137 | * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER 138 | * \ingroup LinkedList 139 | */ 140 | #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) 141 | 142 | /* 143 | * Access macro to get the owner of a list item. The owner of a list item 144 | * is the object (usually a TCB) that contains the list item. 145 | * 146 | * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER 147 | * \ingroup LinkedList 148 | */ 149 | #define listGET_LIST_ITEM_OWNER( pxListItem ) ( pxListItem )->pvOwner 150 | 151 | /* 152 | * Access macro to set the value of the list item. In most cases the value is 153 | * used to sort the list in descending order. 154 | * 155 | * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE 156 | * \ingroup LinkedList 157 | */ 158 | #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = ( xValue ) 159 | 160 | /* 161 | * Access macro to retrieve the value of the list item. The value can 162 | * represent anything - for example a the priority of a task, or the time at 163 | * which a task should be unblocked. 164 | * 165 | * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE 166 | * \ingroup LinkedList 167 | */ 168 | #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) 169 | 170 | /* 171 | * Access macro the retrieve the value of the list item at the head of a given 172 | * list. 173 | * 174 | * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE 175 | * \ingroup LinkedList 176 | */ 177 | #define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->xItemValue ) 178 | 179 | /* 180 | * Access macro to determine if a list contains any items. The macro will 181 | * only have the value true if the list is empty. 182 | * 183 | * \page listLIST_IS_EMPTY listLIST_IS_EMPTY 184 | * \ingroup LinkedList 185 | */ 186 | #define listLIST_IS_EMPTY( pxList ) ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 ) 187 | 188 | /* 189 | * Access macro to return the number of items in the list. 190 | */ 191 | #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) 192 | 193 | /* 194 | * Access function to obtain the owner of the next entry in a list. 195 | * 196 | * The list member pxIndex is used to walk through a list. Calling 197 | * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list 198 | * and returns that entries pxOwner parameter. Using multiple calls to this 199 | * function it is therefore possible to move through every item contained in 200 | * a list. 201 | * 202 | * The pxOwner parameter of a list item is a pointer to the object that owns 203 | * the list item. In the scheduler this is normally a task control block. 204 | * The pxOwner parameter effectively creates a two way link between the list 205 | * item and its owner. 206 | * 207 | * @param pxList The list from which the next item owner is to be returned. 208 | * 209 | * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY 210 | * \ingroup LinkedList 211 | */ 212 | #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ 213 | { \ 214 | xList * const pxConstList = ( pxList ); \ 215 | /* Increment the index to the next item and return the item, ensuring */ \ 216 | /* we don't return the marker used at the end of the list. */ \ 217 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 218 | if( ( pxConstList )->pxIndex == ( xListItem * ) &( ( pxConstList )->xListEnd ) ) \ 219 | { \ 220 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 221 | } \ 222 | ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \ 223 | } 224 | 225 | 226 | /* 227 | * Access function to obtain the owner of the first entry in a list. Lists 228 | * are normally sorted in ascending item value order. 229 | * 230 | * This function returns the pxOwner member of the first item in the list. 231 | * The pxOwner parameter of a list item is a pointer to the object that owns 232 | * the list item. In the scheduler this is normally a task control block. 233 | * The pxOwner parameter effectively creates a two way link between the list 234 | * item and its owner. 235 | * 236 | * @param pxList The list from which the owner of the head item is to be 237 | * returned. 238 | * 239 | * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY 240 | * \ingroup LinkedList 241 | */ 242 | #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner ) 243 | 244 | /* 245 | * Check to see if a list item is within a list. The list item maintains a 246 | * "container" pointer that points to the list it is in. All this macro does 247 | * is check to see if the container and the list match. 248 | * 249 | * @param pxList The list we want to know if the list item is within. 250 | * @param pxListItem The list item we want to know if is in the list. 251 | * @return pdTRUE is the list item is in the list, otherwise pdFALSE. 252 | * pointer against 253 | */ 254 | #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) 255 | 256 | /* 257 | * This provides a crude means of knowing if a list has been initialised, as 258 | * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() 259 | * function. 260 | */ 261 | #define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) 262 | 263 | /* 264 | * Must be called before a list is used! This initialises all the members 265 | * of the list structure and inserts the xListEnd item into the list as a 266 | * marker to the back of the list. 267 | * 268 | * @param pxList Pointer to the list being initialised. 269 | * 270 | * \page vListInitialise vListInitialise 271 | * \ingroup LinkedList 272 | */ 273 | void vListInitialise( xList *pxList ); 274 | 275 | /* 276 | * Must be called before a list item is used. This sets the list container to 277 | * null so the item does not think that it is already contained in a list. 278 | * 279 | * @param pxItem Pointer to the list item being initialised. 280 | * 281 | * \page vListInitialiseItem vListInitialiseItem 282 | * \ingroup LinkedList 283 | */ 284 | void vListInitialiseItem( xListItem *pxItem ); 285 | 286 | /* 287 | * Insert a list item into a list. The item will be inserted into the list in 288 | * a position determined by its item value (descending item value order). 289 | * 290 | * @param pxList The list into which the item is to be inserted. 291 | * 292 | * @param pxNewListItem The item to that is to be placed in the list. 293 | * 294 | * \page vListInsert vListInsert 295 | * \ingroup LinkedList 296 | */ 297 | void vListInsert( xList *pxList, xListItem *pxNewListItem ); 298 | 299 | /* 300 | * Insert a list item into a list. The item will be inserted in a position 301 | * such that it will be the last item within the list returned by multiple 302 | * calls to listGET_OWNER_OF_NEXT_ENTRY. 303 | * 304 | * The list member pvIndex is used to walk through a list. Calling 305 | * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list. 306 | * Placing an item in a list using vListInsertEnd effectively places the item 307 | * in the list position pointed to by pvIndex. This means that every other 308 | * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before 309 | * the pvIndex parameter again points to the item being inserted. 310 | * 311 | * @param pxList The list into which the item is to be inserted. 312 | * 313 | * @param pxNewListItem The list item to be inserted into the list. 314 | * 315 | * \page vListInsertEnd vListInsertEnd 316 | * \ingroup LinkedList 317 | */ 318 | void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ); 319 | 320 | /* 321 | * Remove an item from a list. The list item has a pointer to the list that 322 | * it is in, so only the list item need be passed into the function. 323 | * 324 | * @param vListRemove The item to be removed. The item will remove itself from 325 | * the list pointed to by it's pxContainer parameter. 326 | * 327 | * \page vListRemove vListRemove 328 | * \ingroup LinkedList 329 | */ 330 | void vListRemove( xListItem *pxItemToRemove ); 331 | 332 | #ifdef __cplusplus 333 | } 334 | #endif 335 | 336 | #endif 337 | 338 | -------------------------------------------------------------------------------- /FreeRTOS/Source/croutine.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd. 3 | 4 | 5 | *************************************************************************** 6 | * * 7 | * FreeRTOS tutorial books are available in pdf and paperback. * 8 | * Complete, revised, and edited pdf reference manuals are also * 9 | * available. * 10 | * * 11 | * Purchasing FreeRTOS documentation will not only help you, by * 12 | * ensuring you get running as quickly as possible and with an * 13 | * in-depth knowledge of how to use FreeRTOS, it will also help * 14 | * the FreeRTOS project to continue with its mission of providing * 15 | * professional grade, cross platform, de facto standard solutions * 16 | * for microcontrollers - completely free of charge! * 17 | * * 18 | * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * 19 | * * 20 | * Thank you for using FreeRTOS, and thank you for your support! * 21 | * * 22 | *************************************************************************** 23 | 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | >>>NOTE<<< The modification to the GPL is included to allow you to 31 | distribute a combined work that includes FreeRTOS without being obliged to 32 | provide the source code for proprietary components outside of the FreeRTOS 33 | kernel. FreeRTOS is distributed in the hope that it will be useful, but 34 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 35 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | *************************************************************************** 45 | * * 46 | * Having a problem? Start by reading the FAQ "My application does * 47 | * not run, what could be wrong? * 48 | * * 49 | * http://www.FreeRTOS.org/FAQHelp.html * 50 | * * 51 | *************************************************************************** 52 | 53 | 54 | http://www.FreeRTOS.org - Documentation, training, latest information, 55 | license and contact details. 56 | 57 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 58 | including FreeRTOS+Trace - an indispensable productivity tool. 59 | 60 | Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell 61 | the code with commercial support, indemnification, and middleware, under 62 | the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also 63 | provide a safety engineered and independently SIL3 certified version under 64 | the SafeRTOS brand: http://www.SafeRTOS.com. 65 | */ 66 | 67 | #include "FreeRTOS.h" 68 | #include "task.h" 69 | #include "croutine.h" 70 | 71 | /* 72 | * Some kernel aware debuggers require data to be viewed to be global, rather 73 | * than file scope. 74 | */ 75 | #ifdef portREMOVE_STATIC_QUALIFIER 76 | #define static 77 | #endif 78 | 79 | 80 | /* Lists for ready and blocked co-routines. --------------------*/ 81 | static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ 82 | static xList xDelayedCoRoutineList1; /*< Delayed co-routines. */ 83 | static xList xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ 84 | static xList * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ 85 | static xList * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ 86 | static xList xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ 87 | 88 | /* Other file private variables. --------------------------------*/ 89 | corCRCB * pxCurrentCoRoutine = NULL; 90 | static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0; 91 | static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; 92 | 93 | /* The initial state of the co-routine when it is created. */ 94 | #define corINITIAL_STATE ( 0 ) 95 | 96 | /* 97 | * Place the co-routine represented by pxCRCB into the appropriate ready queue 98 | * for the priority. It is inserted at the end of the list. 99 | * 100 | * This macro accesses the co-routine ready lists and therefore must not be 101 | * used from within an ISR. 102 | */ 103 | #define prvAddCoRoutineToReadyQueue( pxCRCB ) \ 104 | { \ 105 | if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ 106 | { \ 107 | uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ 108 | } \ 109 | vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ 110 | } 111 | 112 | /* 113 | * Utility to ready all the lists used by the scheduler. This is called 114 | * automatically upon the creation of the first co-routine. 115 | */ 116 | static void prvInitialiseCoRoutineLists( void ); 117 | 118 | /* 119 | * Co-routines that are readied by an interrupt cannot be placed directly into 120 | * the ready lists (there is no mutual exclusion). Instead they are placed in 121 | * in the pending ready list in order that they can later be moved to the ready 122 | * list by the co-routine scheduler. 123 | */ 124 | static void prvCheckPendingReadyList( void ); 125 | 126 | /* 127 | * Macro that looks at the list of co-routines that are currently delayed to 128 | * see if any require waking. 129 | * 130 | * Co-routines are stored in the queue in the order of their wake time - 131 | * meaning once one co-routine has been found whose timer has not expired 132 | * we need not look any further down the list. 133 | */ 134 | static void prvCheckDelayedList( void ); 135 | 136 | /*-----------------------------------------------------------*/ 137 | 138 | signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ) 139 | { 140 | signed portBASE_TYPE xReturn; 141 | corCRCB *pxCoRoutine; 142 | 143 | /* Allocate the memory that will store the co-routine control block. */ 144 | pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) ); 145 | if( pxCoRoutine ) 146 | { 147 | /* If pxCurrentCoRoutine is NULL then this is the first co-routine to 148 | be created and the co-routine data structures need initialising. */ 149 | if( pxCurrentCoRoutine == NULL ) 150 | { 151 | pxCurrentCoRoutine = pxCoRoutine; 152 | prvInitialiseCoRoutineLists(); 153 | } 154 | 155 | /* Check the priority is within limits. */ 156 | if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) 157 | { 158 | uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; 159 | } 160 | 161 | /* Fill out the co-routine control block from the function parameters. */ 162 | pxCoRoutine->uxState = corINITIAL_STATE; 163 | pxCoRoutine->uxPriority = uxPriority; 164 | pxCoRoutine->uxIndex = uxIndex; 165 | pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; 166 | 167 | /* Initialise all the other co-routine control block parameters. */ 168 | vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); 169 | vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); 170 | 171 | /* Set the co-routine control block as a link back from the xListItem. 172 | This is so we can get back to the containing CRCB from a generic item 173 | in a list. */ 174 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); 175 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); 176 | 177 | /* Event lists are always in priority order. */ 178 | listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority ); 179 | 180 | /* Now the co-routine has been initialised it can be added to the ready 181 | list at the correct priority. */ 182 | prvAddCoRoutineToReadyQueue( pxCoRoutine ); 183 | 184 | xReturn = pdPASS; 185 | } 186 | else 187 | { 188 | xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; 189 | } 190 | 191 | return xReturn; 192 | } 193 | /*-----------------------------------------------------------*/ 194 | 195 | void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList ) 196 | { 197 | portTickType xTimeToWake; 198 | 199 | /* Calculate the time to wake - this may overflow but this is 200 | not a problem. */ 201 | xTimeToWake = xCoRoutineTickCount + xTicksToDelay; 202 | 203 | /* We must remove ourselves from the ready list before adding 204 | ourselves to the blocked list as the same list item is used for 205 | both lists. */ 206 | vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 207 | 208 | /* The list item will be inserted in wake time order. */ 209 | listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); 210 | 211 | if( xTimeToWake < xCoRoutineTickCount ) 212 | { 213 | /* Wake time has overflowed. Place this item in the 214 | overflow list. */ 215 | vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 216 | } 217 | else 218 | { 219 | /* The wake time has not overflowed, so we can use the 220 | current block list. */ 221 | vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 222 | } 223 | 224 | if( pxEventList ) 225 | { 226 | /* Also add the co-routine to an event list. If this is done then the 227 | function must be called with interrupts disabled. */ 228 | vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); 229 | } 230 | } 231 | /*-----------------------------------------------------------*/ 232 | 233 | static void prvCheckPendingReadyList( void ) 234 | { 235 | /* Are there any co-routines waiting to get moved to the ready list? These 236 | are co-routines that have been readied by an ISR. The ISR cannot access 237 | the ready lists itself. */ 238 | while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) 239 | { 240 | corCRCB *pxUnblockedCRCB; 241 | 242 | /* The pending ready list can be accessed by an ISR. */ 243 | portDISABLE_INTERRUPTS(); 244 | { 245 | pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); 246 | vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 247 | } 248 | portENABLE_INTERRUPTS(); 249 | 250 | vListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); 251 | prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); 252 | } 253 | } 254 | /*-----------------------------------------------------------*/ 255 | 256 | static void prvCheckDelayedList( void ) 257 | { 258 | corCRCB *pxCRCB; 259 | 260 | xPassedTicks = xTaskGetTickCount() - xLastTickCount; 261 | while( xPassedTicks ) 262 | { 263 | xCoRoutineTickCount++; 264 | xPassedTicks--; 265 | 266 | /* If the tick count has overflowed we need to swap the ready lists. */ 267 | if( xCoRoutineTickCount == 0 ) 268 | { 269 | xList * pxTemp; 270 | 271 | /* Tick count has overflowed so we need to swap the delay lists. If there are 272 | any items in pxDelayedCoRoutineList here then there is an error! */ 273 | pxTemp = pxDelayedCoRoutineList; 274 | pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; 275 | pxOverflowDelayedCoRoutineList = pxTemp; 276 | } 277 | 278 | /* See if this tick has made a timeout expire. */ 279 | while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) 280 | { 281 | pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); 282 | 283 | if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) 284 | { 285 | /* Timeout not yet expired. */ 286 | break; 287 | } 288 | 289 | portDISABLE_INTERRUPTS(); 290 | { 291 | /* The event could have occurred just before this critical 292 | section. If this is the case then the generic list item will 293 | have been moved to the pending ready list and the following 294 | line is still valid. Also the pvContainer parameter will have 295 | been set to NULL so the following lines are also valid. */ 296 | vListRemove( &( pxCRCB->xGenericListItem ) ); 297 | 298 | /* Is the co-routine waiting on an event also? */ 299 | if( pxCRCB->xEventListItem.pvContainer ) 300 | { 301 | vListRemove( &( pxCRCB->xEventListItem ) ); 302 | } 303 | } 304 | portENABLE_INTERRUPTS(); 305 | 306 | prvAddCoRoutineToReadyQueue( pxCRCB ); 307 | } 308 | } 309 | 310 | xLastTickCount = xCoRoutineTickCount; 311 | } 312 | /*-----------------------------------------------------------*/ 313 | 314 | void vCoRoutineSchedule( void ) 315 | { 316 | /* See if any co-routines readied by events need moving to the ready lists. */ 317 | prvCheckPendingReadyList(); 318 | 319 | /* See if any delayed co-routines have timed out. */ 320 | prvCheckDelayedList(); 321 | 322 | /* Find the highest priority queue that contains ready co-routines. */ 323 | while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) 324 | { 325 | if( uxTopCoRoutineReadyPriority == 0 ) 326 | { 327 | /* No more co-routines to check. */ 328 | return; 329 | } 330 | --uxTopCoRoutineReadyPriority; 331 | } 332 | 333 | /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines 334 | of the same priority get an equal share of the processor time. */ 335 | listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); 336 | 337 | /* Call the co-routine. */ 338 | ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); 339 | 340 | return; 341 | } 342 | /*-----------------------------------------------------------*/ 343 | 344 | static void prvInitialiseCoRoutineLists( void ) 345 | { 346 | unsigned portBASE_TYPE uxPriority; 347 | 348 | for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) 349 | { 350 | vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); 351 | } 352 | 353 | vListInitialise( ( xList * ) &xDelayedCoRoutineList1 ); 354 | vListInitialise( ( xList * ) &xDelayedCoRoutineList2 ); 355 | vListInitialise( ( xList * ) &xPendingReadyCoRoutineList ); 356 | 357 | /* Start with pxDelayedCoRoutineList using list1 and the 358 | pxOverflowDelayedCoRoutineList using list2. */ 359 | pxDelayedCoRoutineList = &xDelayedCoRoutineList1; 360 | pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; 361 | } 362 | /*-----------------------------------------------------------*/ 363 | 364 | signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ) 365 | { 366 | corCRCB *pxUnblockedCRCB; 367 | signed portBASE_TYPE xReturn; 368 | 369 | /* This function is called from within an interrupt. It can only access 370 | event lists and the pending ready list. This function assumes that a 371 | check has already been made to ensure pxEventList is not empty. */ 372 | pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); 373 | vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 374 | vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); 375 | 376 | if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) 377 | { 378 | xReturn = pdTRUE; 379 | } 380 | else 381 | { 382 | xReturn = pdFALSE; 383 | } 384 | 385 | return xReturn; 386 | } 387 | 388 | --------------------------------------------------------------------------------