diff --git a/Hello_World_FreeRTOS/.cproject b/Hello_World_FreeRTOS/.cproject new file mode 100644 index 0000000000000000000000000000000000000000..b8312be2fc33854528253ad89f2e3137d25fa173 --- /dev/null +++ b/Hello_World_FreeRTOS/.cproject @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962" moduleId="org.eclipse.cdt.core.settings" name="Debug"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962" name="Debug" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug"> + <folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962." name="/" resourcePath=""> + <toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.548125692" name="Cross ARM GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1448195934" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.none" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength.989348626" name="Message length (-fmessage-length=0)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar.573934961" name="'char' is signed (-fsigned-char)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections.1195068176" name="Function sections (-ffunction-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.datasections.1035348629" name="Data sections (-fdata-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.datasections" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level.31679983" name="Debug level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level" value="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level.max" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.1676901946" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.1729767352" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" value="GNU Tools for ARM Embedded Processors" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1708484008" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.178519983" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m3" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.956545422" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.1580514969" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" value="arm-none-eabi-" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1246670973" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" value="gcc" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.cpp.1674926322" name="C++ compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.cpp" value="g++" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.ar.2051566192" name="Archiver" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.ar" value="ar" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.objcopy.408066731" name="Hex/Bin converter" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.objcopy" value="objcopy" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.objdump.1900584936" name="Listing generator" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.objdump" value="objdump" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.size.1096852527" name="Size command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.size" value="size" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.make.937347953" name="Build command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.make" value="make" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.rm.1468247042" name="Remove command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.rm" value="rm" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash.1529750846" name="Create flash image" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize.667765305" name="Print size" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize" value="true" valueType="boolean"/> + <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.786533016" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/> + <builder arguments="ECLIPSE=1" buildPath="${workspace_loc:/FreeRTOSDemo}" command="make" id="ilg.gnuarmeclipse.managedbuild.cross.builder.592880777" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.1648672385" name="Cross ARM GNU Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.1969112665" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" value="true" valueType="boolean"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input.507854261" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.1576427906" name="Cross ARM C Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.1576427906" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath"> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/CMSIS/Device/Maxim/MAX32665/Include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/MAX32665PeriphDriver/Include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/Boards/EvKit_V1/Include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/Boards/Include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/CMSIS/Include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Toolchain/arm-none-eabi/include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Toolchain/arm-none-eabi/include/sys""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Toolchain/lib/gcc/arm-none-eabi/6.3.1/include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/FreeRTOS/Source/include""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/FreeRTOS/Source/portable/GCC/ARM_CM4F""/> + <listOptionValue builtIn="false" value=""${MAXIM_PATH}/Firmware/MAX32665/Libraries/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI""/> + <listOptionValue builtIn="false" value="".././""/> + </option> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.68945223" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.794996645" name="Cross ARM C++ Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler"/> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.675776866" name="Cross ARM C Linker" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.gcsections.185399645" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.gcsections" value="true" valueType="boolean"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input.246156916" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker.391142733" name="Cross ARM C++ Linker" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.gcsections.2099090970" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.gcsections" value="true" valueType="boolean"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.archiver.399743328" name="Cross ARM GNU Archiver" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.archiver"/> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.createflash.822983655" name="Cross ARM GNU Create Flash Image" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.createflash"/> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.createlisting.1050446219" name="Cross ARM GNU Create Listing" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.createlisting"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.source.335976671" name="Display source (--source|-S)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.source" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.allheaders.964898349" name="Display all headers (--all-headers|-x)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.allheaders" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.demangle.972868647" name="Demangle names (--demangle|-C)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.demangle" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.linenumbers.890608562" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.linenumbers" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.wide.1669392057" name="Wide lines (--wide|-w)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.wide" value="true" valueType="boolean"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize.403251962" name="Cross ARM GNU Print Size" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format.1919947275" name="Size format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="FreeRTOSDemo.ilg.gnuarmeclipse.managedbuild.cross.target.elf.737306620" name="Executable" projectType="ilg.gnuarmeclipse.managedbuild.cross.target.elf"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962;ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962.;ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.1576427906;ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.68945223"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> + <storageModule moduleId="refreshScope" versionNumber="2"> + <configuration configurationName="Debug"> + <resource resourceType="PROJECT" workspacePath="/FreeRTOSDemo"/> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> +</cproject> diff --git a/Hello_World_FreeRTOS/.gdbinit b/Hello_World_FreeRTOS/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..85b92cf79c0f29f412a886e093c13da55dfc1bcc --- /dev/null +++ b/Hello_World_FreeRTOS/.gdbinit @@ -0,0 +1,3 @@ +file build/max32665.elf +target remote localhost:3333 + diff --git a/Hello_World_FreeRTOS/.project b/Hello_World_FreeRTOS/.project new file mode 100644 index 0000000000000000000000000000000000000000..c2534f428006bd61ca588800d1201ca4404267e1 --- /dev/null +++ b/Hello_World_FreeRTOS/.project @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>FreeRTOSDemo</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription> diff --git a/Hello_World_FreeRTOS/.settings/language.settings.xml b/Hello_World_FreeRTOS/.settings/language.settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..e5a1647610f97197abe406e8ef1bb9e62065f5a1 --- /dev/null +++ b/Hello_World_FreeRTOS/.settings/language.settings.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<project> + <configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962" name="Debug"> + <extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> + <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> + <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> + <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> + </extension> + </configuration> +</project> diff --git a/Hello_World_FreeRTOS/CLI-commands.c b/Hello_World_FreeRTOS/CLI-commands.c new file mode 100644 index 0000000000000000000000000000000000000000..63a84a942ea0c696b79ada28a584cf9bbd515328 --- /dev/null +++ b/Hello_World_FreeRTOS/CLI-commands.c @@ -0,0 +1,371 @@ +/* + FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + *************************************************************************** + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + *************************************************************************** + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available on the following + link: http://www.freertos.org/a00114.html + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that is more than just the market leader, it * + * is the industry's de facto standard. * + * * + * Help yourself get started quickly while simultaneously helping * + * to support the FreeRTOS project by purchasing a FreeRTOS * + * tutorial book, reference manual, or both: * + * http://www.FreeRTOS.org/Documentation * + * * + *************************************************************************** + + http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading + the FAQ page "My application does not run, what could be wrong?". Have you + defined configASSERT()? + + http://www.FreeRTOS.org/support - In return for receiving this top quality + embedded software for free we request you assist our global community by + participating in the support forum. + + http://www.FreeRTOS.org/training - Investing in training allows your team to + be as productive as possible as early as possible. Now you can receive + FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers + Ltd, and the world's leading authority on the world's leading RTOS. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. + Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. + + http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High + Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and commercial middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +/* Modified by Maxim Integrated 26-Jun-2015 to quiet compiler warnings */ +#include <string.h> +#include <stdio.h> + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* FreeRTOS+CLI includes. */ +#include "FreeRTOS_CLI.h" + +#include "rtc_regs.h" + +extern int disable_tickless; + +/* + * Defines a command that returns a table showing the state of each task at the + * time the command is called. + */ +static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); + +/* + * Define a command which reports how long the scheduler has been operating (uptime) + * + */ +static BaseType_t prvUptimeCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString); + +/* + * Defines a command that expects exactly three parameters. Each of the three + * parameter are echoed back one at a time. + */ +static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); + +/* + * Defines a command that can take a variable number of parameters. Each + * parameter is echoes back one at a time. + */ +static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); + +/* Enable or disable tickless operation */ +static BaseType_t prvTickless( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); + +/* Structure that defines the "ps" command line command. */ +static const CLI_Command_Definition_t xTaskStats = +{ + "ps", /* The command string to type. */ + "\r\nps:\r\n Displays a table showing the state of each FreeRTOS task\r\n\r\n", + prvTaskStatsCommand, /* The function to run. */ + 0 /* No parameters are expected. */ +}; + +/* Structure that defines the "uptime" command line command. */ +static const CLI_Command_Definition_t xUptime = +{ + "uptime", /* The command string to type. */ + "\r\nuptime:\r\n Displays the uptime of the FreeRTOS system\r\n\r\n", + prvUptimeCommand, /* The function to run. */ + 0 /* No parameters are expected. */ +}; + +/* Structure that defines the "tickless" command line command. */ +static const CLI_Command_Definition_t xTickless = +{ + "tickless", /* The command string to type. */ + "\r\ntickless <0/1>:\r\n Disable (0) or enable (1) tick-less operation\r\n\r\n", + prvTickless, /* The function to run. */ + 1 /* One parameter expected */ +}; + +/* Structure that defines the "echo_3_parameters" command line command. This +takes exactly three parameters that the command simply echos back one at a +time. */ +static const CLI_Command_Definition_t xThreeParameterEcho = +{ + "echo_3_parameters", + "\r\necho_3_parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n\r\n", + prvThreeParameterEchoCommand, /* The function to run. */ + 3 /* Three parameters are expected, which can take any value. */ +}; + +/* Structure that defines the "echo_parameters" command line command. This +takes a variable number of parameters that the command simply echos back one at +a time. */ +static const CLI_Command_Definition_t xParameterEcho = +{ + "echo_parameters", + "\r\necho_parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n\r\n", + prvParameterEchoCommand, /* The function to run. */ + -1 /* The user can enter any number of commands. */ +}; + +/*-----------------------------------------------------------*/ + +void vRegisterCLICommands( void ) +{ + /* Register all the command line commands defined immediately above. */ + FreeRTOS_CLIRegisterCommand( &xTaskStats ); + FreeRTOS_CLIRegisterCommand( &xUptime ); + FreeRTOS_CLIRegisterCommand( &xTickless ); + FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho ); + FreeRTOS_CLIRegisterCommand( &xParameterEcho ); +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) +{ +const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n"; + + /* Remove compile time warnings about unused parameters, and check the + write buffer is not NULL. NOTE - for simplicity, this example assumes the + write buffer length is adequate, so does not check for buffer overflows. */ + ( void ) pcCommandString; + ( void ) xWriteBufferLen; + configASSERT( pcWriteBuffer ); + + /* Generate a table of task stats. */ + strcpy( pcWriteBuffer, pcHeader ); + vTaskList( pcWriteBuffer + strlen( pcHeader ) ); + + /* There is no more data to return after this single string, so return + pdFALSE. */ + return pdFALSE; +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvUptimeCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString) +{ + TickType_t ticks; + + ticks = xTaskGetTickCount(); + +#if configUSE_TICKLESS_IDLE + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, + "Uptime is 0x%08x (%u ms)\r\nMXC_RTCTMR->timer is %u\r\n", + ticks, ticks / portTICK_PERIOD_MS, MXC_RTC->sec); +#else + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, + "Uptime is 0x%08x (%u ms)\r\n", + ticks, ticks / portTICK_PERIOD_MS); +#endif + + /* No more data to return */ + return pdFALSE; +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) +{ +const char *pcParameter; +BaseType_t lParameterStringLength, xReturn; +static BaseType_t lParameterNumber = 0; + + /* Remove compile time warnings about unused parameters, and check the + write buffer is not NULL. NOTE - for simplicity, this example assumes the + write buffer length is adequate, so does not check for buffer overflows. */ + ( void ) pcCommandString; + ( void ) xWriteBufferLen; + configASSERT( pcWriteBuffer ); + + if( lParameterNumber == 0 ) + { + /* The first time the function is called after the command has been + entered just a header string is returned. */ + sprintf( pcWriteBuffer, "The three parameters were:\r\n" ); + + /* Next time the function is called the first parameter will be echoed + back. */ + lParameterNumber = 1L; + + /* There is more data to be returned as no parameters have been echoed + back yet. */ + xReturn = pdPASS; + } + else + { + /* Obtain the parameter string. */ + pcParameter = FreeRTOS_CLIGetParameter + ( + pcCommandString, /* The command string itself. */ + lParameterNumber, /* Return the next parameter. */ + &lParameterStringLength /* Store the parameter string length. */ + ); + + /* Sanity check something was returned. */ + configASSERT( pcParameter ); + + /* Return the parameter string. */ + memset( pcWriteBuffer, 0x00, xWriteBufferLen ); + sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber ); + strncat( pcWriteBuffer, pcParameter, lParameterStringLength ); + strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); + + /* If this is the last of the three parameters then there are no more + strings to return after this one. */ + if( lParameterNumber == 3L ) + { + /* If this is the last of the three parameters then there are no more + strings to return after this one. */ + xReturn = pdFALSE; + lParameterNumber = 0L; + } + else + { + /* There are more parameters to return after this one. */ + xReturn = pdTRUE; + lParameterNumber++; + } + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) +{ +const char *pcParameter; +BaseType_t lParameterStringLength, xReturn; +static BaseType_t lParameterNumber = 0; + + /* Remove compile time warnings about unused parameters, and check the + write buffer is not NULL. NOTE - for simplicity, this example assumes the + write buffer length is adequate, so does not check for buffer overflows. */ + ( void ) pcCommandString; + ( void ) xWriteBufferLen; + configASSERT( pcWriteBuffer ); + + if( lParameterNumber == 0 ) + { + /* The first time the function is called after the command has been + entered just a header string is returned. */ + sprintf( pcWriteBuffer, "The parameters were:\r\n" ); + + /* Next time the function is called the first parameter will be echoed + back. */ + lParameterNumber = 1L; + + /* There is more data to be returned as no parameters have been echoed + back yet. */ + xReturn = pdPASS; + } + else + { + /* Obtain the parameter string. */ + pcParameter = FreeRTOS_CLIGetParameter + ( + pcCommandString, /* The command string itself. */ + lParameterNumber, /* Return the next parameter. */ + &lParameterStringLength /* Store the parameter string length. */ + ); + + if( pcParameter != NULL ) + { + /* Return the parameter string. */ + memset( pcWriteBuffer, 0x00, xWriteBufferLen ); + sprintf( pcWriteBuffer, "%d: ", (int)lParameterNumber ); + strncat( pcWriteBuffer, pcParameter, lParameterStringLength ); + strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); + + /* There might be more parameters to return after this one. */ + xReturn = pdTRUE; + lParameterNumber++; + } + else + { + /* No more parameters were found. Make sure the write buffer does + not contain a valid string. */ + pcWriteBuffer[ 0 ] = 0x00; + + /* No more data to return. */ + xReturn = pdFALSE; + + /* Start over the next time this command is executed. */ + lParameterNumber = 0; + } + } + + return xReturn; +} + +static BaseType_t prvTickless( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) +{ + const char *pcParameter; + BaseType_t lParameterStringLength; + + /* Get parameter */ + pcParameter = FreeRTOS_CLIGetParameter(pcCommandString, 1, &lParameterStringLength); + if (pcParameter != NULL) { + if (pcParameter[0] == '0') { + disable_tickless = 1; + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, "Tick-less mode disabled\r\n"); + } else if (pcParameter[0] == '1') { + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, "Tick-less mode enabled\r\n"); + disable_tickless = 0; + } else { + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, "Must supply 0 (Disable) or 1 (Enable)\r\n"); + } + } else { + pcWriteBuffer += snprintf(pcWriteBuffer, xWriteBufferLen, "Must supply 0 (Disable) or 1 (Enable)\r\n"); + } + + return pdFALSE; +} diff --git a/Hello_World_FreeRTOS/FreeRTOSConfig.h b/Hello_World_FreeRTOS/FreeRTOSConfig.h new file mode 100644 index 0000000000000000000000000000000000000000..fc935ceb3891808b64cd5f9f3c84d40c079d17ba --- /dev/null +++ b/Hello_World_FreeRTOS/FreeRTOSConfig.h @@ -0,0 +1,120 @@ +/******************************************************************************* +* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +* +* $Id: FreeRTOSConfig.h 22182 2016-03-30 23:42:14Z zach.metzinger $ +* +******************************************************************************* +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include "max32665.h" + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* CMSIS keeps a global updated with current system clock in Hz */ +#define configCPU_CLOCK_HZ ((unsigned long)120000000) + +/* Tick-less idle forces a 32768 Hz RTC-derived SysTick source, and a 256 Hz task tick */ +#define configUSE_TICKLESS_IDLE 1 +#ifdef configUSE_TICKLESS_IDLE +#define configSYSTICK_CLK_HZ ((unsigned long)32768) +#define configTICK_RATE_HZ ((portTickType)256) +#else +#define configTICK_RATE_HZ ((portTickType)1000) +#endif + +#define configTOTAL_HEAP_SIZE ((size_t)(26 * 1024)) + +#define configMINIMAL_STACK_SIZE ((unsigned short)128) + +#define configMAX_PRIORITIES 5 +#define configUSE_PREEMPTION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configUSE_CO_ROUTINES 0 +#define configUSE_16_BIT_TICKS 0 +#define configUSE_MUTEXES 1 + +/* Run time and task stats gathering related definitions. */ +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 0 +#define INCLUDE_vTaskDelete 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_uxTaskPriorityGet 0 +#define INCLUDE_vTaskDelay 1 + +/* # of priority bits (configured in hardware) is provided by CMSIS */ +#define configPRIO_BITS __NVIC_PRIO_BITS + +/* Priority 7, or 255 as only the top three bits are implemented. This is the lowest priority. */ +#define configKERNEL_INTERRUPT_PRIORITY ( ( unsigned char ) 7 << ( 8 - configPRIO_BITS) ) + +/* Priority 5, or 160 as only the top three bits are implemented. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( ( unsigned char ) 5 << ( 8 - configPRIO_BITS) ) + +/* Alias the default handler names to match CMSIS weak symbols */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler + +#ifdef configUSE_TICKLESS_IDLE +#define configRTC_TICK_RATE_HZ ((portTickType)4096) +/* Provide routines for tickless idle pre- and post- processing */ +void vPreSleepProcessing( unsigned long * ); +void vPostSleepProcessing( unsigned long ); +#define configPRE_SLEEP_PROCESSING( idletime ) vPreSleepProcessing( &idletime ); +#define configPOST_SLEEP_PROCESSING( idletime ) vPostSleepProcessing( idletime ); +#endif + +/* FreeRTOS+CLI requires this size to be defined, but we do not use it */ +#define configCOMMAND_INT_MAX_OUTPUT_SIZE 1 + +#endif /* FREERTOS_CONFIG_H */ + + + diff --git a/Hello_World_FreeRTOS/Makefile b/Hello_World_FreeRTOS/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7884dea65c84788e2eef511fa3dcd917fc115ffa --- /dev/null +++ b/Hello_World_FreeRTOS/Makefile @@ -0,0 +1,153 @@ +################################################################################ +# Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Maxim Integrated +# Products, Inc. shall not be used except as stated in the Maxim Integrated +# Products, Inc. Branding Policy. +# +# The mere transfer of this software does not imply any licenses +# of trade secrets, proprietary technology, copyrights, patents, +# trademarks, maskwork rights, or any other form of intellectual +# property whatsoever. Maxim Integrated Products, Inc. retains all +# ownership rights. +# +############################################################################### + +# This is the name of the build output file +ifeq "$(PROJECT)" "" +PROJECT=max32665 +endif + +# Specify the target processor +ifeq "$(TARGET)" "" +TARGET=MAX32665 +endif + +# Create Target name variables +TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) +TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) + +# Select 'GCC' or 'IAR' compiler +COMPILER=GCC + +# Specify the board used +ifeq "$(BOARD)" "" +#BOARD=EvKit_V1 +BOARD=card10 +endif + +# This is the path to the CMSIS root directory +ifeq "$(MAXIM_PATH)" "" +LIBS_DIR=../sdk/Libraries +else +LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries) +endif +CMSIS_ROOT=$(LIBS_DIR)/CMSIS + +# Source files for this test (add path to VPATH below) +SRCS = main.c +SRCS += FreeRTOS_CLI.c +SRCS += CLI-commands.c +SRCS += freertos_tickless.c +SRCS += pmic.c +SRCS += bosch.c +SRCS += bhy_support.c bhy_uc_driver.c bhy.c +SRCS += MAX77650-Arduino-Library.c +SRCS += bme680.h +SRCS += bma400.c + + +# Where to find source files for this test +VPATH = . + +# Where to find header files for this test +IPATH = . + +IPATH += ../lib/card10 +VPATH += ../lib/card10 + +IPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/driver/inc +IPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/examples/firmware/ +VPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/driver/src + +IPATH += ../lib/maxim/MAX77650-Arduino-Library +VPATH += ../lib/maxim/MAX77650-Arduino-Library + +IPATH += ../lib/bosch/BME680_driver +VPATH += ../lib/bosch/BME680_driver + +IPATH += ../lib/bosch/BMA400-API +VPATH += ../lib/bosch/BMA400-API + +# Enable assertion checking for development +PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE + +# Specify the target revision to override default +# "A2" in ASCII +# TARGET_REV=0x4132 + +# Use this variables to specify and alternate tool path +#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin + +# Use these variables to add project specific tool options +#PROJ_CFLAGS+=--specs=nano.specs +#PROJ_LDFLAGS+=--specs=nano.specs + +PROJ_CFLAGS+=-std=c99 + +# Point this variable to a startup file to override the default file +#STARTUPFILE=start.S + +# Override the default optimization level using this variable +#MXC_OPTIMIZE_CFLAGS=-O1 + +# Point this variable to a linker file to override the default file +ifneq "$(APP)" "" +LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC)_app.ld +endif + +################################################################################ +# Include external library makefiles here + +# Include the BSP +BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD) +include $(BOARD_DIR)/board.mk + +# Include the peripheral driver +PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver +include $(PERIPH_DRIVER_DIR)/periphdriver.mk + +# Include the FreeRTOS library, and specify a local FreeRTOSConfig.h file +RTOS_CONFIG_DIR=. +RTOS_DIR=$(LIBS_DIR)/FreeRTOS +include $(RTOS_DIR)/freertos.mk +# Include the FreeRTOS-Plus-CLI (please read license file before using commercially) +IPATH +=$(LIBS_DIR)/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI +VPATH +=$(LIBS_DIR)/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI + +################################################################################ +# Include the rules for building for this target. All other makefiles should be +# included before this one. +include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk + +# The rule to clean out all the build products. +distclean: clean + $(MAKE) -C ${PERIPH_DRIVER_DIR} clean diff --git a/Hello_World_FreeRTOS/build_image b/Hello_World_FreeRTOS/build_image new file mode 100755 index 0000000000000000000000000000000000000000..efcda785f8ef3137326531e085cdccaa7baac919 --- /dev/null +++ b/Hello_World_FreeRTOS/build_image @@ -0,0 +1,5 @@ +make clean +make APP=1 +make build/max32665.bin +cp build/max32665.bin card10.bin +python ../bootloader/crc_patch.py card10.bin diff --git a/Hello_World_FreeRTOS/freertos_tickless.c b/Hello_World_FreeRTOS/freertos_tickless.c new file mode 100644 index 0000000000000000000000000000000000000000..da328c0d123a04a35635a7dbc5b70990acd1be1f --- /dev/null +++ b/Hello_World_FreeRTOS/freertos_tickless.c @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +/* MXC */ +#include "mxc_config.h" +#include "board.h" +#include "mxc_assert.h" + +/* FreeRTOS includes */ +#include "FreeRTOS.h" +#include "task.h" + +/* Maxim CMSIS */ +#include "lp.h" +#include "rtc.h" +#include "pwrseq_regs.h" + +#define RTC_RATIO (configRTC_TICK_RATE_HZ / configTICK_RATE_HZ) +#define MAX_SNOOZE 0xFF +#define MIN_SYSTICK 2 +#define MIN_RTC_TICKS 5 + +static uint32_t residual = 0; + +/* + * Sleep-check function + * + * Your code should over-ride this weak function and return E_NO_ERROR if + * tickless sleep is permissible (ie. no UART/SPI/I2C activity). Any other + * return code will prevent FreeRTOS from entering tickless idle. + */ +__attribute__((weak)) int freertos_permit_tickless(void) +{ + return E_NO_ERROR; +} + +/* + * This function overrides vPortSuppressTicksAndSleep in portable/.../ARM_CM4F/port.c + * + * DEEPSLEEP mode will stop SysTick from counting, so that can't be + * used to wake up. Instead, calculate a wake-up period for the RTC to + * interrupt the WFI and continue execution. + * + */ +void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) +{ + volatile uint32_t rtc_ticks, rtc_ss_val; + volatile uint32_t actual_ticks; + volatile uint32_t pre_capture, post_capture; + gpio_cfg_t uart_rx_pin = {PORT_0, PIN_10, GPIO_FUNC_IN, GPIO_PAD_PULL_UP}; + + /* Example: + * + * configTICK_RATE_HZ 512 + * configRTC_TICK_RATE_HZ 4096 + * + * RTC is 8x more accurate than the normal tick in this case. We can accumulate an error term and + * fix up when called again as the error term equals 1 task tick + */ + + /* We do not currently handle to case where the RTC is slower than the RTOS tick */ + MXC_ASSERT(configRTC_TICK_RATE_HZ >= configTICK_RATE_HZ); + + if (SysTick->VAL < MIN_SYSTICK) { + /* Avoid sleeping too close to a systick interrupt */ + return; + } + + /* Deep sleep time is limited */ + if (xExpectedIdleTime > (MAX_SNOOZE / RTC_RATIO)) { + xExpectedIdleTime = (MAX_SNOOZE / RTC_RATIO); + } + + /* Calculate the number of RTC ticks, but we need a few ticks to synchronize */ + rtc_ticks = (xExpectedIdleTime - 4UL) * RTC_RATIO; + + if ((xExpectedIdleTime < 5) || (rtc_ticks < MIN_RTC_TICKS)) { + /* Finish out the rest of this tick with normal sleep */ + LP_EnterSleepMode(); + return; + } + + /* Enter a critical section but don't use the taskENTER_CRITICAL() + method as that will mask interrupts that should exit sleep mode. */ + __asm volatile( "cpsid i" ); + + /* If a context switch is pending or a task is waiting for the scheduler + to be unsuspended then abandon the low power entry. */ + /* Also check the MXC drivers for any in-progress activity */ + if ((eTaskConfirmSleepModeStatus() == eAbortSleep) || + (freertos_permit_tickless() != E_NO_ERROR)) { + /* Re-enable interrupts - see comments above the cpsid instruction() + above. */ + __asm volatile( "cpsie i" ); + return; + } + + /* Use sub-second roll-over to wake up */ + rtc_ss_val = 0xFFFFFFFF - (rtc_ticks - 1); + RTC_SetSubsecondAlarm(MXC_RTC, rtc_ss_val); + + MXC_RTC->ctrl &= ~(MXC_F_RTC_CTRL_ALSF); + RTC_EnableSubsecondInterrupt(MXC_RTC); + + /* Pin used for UART RX must have GPIO interrupt enabled */ + GPIO_IntEnable(&uart_rx_pin); + + /* Snapshot the current RTC value */ + pre_capture = MXC_RTC->ssec; + + /* Sleep */ + LP_EnterDeepSleepMode(); + + /* -- WAKE HERE -- */ + + /* We'll need to wait for the RTC to synchronize */ + MXC_RTC->ctrl &= ~MXC_F_RTC_CTRL_RDY; + + /* Remove interrupt flag and configuration for GPIO on UART RX pin */ + GPIO_IntClr(&uart_rx_pin); + GPIO_IntDisable(&uart_rx_pin); + + /* Snapshot the current RTC value */ + while (!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)); + post_capture = MXC_RTC->ssec; + + /* Dermine wake cause */ + if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_ALSF) { + /* RTC woke the processor */ + actual_ticks = rtc_ticks; + } else { + /* Determine the actual duration of sleep */ + if (post_capture < pre_capture) { + /* Rollover */ + post_capture += 0x1000; + } + actual_ticks = post_capture - pre_capture; + if (actual_ticks > rtc_ticks) { + /* Assert or just fix up */ + MXC_ASSERT_FAIL(); + actual_ticks = rtc_ticks; + } + + if (RTC_RATIO > 1) { + /* Add residual from any previous early wake */ + actual_ticks += residual; + /* Find new residual */ + residual = actual_ticks % RTC_RATIO; + } + } + + /* RTC sub-second interrupt no longer desired */ + RTC_DisableSubsecondInterrupt(MXC_RTC); + MXC_RTC->ctrl &= ~(MXC_F_RTC_CTRL_ALSF); + + /* Re-enable interrupts - see comments above the cpsid instruction() + above. */ + __asm volatile( "cpsie i" ); + + /* + * Advance ticks by # actually elapsed + */ + portENTER_CRITICAL(); + /* Future enhancement: Compare time in seconds to RTC and slew to correct */ + vTaskStepTick( actual_ticks / RTC_RATIO ); + portEXIT_CRITICAL(); +} diff --git a/Hello_World_FreeRTOS/main.c b/Hello_World_FreeRTOS/main.c new file mode 100644 index 0000000000000000000000000000000000000000..3600e2fe738e5d117003a061a7cf39e774ae883a --- /dev/null +++ b/Hello_World_FreeRTOS/main.c @@ -0,0 +1,427 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +/* config.h is the required application configuration; RAM layout, stack, chip type etc. */ +#include "mxc_config.h" +#include "board.h" + +#include <stdio.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/stat.h> + +/* FreeRTOS */ +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" + +/* FreeRTOS+ */ +#include "FreeRTOS_CLI.h" + +/* Maxim CMSIS SDK */ +#include "rtc.h" +#include "uart.h" +#include "lp.h" +#include "led.h" +#include "board.h" + +/* FreeRTOS+CLI */ +void vRegisterCLICommands(void); + +/* Mutual exclusion (mutex) semaphores */ +SemaphoreHandle_t xGPIOmutex; + +/* Task IDs */ +TaskHandle_t cmd_task_id; + +/* Enables/disables tick-less mode */ +unsigned int disable_tickless = 1; + +/* Stringification macros */ +#define STRING(x) STRING_(x) +#define STRING_(x) #x + +/* Console ISR selection */ +#if (CONSOLE_UART==0) +#define UARTx_IRQHandler UART0_IRQHandler +#define UARTx_IRQn UART0_IRQn +#elif (CONSOLE_UART==1) +#define UARTx_IRQHandler UART1_IRQHandler +#define UARTx_IRQn UART1_IRQn +#else +#error "Please update ISR macro for UART CONSOLE_UART" +#endif +mxc_uart_regs_t *ConsoleUART = MXC_UART_GET_UART(CONSOLE_UART); + +/* Array sizes */ +#define CMD_LINE_BUF_SIZE 80 +#define OUTPUT_BUF_SIZE 512 + +/* =| vTask0 |============================================ + * + * This task blinks LED0 at a 0.5Hz rate, and does not + * drift due to the use of vTaskDelayUntil(). It may have + * jitter, however, due to any higher-priority task or + * interrupt causing delays in scheduling. + * + * ======================================================= + */ +void vTask0(void *pvParameters) +{ + TickType_t xLastWakeTime; + unsigned int x = LED_OFF; + + /* Get task start time */ + xLastWakeTime = xTaskGetTickCount(); + + while (1) { + /* Protect hardware access with mutex + * + * Note: This is not strictly necessary, since GPIO_SetOutVal() is implemented with bit-band + * access, which is inherently task-safe. However, for other drivers, this would be required. + * + */ + if (xSemaphoreTake(xGPIOmutex, portMAX_DELAY) == pdTRUE) { + if (x == LED_OFF) { + x = LED_ON; + } else { + x = LED_OFF; + } + /* Return the mutex after we have modified the hardware state */ + xSemaphoreGive(xGPIOmutex); + } + /* Wait 1 second until next run */ + vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ); + } +} + +/* =| vTask1 |============================================ + * + * This task blinks LED1 at a 0.5Hz rate, and does not + * drift due to the use of vTaskDelayUntil(). It may have + * jitter, however, due to any higher-priority task or + * interrupt causing delays in scheduling. + * + * NOTE: The MAX32660 EV Kit has only 1 LED, so this task + * does not blink an LED. + * + * ======================================================= + */ +void vTask1(void *pvParameters) +{ + TickType_t xLastWakeTime; + unsigned int x = LED_ON; + + /* Get task start time */ + xLastWakeTime = xTaskGetTickCount(); + + while (1) { + /* Protect hardware access with mutex + * + * Note: This is not strictly necessary, since GPIO_SetOutVal() is implemented with bit-band + * access, which is inherently task-safe. However, for other drivers, this would be required. + * + */ + if (xSemaphoreTake(xGPIOmutex, portMAX_DELAY) == pdTRUE) { + if (x == LED_OFF) { + LED_On(0); + x = LED_ON; + } else { + LED_Off(0); + x = LED_OFF; + } + /* Return the mutex after we have modified the hardware state */ + xSemaphoreGive(xGPIOmutex); + } + /* Wait 1 second until next run */ + vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ); + } +} + +/* =| vTickTockTask |============================================ + * + * This task writes the current RTOS tick time to the console + * + * ======================================================= + */ +void vTickTockTask(void *pvParameters) +{ + TickType_t ticks = 0; + TickType_t xLastWakeTime; + + /* Get task start time */ + xLastWakeTime = xTaskGetTickCount(); + + while (1) { + ticks = xTaskGetTickCount(); + printf("Uptime is 0x%08x (%u seconds), tickless-idle is %s\n", + ticks, ticks / configTICK_RATE_HZ, + disable_tickless ? "disabled" : "ENABLED"); + vTaskDelayUntil(&xLastWakeTime, (configTICK_RATE_HZ * 60)); + } +} + +/* =| UART0_IRQHandler |====================================== + * + * This function overrides the weakly-declared interrupt handler + * in system_max326xx.c and is needed for asynchronous UART + * calls to work properly + * + * =========================================================== + */ +void UARTx_IRQHandler(void) +{ + UART_Handler(ConsoleUART); +} + +/* =| vCmdLineTask_cb |====================================== + * + * Callback on asynchronous reads to wake the waiting command + * processor task + * + * =========================================================== + */ +void vCmdLineTask_cb(uart_req_t *req, int error) +{ + BaseType_t xHigherPriorityTaskWoken; + + /* Wake the task */ + xHigherPriorityTaskWoken = pdFALSE; + vTaskNotifyGiveFromISR(cmd_task_id, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +} + +/* =| vCmdLineTask |====================================== + * + * The command line task provides a prompt on the serial + * interface and takes input from the user to evaluate + * via the FreeRTOS+CLI parser. + * + * NOTE: FreeRTOS+CLI is part of FreeRTOS+ and has + * different licensing requirements. Please see + * http://www.freertos.org/FreeRTOS-Plus for more information + * + * ======================================================= + */ +void vCmdLineTask(void *pvParameters) +{ + unsigned char tmp; + unsigned int index; /* Index into buffer */ + unsigned int x; + char buffer[CMD_LINE_BUF_SIZE]; /* Buffer for input */ + char output[OUTPUT_BUF_SIZE]; /* Buffer for output */ + BaseType_t xMore; + uart_req_t async_read_req; + gpio_cfg_t uart_rx_pin = {PORT_0, PIN_10, GPIO_FUNC_IN, GPIO_PAD_NONE}; + + memset(buffer, 0, CMD_LINE_BUF_SIZE); + index = 0; + + /* Register available CLI commands */ + vRegisterCLICommands(); + +#if configUSE_TICKLESS_IDLE + /* Configure wake-up for GPIO pin corresponding to the UART RX line */ + LP_EnableGPIOWakeup(&uart_rx_pin); + GPIO_IntConfig(&uart_rx_pin, GPIO_INT_EDGE, GPIO_INT_FALLING); +#endif + + /* Enable UART0 interrupt */ + NVIC_ClearPendingIRQ(UARTx_IRQn); + NVIC_DisableIRQ(UARTx_IRQn); + NVIC_SetPriority(UARTx_IRQn, 1); + NVIC_EnableIRQ(UARTx_IRQn); + + /* Async read will be used to wake process */ + async_read_req.data = &tmp; + async_read_req.len = 1; + async_read_req.callback = vCmdLineTask_cb; + + printf("\nEnter 'help' to view a list of available commands.\n"); + printf("cmd> "); + fflush(stdout); + while (1) { + /* Register async read request */ + if (UART_ReadAsync(ConsoleUART, &async_read_req) != E_NO_ERROR) { + printf("Error registering async request. Command line unavailable.\n"); + vTaskDelay(portMAX_DELAY); + } + /* Hang here until ISR wakes us for a character */ + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + /* Check that we have a valid character */ + if (async_read_req.num > 0) { + /* Process character */ + do { + if (tmp == 0x08) { + /* Backspace */ + if (index > 0) { + index--; + printf("\x08 \x08"); + } + fflush(stdout); + } else if (tmp == 0x03) { + /* ^C abort */ + index = 0; + printf("^C"); + printf("\ncmd> "); + fflush(stdout); + } else if ((tmp == '\r') || + (tmp == '\n')) { + printf("\r\n"); + /* Null terminate for safety */ + buffer[index] = 0x00; + /* Evaluate */ + do { + xMore = FreeRTOS_CLIProcessCommand(buffer, output, OUTPUT_BUF_SIZE); + /* If xMore == pdTRUE, then output buffer contains no null termination, so + * we know it is OUTPUT_BUF_SIZE. If pdFALSE, we can use strlen. + */ + for (x = 0; x < (xMore == pdTRUE ? OUTPUT_BUF_SIZE : strlen(output)) ; x++) { + putchar(*(output+x)); + } + } while (xMore != pdFALSE); + /* New prompt */ + index = 0; + printf("\ncmd> "); + fflush(stdout); + } else if (index < CMD_LINE_BUF_SIZE) { + putchar(tmp); + buffer[index++] = tmp; + fflush(stdout); + } else { + /* Throw away data and beep terminal */ + putchar(0x07); + fflush(stdout); + } + /* If more characters are ready, process them here */ + } while ((UART_NumReadAvail(MXC_UART_GET_UART(CONSOLE_UART)) > 0) && + UART_Read(MXC_UART_GET_UART(CONSOLE_UART), (uint8_t *)&tmp, 1, NULL)); + } + } +} + +#if configUSE_TICKLESS_IDLE +/* =| freertos_permit_tickless |========================== + * + * Determine if any hardware activity should prevent + * low-power tickless operation. + * + * ======================================================= + */ +int freertos_permit_tickless(void) +{ + if (disable_tickless == 1) { + return E_BUSY; + } + + return UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART)); +} +#endif + +void RTC_IRQHandler(void) +{ + MXC_RTC->ctrl &= ~(MXC_F_RTC_CTRL_ALSF); +} + +/* =| main |============================================== + * + * This program demonstrates FreeRTOS tasks, mutexes, + * and the FreeRTOS+CLI extension. + * + * ======================================================= + */ +int main(void) +{ +#if configUSE_TICKLESS_IDLE + uart_cfg_t uart_cfg = { + .parity = UART_PARITY_DISABLE, + .size = UART_DATA_SIZE_8_BITS, + .stop = UART_STOP_1, + .flow = UART_FLOW_CTRL_DIS, + .pol = UART_FLOW_POL_DIS, + .baud = 115200, + .clksel = UART_CLKSEL_SYSTEM + }; + sys_cfg_uart_t uart_sys_cfg = {MAP_A, Enable}; + + /* The RTC must be enabled for tickless operation */ + RTC_Init(MXC_RTC, 0, 0, NULL); + RTC_EnableRTCE(MXC_RTC); + NVIC_ClearPendingIRQ(RTC_IRQn); + NVIC_EnableIRQ(RTC_IRQn); + LP_EnableRTCAlarmWakeup(); + /* If running tickless idle, must reduce baud rate to avoid losing character */ + if (UART_Init(ConsoleUART, &uart_cfg, &uart_sys_cfg) != E_NO_ERROR) { + MXC_ASSERT_FAIL(); + } +#endif + + /* Print banner (RTOS scheduler not running) */ + printf("\n-=- %s FreeRTOS (%s) Demo -=-\n", STRING(TARGET), tskKERNEL_VERSION_NUMBER); +#if configUSE_TICKLESS_IDLE + printf("Tickless idle is configured. Type 'tickless 1' to enable.\n"); +#endif + + /* Create mutexes */ + xGPIOmutex = xSemaphoreCreateMutex(); + if (xGPIOmutex == NULL) { + printf("xSemaphoreCreateMutex failed to create a mutex.\n"); + } else { + /* Configure task */ + if ((xTaskCreate(vTask0, (const char *)"Task0", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) || + (xTaskCreate(vTask1, (const char *)"Task1", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) || + (xTaskCreate(vTickTockTask, (const char *)"TickTock", + 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL) != pdPASS) || + (xTaskCreate(vCmdLineTask, (const char *)"CmdLineTask", + configMINIMAL_STACK_SIZE+CMD_LINE_BUF_SIZE+OUTPUT_BUF_SIZE, NULL, tskIDLE_PRIORITY+1, &cmd_task_id) != pdPASS)) { + printf("xTaskCreate() failed to create a task.\n"); + } else { + /* Start scheduler */ + printf("Starting scheduler.\n"); + vTaskStartScheduler(); + } + } + + /* This code is only reached if the scheduler failed to start */ + printf("ERROR: FreeRTOS did not start due to above error!\n"); + while (1) { + __NOP(); + } + + /* Quiet GCC warnings */ + return -1; +}