Use CI-CD-Github-Actions for spelling and formatting, add in the bot formatting action, update the CI-CD workflow files. Fix incorrect spelling and formatting on files. (#1083)

* Use new version of CI-CD Actions,  checkout@v3 instead of checkout@v2 on all jobs
* Use cSpell spell check, and use ubuntu-20.04 for formatting check
* Add in bot formatting action
* Update freertos_demo.yml and freertos_plus_demo.yml files to increase github log readability
* Add in a Qemu demo onto the workflows.
This commit is contained in:
Soren Ptak 2023-09-06 15:35:37 -04:00 committed by GitHub
parent 537007d96c
commit 3a2f6646f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1036 changed files with 134568 additions and 127281 deletions

6150
.github/.cSpellWords.txt vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,14 @@
certifi==2023.7.22 Deprecated
chardet==4.0.0 GitPython
PyGithub
PyJWT
PyYAML
certifi
chardet
colorama colorama
Deprecated==1.2.10 gitdb
gitdb==4.0.5 idna
GitPython==3.1.32
idna==2.10
PyGithub==1.55
PyJWT==2.4.0
PyYAML==5.4
requests requests
smmap==3.0.4 smmap
urllib3==1.26.5 urllib3
wrapt==1.12.1 wrapt

View file

@ -119,6 +119,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.ipcf', '.ipcf',
'.ise', '.ise',
'.jlink', '.jlink',
'.js',
'.json', '.json',
'.la', '.la',
'.launch', '.launch',
@ -172,6 +173,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.pl', '.pl',
'.plg', '.plg',
'.png', '.png',
'.props',
'.prc', '.prc',
'.pref', '.pref',
'.prefs', '.prefs',
@ -216,6 +218,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.tags', '.tags',
'.tcl', '.tcl',
'.tdt', '.tdt',
'.templ',
'.template', '.template',
'.tgt', '.tgt',
'.tps', '.tps',
@ -250,14 +253,12 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.xmsgs', '.xmsgs',
'.xsl', '.xsl',
'.yml', '.yml',
'.md',
'.zip' '.zip'
] ]
FREERTOS_IGNORED_PATTERNS = [ FREERTOS_IGNORED_PATTERNS = [
r'.*\.git.*', r'.*\.git.*',
r'.*mbedtls_config\.h.*', r'.*mbedtls_config\.h.*',
r'.*mbedtls_config\.h.*',
r'.*CMSIS.*', r'.*CMSIS.*',
r'.*/Nordic_Code/*', r'.*/Nordic_Code/*',
r'.*/Nuvoton_Code/*', r'.*/Nuvoton_Code/*',
@ -275,8 +276,40 @@ FREERTOS_IGNORED_PATTERNS = [
r'.*/trcKernelPortSnapshotConfig\.h.*', r'.*/trcKernelPortSnapshotConfig\.h.*',
r'.*/MicroZed_hw_platform.*', r'.*/MicroZed_hw_platform.*',
r'.*/ThirdParty/.*', r'.*/ThirdParty/.*',
r'FreeRTOS\-Plus/Demo/Common/WinPCap/.*', r'.*/WinPCap/.*',
r'FreeRTOS\-Plus/Source/FreeRTOS-Plus-Trace/.*', r'.*/DRIVERS/.*',
r'.*/FreeRTOS-Plus-Trace/.*',
r'.*/Reliance-Edge/.*',
r'.*/HCS12_CodeWarrior_banked/.*',
r'.*/ARM7_STR75x_GCC/.*',
r'.*/ARM7_STR75x_IAR/.*',
r'.*/lwip-1.4.0/.*',
r'.*/lwip-1.1.0/.*',
r'.*/MSP430X_MSP430F5438_CCS/.*',
r'.*/Atmel/.*',
r'.*/drivers/.*',
r'.*/lwIP/.*',
r'.*/ARM7_AT91FR40008_GCC/.*',
r'.*/ARM7_AT91SAM7S64_IAR/.*',
r'.*/ARM7_LPC2106_GCC/.*',
r'.*/CORTEX_A9_Cyclone_V_SoC_DK/.*',
r'.*/CORTEX_A9_Zynq_ZC702/.*',
r'.*/FreeRTOS-Plus/Demo/FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator/ConfigurationFiles//.*',
r'.*/ARM7_AT91FR40008_GCC/.*',
r'.*/ARM7_STR71x_IAR/.*',
r'FreeRTOS/Demo/HCS12_GCC_banked/.*',
r'FreeRTOS/Demo/CORTEX_LM3S102_GCC/hw_include/.*',
r'FreeRTOS/Demo/CORTEX_LM3S102_GCC/hw_include/.*',
r'FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/include/.*',
r'FreeRTOS/Demo/CORTEX_M0_Infineon_XMC1000_IAR_Keil_GCC/.*',
r'FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_Keil/.*',
r'FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/.*',
r'FreeRTOS/Demo/AVR32_UC3/.*',
r'FreeRTOS/Demo/ARM7_STR75x_GCC/STLibrary/inc/.*',
r'FreeRTOS/Demo/ARM7_STR75x_IAR/STLibrary/inc/.*',
r'FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR/System/GCC/inc/.*',
r'FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/misc/.*',
r'FreeRTOS/Demo/CORTEX_ATSAM3X_Atmel_Studio/src/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_CLI_with_Trace_Windows_Simulator/Trace_Recorder_Configuration/.*', r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_CLI_with_Trace_Windows_Simulator/Trace_Recorder_Configuration/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/.*', r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/pcap/.*', r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/pcap/.*',
@ -291,6 +324,7 @@ FREERTOS_IGNORED_PATTERNS = [
] ]
FREERTOS_IGNORED_FILES = [ FREERTOS_IGNORED_FILES = [
'cspell.config.yaml',
'.cproject', '.cproject',
'.project', '.project',
'fyi-another-way-to-ignore-file.txt', 'fyi-another-way-to-ignore-file.txt',
@ -310,6 +344,22 @@ FREERTOS_IGNORED_FILES = [
'reg_test.S', 'reg_test.S',
'gdbinit', 'gdbinit',
'libslirp-version.h', 'libslirp-version.h',
'LPC21xx.h',
'lpc221x.h',
'winbase.h',
'windows.h',
'direct.h',
'stm32f10x_conf.h',
'lwipopts.h',
'lwipopts.h',
'xil_assert.h',
'alt_i2c.h',
'alt_clkmgr.h',
'hal_lcd.c',
'adc.h',
'redconf.c',
'redconf.h',
'redtypes.h',
] ]
FREERTOS_HEADER = [ FREERTOS_HEADER = [

38
.github/scripts/qemu_reader.c vendored Normal file
View file

@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv[] )
{
setvbuf( stdout, NULL, _IONBF, 0 );
FILE * fp;
char path[ 256 ];
char cmd[ 256 ];
/* Open the command for reading. */
fp = popen("find . -name RTOSDemo.out", "r");
/* Read the output a line at a time - output it. */
while( fgets( path, sizeof( path ), fp ) != NULL )
{
printf( "Path: %s\n", path );
}
sprintf(cmd, "qemu-system-arm -machine mps2-an385 -monitor null -semihosting --semihosting-config enable=on,target=native -serial stdio -nographic -kernel %s", path);
printf("cmd= %s\n", cmd);
fp = popen( cmd, "r" );
if( fp == NULL )
{
printf( "Failed to run command\n" );
exit( 1 );
}
/* Read the output a line at a time - output it. */
while( fgets( path, sizeof( path ), fp ) != NULL )
{
printf( "%s", path );
}
/* close */
pclose( fp );
return 0;
}

View file

@ -1,13 +1,14 @@
certifi>=2020.12.5 Deprecated
chardet>=3.0.4 GitPython
Deprecated>=1.2.10 PyGithub
gitdb>=4.0.5 PyJWT
GitPython>=3.1.11 PyYAML
idna>=2.10 certifi
PyGithub>=1.54 chardet
PyJWT>=1.7.1 colorama
PyYAML>=5.3.1 gitdb
requests>=2.24.0 idna
smmap>=3.0.4 requests
urllib3>=1.25.11 smmap
wrapt>=1.12.1 urllib3
wrapt

View file

@ -26,13 +26,13 @@ jobs:
# Source the release tools from FreeRTOS/FreeRTOS # Source the release tools from FreeRTOS/FreeRTOS
- name: Checkout FreeRTOS Release Tools - name: Checkout FreeRTOS Release Tools
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
path: tools path: tools
# Simpler git auth if we use checkout action and forward the repo to release script # Simpler git auth if we use checkout action and forward the repo to release script
- name: Checkout FreeRTOS - name: Checkout FreeRTOS
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
path: local_core path: local_core
fetch-depth: 0 fetch-depth: 0

View file

@ -1,5 +1,11 @@
name: CI Checks name: CI Checks
env:
bashPass: \033[32;1mPASSED -
bashWarn: \033[33;1mWARNING -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
on: on:
push: push:
pull_request: pull_request:
@ -7,13 +13,13 @@ on:
jobs: jobs:
git-secrets: git-secrets:
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
- name: Checkout awslabs/git-secrets - name: Checkout awslabs/git-secrets
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
repository: awslabs/git-secrets repository: awslabs/git-secrets
ref: master ref: master
@ -28,66 +34,47 @@ jobs:
formatting: formatting:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Install Uncrustify
run: sudo apt-get install uncrustify=0.69.0+dfsg1-1build1
- name: Run Uncrustify
run: |
# Uncrustify on C files while ignoring symlinks.
# Make a collapsible section in the log to run uncrustify
echo "::group::Uncrustify Check"
# GitHub automtically use "set -e" which causes scripts to fail on the first exit code
# This would mean the first time a file fails the check that we exit without formatting all files.
set +e
uncrustify --version
find FreeRTOS/Demo/Common FreeRTOS/Test \( -name ethernet -o -name drivers -o -path 'FreeRTOS/Test/CMock/CMock' \) -prune -false -o -name "*.[hc]" | xargs uncrustify --no-backup --replace --if-changed -c tools/uncrustify.cfg -l C
echo "::endgroup::"
# Run a git diff to print the differences if any exist, return an error code if there are any
git diff --exit-code
if [ "$?" = "0" ]; then
echo -e "\033[32;3mUncrustify check passed\033[0m"
exit 0
else
echo -e "\033[32;31mFormatting check (using Uncrustify) failed...\033[0m"
# If there is an error, set this flag high again so the exit 1 fails the run
set -e
exit 1
fi
- name: Check For Trailing Whitespace
run: |
# Trailing Whitespace Check
set +e
ERROR=0
find . \( -name '.git' -o -path "./FreeRTOS/Test/CBMC/patches" -o -path "./FreeRTOS-Plus" -o -path "./FreeRTOS/Source" -o -path "./FreeRTOS/Test/CMock/CMock" -o -path "./FreeRTOS/Demo" \) -prune -false -o -type f -a -name "*" -exec grep -In -e "[[:blank:]]$" {} +
if [ "$?" = "0" ]; then
ERROR=1
fi
find FreeRTOS/Demo/Common \( -name "ethernet" \) -prune -o -false -o -type f -a -name "*" -exec grep --color=yes -In -e "[[:blank:]]$" {} + - name: Check Formatting of Common Demo Files
if [ "$?" = "0" ]; then uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
echo -e "\033[32;31mFiles have trailing whitespace.\033[0m" with:
exit 1 path: FreeRTOS/Demo/Common
else exclude-dirs: ethernet, drivers
if [ "$ERROR" -eq "1" ]; then
echo -e "\033[32;31mFiles have trailing whitespace.\033[0m" - name: Check Formatting
exit 1 uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
fi with:
echo -e "\033[32;3mTrailing whitespace check passed\033[0m" exclude-dirs: ethernet, drivers, FreeRTOS/Demo
exit 0
fi spell-check:
runs-on: ubuntu-latest
steps:
- name: Checkout Parent Repo
uses: actions/checkout@v3
- name: Check Spelling of Common Demo Files
uses: FreeRTOS/CI-CD-GitHub-Actions/spellings@main
with:
path: FreeRTOS/Demo/Common
exclude-dirs: ethernet, drivers
- name: Check Spelling
uses: FreeRTOS/CI-CD-GitHub-Actions/spellings@main
with:
exclude-dirs: ethernet, drivers, FreeRTOS/Demo
doxygen: doxygen:
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
path: freertos path: freertos
- name: Install Python3 - name: Install Python3
uses: actions/setup-python@v2 uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Download tag dependency of coreMQTT-Agent - name: Download tag dependency of coreMQTT-Agent
run: | run: |
# We don't need to generate the coreMQTT docs, we only need the tag file. # We don't need to generate the coreMQTT docs, we only need the tag file.
@ -95,8 +82,9 @@ jobs:
mkdir -p freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output mkdir -p freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output
wget -O freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output/mqtt.tag \ wget -O freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output/mqtt.tag \
"https://freertos.org/Documentation/api-ref/coreMQTT/docs/doxygen/output/mqtt.tag" "https://freertos.org/Documentation/api-ref/coreMQTT/docs/doxygen/output/mqtt.tag"
- name: Generate doxygen ZIP - name: Generate doxygen ZIP
uses: FreeRTOS/CI-CD-GitHub-Actions/doxygen@main uses: FreeRTOS/CI-CD-Github-Actions/doxygen@main
with: with:
path: ./freertos path: ./freertos
# List of directories containing libraries whose doxygen output will be generated. # List of directories containing libraries whose doxygen output will be generated.
@ -112,77 +100,49 @@ jobs:
path: ./freertos/doxygen.zip path: ./freertos/doxygen.zip
retention-days: 2 retention-days: 2
spell-check:
runs-on: ubuntu-20.04
steps:
- name: Checkout Parent Repo
uses: actions/checkout@v2
with:
ref: main
repository: FreeRTOS/CI-CD-Github-Actions
path: commonCI
- name: Clone This Repo
uses: actions/checkout@v2
with:
path: ./FreeRTOS
- name: Install spell
run: |
sudo apt-get install spell
sudo apt-get install util-linux
- name: Check spelling
run: |
# Add path to the tool to the environment variable.
PATH=$PATH:commonCI/spellings/tools
# Make sure that only Amazon licenced files are checked.
sed -i 's/`find $DIRNAME \\( -iname \\\*\.\[ch\] -o -iname \\\*\.dox \\) -type f`/`grep -ril "copyright \(c\) \[0-9\]\[0-9\]\[0-9\]\[0-9\] amazon.com" | grep "\\.\[ch\]" | grep -v "FreeRTOS\/FreeRTOS\/Test\/VeriFast"`/g' commonCI/spellings/tools/find-unknown-comment-words
# Run the spell check script.
find-unknown-comment-words --directory FreeRTOS/ --lexicon FreeRTOS/lexicon.txt
# Check the exit status.
if [ "$?" = "0" ]; then
exit 0
else
exit 1
fi
verify-manifest: verify-manifest:
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
submodules: true submodules: true
fetch-depth: 0 fetch-depth: 0
- name: Install Python3
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Run manifest verifier - name: Run manifest verifier
uses: FreeRTOS/CI-CD-Github-Actions/manifest-verifier@main uses: FreeRTOS/CI-CD-GitHub-Actions/manifest-verifier@v2
with: with:
path: ./ path: ./
exclude-submodules: FreeRTOS-Plus/Test/CMock,FreeRTOS/Test/CMock/CMock,FreeRTOS/Test/litani
fail-on-incorrect-version: true fail-on-incorrect-version: true
memory-statistics: memory-statistics:
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
env: env:
ARM_GCC_TOOLCHAIN_URL: "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A" ARM_GCC_TOOLCHAIN_URL: "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A"
steps: steps:
- name: Install ARM GCC - name: Install ARM GCC
run: wget -qO- "${{ env.ARM_GCC_TOOLCHAIN_URL }}" | sudo tar --strip-components=1 -xj -C /usr/local run:
wget -qO- "${{ env.ARM_GCC_TOOLCHAIN_URL }}" | sudo tar
--strip-components=1 -xj -C /usr/local
- name: Clone FreeRTOS Repository with submodules - name: Clone FreeRTOS Repository with submodules
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
- name: Clone mbedTLS submodule from corePKCS11 - name: Clone mbedTLS submodule from corePKCS11
run: git submodule update --init --recursive --checkout -- FreeRTOS-Plus/Source/corePKCS11 run:
git submodule update --init --recursive --checkout --
FreeRTOS-Plus/Source/corePKCS11
- name: Clone CI-CD-Github-Actions repository - name: Clone CI-CD-Github-Actions repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
repository: FreeRTOS/CI-CD-Github-Actions repository: FreeRTOS/CI-CD-GitHub-Actions
path: tools path: tools
- name: Run script to generate JSON memory statistics - name: Run script to generate JSON memory statistics
run: tools/memory_statistics/memory_statistics.py --json_report --config tools/memory_statistics/paths.json --output freertos_lts_memory_estimates.json run:
- name: Upload memory size report as artifact (for main and release-candidate ONLY) tools/memory_statistics/memory_statistics.py --json_report
--config tools/memory_statistics/paths.json --output
freertos_lts_memory_estimates.json
- name:
Upload memory size report as artifact (for main and
release-candidate ONLY)
if: success() && ( github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release-candidate' ) if: success() && ( github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release-candidate' )
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
@ -191,15 +151,23 @@ jobs:
retention-days: 2 retention-days: 2
proof_ci: proof_ci:
if: ${{ github.event.pull_request }}
runs-on: cbmc_ubuntu-latest_16-core runs-on: cbmc_ubuntu-latest_16-core
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- run: | - env:
stepName: Install Dependencies
run: |
echo -e "::group::${{ env.stepName }}"
git submodule update --init --checkout --recursive --depth 1 git submodule update --init --checkout --recursive --depth 1
sudo apt-get update sudo apt-get update
sudo apt-get install --yes --no-install-recommends gcc-multilib sudo apt-get install --yes --no-install-recommends gcc-multilib
echo -e "::endgroup::"
echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
- name: Set up CBMC runner - name: Set up CBMC runner
uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main
- name: Run CBMC - name: Run CBMC
uses: FreeRTOS/CI-CD-Github-Actions/run_cbmc@main uses: FreeRTOS/CI-CD-Github-Actions/run_cbmc@main
with: with:

View file

@ -18,14 +18,14 @@ jobs:
# Use the checks as defined by the user, so they can locally adjust as needed # Use the checks as defined by the user, so they can locally adjust as needed
- name: Checkout FreeRTOS Tools - name: Checkout FreeRTOS Tools
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
path: tools path: tools
# Checkout user pull request changes # Checkout user pull request changes
- name: Checkout Pull Request - name: Checkout Pull Request
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
path: inspect path: inspect

23
.github/workflows/formatting.yml vendored Normal file
View file

@ -0,0 +1,23 @@
name: Format Pull Request Files
on:
issue_comment:
types: [created]
env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
jobs:
Formatting:
name: Run Formatting Check
if: ${{ github.event.issue.pull_request }} &&
( ( github.event.comment.body == '/bot run uncrustify' ) ||
( github.event.comment.body == '/bot run formatting' ) )
runs-on: ubuntu-20.04
steps:
- name: Apply Formatting Fix
uses: FreeRTOS/CI-CD-Github-Actions/formatting-bot@main
id: check-formatting

View file

@ -4,192 +4,227 @@ on:
pull_request: pull_request:
workflow_dispatch: workflow_dispatch:
env:
bashPass: \033[32;1mPASSED -
bashWarn: \033[33;1mWARNING -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
pwshPass: "`e[32;1mPASSED -"
pwshWarn: "`e[33;1mWARNING -"
pwshFail: "`e[31;1mFAILED -"
pwshEnd: "`e[0m"
jobs: jobs:
WIN32-MSVC: WIN32-MSVC:
name: WIN32 MSVC name: WIN32 MSVC
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- name: Checkout Repository - env:
uses: actions/checkout@v2 stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- name: Fetch Kernel Submodule - env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Fetch Kernel Submodule # ${{ env.stepName }}
echo "::group::Fetch Kernel Submodule" echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::" exitStatus=$?
if [[ "$?" = "0" ]] set -e
then echo -e "::endgroup::"
echo -e "\033[32;3mCloned the Kernel\033[0m" if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mKernel Clone Failed...\033[0m" echo -e "${{ env.bashFail }} ${{env.stepName}} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Add msbuild to PATH - env:
stepName: Add msbuild to PATH
name: ${{ env.stepName }}
uses: microsoft/setup-msbuild@v1.1 uses: microsoft/setup-msbuild@v1.1
- name: Build WIN32-MSVC Full Demo - env:
stepName: Build WIN32-MSVC Full Demo
name: ${{ env.stepName }}
id: build-win32-msvs-full-demo id: build-win32-msvs-full-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC working-directory: FreeRTOS/Demo/WIN32-MSVC
run: | run: |
# Build WIN32-MSVC Full Demo # ${{ env.stepName }}
echo "::group::Build WIN32-MSVC Full Demo" echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw $content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );' $newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c' $newContent | Set-Content -Path 'main.c'
msbuild WIN32.sln -t:rebuild msbuild WIN32.sln -t:rebuild
$exitStatus = $?
echo "::endgroup::" echo "::endgroup::"
if($? -eq 1) { if($exitStatus -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MSVC Full Demo" echo "${{ env.pwshPass }} ${{env.stepName}} ${{ env.pwshEnd }}"
}else { }else {
Write-Host -ForegroundColor red "Build WIN32-MSVC Full Demo Failed..." echo "${{ env.pwshFail }} ${{env.stepName}} ${{ env.pwshEnd }}"
exit 1 exit 1
} }
- name: Run and monitor WIN32-MSVC Full Demo - env:
if: success() || failure() && steps.build-win32-msvs-full-demo.outcome == 'success' stepName: Run and monitor WIN32-MSVC Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "No errors - tick count" success-line: "No errors - tick count"
retry-attempts: 3
- name: Build WIN32-MSVC Blinky Demo - env:
stepName: Build WIN32-MSVC Blinky Demo
name: ${{ env.stepName }}
id: build-win32-msvs-blinky-demo id: build-win32-msvs-blinky-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC working-directory: FreeRTOS/Demo/WIN32-MSVC
run: | run: |
# Build WIN32-MSVC Blinky Demo # ${{ env.stepName }}
echo "::group::MSBuild of WIN32-MSVC Blinky Demo" echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw $content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1' $newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1'
$newContent | Set-Content -Path 'main.c' $newContent | Set-Content -Path 'main.c'
# Perform MSBuild of WIN32-MSVC Blinky Demo
msbuild WIN32.sln -t:rebuild msbuild WIN32.sln -t:rebuild
echo "::endgroup::" echo "::endgroup::"
if($? -eq 1) { $exitStatus = $?
Write-Host -ForegroundColor green "Built the WIN32-MSVC Blinky Demo" if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else { }else {
Write-Host -ForegroundColor red "Build WIN32-MSVC Blinky Demo Failed..." echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1 exit 1
} }
- name: Run and monitor WIN32-MSVC Blinky Demo - env:
if: success() || failure() && steps.build-win32-msvs-blinky-demo.outcome == 'success' stepName: Run and monitor WIN32-MSVC Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "Message received from software timer" success-line: "Message received from software timer"
retry-attempts: 3
- name: Build WIN32-MSVC-Static-Allocation-Only Demo - env:
stepName: Build WIN32-MSVC-Static-Allocation-Only Demo
name: ${{ env.stepName }}
id: build-win32-msvs-static-allocation-only-demo id: build-win32-msvs-static-allocation-only-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only working-directory: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only
run: | run: |
# Build WIN32-MSVC-Static-Allocation-Only Demo # ${{ env.stepName }}
echo "::group::Build WIN32-MSVC-Static-Allocation-Only Demo" echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw $content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );' $newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c' $newContent | Set-Content -Path 'main.c'
msbuild WIN32.sln -t:rebuild msbuild WIN32.sln -t:rebuild
$exitStatus = $?
echo "::endgroup::" echo "::endgroup::"
if($? -eq 1) { if($exitStatus -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MSVC-Static-Allocation-Only Demo" echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else { }else {
Write-Host -ForegroundColor red "Build WIN32-MSVC-Static-Allocation-Only Demo Failed..." echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1 exit 1
} }
- name: Run and monitor WIN32-MSVC-Static-Allocation-Only Demo - env:
if: success() || failure() && steps.build-win32-msvs-static-allocation-only-demo.outcome == 'success' stepName:
Run and monitor WIN32-MSVC-Static-Allocation-Only Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only/Debug/RTOSDemo.exe exe-path: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "No errors - tick count" success-line: "No errors - tick count"
retry-attempts: 3
WIN32-MingW: WIN32-MingW:
name: WIN32 MingW name: WIN32 MingW
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- name: Checkout Repository - env:
uses: actions/checkout@v2 stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- name: Fetch Kernel Submodule - env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Fetch Kernel Submodule # ${{ env.stepName }}
echo "::group::Fetch Kernel Submodule" echo -e "::group::${{ env.stepName }}"
git submodule update --checkout --init --depth 1 FreeRTOS/Source git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::" echo -e "::endgroup::"
if [[ "$?" = "0" ]] echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
then
echo -e "\033[32;3mCloned the Kernel\033[0m"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
exit 1
fi
- env:
- name: Build WIN32-MingW Full Demo stepName: Build WIN32-MingW Full Demo
name: ${{ env.stepName }}
id: build-win32-mingw-full-demo id: build-win32-mingw-full-demo
working-directory: FreeRTOS/Demo/WIN32-MingW working-directory: FreeRTOS/Demo/WIN32-MingW
run: | run: |
# Build WIN32-MingW Full Demo # ${{ env.stepName }}
echo "::group::Build WIN32-MingW Full Demo" echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw $content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );' $newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c' $newContent | Set-Content -Path 'main.c'
gcc --version gcc --version
make --version make --version
make make
$exitStatus = $?
echo "::endgroup::" echo "::endgroup::"
if($? -eq 1) { if($exitStatus -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MingW Full Demo" echo "${{ env.pwshPass }} ${{ env.stepName }} ${{env.pwshEnd}}"
}else { }else {
Write-Host -ForegroundColor red "Build WIN32-MingW Full Demo Failed..." echo "${{ env.pwshFail }} ${{ env.stepName }} ${{env.pwshEnd}}"
exit 1 exit 1
} }
- name: Run and monitor WIN32-MingW Full Demo - env:
if: success() || failure() && steps.build-win32-mingw-full-demo.outcome == 'success' stepName: Run and monitor WIN32-MingW Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "No errors - tick count" success-line: "No errors - tick count"
- name: Build WIN32-MingW Blinky Demo - env:
stepName: Build WIN32-MingW Blinky Demo
name: ${{ env.stepName }}
id: build-win32-mingw-blinky-demo id: build-win32-mingw-blinky-demo
working-directory: FreeRTOS/Demo/WIN32-MingW working-directory: FreeRTOS/Demo/WIN32-MingW
run: | run: |
# Build WIN32-MingW Blinky Demo # ${{ env.stepName }}
echo "::group::Build WIN32-MingW Blinky Demo" echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw $content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1' $newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1'
$newContent = $newContent -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c' $newContent | Set-Content -Path 'main.c'
gcc --version gcc --version
make --version make --version
make make
$exitStatus = $?
echo "::endgroup::" echo "::endgroup::"
if($? -eq 1) { if($exitStatus -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MingW Blinky Demo" echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else { }else {
Write-Host -ForegroundColor red "Build WIN32-MingW Blinky Demo Failed..." echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1 exit 1
} }
- name: Run and monitor WIN32-MingW Blinky Demo - env:
if: success() || failure() && steps.build-win32-mingw-blinky-demo.outcome == 'success' stepName: Run and monitor WIN32-MingW Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "Message received from software timer" success-line: "Message received from software timer"
@ -197,96 +232,111 @@ jobs:
name: Posix GCC name: Posix GCC
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Repository - env:
uses: actions/checkout@v2 stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- name: Fetch Kernel Submodule - env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Fetch Kernel Submodule # ${{ env.stepName }}
echo "::group::Fetch Kernel Submodule" echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::" set -e
if [ "$?" = "0" ]; then exitStatus=$?
echo -e "\033[32;3mCloned the Kernel\033[0m" set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mKernel Clone Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Install GCC - env:
stepName: Install GCC
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Install GCC # ${{ env.stepName }}
echo "::group::Install GCC" echo -e "::group::${{ env.stepName }}"
set +e
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y install build-essential sudo apt-get -y install build-essential
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then
echo -e "\e[0;32mInstall GCC Passed\e[0m"
else
echo -e "\e[0;32mInstall GCC Failed\e[0m"
# If there is an error, set this flag high again so the exit 1 fails the run
set -e set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build Posix_GCC Demo for Coverage Test - env:
shell: bash stepName: Build Posix_GCC Full Demo
working-directory: FreeRTOS/Demo/Posix_GCC name: ${{ env.stepName }}
run: make -j COVERAGE_TEST=1
- name: Build Posix_GCC Full Demo
id: build-posix-gcc-full-demo id: build-posix-gcc-full-demo
shell: bash shell: bash
working-directory: FreeRTOS/Demo/Posix_GCC working-directory: FreeRTOS/Demo/Posix_GCC
run: | run: |
# Build Posix_GCC Full Demo # ${{ env.stepName }}
echo "::group::Build Posix_GCC Full Demo" echo -e "::group::${{ env.stepName }}"
set +e
sed -i -z "s/int[[:space:]]*main[[:space:]]*([[:space:]]*void[[:space:]]*)\n{/int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );/g" main.c sed -i -z "s/int[[:space:]]*main[[:space:]]*([[:space:]]*void[[:space:]]*)\n{/int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );/g" main.c
make clean
make -j make -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuild Posix_GCC Full Demo Passed\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild Posix_GCC Full Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Run and monitor Posix_GCC Full Demo - env:
if: success() || failure() && steps.build-posix-gcc-full-demo.outcome == 'success' stepName: Run and monitor Posix_GCC Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "OK: No errors" success-line: "OK: No errors"
retry-attempts: 3
- name: Build Posix_GCC Blinky Demo - env:
stepName: Build Posix_GCC Blinky Demo
name: ${{ env.stepName }}
id: build-posix-gcc-blinky-demo id: build-posix-gcc-blinky-demo
if: success() || failure()
shell: bash shell: bash
working-directory: FreeRTOS/Demo/Posix_GCC working-directory: FreeRTOS/Demo/Posix_GCC
run: | run: |
# Build Posix_GCC Blinky Demo # ${{ env.stepName }}
echo "::group::Build Posix_GCC Blinky Demo" echo -e "::group::${{ env.stepName }}"
rm -rf build rm -rf build
set +e
make -j USER_DEMO=BLINKY_DEMO make -j USER_DEMO=BLINKY_DEMO
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the Posix_GCC Blinky Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild Posix_GCC Blinky Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{env.stepName}} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Run and monitor Posix_GCC Blinky Demo - env:
if: success() || failure() && steps.build-posix-gcc-blinky-demo.outcome == 'success' stepName: Run and monitor Posix_GCC Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with: with:
exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo
log-dir: demo_run_logs
timeout-seconds: 60 timeout-seconds: 60
success-line: "Message received from software timer" success-line: "Message received from software timer"
@ -294,50 +344,69 @@ jobs:
name: GNU MSP430 Toolchain name: GNU MSP430 Toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Repository - env:
uses: actions/checkout@v2 stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
with:
submodules: true
- name: Fetch Kernel Submodule - env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Fetch Kernel Submodule # ${{ env.stepName }}
echo "::group::Fetch Kernel Submodule" echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mCloned the Kernel\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mKernel Clone Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Install MSP430 Toolchain - env:
stepName: Install MSP430 Toolchain
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Install MSP430 Toolchain # ${{ env.stepName }}
echo "::group::Install MSP430 Toolchain" echo -e "::group::${{ env.stepName }}"
set +e
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y install gcc-msp430 build-essential sudo apt-get -y install gcc-msp430 build-essential
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mInstalled the MSP430 Toolchain\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mInstalling the MSP430 ToolchainFailed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build msp430_GCC Demo - env:
stepName: Build msp430_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/msp430_GCC working-directory: FreeRTOS/Demo/msp430_GCC
run: | run: |
# Build msp430_GCC Demo # ${{ env.stepName }}
echo "::group::Build msp430_GCC Demo" echo -e "::group::${{ env.stepName }}"
set +e
make -j make -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the msp430_GCC Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuilding the msp430_GCC Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
@ -345,157 +414,220 @@ jobs:
name: GNU ARM Toolchain name: GNU ARM Toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Repository - env:
uses: actions/checkout@v2 stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- name: Fetch Kernel Submodule - env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash shell: bash
run: | run: |
# Fetch Kernel Submodule # ${{ env.stepName }}
echo "::group::Fetch Kernel Submodule" echo -e "::group::${{ env.stepName }}"
git submodule update --checkout --init --depth 1 FreeRTOS/Source set +e
echo "::endgroup::" git submodule update --checkout --init --depth 1 FreeRTOS/Source FreeRTOS/Demo/ThirdParty/Community-Supported-Demos
if [ "$?" = "0" ]; then exitStatus=$?
echo -e "\033[32;3mCloned the Kernel\033[0m" set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mKernel Clone Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Fetch Community-Supported-Demos Submodule - env:
stepName: Install GNU ARM Toolchain
name: Install GNU ARM Toolchain
shell: bash shell: bash
run: | run: |
# Fetch Community-Supported-Demos Submodule # ${{ env.stepName }}
echo "::group::Fetch Community-Supported-Demos Submodule" echo -e "::group::${{ env.stepName }}"
git submodule update --checkout --init --depth 1 FreeRTOS/Demo/ThirdParty/Community-Supported-Demos set +e
echo "::engdroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mCloned the Community-Supported-Demos\033[0m"
else
echo -e "\033[32;31mCommunity-Supported-Demos Clone Failed...\033[0m"
exit 1
fi
- name: Install GNU ARM Toolchain
shell: bash
run: |
# Install GNU ARM Toolchain
echo "::group::Install GNU ARM Toolchain"
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y install gcc-arm-none-eabi build-essential cmake git ninja-build python3-minimal sudo apt-get -y install gcc-arm-none-eabi build-essential cmake git ninja-build python3-minimal
echo "::endgroup::" sudo apt-get -y install qemu-system-arm qemu-efi
if [ "$?" = "0" ]; then exitStatus=$?
echo -e "\033[32;3mInstalled the GNU ARM Toolchain\033[0m" set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mInstalling GNU ARM Toolchain Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo - env:
stepName: Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC working-directory: FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC
run: | run: |
# Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo # ${{ env.stepName }}
echo "::group::Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo" echo -e "::group::${{ env.stepName }}"
set +e
make -j make -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuild CORTEX_MPU_M3_MPS2_QEMU_GCC Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_MPU_M3_MPS2_QEMU_GCC Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_LM3S102_GCC Demo - env:
stepName: Build CORTEX_LM3S102_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/CORTEX_LM3S102_GCC working-directory: FreeRTOS/Demo/CORTEX_LM3S102_GCC
run: | run: |
# Build CORTEX_LM3S102_GCC Demo # ${{ env.stepName }}
echo "::group::Build CORTEX_LM3S102_GCC Demo" echo -e "::group::${{ env.stepName }}"
make -j set +e
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_LM3S102_GCC Demo Kernel\033[0m"
else
echo -e "\033[32;31mBuild CORTEX_LM3S102_GCC Demo Failed...\033[0m"
exit 1
fi
- name: Build CORTEX_M3_MPS2_QEMU_GCC Demo
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC
run: |
# Build CORTEX_M3_MPS2_QEMU_GCC Demo
echo "::group::Build CORTEX_M3_MPS2_QEMU_GCC Demo"
make clean make clean
make -j make -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the CORTEX_M3_MPS2_QEMU_GCC Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_M3_MPS2_QEMU_GCC Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_M3_MPS2_QEMU_GCC Full Demo - env:
stepName: Build CORTEX_M3_MPS2_QEMU_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC
run: | run: |
# Build CORTEX_M3_MPS2_QEMU_GCC Full Demo # ${{ env.stepName }}
echo "::group::Build CORTEX_M3_MPS2_QEMU_GCC Full Demo" echo -e "::group::${{ env.stepName }}"
set +e
make clean
make -j
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Build CORTEX_M3_MPS2_QEMU_GCC Full Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make clean make clean
make FULL_DEMO=1 -j make FULL_DEMO=1 -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the CORTEX_M3_MPS2_QEMU_GCC Full Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_M3_MPS2_QEMU_GCC Full Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_LM3S811_GCC Demo - env:
stepName: Build CORTEX_LM3S811_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/CORTEX_LM3S811_GCC working-directory: FreeRTOS/Demo/CORTEX_LM3S811_GCC
run: | run: |
# Build CORTEX_LM3S811_GCC Demo # ${{ env.stepName }}
echo "::group::Build CORTEX_LM3S811_GCC Demo" echo -e "::group::${{ env.stepName }}"
set +e
make -j make -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the CORTEX_LM3S811_GCC Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_LM3S811_GCC Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_M0+_RP2040 Demos - env:
stepName: Build CORTEX_M0+_RP2040 Demos
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/CORTEX_M0+_RP2040 working-directory: FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/CORTEX_M0+_RP2040
run: | run: |
# Build CORTEX_M0+_RP2040 Demos # ${{ env.stepName }}
echo "::group::Build CORTEX_M0+_RP2040 Demos" echo -e "::group::${{ env.stepName }}"
set +e
git clone https://github.com/raspberrypi/pico-sdk.git git clone https://github.com/raspberrypi/pico-sdk.git
cmake -B build -DPICO_SDK_PATH=pico-sdk -GNinja cmake -B build -DPICO_SDK_PATH=pico-sdk -GNinja
ninja -C build --verbose ninja -C build --verbose
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt CORTEX_M0+_RP2040 Demos\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_M0+_RP2040 Demos Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- name: Build CORTEX_MPS2_QEMU_IAR_GCC Demo - env:
stepName: Build Qemu Runner File
name: ${{ env.stepName }}
shell: bash
working-directory: .github/scripts
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
gcc qemu_reader.c -o ../../FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/qemu_reader.out
exitStatus=$?
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Build CORTEX_MPS2_QEMU_IAR_GCC Demo
name: ${{ env.stepName }}
shell: bash shell: bash
working-directory: FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC working-directory: FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC
run: | run: |
# Build CORTEX_MPS2_QEMU_IAR_GCC Demo # ${{ env.stepName }}
echo "::group::Build CORTEX_MPS2_QEMU_IAR_GCC Demo" echo -e "::group::${{ env.stepName }}"
set +e
make -C build/gcc -j make -C build/gcc -j
echo "::endgroup::" exitStatus=$?
if [ "$?" = "0" ]; then set -e
echo -e "\033[32;3mBuilt the CORTEX_MPS2_QEMU_IAR_GCC Demo\033[0m" echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else else
echo -e "\033[32;31mBuild CORTEX_MPS2_QEMU_IAR_GCC Demo Failed...\033[0m" echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1 exit 1
fi fi
- env:
stepName: Run and monitor CORTEX_MPS2_QEMU_IAR_GCC Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/qemu_reader.out
timeout-seconds: 20
success-line: "Message received from software timer"
retry-attempts: 1

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
submodules: 'recursive' submodules: 'recursive'
fetch-depth: 5 fetch-depth: 5
@ -42,12 +42,12 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
submodules: 'recursive' submodules: 'recursive'
fetch-depth: 5 fetch-depth: 5
- name: Checkout the main branch from the FreeRTOS-Kernel repository - name: Checkout the main branch from the FreeRTOS-Kernel repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
path: ./FreeRTOS/Source path: ./FreeRTOS/Source
ref: main ref: main

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 16.0.31205.134

View file

@ -238,8 +238,8 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos, lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength, xRemainingBufferLength,
"{" "{"
"\""DEFENDER_REPORT_LOCAL_PORT_KEY"\": %u," "\""DEFENDER_REPORT_LOCAL_PORT_KEY "\": %u,"
"\""DEFENDER_REPORT_REMOTE_ADDR_KEY"\": \"%u.%u.%u.%u:%u\"" "\""DEFENDER_REPORT_REMOTE_ADDR_KEY "\": \"%u.%u.%u.%u:%u\""
"},", "},",
( unsigned int ) pxConn->usLocalPort, ( unsigned int ) pxConn->usLocalPort,
( unsigned int ) ( pxConn->ulRemoteIp >> 24 ) & 0xFF, ( unsigned int ) ( pxConn->ulRemoteIp >> 24 ) & 0xFF,
@ -399,13 +399,13 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos, lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength, xRemainingBufferLength,
"{" "{"
"\""DEFENDER_REPORT_HEADER_KEY"\": {" "\""DEFENDER_REPORT_HEADER_KEY "\": {"
"\""DEFENDER_REPORT_ID_KEY"\": %u," "\""DEFENDER_REPORT_ID_KEY "\": %u,"
"\""DEFENDER_REPORT_VERSION_KEY"\": \"%u.%u\"" "\""DEFENDER_REPORT_VERSION_KEY "\": \"%u.%u\""
"}," "},"
"\""DEFENDER_REPORT_METRICS_KEY"\": {" "\""DEFENDER_REPORT_METRICS_KEY "\": {"
"\""DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY"\": {" "\""DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY "\": {"
"\""DEFENDER_REPORT_PORTS_KEY"\": ", "\""DEFENDER_REPORT_PORTS_KEY "\": ",
( unsigned int ) ulReportId, ( unsigned int ) ulReportId,
( unsigned int ) ulMajorReportVersion, ( unsigned int ) ulMajorReportVersion,
( unsigned int ) ulMinorReportVersion ); ( unsigned int ) ulMinorReportVersion );
@ -448,10 +448,10 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos, lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength, xRemainingBufferLength,
"," ","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u" "\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"}," "},"
"\""DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY"\": {" "\""DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY "\": {"
"\""DEFENDER_REPORT_PORTS_KEY"\": ", "\""DEFENDER_REPORT_PORTS_KEY "\": ",
( unsigned int ) pxMetrics->xOpenTcpPortsArrayLength ); ( unsigned int ) pxMetrics->xOpenTcpPortsArrayLength );
if( !reportbuilderSNPRINTF_SUCCESS( lCharactersWritten, xRemainingBufferLength ) ) if( !reportbuilderSNPRINTF_SUCCESS( lCharactersWritten, xRemainingBufferLength ) )
@ -492,17 +492,17 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos, lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength, xRemainingBufferLength,
"," ","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u" "\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"}," "},"
"\""DEFENDER_REPORT_NETWORK_STATS_KEY"\": {" "\""DEFENDER_REPORT_NETWORK_STATS_KEY "\": {"
"\""DEFENDER_REPORT_BYTES_IN_KEY"\": %u," "\""DEFENDER_REPORT_BYTES_IN_KEY "\": %u,"
"\""DEFENDER_REPORT_BYTES_OUT_KEY"\": %u," "\""DEFENDER_REPORT_BYTES_OUT_KEY "\": %u,"
"\""DEFENDER_REPORT_PKTS_IN_KEY"\": %u," "\""DEFENDER_REPORT_PKTS_IN_KEY "\": %u,"
"\""DEFENDER_REPORT_PKTS_OUT_KEY"\": %u" "\""DEFENDER_REPORT_PKTS_OUT_KEY "\": %u"
"}," "},"
"\""DEFENDER_REPORT_TCP_CONNECTIONS_KEY"\": {" "\""DEFENDER_REPORT_TCP_CONNECTIONS_KEY "\": {"
"\""DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY"\": {" "\""DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY "\": {"
"\""DEFENDER_REPORT_CONNECTIONS_KEY"\": ", "\""DEFENDER_REPORT_CONNECTIONS_KEY "\": ",
( unsigned int ) pxMetrics->xOpenUdpPortsArrayLength, ( unsigned int ) pxMetrics->xOpenUdpPortsArrayLength,
( unsigned int ) pxMetrics->pxNetworkStats->uxBytesReceived, ( unsigned int ) pxMetrics->pxNetworkStats->uxBytesReceived,
( unsigned int ) pxMetrics->pxNetworkStats->uxBytesSent, ( unsigned int ) pxMetrics->pxNetworkStats->uxBytesSent,
@ -547,19 +547,19 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos, lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength, xRemainingBufferLength,
"," ","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u" "\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"}" "}"
"}" "}"
"}," "},"
"\""DEFENDER_REPORT_CUSTOM_METRICS_KEY"\": {" "\""DEFENDER_REPORT_CUSTOM_METRICS_KEY "\": {"
"\"stack_high_water_mark\": [" "\"stack_high_water_mark\": ["
"{" "{"
"\""DEFENDER_REPORT_NUMBER_KEY"\": %u" "\""DEFENDER_REPORT_NUMBER_KEY "\": %u"
"}" "}"
"]," "],"
"\"task_numbers\": [" "\"task_numbers\": ["
"{" "{"
"\""DEFENDER_REPORT_NUMBER_LIST_KEY"\": ", "\""DEFENDER_REPORT_NUMBER_LIST_KEY "\": ",
( unsigned int ) pxMetrics->xEstablishedConnectionsArrayLength, ( unsigned int ) pxMetrics->xEstablishedConnectionsArrayLength,
( unsigned int ) pxMetrics->ulStackHighWaterMark ); ( unsigned int ) pxMetrics->ulStackHighWaterMark );

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -20,8 +20,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
*
*/ */
#ifndef CORE_MQTT_CONFIG_H #ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H #define CORE_MQTT_CONFIG_H

View file

@ -1,5 +1,5 @@
/* /*
* AWS IoT Device SDK for Embedded C V202009.00 * FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * Permission is hereby granted, free of charge, to any person obtaining a copy of
@ -18,6 +18,10 @@
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
#ifndef SHADOW_CONFIG_H #ifndef SHADOW_CONFIG_H

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 16.0.31205.134

View file

@ -316,11 +316,11 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
configASSERT( pxDeserializedInfo->pPublishInfo != NULL ); configASSERT( pxDeserializedInfo->pPublishInfo != NULL );
pxPublishInfo = pxDeserializedInfo->pPublishInfo; pxPublishInfo = pxDeserializedInfo->pPublishInfo;
xStatus = FleetProvisioning_MatchTopic(pxPublishInfo->pTopicName, xStatus = FleetProvisioning_MatchTopic( pxPublishInfo->pTopicName,
pxPublishInfo->topicNameLength, pxPublishInfo->topicNameLength,
&xApi); &xApi );
if (xStatus != FleetProvisioningSuccess) if( xStatus != FleetProvisioningSuccess )
{ {
LogWarn( ( "Unexpected publish message received. Topic: %.*s.", LogWarn( ( "Unexpected publish message received. Topic: %.*s.",
( int ) pxPublishInfo->topicNameLength, ( int ) pxPublishInfo->topicNameLength,
@ -328,7 +328,7 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
} }
else else
{ {
if (xApi == FleetProvCborCreateCertFromCsrAccepted) if( xApi == FleetProvCborCreateCertFromCsrAccepted )
{ {
LogInfo( ( "Received accepted response from Fleet Provisioning CreateCertificateFromCsr API." ) ); LogInfo( ( "Received accepted response from Fleet Provisioning CreateCertificateFromCsr API." ) );
@ -341,13 +341,13 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
xPayloadLength = pxPublishInfo->payloadLength; xPayloadLength = pxPublishInfo->payloadLength;
} }
else if (xApi == FleetProvCborCreateCertFromCsrRejected) else if( xApi == FleetProvCborCreateCertFromCsrRejected )
{ {
LogError( ( "Received rejected response from Fleet Provisioning CreateCertificateFromCsr API." ) ); LogError( ( "Received rejected response from Fleet Provisioning CreateCertificateFromCsr API." ) );
xResponseStatus = ResponseRejected; xResponseStatus = ResponseRejected;
} }
else if (xApi == FleetProvCborRegisterThingAccepted) else if( xApi == FleetProvCborRegisterThingAccepted )
{ {
LogInfo( ( "Received accepted response from Fleet Provisioning RegisterThing API." ) ); LogInfo( ( "Received accepted response from Fleet Provisioning RegisterThing API." ) );
@ -360,7 +360,7 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
xPayloadLength = pxPublishInfo->payloadLength; xPayloadLength = pxPublishInfo->payloadLength;
} }
else if (xApi == FleetProvCborRegisterThingRejected) else if( xApi == FleetProvCborRegisterThingRejected )
{ {
LogError( ( "Received rejected response from Fleet Provisioning RegisterThing API." ) ); LogError( ( "Received rejected response from Fleet Provisioning RegisterThing API." ) );
@ -804,7 +804,7 @@ int prvFleetProvisioningTask( void * pvParameters )
} }
else else
{ {
LogInfo( ( "Sucessfully established connection with provisioned credentials." ) ); LogInfo( ( "Successfully established connection with provisioned credentials." ) );
xConnectionEstablished = true; xConnectionEstablished = true;
} }
} }

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.33027.164 VisualStudioVersion = 16.0.33027.164

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source"> <Filter Include="Source">

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -20,8 +20,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
*
*/ */
#ifndef CORE_MQTT_CONFIG_H #ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H #define CORE_MQTT_CONFIG_H

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 16.0.31205.134

View file

@ -379,6 +379,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
uint16_t usNextRetryBackOff = 0U; uint16_t usNextRetryBackOff = 0U;
#if defined( democonfigCLIENT_USERNAME ) #if defined( democonfigCLIENT_USERNAME )
/* /*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect * When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443. * to AWS IoT Core with Custom Authentication on port 443.
@ -394,6 +395,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn." #error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */ #endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */ #else /* if !defined( democonfigCLIENT_USERNAME ) */
/* /*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using * Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication. * x509 Certificate Authentication.

View file

@ -377,6 +377,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
uint16_t usNextRetryBackOff = 0U; uint16_t usNextRetryBackOff = 0U;
#if defined( democonfigCLIENT_USERNAME ) #if defined( democonfigCLIENT_USERNAME )
/* /*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect * When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443. * to AWS IoT Core with Custom Authentication on port 443.
@ -392,6 +393,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn." #error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */ #endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */ #else /* if !defined( democonfigCLIENT_USERNAME ) */
/* /*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using * Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication. * x509 Certificate Authentication.

View file

@ -24,7 +24,7 @@
* *
*/ */
/** /**
* @file aws_ota_codesigner_certificate.h * @file aws_ota_codesigner_certificate.h
* @brief Code signer certificate as char array. * @brief Code signer certificate as char array.
* *

View file

@ -24,7 +24,7 @@
* *
*/ */
/** /**
* @file code_signature_verification.h * @file code_signature_verification.h
* @brief Interface for code signature verification functions. * @brief Interface for code signature verification functions.
* *
@ -35,11 +35,11 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
/** /**
* @brief Validate the integrity of the new image to be activated. * @brief Validate the integrity of the new image to be activated.
* @param[in] pFileContext pointer to File context * @param[in] pFileContext pointer to File context
* @return OtaPalMainStatus_t , OtaPalSuccess if the signature of the image is valid. * @return OtaPalMainStatus_t , OtaPalSuccess if the signature of the image is valid.
*/ */
OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t* const pFileContext ); OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t * const pFileContext );
#endif #endif

View file

@ -24,7 +24,7 @@
* *
*/ */
/** /**
* @file code_signature_verification_mbedtls.c * @file code_signature_verification_mbedtls.c
* @brief Code signature verification using mbedtls crypto. * @brief Code signature verification using mbedtls crypto.
* *
@ -32,17 +32,17 @@
* the specified file using mbedtls for SHA256 ECDSA. * the specified file using mbedtls for SHA256 ECDSA.
*/ */
/* C runtime includes. */ /* C runtime includes. */
#include <string.h> #include <string.h>
/* FreeRTOS includes. */ /* FreeRTOS includes. */
#include "FreeRTOS.h" #include "FreeRTOS.h"
/* mbedTLS includes. */ /* mbedTLS includes. */
#if !defined( MBEDTLS_CONFIG_FILE ) #if !defined( MBEDTLS_CONFIG_FILE )
#include "mbedtls_config_v3.2.1.h" #include "mbedtls_config_v3.2.1.h"
#else #else
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#include "mbedtls/sha256.h" #include "mbedtls/sha256.h"
@ -62,7 +62,7 @@
*/ */
#define SHA256_DIGEST_BYTES 32 #define SHA256_DIGEST_BYTES 32
/* Size of buffer used in file operations on this platform (Windows). */ /* Size of buffer used in file operations on this platform (Windows). */
#define OTA_PAL_WIN_BUF_SIZE ( ( size_t ) 4096UL ) #define OTA_PAL_WIN_BUF_SIZE ( ( size_t ) 4096UL )
/** /**
@ -73,7 +73,7 @@
#define ASYMMETRIC_ALGORITHM_RSA 1 #define ASYMMETRIC_ALGORITHM_RSA 1
#define ASYMMETRIC_ALGORITHM_ECDSA 2 #define ASYMMETRIC_ALGORITHM_ECDSA 2
/** /**
* @brief Internal signature verification context structure. * @brief Internal signature verification context structure.
*/ */
typedef struct SignatureVerificationState typedef struct SignatureVerificationState
@ -92,9 +92,9 @@ typedef struct SignatureVerificationState
* *
* @return pdTRUE if initialization succeeds, or pdFALSE otherwise. * @return pdTRUE if initialization succeeds, or pdFALSE otherwise.
*/ */
static BaseType_t prvSignatureVerificationStart(void** ppvContext, static BaseType_t prvSignatureVerificationStart( void ** ppvContext,
BaseType_t xAsymmetricAlgorithm, BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm); BaseType_t xHashAlgorithm );
/** /**
* @brief Updates a cryptographic hash computation with the specified byte array. * @brief Updates a cryptographic hash computation with the specified byte array.
@ -103,9 +103,9 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
* @param[in] pucData Byte array that was signed. * @param[in] pucData Byte array that was signed.
* @param[in] xDataLength Length in bytes of data that was signed. * @param[in] xDataLength Length in bytes of data that was signed.
*/ */
static void prvSignatureVerificationUpdate(void* pvContext, static void prvSignatureVerificationUpdate( void * pvContext,
const uint8_t* pucData, const uint8_t * pucData,
size_t xDataLength); size_t xDataLength );
/** /**
* @brief Verifies a digital signature computation using the public key from the * @brief Verifies a digital signature computation using the public key from the
@ -120,40 +120,40 @@ static void prvSignatureVerificationUpdate(void* pvContext,
* *
* @return pdTRUE if the signature is correct or pdFALSE if the signature is invalid. * @return pdTRUE if the signature is correct or pdFALSE if the signature is invalid.
*/ */
static BaseType_t prvSignatureVerificationFinal(void* pvContext, static BaseType_t prvSignatureVerificationFinal( void * pvContext,
char* pcSignerCertificate, char * pcSignerCertificate,
size_t xSignerCertificateLength, size_t xSignerCertificateLength,
uint8_t* pucSignature, uint8_t * pucSignature,
size_t xSignatureLength); size_t xSignatureLength );
/* Read the specified signer certificate from the filesystem into a local buffer. The allocated /* Read the specified signer certificate from the filesystem into a local buffer. The allocated
* memory becomes the property of the caller who is responsible for freeing it. * memory becomes the property of the caller who is responsible for freeing it.
*/ */
static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName, static uint8_t * otaPal_ReadAndAssumeCertificate( const uint8_t * const pucCertName,
uint32_t* const ulSignerCertSize) uint32_t * const ulSignerCertSize )
{ {
FILE* pFile; FILE * pFile;
uint8_t* pucSignerCert = NULL; uint8_t * pucSignerCert = NULL;
uint8_t* pucCertData = NULL; uint8_t * pucCertData = NULL;
int32_t lSize = 0; /* For MISRA mandatory. */ int32_t lSize = 0; /* For MISRA mandatory. */
int32_t lWindowsError; int32_t lWindowsError;
pFile = fopen((const char*)pucCertName, "rb"); /*lint !e586 pFile = fopen( ( const char * ) pucCertName, "rb" ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
if (pFile != NULL) if( pFile != NULL )
{ {
lWindowsError = fseek(pFile, 0, SEEK_END); /*lint !e586 lWindowsError = fseek( pFile, 0, SEEK_END ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
if (lWindowsError == 0) /* fseek returns a non-zero value on error. */ if( lWindowsError == 0 ) /* fseek returns a non-zero value on error. */
{ {
lSize = (int32_t)ftell(pFile); /*lint !e586 Allow call in this context. */ lSize = ( int32_t ) ftell( pFile ); /*lint !e586 Allow call in this context. */
if (lSize != -1L) /* ftell returns -1 on error. */ if( lSize != -1L ) /* ftell returns -1 on error. */
{ {
lWindowsError = fseek(pFile, 0, SEEK_SET); /*lint !e586 lWindowsError = fseek( pFile, 0, SEEK_SET ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
} }
else /* ftell returned an error, pucSignerCert remains NULL. */ else /* ftell returned an error, pucSignerCert remains NULL. */
@ -162,60 +162,60 @@ static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName
} }
} /* else fseek returned an error, pucSignerCert remains NULL. */ } /* else fseek returned an error, pucSignerCert remains NULL. */
if (lWindowsError == 0) if( lWindowsError == 0 )
{ {
/* Allocate memory for the signer certificate plus a terminating zero so we can load and return it to the caller. */ /* Allocate memory for the signer certificate plus a terminating zero so we can load and return it to the caller. */
pucSignerCert = pvPortMalloc(lSize + 1); /*lint !e732 !e9034 !e9079 Allow conversion. */ pucSignerCert = pvPortMalloc( lSize + 1 ); /*lint !e732 !e9034 !e9079 Allow conversion. */
} }
if (pucSignerCert != NULL) if( pucSignerCert != NULL )
{ {
if (fread(pucSignerCert, 1, lSize, pFile) == (size_t)lSize) /*lint !e586 !e732 !e9034 if( fread( pucSignerCert, 1, lSize, pFile ) == ( size_t ) lSize ) /*lint !e586 !e732 !e9034
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
{ {
/* The crypto code requires the terminating zero to be part of the length so add 1 to the size. */ /* The crypto code requires the terminating zero to be part of the length so add 1 to the size. */
*ulSignerCertSize = lSize + 1; *ulSignerCertSize = lSize + 1;
pucSignerCert[lSize] = 0; pucSignerCert[ lSize ] = 0;
} }
else else
{ /* There was a problem reading the certificate file so free the memory and abort. */ { /* There was a problem reading the certificate file so free the memory and abort. */
vPortFree(pucSignerCert); vPortFree( pucSignerCert );
pucSignerCert = NULL; pucSignerCert = NULL;
} }
} }
else else
{ {
LogError(("Failed to allocate memory for signer cert contents.\r\n")); LogError( ( "Failed to allocate memory for signer cert contents.\r\n" ) );
/* Nothing special to do. */ /* Nothing special to do. */
} }
lWindowsError = fclose(pFile); /*lint !e586 lWindowsError = fclose( pFile ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
if (lWindowsError != 0) if( lWindowsError != 0 )
{ {
LogError(("File pointer operation failed.\r\n")); LogError( ( "File pointer operation failed.\r\n" ) );
pucSignerCert = NULL; pucSignerCert = NULL;
} }
} }
else else
{ {
LogError(("No such certificate file: %s. Using aws_ota_codesigner_certificate.h.\r\n", LogError( ( "No such certificate file: %s. Using aws_ota_codesigner_certificate.h.\r\n",
(const char*)pucCertName)); ( const char * ) pucCertName ) );
/* Allocate memory for the signer certificate plus a terminating zero so we can copy it and return to the caller. */ /* Allocate memory for the signer certificate plus a terminating zero so we can copy it and return to the caller. */
lSize = sizeof(signingcredentialSIGNING_CERTIFICATE_PEM); lSize = sizeof( signingcredentialSIGNING_CERTIFICATE_PEM );
pucSignerCert = pvPortMalloc(lSize); /*lint !e9029 !e9079 !e838 malloc proto requires void*. */ pucSignerCert = pvPortMalloc( lSize ); /*lint !e9029 !e9079 !e838 malloc proto requires void*. */
pucCertData = (uint8_t*)signingcredentialSIGNING_CERTIFICATE_PEM; /*lint !e9005 we don't modify the cert but it could be set by PKCS11 so it's not const. */ pucCertData = ( uint8_t * ) signingcredentialSIGNING_CERTIFICATE_PEM; /*lint !e9005 we don't modify the cert but it could be set by PKCS11 so it's not const. */
if (pucSignerCert != NULL) if( pucSignerCert != NULL )
{ {
memcpy(pucSignerCert, pucCertData, lSize); memcpy( pucSignerCert, pucCertData, lSize );
*ulSignerCertSize = lSize; *ulSignerCertSize = lSize;
} }
else else
{ {
LogError(("No memory for certificate of size %d!\r\n", lSize)); LogError( ( "No memory for certificate of size %d!\r\n", lSize ) );
} }
} }
@ -226,29 +226,29 @@ static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName
* @brief Verifies a cryptographic signature based on the signer * @brief Verifies a cryptographic signature based on the signer
* certificate, hash algorithm, and the data that was signed. * certificate, hash algorithm, and the data that was signed.
*/ */
static BaseType_t prvVerifySignature(char* pcSignerCertificate, static BaseType_t prvVerifySignature( char * pcSignerCertificate,
size_t xSignerCertificateLength, size_t xSignerCertificateLength,
BaseType_t xHashAlgorithm, BaseType_t xHashAlgorithm,
uint8_t* pucHash, uint8_t * pucHash,
size_t xHashLength, size_t xHashLength,
uint8_t* pucSignature, uint8_t * pucSignature,
size_t xSignatureLength) size_t xSignatureLength )
{ {
BaseType_t xResult = pdTRUE; BaseType_t xResult = pdTRUE;
mbedtls_x509_crt xCertCtx; mbedtls_x509_crt xCertCtx;
mbedtls_md_type_t xMbedHashAlg = MBEDTLS_MD_SHA256; mbedtls_md_type_t xMbedHashAlg = MBEDTLS_MD_SHA256;
(void)xHashAlgorithm; ( void ) xHashAlgorithm;
memset(&xCertCtx, 0, sizeof(mbedtls_x509_crt)); memset( &xCertCtx, 0, sizeof( mbedtls_x509_crt ) );
/* /*
* Decode and create a certificate context * Decode and create a certificate context
*/ */
mbedtls_x509_crt_init(&xCertCtx); mbedtls_x509_crt_init( &xCertCtx );
if (0 != mbedtls_x509_crt_parse( if( 0 != mbedtls_x509_crt_parse(
&xCertCtx, (const unsigned char*)pcSignerCertificate, xSignerCertificateLength)) &xCertCtx, ( const unsigned char * ) pcSignerCertificate, xSignerCertificateLength ) )
{ {
xResult = pdFALSE; xResult = pdFALSE;
} }
@ -256,15 +256,15 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/* /*
* Verify the signature using the public key from the decoded certificate * Verify the signature using the public key from the decoded certificate
*/ */
if (pdTRUE == xResult) if( pdTRUE == xResult )
{ {
if (0 != mbedtls_pk_verify( if( 0 != mbedtls_pk_verify(
&xCertCtx.pk, &xCertCtx.pk,
xMbedHashAlg, xMbedHashAlg,
pucHash, pucHash,
xHashLength, xHashLength,
pucSignature, pucSignature,
xSignatureLength)) xSignatureLength ) )
{ {
xResult = pdFALSE; xResult = pdFALSE;
} }
@ -273,7 +273,7 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/* /*
* Clean-up * Clean-up
*/ */
mbedtls_x509_crt_free(&xCertCtx); mbedtls_x509_crt_free( &xCertCtx );
return xResult; return xResult;
} }
@ -283,23 +283,23 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/** /**
* @brief Creates signature verification context. * @brief Creates signature verification context.
*/ */
static BaseType_t prvSignatureVerificationStart(void** ppvContext, static BaseType_t prvSignatureVerificationStart( void ** ppvContext,
BaseType_t xAsymmetricAlgorithm, BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm) BaseType_t xHashAlgorithm )
{ {
BaseType_t xResult = pdTRUE; BaseType_t xResult = pdTRUE;
SignatureVerificationState_t* pxCtx = NULL; SignatureVerificationState_t * pxCtx = NULL;
/* /*
* Allocate the context * Allocate the context
*/ */
if (NULL == (pxCtx = (SignatureVerificationStatePtr_t)pvPortMalloc( if( NULL == ( pxCtx = ( SignatureVerificationStatePtr_t ) pvPortMalloc(
sizeof(*pxCtx)))) /*lint !e9087 Allow casting void* to other types. */ sizeof( *pxCtx ) ) ) ) /*lint !e9087 Allow casting void* to other types. */
{ {
xResult = pdFALSE; xResult = pdFALSE;
} }
if (pdTRUE == xResult) if( pdTRUE == xResult )
{ {
*ppvContext = pxCtx; *ppvContext = pxCtx;
@ -312,8 +312,8 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
/* /*
* Initialize the requested hash type * Initialize the requested hash type
*/ */
mbedtls_sha256_init(&pxCtx->xSHA256Context); mbedtls_sha256_init( &pxCtx->xSHA256Context );
(void)mbedtls_sha256_starts(&pxCtx->xSHA256Context, 0); ( void ) mbedtls_sha256_starts( &pxCtx->xSHA256Context, 0 );
} }
return xResult; return xResult;
@ -322,59 +322,58 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
/** /**
* @brief Adds bytes to an in-progress hash for subsequent signature verification. * @brief Adds bytes to an in-progress hash for subsequent signature verification.
*/ */
static void prvSignatureVerificationUpdate(void* pvContext, static void prvSignatureVerificationUpdate( void * pvContext,
const uint8_t* pucData, const uint8_t * pucData,
size_t xDataLength) size_t xDataLength )
{ {
SignatureVerificationState_t* pxCtx = (SignatureVerificationStatePtr_t)pvContext; /*lint !e9087 Allow casting void* to other types. */ SignatureVerificationState_t * pxCtx = ( SignatureVerificationStatePtr_t ) pvContext; /*lint !e9087 Allow casting void* to other types. */
/* /*
* Add the data to the hash of the requested type * Add the data to the hash of the requested type
*/ */
(void)mbedtls_sha256_update(&pxCtx->xSHA256Context, pucData, xDataLength); ( void ) mbedtls_sha256_update( &pxCtx->xSHA256Context, pucData, xDataLength );
} }
/** /**
* @brief Performs signature verification on a cryptographic hash. * @brief Performs signature verification on a cryptographic hash.
*/ */
static BaseType_t prvSignatureVerificationFinal(void* pvContext, static BaseType_t prvSignatureVerificationFinal( void * pvContext,
char* pcSignerCertificate, char * pcSignerCertificate,
size_t xSignerCertificateLength, size_t xSignerCertificateLength,
uint8_t* pucSignature, uint8_t * pucSignature,
size_t xSignatureLength) size_t xSignatureLength )
{ {
BaseType_t xResult = pdFALSE; BaseType_t xResult = pdFALSE;
if (pvContext != NULL) if( pvContext != NULL )
{ {
SignatureVerificationStatePtr_t pxCtx = (SignatureVerificationStatePtr_t)pvContext; /*lint !e9087 Allow casting void* to other types. */ SignatureVerificationStatePtr_t pxCtx = ( SignatureVerificationStatePtr_t ) pvContext; /*lint !e9087 Allow casting void* to other types. */
uint8_t ucSHA256[SHA256_DIGEST_BYTES]; /* Reserve enough space for the larger for SHA256 results. */ uint8_t ucSHA256[ SHA256_DIGEST_BYTES ]; /* Reserve enough space for the larger for SHA256 results. */
uint8_t* pucHash = NULL; uint8_t * pucHash = NULL;
size_t xHashLength = 0; size_t xHashLength = 0;
if ((pcSignerCertificate != NULL) && if( ( pcSignerCertificate != NULL ) &&
(pucSignature != NULL) && ( pucSignature != NULL ) &&
(xSignerCertificateLength > 0UL) && ( xSignerCertificateLength > 0UL ) &&
(xSignatureLength > 0UL)) ( xSignatureLength > 0UL ) )
{ {
/* /*
* Finish the hash. * Finish the hash.
*/ */
(void)mbedtls_sha256_finish(&pxCtx->xSHA256Context, ucSHA256); ( void ) mbedtls_sha256_finish( &pxCtx->xSHA256Context, ucSHA256 );
pucHash = ucSHA256; pucHash = ucSHA256;
xHashLength = SHA256_DIGEST_BYTES; xHashLength = SHA256_DIGEST_BYTES;
/* /*
* Verify the signature. * Verify the signature.
*/ */
xResult = prvVerifySignature(pcSignerCertificate, xResult = prvVerifySignature( pcSignerCertificate,
xSignerCertificateLength, xSignerCertificateLength,
pxCtx->xHashAlgorithm, pxCtx->xHashAlgorithm,
pucHash, pucHash,
xHashLength, xHashLength,
pucSignature, pucSignature,
xSignatureLength); xSignatureLength );
} }
else else
{ {
@ -384,58 +383,59 @@ static BaseType_t prvSignatureVerificationFinal(void* pvContext,
/* /*
* Clean-up * Clean-up
*/ */
vPortFree(pxCtx); vPortFree( pxCtx );
} }
return xResult; return xResult;
} }
/* Verify the signature of the specified file. */ /* Verify the signature of the specified file. */
OtaPalMainStatus_t xValidateImageSignature(OtaFileContext_t* const C) OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t * const C )
{ {
OtaPalMainStatus_t eResult = OtaPalSuccess; OtaPalMainStatus_t eResult = OtaPalSuccess;
uint32_t ulBytesRead; uint32_t ulBytesRead;
uint32_t ulSignerCertSize; uint32_t ulSignerCertSize;
uint8_t* pucBuf, * pucSignerCert; uint8_t * pucBuf, * pucSignerCert;
void* pvSigVerifyContext; void * pvSigVerifyContext;
/* Verify an ECDSA-SHA256 signature. */ /* Verify an ECDSA-SHA256 signature. */
if (pdFALSE == prvSignatureVerificationStart(&pvSigVerifyContext, ASYMMETRIC_ALGORITHM_ECDSA, HASH_ALGORITHM_SHA256)) if( pdFALSE == prvSignatureVerificationStart( &pvSigVerifyContext, ASYMMETRIC_ALGORITHM_ECDSA, HASH_ALGORITHM_SHA256 ) )
{ {
eResult = OtaPalSignatureCheckFailed; eResult = OtaPalSignatureCheckFailed;
} }
else else
{ {
LogInfo(("Started %s signature verification, file: %s\r\n", LogInfo( ( "Started %s signature verification, file: %s\r\n",
OTA_JsonFileSignatureKey, (const char*)C->pCertFilepath)); OTA_JsonFileSignatureKey, ( const char * ) C->pCertFilepath ) );
pucSignerCert = otaPal_ReadAndAssumeCertificate((const uint8_t* const)C->pCertFilepath, &ulSignerCertSize); pucSignerCert = otaPal_ReadAndAssumeCertificate( ( const uint8_t * const ) C->pCertFilepath, &ulSignerCertSize );
if (pucSignerCert != NULL) if( pucSignerCert != NULL )
{ {
pucBuf = pvPortMalloc( OTA_PAL_WIN_BUF_SIZE ); /*lint !e9079 Allow conversion. */ pucBuf = pvPortMalloc( OTA_PAL_WIN_BUF_SIZE ); /*lint !e9079 Allow conversion. */
if (pucBuf != NULL) if( pucBuf != NULL )
{ {
/* Rewind the received file to the beginning. */ /* Rewind the received file to the beginning. */
if (fseek(C->pFile, 0L, SEEK_SET) == 0) /*lint !e586 if( fseek( C->pFile, 0L, SEEK_SET ) == 0 ) /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
{ {
do do
{ {
ulBytesRead = fread(pucBuf, 1, OTA_PAL_WIN_BUF_SIZE, C->pFile); /*lint !e586 ulBytesRead = fread( pucBuf, 1, OTA_PAL_WIN_BUF_SIZE, C->pFile ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
/* Include the file chunk in the signature validation. Zero size is OK. */ /* Include the file chunk in the signature validation. Zero size is OK. */
prvSignatureVerificationUpdate(pvSigVerifyContext, pucBuf, ulBytesRead); prvSignatureVerificationUpdate( pvSigVerifyContext, pucBuf, ulBytesRead );
} while (ulBytesRead > 0UL); } while( ulBytesRead > 0UL );
if (pdFALSE == prvSignatureVerificationFinal(pvSigVerifyContext, if( pdFALSE == prvSignatureVerificationFinal( pvSigVerifyContext,
(char*)pucSignerCert, ( char * ) pucSignerCert,
(size_t)ulSignerCertSize, ( size_t ) ulSignerCertSize,
C->pSignature->data, C->pSignature->data,
C->pSignature->size)) /*lint !e732 !e9034 Allow comparison in this context. */ C->pSignature->size ) ) /*lint !e732 !e9034 Allow comparison in this context. */
{ {
eResult = OtaPalSignatureCheckFailed; eResult = OtaPalSignatureCheckFailed;
} }
pvSigVerifyContext = NULL; /* The context has been freed by prvSignatureVerificationFinal(). */ pvSigVerifyContext = NULL; /* The context has been freed by prvSignatureVerificationFinal(). */
} }
else else
@ -444,16 +444,16 @@ OtaPalMainStatus_t xValidateImageSignature(OtaFileContext_t* const C)
} }
/* Free the temporary file page buffer. */ /* Free the temporary file page buffer. */
vPortFree(pucBuf); vPortFree( pucBuf );
} }
else else
{ {
LogError(("Failed to allocate buffer memory.\r\n")); LogError( ( "Failed to allocate buffer memory.\r\n" ) );
eResult = OtaPalOutOfMemory; eResult = OtaPalOutOfMemory;
} }
/* Free the signer certificate that we now own after prvReadAndAssumeCertificate(). */ /* Free the signer certificate that we now own after prvReadAndAssumeCertificate(). */
vPortFree(pucSignerCert); vPortFree( pucSignerCert );
} }
else else
{ {

View file

@ -52,7 +52,7 @@ static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t * const C
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static inline BaseType_t prvContextValidate( OtaFileContext_t* pFileContext ) static inline BaseType_t prvContextValidate( OtaFileContext_t * pFileContext )
{ {
return( ( pFileContext != NULL ) && return( ( pFileContext != NULL ) &&
( pFileContext->pFile != NULL ) ); /*lint !e9034 Comparison is correct for file pointer type. */ ( pFileContext->pFile != NULL ) ); /*lint !e9034 Comparison is correct for file pointer type. */
@ -63,19 +63,19 @@ static inline BaseType_t prvContextValidate( OtaFileContext_t* pFileContext )
/* Attempt to create a new receive file for the file chunks as they come in. */ /* Attempt to create a new receive file for the file chunks as they come in. */
OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t* const C ) OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C )
{ {
OtaPalMainStatus_t mainErr = OtaPalUninitialized; OtaPalMainStatus_t mainErr = OtaPalUninitialized;
OtaPalSubStatus_t subErr = 0; OtaPalSubStatus_t subErr = 0;
if( C != NULL ) if( C != NULL )
{ {
if ( C->pFilePath != NULL ) if( C->pFilePath != NULL )
{ {
C->pFile = fopen( ( const char * )C->pFilePath, "w+b" ); /*lint !e586 C->pFile = fopen( ( const char * ) C->pFilePath, "w+b" ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
if ( C->pFile != NULL ) if( C->pFile != NULL )
{ {
mainErr = OtaPalSuccess; mainErr = OtaPalSuccess;
LogInfo( ( "Receive file created.\r\n" ) ); LogInfo( ( "Receive file created.\r\n" ) );
@ -99,7 +99,7 @@ OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t* const C )
LogError( ( "ERROR - Invalid file context provided.\r\n" ) ); LogError( ( "ERROR - Invalid file context provided.\r\n" ) );
} }
return OTA_PAL_COMBINE_ERR(mainErr,subErr); return OTA_PAL_COMBINE_ERR( mainErr, subErr );
} }
@ -145,7 +145,7 @@ OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C )
mainErr = OtaPalFileAbort; mainErr = OtaPalFileAbort;
} }
return OTA_PAL_COMBINE_ERR(mainErr,subErr); return OTA_PAL_COMBINE_ERR( mainErr, subErr );
} }
/* Write a block of data to the specified file. */ /* Write a block of data to the specified file. */
@ -233,11 +233,10 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
else else
{ {
LogError( ( "Failed to pass %s signature verification: %d.\r\n", LogError( ( "Failed to pass %s signature verification: %d.\r\n",
OTA_JsonFileSignatureKey, OTA_PAL_COMBINE_ERR(mainErr,subErr) ) ); OTA_JsonFileSignatureKey, OTA_PAL_COMBINE_ERR( mainErr, subErr ) ) );
/* If we fail to verify the file signature that means the image is not valid. We need to set the image state to aborted. */ /* If we fail to verify the file signature that means the image is not valid. We need to set the image state to aborted. */
otaPal_SetPlatformImageState( C, OtaImageStateAborted ); otaPal_SetPlatformImageState( C, OtaImageStateAborted );
} }
} }
else /* Invalid OTA Context. */ else /* Invalid OTA Context. */
@ -247,17 +246,17 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
mainErr = OtaPalFileClose; mainErr = OtaPalFileClose;
} }
return OTA_PAL_COMBINE_ERR(mainErr,subErr); return OTA_PAL_COMBINE_ERR( mainErr, subErr );
} }
/* Verify the signature of the specified file. */ /* Verify the signature of the specified file. */
static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t* const C ) static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t * const C )
{ {
OtaPalMainStatus_t eResult = OtaPalSignatureCheckFailed; OtaPalMainStatus_t eResult = OtaPalSignatureCheckFailed;
if ( prvContextValidate( C ) == pdTRUE ) if( prvContextValidate( C ) == pdTRUE )
{ {
eResult = xValidateImageSignature( C ); eResult = xValidateImageSignature( C );
} }
@ -271,40 +270,41 @@ static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t* const C )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t* const pFileContext ) OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const pFileContext )
{ {
(void)pFileContext; ( void ) pFileContext;
/* Return no error. Windows implementation does not reset device. */ /* Return no error. Windows implementation does not reset device. */
return OTA_PAL_COMBINE_ERR(OtaPalSuccess,0); return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t* const pFileContext ) OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const pFileContext )
{ {
(void)pFileContext; ( void ) pFileContext;
/* Return no error. Windows implementation simply does nothing on activate. /* Return no error. Windows implementation simply does nothing on activate.
* To run the new firmware image, double click the newly downloaded exe */ * To run the new firmware image, double click the newly downloaded exe */
return OTA_PAL_COMBINE_ERR(OtaPalSuccess,0); return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
} }
/* /*
* Set the final state of the last transferred (final) OTA file (or bundle). * Set the final state of the last transferred (final) OTA file (or bundle).
* On Windows, the state of the OTA image is stored in PlaformImageState.txt. * On Windows, the state of the OTA image is stored in PlatformImageState.txt.
*/ */
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileContext, OtaImageState_t eState ) OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileContext,
OtaImageState_t eState )
{ {
(void)pFileContext; ( void ) pFileContext;
OtaPalMainStatus_t mainErr = OtaPalSuccess; OtaPalMainStatus_t mainErr = OtaPalSuccess;
OtaPalSubStatus_t subErr = 0; OtaPalSubStatus_t subErr = 0;
FILE * pstPlatformImageState; FILE * pstPlatformImageState;
if( eState != OtaImageStateUnknown && eState <= OtaLastImageState ) if( ( eState != OtaImageStateUnknown ) && ( eState <= OtaLastImageState ) )
{ {
pstPlatformImageState = fopen( "PlatformImageState.txt", "w+b" ); /*lint !e586 pstPlatformImageState = fopen( "PlatformImageState.txt", "w+b" ); /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
@ -341,7 +341,7 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileConte
mainErr = OtaPalBadImageState; mainErr = OtaPalBadImageState;
} }
return OTA_PAL_COMBINE_ERR(mainErr,subErr); return OTA_PAL_COMBINE_ERR( mainErr, subErr );
} }
/* Get the state of the currently running image. /* Get the state of the currently running image.
@ -358,7 +358,7 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileConte
*/ */
OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileContext ) OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileContext )
{ {
(void)pFileContext; ( void ) pFileContext;
FILE * pstPlatformImageState; FILE * pstPlatformImageState;
OtaImageState_t eSavedAgentState = OtaImageStateUnknown; OtaImageState_t eSavedAgentState = OtaImageStateUnknown;
@ -369,23 +369,25 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
if( pstPlatformImageState != NULL ) if( pstPlatformImageState != NULL )
{ {
if( 1 != fread( &eSavedAgentState, sizeof(OtaImageState_t), 1, pstPlatformImageState ) ) /*lint !e586 !e9029 if( 1 != fread( &eSavedAgentState, sizeof( OtaImageState_t ), 1, pstPlatformImageState ) ) /*lint !e586 !e9029
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
{ {
/* If an error occurred reading the file, mark the state as aborted. */ /* If an error occurred reading the file, mark the state as aborted. */
LogError( ( "Unable to read image state file.\r\n" ) ); LogError( ( "Unable to read image state file.\r\n" ) );
ePalState = ( OtaPalImageStateInvalid | (errno & OTA_PAL_ERR_MASK) ); ePalState = ( OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) );
} }
else else
{ {
switch (eSavedAgentState) switch( eSavedAgentState )
{ {
case OtaImageStateTesting: case OtaImageStateTesting:
ePalState = OtaPalImageStatePendingCommit; ePalState = OtaPalImageStatePendingCommit;
break; break;
case OtaImageStateAccepted: case OtaImageStateAccepted:
ePalState = OtaPalImageStateValid; ePalState = OtaPalImageStateValid;
break; break;
case OtaImageStateRejected: case OtaImageStateRejected:
case OtaImageStateAborted: case OtaImageStateAborted:
default: default:
@ -394,12 +396,11 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
} }
} }
if( 0 != fclose( pstPlatformImageState ) ) /*lint !e586 if( 0 != fclose( pstPlatformImageState ) ) /*lint !e586
* C standard library call is being used for portability. */ * C standard library call is being used for portability. */
{ {
LogError( ( "Unable to close image state file.\r\n" ) ); LogError( ( "Unable to close image state file.\r\n" ) );
ePalState = (OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) ); ePalState = ( OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) );
} }
} }
else else
@ -415,5 +416,5 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
/* Provide access to private members for testing. */ /* Provide access to private members for testing. */
#ifdef FREERTOS_ENABLE_UNIT_TESTS #ifdef FREERTOS_ENABLE_UNIT_TESTS
#include "aws_ota_pal_test_access_define.h" #include "aws_ota_pal_test_access_define.h"
#endif #endif

View file

@ -26,7 +26,7 @@
/** /**
* @file ota_pal.h * @file ota_pal.h
* @brief Function declarations for ota_ptal.c. * @brief Function declarations for ota_pal.c.
*/ */
#ifndef _OTA_PAL_H_ #ifndef _OTA_PAL_H_

View file

@ -672,7 +672,7 @@ static void prvMQTTAgentTask( void * pParam );
* *
* The implementation uses MQTT agent to queue a publish request. It then waits * The implementation uses MQTT agent to queue a publish request. It then waits
* for the request complete notification from the agent. The notification along with result of the * for the request complete notification from the agent. The notification along with result of the
* operation is sent back to the caller task using xTaksNotify API. For publishes involving QOS 1 and * operation is sent back to the caller task using xTaskNotify API. For publishes involving QOS 1 and
* QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function * QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function
* to fetch new job, provide status update and send other control related messages to the MQTT broker. * to fetch new job, provide status update and send other control related messages to the MQTT broker.
* *
@ -808,7 +808,7 @@ static void prvMqttDataCallback( void * pContext,
* *
* The callback is not subscribed with MQTT broker, but only with local subscription manager. * The callback is not subscribed with MQTT broker, but only with local subscription manager.
* A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is * A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is
* forwarded to this callback for filteration. Right now the callback is used to filter responses to job requests * forwarded to this callback for filtration. Right now the callback is used to filter responses to job requests
* from the OTA service. * from the OTA service.
* *
* @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection. * @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection.
@ -1186,12 +1186,12 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext,
static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext, static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext,
MQTTAgentReturnInfo_t * pxReturnInfo ) MQTTAgentReturnInfo_t * pxReturnInfo )
{ {
MQTTAgentSubscribeArgs_t * pSubsribeArgs; MQTTAgentSubscribeArgs_t * pSubscribeArgs;
if( pxReturnInfo->returnCode == MQTTSuccess ) if( pxReturnInfo->returnCode == MQTTSuccess )
{ {
pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs ); pSubscribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength ); prvRegisterOTACallback( pSubscribeArgs->pSubscribeInfo->pTopicFilter, pSubscribeArgs->pSubscribeInfo->topicFilterLength );
} }
/* Store the result in the application defined context so the task that /* Store the result in the application defined context so the task that
@ -1432,6 +1432,7 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) #if defined( democonfigUSE_AWS_IOT_CORE_BROKER )
#if defined( democonfigCLIENT_USERNAME ) #if defined( democonfigCLIENT_USERNAME )
/* /*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect * When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443. * to AWS IoT Core with Custom Authentication on port 443.
@ -1447,6 +1448,7 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn." #error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */ #endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */ #else /* if !defined( democonfigCLIENT_USERNAME ) */
/* /*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using * Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication. * x509 Certificate Authentication.
@ -2501,7 +2503,7 @@ static BaseType_t prvRunOTADemo( void )
} }
/** /**
* Remvove callback for receiving messages intended for OTA agent from broker, * Remove callback for receiving messages intended for OTA agent from broker,
* for which the topic has not been subscribed for. * for which the topic has not been subscribed for.
*/ */
removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext, removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext,

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -76,8 +76,9 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_STATE_ARRAY_MAX_COUNT 10U #define MQTT_STATE_ARRAY_MAX_COUNT 10U
/*********************** coreMQTT Agent Configurations **********************/ /*********************** coreMQTT Agent Configurations **********************/
/**
/**
* @brief The maximum number of pending acknowledgments to track for a single * @brief The maximum number of pending acknowledgments to track for a single
* connection. * connection.
* *
@ -88,7 +89,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U ) #define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U )
/** /**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so * @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before * not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop(). * exiting the blocked state so it can call MQTT_ProcessLoop().
@ -99,7 +100,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 ) #define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 )
/** /**
* @brief The number of command structures to allocate in the pool * @brief The number of command structures to allocate in the pool
* for the agent. * for the agent.
*/ */

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 16.0.31205.134

View file

@ -304,7 +304,7 @@
#ifndef democonfigCLIENT_IDENTIFIER #ifndef democonfigCLIENT_IDENTIFIER
/** /**
* @brief The MQTT client identifier used in this example. Each client identifier * @brief The MQTT client identifier used in this example. Each client identifier
* must be unique so edit as required to ensure no two clients connecting to the * must be unique so edit as required to ensure no two clients connecting to the
* same broker use the same client identifier. Using a #define is for convenience * same broker use the same client identifier. Using a #define is for convenience
@ -320,10 +320,10 @@
#error "Please define Root CA certificate of the MQTT broker(democonfigROOT_CA_PEM) in demo_config.h." #error "Please define Root CA certificate of the MQTT broker(democonfigROOT_CA_PEM) in demo_config.h."
#endif #endif
/* If no username is defined, then a client certificate/key is required. */ /* If no username is defined, then a client certificate/key is required. */
#ifndef democonfigCLIENT_USERNAME #ifndef democonfigCLIENT_USERNAME
/* /*
*!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for *!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for
*!!! convenience of demonstration only. Production devices should *!!! convenience of demonstration only. Production devices should
*!!! store keys securely, such as within a secure element. *!!! store keys securely, such as within a secure element.
@ -337,13 +337,13 @@
#endif #endif
#else #else
/* If a username is defined, a client password also would need to be defined for /* If a username is defined, a client password also would need to be defined for
* client authentication. */ * client authentication. */
#ifndef democonfigCLIENT_PASSWORD #ifndef democonfigCLIENT_PASSWORD
#error "Please define client password(democonfigCLIENT_PASSWORD) in demo_config.h for client authentication based on username/password." #error "Please define client password(democonfigCLIENT_PASSWORD) in demo_config.h for client authentication based on username/password."
#endif #endif
/* AWS IoT MQTT broker port needs to be 443 for client authentication based on /* AWS IoT MQTT broker port needs to be 443 for client authentication based on
* username/password. */ * username/password. */
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) && democonfigMQTT_BROKER_PORT != 443 #if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) && democonfigMQTT_BROKER_PORT != 443
#error "Broker port(democonfigMQTT_BROKER_PORT) should be defined as 443 in demo_config.h for client authentication based on username/password in AWS IoT Core." #error "Broker port(democonfigMQTT_BROKER_PORT) should be defined as 443 in demo_config.h for client authentication based on username/password in AWS IoT Core."
@ -529,7 +529,7 @@ static void prvMQTTAgentTask( void * pParam );
* *
* The implementation uses MQTT agent to queue a publish request. It then waits * The implementation uses MQTT agent to queue a publish request. It then waits
* for the request complete notification from the agent. The notification along with result of the * for the request complete notification from the agent. The notification along with result of the
* operation is sent back to the caller task using xTaksNotify API. For publishes involving QOS 1 and * operation is sent back to the caller task using xTaskNotify API. For publishes involving QOS 1 and
* QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function * QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function
* to fetch new job, provide status update and send other control related messages to the MQTT broker. * to fetch new job, provide status update and send other control related messages to the MQTT broker.
* *
@ -593,7 +593,7 @@ static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter,
* within ota_config.h. This function is used to fetch a free buffer from the pool for processing * within ota_config.h. This function is used to fetch a free buffer from the pool for processing
* by the OTA agent task. It uses a mutex for thread safe access to the pool. * by the OTA agent task. It uses a mutex for thread safe access to the pool.
* *
* @return A pointer to an unusued buffer. NULL if there are no buffers available. * @return A pointer to an unused buffer. NULL if there are no buffers available.
*/ */
static OtaEventData_t * prvOTAEventBufferGet( void ); static OtaEventData_t * prvOTAEventBufferGet( void );
@ -667,7 +667,7 @@ static void prvMqttDataCallback( void * pContext,
* *
* The callback is not subscribed with MQTT broker, but only with local subscription manager. * The callback is not subscribed with MQTT broker, but only with local subscription manager.
* A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is * A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is
* forwarded to this callback for filteration. Right now the callback is used to filter responses to job requests * forwarded to this callback for filtration. Right now the callback is used to filter responses to job requests
* from the OTA service. * from the OTA service.
* *
* @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection. * @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection.
@ -1043,12 +1043,12 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext,
static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext, static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext,
MQTTAgentReturnInfo_t * pxReturnInfo ) MQTTAgentReturnInfo_t * pxReturnInfo )
{ {
MQTTAgentSubscribeArgs_t * pSubsribeArgs; MQTTAgentSubscribeArgs_t * pSubscribeArgs;
if( pxReturnInfo->returnCode == MQTTSuccess ) if( pxReturnInfo->returnCode == MQTTSuccess )
{ {
pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs ); pSubscribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength ); prvRegisterOTACallback( pSubscribeArgs->pSubscribeInfo->pTopicFilter, pSubscribeArgs->pSubscribeInfo->topicFilterLength );
} }
/* Store the result in the application defined context so the task that /* Store the result in the application defined context so the task that
@ -1289,6 +1289,7 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) #if defined( democonfigUSE_AWS_IOT_CORE_BROKER )
#if defined( democonfigCLIENT_USERNAME ) #if defined( democonfigCLIENT_USERNAME )
/* /*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect * When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443. * to AWS IoT Core with Custom Authentication on port 443.
@ -1304,12 +1305,12 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn." #error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */ #endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */ #else /* if !defined( democonfigCLIENT_USERNAME ) */
/* /*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using * Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication. * x509 Certificate Authentication.
*/ */
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL }; static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */ #endif /* !defined( democonfigCLIENT_USERNAME ) */
/* /*
@ -2037,7 +2038,7 @@ static BaseType_t prvRunOTADemo( void )
} }
/** /**
* Remvove callback for receiving messages intended for OTA agent from broker, * Remove callback for receiving messages intended for OTA agent from broker,
* for which the topic has not been subscribed for. * for which the topic has not been subscribed for.
*/ */
removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext, removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext,
@ -2086,6 +2087,7 @@ void vOtaDemoTask( void * pvParam )
if( xPlatformIsNetworkUp() == pdFALSE ) if( xPlatformIsNetworkUp() == pdFALSE )
{ {
LogInfo( ( "Waiting for the network link up event..." ) ); LogInfo( ( "Waiting for the network link up event..." ) );
while( xPlatformIsNetworkUp() == pdFALSE ) while( xPlatformIsNetworkUp() == pdFALSE )
{ {
vTaskDelay( pdMS_TO_TICKS( 1000U ) ); vTaskDelay( pdMS_TO_TICKS( 1000U ) );

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -76,8 +76,9 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_STATE_ARRAY_MAX_COUNT 10U #define MQTT_STATE_ARRAY_MAX_COUNT 10U
/*********************** coreMQTT Agent Configurations **********************/ /*********************** coreMQTT Agent Configurations **********************/
/**
/**
* @brief The maximum number of pending acknowledgments to track for a single * @brief The maximum number of pending acknowledgments to track for a single
* connection. * connection.
* *
@ -88,7 +89,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U ) #define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U )
/** /**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so * @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before * not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop(). * exiting the blocked state so it can call MQTT_ProcessLoop().
@ -99,7 +100,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/ */
#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 ) #define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 )
/** /**
* @brief The number of command structures to allocate in the pool * @brief The number of command structures to allocate in the pool
* for the agent. * for the agent.
*/ */

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134 VisualStudioVersion = 16.0.31205.134

View file

@ -41,25 +41,28 @@
#include "FreeRTOS_server_private.h" #include "FreeRTOS_server_private.h"
/* Remove the entire file if TCP is not being used. */ /* Remove the entire file if TCP is not being used. */
#if( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) ) #if ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) )
#if !defined( ARRAY_SIZE ) #if !defined( ARRAY_SIZE )
#define ARRAY_SIZE(x) ( BaseType_t ) (sizeof( x ) / sizeof( x )[ 0 ] ) #define ARRAY_SIZE( x ) ( BaseType_t ) ( sizeof( x ) / sizeof( x )[ 0 ] )
#endif #endif
static void prvReceiveNewClient( TCPServer_t *pxServer, BaseType_t xIndex, Socket_t xNexSocket ); static void prvReceiveNewClient( TCPServer_t * pxServer,
static char *strnew( const char *pcString ); BaseType_t xIndex,
Socket_t xNexSocket );
static char * strnew( const char * pcString );
/* Remove slashes at the end of a path. */ /* Remove slashes at the end of a path. */
static void prvRemoveSlash( char *pcDir ); static void prvRemoveSlash( char * pcDir );
TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount ) TCPServer_t * FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG * pxConfigs,
{ BaseType_t xCount )
TCPServer_t *pxServer; {
SocketSet_t xSocketSet; TCPServer_t * pxServer;
SocketSet_t xSocketSet;
/* Create a new server. /* Create a new server.
xPort / xPortAlt : Make the service available on 1 or 2 public port numbers. */ * xPort / xPortAlt : Make the service available on 1 or 2 public port numbers. */
xSocketSet = FreeRTOS_CreateSocketSet(); xSocketSet = FreeRTOS_CreateSocketSet();
if( xSocketSet != NULL ) if( xSocketSet != NULL )
@ -69,6 +72,7 @@ SocketSet_t xSocketSet;
xSize = sizeof( *pxServer ) - sizeof( pxServer->xServers ) + xCount * sizeof( pxServer->xServers[ 0 ] ); xSize = sizeof( *pxServer ) - sizeof( pxServer->xServers ) + xCount * sizeof( pxServer->xServers[ 0 ] );
pxServer = ( TCPServer_t * ) pvPortMallocLarge( xSize ); pxServer = ( TCPServer_t * ) pvPortMallocLarge( xSize );
if( pxServer != NULL ) if( pxServer != NULL )
{ {
struct freertos_sockaddr xAddress; struct freertos_sockaddr xAddress;
@ -88,7 +92,7 @@ SocketSet_t xSocketSet;
Socket_t xSocket; Socket_t xSocket;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
FreeRTOS_printf( ( "TCP socket on port %d\n", ( int )xPortNumber ) ); FreeRTOS_printf( ( "TCP socket on port %d\n", ( int ) xPortNumber ) );
if( xSocket != FREERTOS_INVALID_SOCKET ) if( xSocket != FREERTOS_INVALID_SOCKET )
{ {
@ -111,15 +115,16 @@ SocketSet_t xSocketSet;
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
#if( ipconfigHTTP_RX_BUFSIZE > 0 ) #if ( ipconfigHTTP_RX_BUFSIZE > 0 )
{ {
if( pxConfigs[ xIndex ].eType == eSERVER_HTTP ) if( pxConfigs[ xIndex ].eType == eSERVER_HTTP )
{ {
WinProperties_t xWinProps; WinProperties_t xWinProps;
memset( &xWinProps, '\0', sizeof( xWinProps ) ); memset( &xWinProps, '\0', sizeof( xWinProps ) );
/* The parent socket itself won't get connected. The properties below /* The parent socket itself won't get connected. The properties below
will be inherited by each new child socket. */ * will be inherited by each new child socket. */
xWinProps.lTxBufSize = ipconfigHTTP_TX_BUFSIZE; xWinProps.lTxBufSize = ipconfigHTTP_TX_BUFSIZE;
xWinProps.lTxWinSize = ipconfigHTTP_TX_WINSIZE; xWinProps.lTxWinSize = ipconfigHTTP_TX_WINSIZE;
xWinProps.lRxBufSize = ipconfigHTTP_RX_BUFSIZE; xWinProps.lRxBufSize = ipconfigHTTP_RX_BUFSIZE;
@ -129,9 +134,9 @@ SocketSet_t xSocketSet;
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
} }
} }
#endif #endif /* if ( ipconfigHTTP_RX_BUFSIZE > 0 ) */
FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_READ|eSELECT_EXCEPT ); FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_READ | eSELECT_EXCEPT );
pxServer->xServers[ xIndex ].xSocket = xSocket; pxServer->xServers[ xIndex ].xSocket = xSocket;
pxServer->xServers[ xIndex ].eType = pxConfigs[ xIndex ].eType; pxServer->xServers[ xIndex ].eType = pxConfigs[ xIndex ].eType;
pxServer->xServers[ xIndex ].pcRootDir = strnew( pxConfigs[ xIndex ].pcRootDir ); pxServer->xServers[ xIndex ].pcRootDir = strnew( pxConfigs[ xIndex ].pcRootDir );
@ -153,20 +158,22 @@ SocketSet_t xSocketSet;
} }
return pxServer; return pxServer;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvReceiveNewClient( TCPServer_t *pxServer, BaseType_t xIndex, Socket_t xNexSocket ) static void prvReceiveNewClient( TCPServer_t * pxServer,
{ BaseType_t xIndex,
TCPClient_t *pxClient = NULL; Socket_t xNexSocket )
BaseType_t xSize = 0; {
FTCPWorkFunction fWorkFunc = NULL; TCPClient_t * pxClient = NULL;
FTCPDeleteFunction fDeleteFunc = NULL; BaseType_t xSize = 0;
const char *pcType = "Unknown"; FTCPWorkFunction fWorkFunc = NULL;
FTCPDeleteFunction fDeleteFunc = NULL;
const char * pcType = "Unknown";
/*_RB_ Can the work and delete functions be part of the xSERVER_CONFIG structure /*_RB_ Can the work and delete functions be part of the xSERVER_CONFIG structure
becomes generic, with no pre-processing required? */ * becomes generic, with no pre-processing required? */
#if( ipconfigUSE_HTTP != 0 ) #if ( ipconfigUSE_HTTP != 0 )
{ {
if( pxServer->xServers[ xIndex ].eType == eSERVER_HTTP ) if( pxServer->xServers[ xIndex ].eType == eSERVER_HTTP )
{ {
@ -178,7 +185,7 @@ const char *pcType = "Unknown";
} }
#endif /* ipconfigUSE_HTTP != 0 */ #endif /* ipconfigUSE_HTTP != 0 */
#if( ipconfigUSE_FTP != 0 ) #if ( ipconfigUSE_FTP != 0 )
{ {
if( pxServer->xServers[ xIndex ].eType == eSERVER_FTP ) if( pxServer->xServers[ xIndex ].eType == eSERVER_FTP )
{ {
@ -193,7 +200,7 @@ const char *pcType = "Unknown";
/* Malloc enough space for a new HTTP-client */ /* Malloc enough space for a new HTTP-client */
if( xSize ) if( xSize )
{ {
pxClient = ( TCPClient_t* ) pvPortMallocLarge( xSize ); pxClient = ( TCPClient_t * ) pvPortMallocLarge( xSize );
} }
if( pxClient != NULL ) if( pxClient != NULL )
@ -210,37 +217,39 @@ const char *pcType = "Unknown";
pxClient->fDeleteFunction = fDeleteFunc; pxClient->fDeleteFunction = fDeleteFunc;
pxServer->pxClients = pxClient; pxServer->pxClients = pxClient;
FreeRTOS_FD_SET( xNexSocket, pxServer->xSocketSet, eSELECT_READ|eSELECT_EXCEPT ); FreeRTOS_FD_SET( xNexSocket, pxServer->xSocketSet, eSELECT_READ | eSELECT_EXCEPT );
} }
else else
{ {
pcType = "closed"; pcType = "closed";
FreeRTOS_closesocket( xNexSocket ); FreeRTOS_closesocket( xNexSocket );
} }
{ {
struct freertos_sockaddr xRemoteAddress; struct freertos_sockaddr xRemoteAddress;
FreeRTOS_GetRemoteAddress( pxClient->xSocket, &xRemoteAddress ); FreeRTOS_GetRemoteAddress( pxClient->xSocket, &xRemoteAddress );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{ {
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, (unsigned)FreeRTOS_ntohl( xRemoteAddress.sin_address.ulIP_IPv4 ) ) ); FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, ( unsigned ) FreeRTOS_ntohl( xRemoteAddress.sin_address.ulIP_IPv4 ) ) );
} }
#else #else
{ {
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, (unsigned)FreeRTOS_ntohl( xRemoteAddress.sin_addr ) ) ); FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, ( unsigned ) FreeRTOS_ntohl( xRemoteAddress.sin_addr ) ) );
} }
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */ #endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
} }
/* Remove compiler warnings in case FreeRTOS_printf() is not used. */ /* Remove compiler warnings in case FreeRTOS_printf() is not used. */
( void ) pcType; ( void ) pcType;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime ) void FreeRTOS_TCPServerWork( TCPServer_t * pxServer,
{ TickType_t xBlockingTime )
TCPClient_t **ppxClient; {
BaseType_t xIndex; TCPClient_t ** ppxClient;
BaseType_t xRc; BaseType_t xIndex;
BaseType_t xRc;
/* Let the server do one working cycle */ /* Let the server do one working cycle */
xRc = FreeRTOS_select( pxServer->xSocketSet, xBlockingTime ); xRc = FreeRTOS_select( pxServer->xSocketSet, xBlockingTime );
@ -259,7 +268,7 @@ BaseType_t xRc;
} }
xSocketLength = sizeof( xAddress ); xSocketLength = sizeof( xAddress );
xNexSocket = FreeRTOS_accept( pxServer->xServers[ xIndex ].xSocket, &xAddress, &xSocketLength); xNexSocket = FreeRTOS_accept( pxServer->xServers[ xIndex ].xSocket, &xAddress, &xSocketLength );
if( ( xNexSocket != FREERTOS_NO_SOCKET ) && ( xNexSocket != FREERTOS_INVALID_SOCKET ) ) if( ( xNexSocket != FREERTOS_NO_SOCKET ) && ( xNexSocket != FREERTOS_INVALID_SOCKET ) )
{ {
@ -270,14 +279,14 @@ BaseType_t xRc;
ppxClient = &pxServer->pxClients; ppxClient = &pxServer->pxClients;
while( ( * ppxClient ) != NULL ) while( ( *ppxClient ) != NULL )
{ {
TCPClient_t *pxThis = *ppxClient; TCPClient_t * pxThis = *ppxClient;
/* Almost C++ */ /* Almost C++ */
xRc = pxThis->fWorkFunction( pxThis ); xRc = pxThis->fWorkFunction( pxThis );
if (xRc < 0 ) if( xRc < 0 )
{ {
*ppxClient = pxThis->pxNextClient; *ppxClient = pxThis->pxNextClient;
/* Close handles, resources */ /* Close handles, resources */
@ -290,46 +299,48 @@ BaseType_t xRc;
ppxClient = &( pxThis->pxNextClient ); ppxClient = &( pxThis->pxNextClient );
} }
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static char *strnew( const char *pcString ) static char * strnew( const char * pcString )
{ {
BaseType_t xLength; BaseType_t xLength;
char *pxBuffer; char * pxBuffer;
xLength = strlen( pcString ) + 1; xLength = strlen( pcString ) + 1;
pxBuffer = ( char * ) pvPortMalloc( xLength ); pxBuffer = ( char * ) pvPortMalloc( xLength );
if( pxBuffer != NULL ) if( pxBuffer != NULL )
{ {
memcpy( pxBuffer, pcString, xLength ); memcpy( pxBuffer, pcString, xLength );
} }
return pxBuffer; return pxBuffer;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvRemoveSlash( char *pcDir ) static void prvRemoveSlash( char * pcDir )
{ {
BaseType_t xLength = strlen( pcDir ); BaseType_t xLength = strlen( pcDir );
while( ( xLength > 0 ) && ( pcDir[ xLength - 1 ] == '/' ) ) while( ( xLength > 0 ) && ( pcDir[ xLength - 1 ] == '/' ) )
{ {
pcDir[ --xLength ] = '\0'; pcDir[ --xLength ] = '\0';
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if( ipconfigSUPPORT_SIGNALS != 0 ) #if ( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select(). /* FreeRTOS_TCPServerWork() calls select().
The two functions below provide a possibility to interrupt * The two functions below provide a possibility to interrupt
the call to select(). After the interruption, resume * the call to select(). After the interruption, resume
by calling FreeRTOS_TCPServerWork() again. */ * by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer ) BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t * pxServer )
{ {
BaseType_t xIndex; BaseType_t xIndex;
BaseType_t xResult = pdFALSE; BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ ) for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{ {
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET ) if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
@ -343,17 +354,19 @@ BaseType_t xLength = strlen( pcDir );
return xResult; return xResult;
} }
#endif /* ipconfigSUPPORT_SIGNALS */ #endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if( ipconfigSUPPORT_SIGNALS != 0 ) #if ( ipconfigSUPPORT_SIGNALS != 0 )
/* Same as above: this function may be called from an ISR, /* Same as above: this function may be called from an ISR,
for instance a GPIO interrupt. */ * for instance a GPIO interrupt. */
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken ) BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t * pxServer,
BaseType_t * pxHigherPriorityTaskWoken )
{ {
BaseType_t xIndex; BaseType_t xIndex;
BaseType_t xResult = pdFALSE; BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ ) for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{ {
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET ) if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
@ -366,7 +379,7 @@ BaseType_t xLength = strlen( pcDir );
return xResult; return xResult;
} }
#endif /* ipconfigSUPPORT_SIGNALS */ #endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#endif /* ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) ) */ #endif /* ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) ) */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS+TCP V2.0.3 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -19,8 +19,9 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
/* FreeRTOS includes. */ /* FreeRTOS includes. */

View file

@ -1,11 +1,6 @@
/* /*
*! * FreeRTOS V202212.00
*! The protocols implemented in this file are intended to be demo quality only, * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*! and not for production devices.
*!
*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -24,10 +19,17 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
/**
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*/
/* Standard includes. */ /* Standard includes. */
#include <stdio.h> #include <stdio.h>
@ -52,25 +54,34 @@ const struct xWEB_COMMAND xWebCommands[ WEB_CMD_COUNT ] =
{ 4, "UNKN", ECMD_UNK }, { 4, "UNKN", ECMD_UNK },
}; };
const char *webCodename (int aCode) const char * webCodename( int aCode )
{ {
switch (aCode) { switch( aCode )
case WEB_REPLY_OK: // = 200, {
case WEB_REPLY_OK: /* = 200, */
return "OK"; return "OK";
case WEB_NO_CONTENT: // 204
case WEB_NO_CONTENT: /* 204 */
return "No content"; return "No content";
case WEB_BAD_REQUEST: // = 400,
case WEB_BAD_REQUEST: /* = 400, */
return "Bad request"; return "Bad request";
case WEB_UNAUTHORIZED: // = 401,
case WEB_UNAUTHORIZED: /* = 401, */
return "Authorization Required"; return "Authorization Required";
case WEB_NOT_FOUND: // = 404,
case WEB_NOT_FOUND: /* = 404, */
return "Not Found"; return "Not Found";
case WEB_GONE: // = 410,
case WEB_GONE: /* = 410, */
return "Done"; return "Done";
case WEB_PRECONDITION_FAILED: // = 412,
case WEB_PRECONDITION_FAILED: /* = 412, */
return "Precondition Failed"; return "Precondition Failed";
case WEB_INTERNAL_SERVER_ERROR: // = 500,
case WEB_INTERNAL_SERVER_ERROR: /* = 500, */
return "Internal Server Error"; return "Internal Server Error";
} }
return "Unknown"; return "Unknown";
} }

View file

@ -1,11 +1,6 @@
/* /*
*! * FreeRTOS V202212.00
*! The protocols implemented in this file are intended to be demo quality only, * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*! and not for production devices.
*!
*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -24,8 +19,16 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/**
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*/ */
/* Standard includes. */ /* Standard includes. */
@ -46,50 +49,52 @@
#include "FreeRTOS_server_private.h" #include "FreeRTOS_server_private.h"
/* Remove the whole file if HTTP is not supported. */ /* Remove the whole file if HTTP is not supported. */
#if( ipconfigUSE_HTTP == 1 ) #if ( ipconfigUSE_HTTP == 1 )
/* FreeRTOS+FAT includes. */ /* FreeRTOS+FAT includes. */
#include "ff_stdio.h" #include "ff_stdio.h"
#ifndef HTTP_SERVER_BACKLOG #ifndef HTTP_SERVER_BACKLOG
#define HTTP_SERVER_BACKLOG ( 12 ) #define HTTP_SERVER_BACKLOG ( 12 )
#endif #endif
#ifndef USE_HTML_CHUNKS #ifndef USE_HTML_CHUNKS
#define USE_HTML_CHUNKS ( 0 ) #define USE_HTML_CHUNKS ( 0 )
#endif #endif
#if !defined( ARRAY_SIZE ) #if !defined( ARRAY_SIZE )
#define ARRAY_SIZE(x) ( BaseType_t ) (sizeof( x ) / sizeof( x )[ 0 ] ) #define ARRAY_SIZE( x ) ( BaseType_t ) ( sizeof( x ) / sizeof( x )[ 0 ] )
#endif #endif
/* Some defines to make the code more readbale */ /* Some defines to make the code more readbale */
#define pcCOMMAND_BUFFER pxClient->pxParent->pcCommandBuffer #define pcCOMMAND_BUFFER pxClient->pxParent->pcCommandBuffer
#define pcNEW_DIR pxClient->pxParent->pcNewDir #define pcNEW_DIR pxClient->pxParent->pcNewDir
#define pcFILE_BUFFER pxClient->pxParent->pcFileBuffer #define pcFILE_BUFFER pxClient->pxParent->pcFileBuffer
#ifndef ipconfigHTTP_REQUEST_CHARACTER #ifndef ipconfigHTTP_REQUEST_CHARACTER
#define ipconfigHTTP_REQUEST_CHARACTER '?' #define ipconfigHTTP_REQUEST_CHARACTER '?'
#endif #endif
/*_RB_ Need comment block, although fairly self evident. */ /*_RB_ Need comment block, although fairly self evident. */
static void prvFileClose( HTTPClient_t *pxClient ); static void prvFileClose( HTTPClient_t * pxClient );
static BaseType_t prvProcessCmd( HTTPClient_t *pxClient, BaseType_t xIndex ); static BaseType_t prvProcessCmd( HTTPClient_t * pxClient,
static const char *pcGetContentsType( const char *apFname ); BaseType_t xIndex );
static BaseType_t prvOpenURL( HTTPClient_t *pxClient ); static const char * pcGetContentsType( const char * apFname );
static BaseType_t prvSendFile( HTTPClient_t *pxClient ); static BaseType_t prvOpenURL( HTTPClient_t * pxClient );
static BaseType_t prvSendReply( HTTPClient_t *pxClient, BaseType_t xCode ); static BaseType_t prvSendFile( HTTPClient_t * pxClient );
static BaseType_t prvSendReply( HTTPClient_t * pxClient,
BaseType_t xCode );
static const char pcEmptyString[1] = { '\0' }; static const char pcEmptyString[ 1 ] = { '\0' };
typedef struct xTYPE_COUPLE typedef struct xTYPE_COUPLE
{ {
const char *pcExtension; const char * pcExtension;
const char *pcType; const char * pcType;
} TypeCouple_t; } TypeCouple_t;
static TypeCouple_t pxTypeCouples[ ] = static TypeCouple_t pxTypeCouples[] =
{ {
{ "html", "text/html" }, { "html", "text/html" },
{ "css", "text/css" }, { "css", "text/css" },
{ "js", "text/javascript" }, { "js", "text/javascript" },
@ -103,11 +108,11 @@ static TypeCouple_t pxTypeCouples[ ] =
{ "pdf", "application/pdf" }, { "pdf", "application/pdf" },
{ "ttf", "application/x-font-ttf" }, { "ttf", "application/x-font-ttf" },
{ "ttc", "application/x-font-ttf" } { "ttc", "application/x-font-ttf" }
}; };
void vHTTPClientDelete( TCPClient_t *pxTCPClient ) void vHTTPClientDelete( TCPClient_t * pxTCPClient )
{ {
HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient; HTTPClient_t * pxClient = ( HTTPClient_t * ) pxTCPClient;
/* This HTTP client stops, close / release all resources. */ /* This HTTP client stops, close / release all resources. */
if( pxClient->xSocket != FREERTOS_NO_SOCKET ) if( pxClient->xSocket != FREERTOS_NO_SOCKET )
@ -116,57 +121,59 @@ HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
FreeRTOS_closesocket( pxClient->xSocket ); FreeRTOS_closesocket( pxClient->xSocket );
pxClient->xSocket = FREERTOS_NO_SOCKET; pxClient->xSocket = FREERTOS_NO_SOCKET;
} }
prvFileClose( pxClient ); prvFileClose( pxClient );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvFileClose( HTTPClient_t *pxClient ) static void prvFileClose( HTTPClient_t * pxClient )
{ {
if( pxClient->pxFileHandle != NULL ) if( pxClient->pxFileHandle != NULL )
{ {
FreeRTOS_printf( ( "Closing file: %s\n", pxClient->pcCurrentFilename ) ); FreeRTOS_printf( ( "Closing file: %s\n", pxClient->pcCurrentFilename ) );
ff_fclose( pxClient->pxFileHandle ); ff_fclose( pxClient->pxFileHandle );
pxClient->pxFileHandle = NULL; pxClient->pxFileHandle = NULL;
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvSendReply( HTTPClient_t *pxClient, BaseType_t xCode ) static BaseType_t prvSendReply( HTTPClient_t * pxClient,
{ BaseType_t xCode )
struct xTCP_SERVER *pxParent = pxClient->pxParent; {
BaseType_t xRc; struct xTCP_SERVER * pxParent = pxClient->pxParent;
BaseType_t xRc;
/* A normal command reply on the main socket (port 21). */ /* A normal command reply on the main socket (port 21). */
char *pcBuffer = pxParent->pcFileBuffer; char * pcBuffer = pxParent->pcFileBuffer;
xRc = snprintf( pcBuffer, sizeof( pxParent->pcFileBuffer ), xRc = snprintf( pcBuffer, sizeof( pxParent->pcFileBuffer ),
"HTTP/1.1 %d %s\r\n" "HTTP/1.1 %d %s\r\n"
#if USE_HTML_CHUNKS #if USE_HTML_CHUNKS
"Transfer-Encoding: chunked\r\n" "Transfer-Encoding: chunked\r\n"
#endif #endif
"Content-Type: %s\r\n" "Content-Type: %s\r\n"
"Connection: keep-alive\r\n" "Connection: keep-alive\r\n"
"%s\r\n", "%s\r\n",
( int ) xCode, ( int ) xCode,
webCodename (xCode), webCodename( xCode ),
pxParent->pcContentsType[0] ? pxParent->pcContentsType : "text/html", pxParent->pcContentsType[ 0 ] ? pxParent->pcContentsType : "text/html",
pxParent->pcExtraContents ); pxParent->pcExtraContents );
pxParent->pcContentsType[0] = '\0'; pxParent->pcContentsType[ 0 ] = '\0';
pxParent->pcExtraContents[0] = '\0'; pxParent->pcExtraContents[ 0 ] = '\0';
xRc = FreeRTOS_send( pxClient->xSocket, ( const void * ) pcBuffer, xRc, 0 ); xRc = FreeRTOS_send( pxClient->xSocket, ( const void * ) pcBuffer, xRc, 0 );
pxClient->bits.bReplySent = pdTRUE_UNSIGNED; pxClient->bits.bReplySent = pdTRUE_UNSIGNED;
return xRc; return xRc;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvSendFile( HTTPClient_t *pxClient ) static BaseType_t prvSendFile( HTTPClient_t * pxClient )
{ {
size_t uxSpace; size_t uxSpace;
size_t uxCount; size_t uxCount;
BaseType_t xRc = 0; BaseType_t xRc = 0;
if( pxClient->bits.bReplySent == pdFALSE_UNSIGNED ) if( pxClient->bits.bReplySent == pdFALSE_UNSIGNED )
{ {
@ -180,7 +187,9 @@ BaseType_t xRc = 0;
xRc = prvSendReply( pxClient, WEB_REPLY_OK ); xRc = prvSendReply( pxClient, WEB_REPLY_OK );
} }
if( xRc >= 0 ) do if( xRc >= 0 )
{
do
{ {
uxSpace = FreeRTOS_tx_space( pxClient->xSocket ); uxSpace = FreeRTOS_tx_space( pxClient->xSocket );
@ -199,16 +208,19 @@ BaseType_t xRc = 0;
{ {
uxCount = sizeof( pxClient->pxParent->pcFileBuffer ); uxCount = sizeof( pxClient->pxParent->pcFileBuffer );
} }
ff_fread( pxClient->pxParent->pcFileBuffer, 1, uxCount, pxClient->pxFileHandle ); ff_fread( pxClient->pxParent->pcFileBuffer, 1, uxCount, pxClient->pxFileHandle );
pxClient->uxBytesLeft -= uxCount; pxClient->uxBytesLeft -= uxCount;
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pxParent->pcFileBuffer, uxCount, 0 ); xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pxParent->pcFileBuffer, uxCount, 0 );
if( xRc < 0 ) if( xRc < 0 )
{ {
break; break;
} }
} }
} while( uxCount > 0u ); } while( uxCount > 0u );
}
if( pxClient->uxBytesLeft == 0u ) if( pxClient->uxBytesLeft == 0u )
{ {
@ -223,35 +235,38 @@ BaseType_t xRc = 0;
} }
return xRc; return xRc;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvOpenURL( HTTPClient_t *pxClient ) static BaseType_t prvOpenURL( HTTPClient_t * pxClient )
{ {
BaseType_t xRc; BaseType_t xRc;
char pcSlash[ 2 ]; char pcSlash[ 2 ];
pxClient->bits.ulFlags = 0; pxClient->bits.ulFlags = 0;
#if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 ) #if ( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
{ {
if( strchr( pxClient->pcUrlData, ipconfigHTTP_REQUEST_CHARACTER ) != NULL ) if( strchr( pxClient->pcUrlData, ipconfigHTTP_REQUEST_CHARACTER ) != NULL )
{ {
size_t xResult; size_t xResult;
xResult = uxApplicationHTTPHandleRequestHook( pxClient->pcUrlData, pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ) ); xResult = uxApplicationHTTPHandleRequestHook( pxClient->pcUrlData, pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ) );
if( xResult > 0 ) if( xResult > 0 )
{ {
strcpy( pxClient->pxParent->pcContentsType, "text/html" ); strcpy( pxClient->pxParent->pcContentsType, "text/html" );
snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ), snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ),
"Content-Length: %d\r\n", ( int ) xResult ); "Content-Length: %d\r\n", ( int ) xResult );
xRc = prvSendReply( pxClient, WEB_REPLY_OK ); /* "Requested file action OK" */ xRc = prvSendReply( pxClient, WEB_REPLY_OK ); /* "Requested file action OK" */
if( xRc > 0 ) if( xRc > 0 )
{ {
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pcCurrentFilename, xResult, 0 ); xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pcCurrentFilename, xResult, 0 );
} }
/* Although against the coding standard of FreeRTOS, a return is /* Although against the coding standard of FreeRTOS, a return is
done here to simplify this conditional code. */ * done here to simplify this conditional code. */
return xRc; return xRc;
} }
} }
@ -269,10 +284,11 @@ char pcSlash[ 2 ];
/* The browser provided a starting '/' already. */ /* The browser provided a starting '/' already. */
pcSlash[ 0 ] = '\0'; pcSlash[ 0 ] = '\0';
} }
snprintf( pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ), "%s%s%s", snprintf( pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ), "%s%s%s",
pxClient->pcRootDir, pxClient->pcRootDir,
pcSlash, pcSlash,
pxClient->pcUrlData); pxClient->pcUrlData );
pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" ); pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" );
@ -291,12 +307,13 @@ char pcSlash[ 2 ];
} }
return xRc; return xRc;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvProcessCmd( HTTPClient_t *pxClient, BaseType_t xIndex ) static BaseType_t prvProcessCmd( HTTPClient_t * pxClient,
{ BaseType_t xIndex )
BaseType_t xResult = 0; {
BaseType_t xResult = 0;
/* A new command has been received. Process it. */ /* A new command has been received. Process it. */
switch( xIndex ) switch( xIndex )
@ -314,44 +331,44 @@ BaseType_t xResult = 0;
case ECMD_CONNECT: case ECMD_CONNECT:
case ECMD_PATCH: case ECMD_PATCH:
case ECMD_UNK: case ECMD_UNK:
{
FreeRTOS_printf( ( "prvProcessCmd: Not implemented: %s\n", FreeRTOS_printf( ( "prvProcessCmd: Not implemented: %s\n",
xWebCommands[xIndex].pcCommandName ) ); xWebCommands[ xIndex ].pcCommandName ) );
}
break; break;
} }
return xResult; return xResult;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xHTTPClientWork( TCPClient_t *pxTCPClient ) BaseType_t xHTTPClientWork( TCPClient_t * pxTCPClient )
{ {
BaseType_t xRc; BaseType_t xRc;
HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient; HTTPClient_t * pxClient = ( HTTPClient_t * ) pxTCPClient;
if( pxClient->pxFileHandle != NULL ) if( pxClient->pxFileHandle != NULL )
{ {
prvSendFile( pxClient ); prvSendFile( pxClient );
} }
xRc = FreeRTOS_recv( pxClient->xSocket, ( void * )pcCOMMAND_BUFFER, sizeof( pcCOMMAND_BUFFER ), 0 ); xRc = FreeRTOS_recv( pxClient->xSocket, ( void * ) pcCOMMAND_BUFFER, sizeof( pcCOMMAND_BUFFER ), 0 );
if( xRc > 0 ) if( xRc > 0 )
{ {
BaseType_t xIndex; BaseType_t xIndex;
const char *pcEndOfCmd; const char * pcEndOfCmd;
const struct xWEB_COMMAND *curCmd; const struct xWEB_COMMAND * curCmd;
char *pcBuffer = pcCOMMAND_BUFFER; char * pcBuffer = pcCOMMAND_BUFFER;
if( xRc < ( BaseType_t ) sizeof( pcCOMMAND_BUFFER ) ) if( xRc < ( BaseType_t ) sizeof( pcCOMMAND_BUFFER ) )
{ {
pcBuffer[ xRc ] = '\0'; pcBuffer[ xRc ] = '\0';
} }
while( xRc && ( pcBuffer[ xRc - 1 ] == 13 || pcBuffer[ xRc - 1 ] == 10 ) ) while( xRc && ( pcBuffer[ xRc - 1 ] == 13 || pcBuffer[ xRc - 1 ] == 10 ) )
{ {
pcBuffer[ --xRc ] = '\0'; pcBuffer[ --xRc ] = '\0';
} }
pcEndOfCmd = pcBuffer + xRc; pcEndOfCmd = pcBuffer + xRc;
curCmd = xWebCommands; curCmd = xWebCommands;
@ -368,14 +385,17 @@ HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
BaseType_t xLength; BaseType_t xLength;
xLength = curCmd->xCommandLength; xLength = curCmd->xCommandLength;
if( ( xRc >= xLength ) && ( memcmp( curCmd->pcCommandName, pcBuffer, xLength ) == 0 ) ) if( ( xRc >= xLength ) && ( memcmp( curCmd->pcCommandName, pcBuffer, xLength ) == 0 ) )
{ {
char *pcLastPtr; char * pcLastPtr;
pxClient->pcUrlData += xLength + 1; pxClient->pcUrlData += xLength + 1;
for( pcLastPtr = (char *)pxClient->pcUrlData; pcLastPtr < pcEndOfCmd; pcLastPtr++ )
for( pcLastPtr = ( char * ) pxClient->pcUrlData; pcLastPtr < pcEndOfCmd; pcLastPtr++ )
{ {
char ch = *pcLastPtr; char ch = *pcLastPtr;
if( ( ch == '\0' ) || ( strchr( "\n\r \t", ch ) != NULL ) ) if( ( ch == '\0' ) || ( strchr( "\n\r \t", ch ) != NULL ) )
{ {
*pcLastPtr = '\0'; *pcLastPtr = '\0';
@ -383,6 +403,7 @@ HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
break; break;
} }
} }
break; break;
} }
} }
@ -397,26 +418,36 @@ HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
/* The connection will be closed and the client will be deleted. */ /* The connection will be closed and the client will be deleted. */
FreeRTOS_printf( ( "xHTTPClientWork: rc = %ld\n", xRc ) ); FreeRTOS_printf( ( "xHTTPClientWork: rc = %ld\n", xRc ) );
} }
return xRc; return xRc;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static const char *pcGetContentsType (const char *apFname) static const char * pcGetContentsType( const char * apFname )
{ {
const char *slash = NULL; const char * slash = NULL;
const char *dot = NULL; const char * dot = NULL;
const char *ptr; const char * ptr;
const char *pcResult = "text/html"; const char * pcResult = "text/html";
BaseType_t x; BaseType_t x;
for( ptr = apFname; *ptr; ptr++ ) for( ptr = apFname; *ptr; ptr++ )
{ {
if (*ptr == '.') dot = ptr; if( *ptr == '.' )
if (*ptr == '/') slash = ptr; {
dot = ptr;
} }
if( *ptr == '/' )
{
slash = ptr;
}
}
if( dot > slash ) if( dot > slash )
{ {
dot++; dot++;
for( x = 0; x < ARRAY_SIZE( pxTypeCouples ); x++ ) for( x = 0; x < ARRAY_SIZE( pxTypeCouples ); x++ )
{ {
if( strcasecmp( dot, pxTypeCouples[ x ].pcExtension ) == 0 ) if( strcasecmp( dot, pxTypeCouples[ x ].pcExtension ) == 0 )
@ -426,8 +457,8 @@ static const char *pcGetContentsType (const char *apFname)
} }
} }
} }
return pcResult; return pcResult;
} }
#endif /* ipconfigUSE_HTTP */ #endif /* ipconfigUSE_HTTP */

View file

@ -62,7 +62,8 @@
#include "date_and_time.h" #include "date_and_time.h"
enum EStatus { enum EStatus
{
EStatusLookup, EStatusLookup,
EStatusAsking, EStatusAsking,
EStatusPause, EStatusPause,
@ -71,13 +72,14 @@ enum EStatus {
static struct SNtpPacket xNTPPacket; static struct SNtpPacket xNTPPacket;
#if( ipconfigUSE_CALLBACKS == 0 ) #if ( ipconfigUSE_CALLBACKS == 0 )
static char cRecvBuffer[ sizeof( struct SNtpPacket ) + 64 ]; static char cRecvBuffer[ sizeof( struct SNtpPacket ) + 64 ];
#endif #endif
static enum EStatus xStatus = EStatusLookup; static enum EStatus xStatus = EStatusLookup;
static const char *pcTimeServers[] = { static const char * pcTimeServers[] =
{
"0.asia.pool.ntp.org", "0.asia.pool.ntp.org",
"0.europe.pool.ntp.org", "0.europe.pool.ntp.org",
"0.id.pool.ntp.org", "0.id.pool.ntp.org",
@ -92,29 +94,31 @@ static Socket_t xUDPSocket = NULL;
static TaskHandle_t xNTPTaskhandle = NULL; static TaskHandle_t xNTPTaskhandle = NULL;
static TickType_t uxSendTime; static TickType_t uxSendTime;
static void prvNTPTask( void *pvParameters ); static void prvNTPTask( void * pvParameters );
static void vSignalTask( void ) static void vSignalTask( void )
{ {
#if( ipconfigUSE_CALLBACKS == 0 ) #if ( ipconfigUSE_CALLBACKS == 0 )
if( xUDPSocket != NULL ) if( xUDPSocket != NULL )
{ {
/* Send a signal to the socket so that the /* Send a signal to the socket so that the
FreeRTOS_recvfrom will get interrupted. */ * FreeRTOS_recvfrom will get interrupted. */
FreeRTOS_SignalSocket( xUDPSocket ); FreeRTOS_SignalSocket( xUDPSocket );
} }
else else
#endif #endif
if( xNTPWakeupSem != NULL ) if( xNTPWakeupSem != NULL )
{ {
xSemaphoreGive( xNTPWakeupSem ); xSemaphoreGive( xNTPWakeupSem );
} }
} }
void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ) void vStartNTPTask( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority )
{ {
/* The only public function in this module: start a task to contact /* The only public function in this module: start a task to contact
some NTP server. */ * some NTP server. */
if( xNTPTaskhandle != NULL ) if( xNTPTaskhandle != NULL )
{ {
@ -124,12 +128,15 @@ void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority )
xStatus = EStatusAsking; xStatus = EStatusAsking;
vSignalTask(); vSignalTask();
break; break;
case EStatusLookup: case EStatusLookup:
FreeRTOS_printf( ( "NTP looking up server\n" ) ); FreeRTOS_printf( ( "NTP looking up server\n" ) );
break; break;
case EStatusAsking: case EStatusAsking:
FreeRTOS_printf( ( "NTP still asking\n" ) ); FreeRTOS_printf( ( "NTP still asking\n" ) );
break; break;
case EStatusFailed: case EStatusFailed:
FreeRTOS_printf( ( "NTP failed somehow\n" ) ); FreeRTOS_printf( ( "NTP failed somehow\n" ) );
ulIPAddressFound = 0ul; ulIPAddressFound = 0ul;
@ -141,10 +148,11 @@ void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority )
else else
{ {
xUDPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); xUDPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xUDPSocket != FREERTOS_INVALID_SOCKET ) if( xUDPSocket != FREERTOS_INVALID_SOCKET )
{ {
struct freertos_sockaddr xAddress; struct freertos_sockaddr xAddress;
#if( ipconfigUSE_CALLBACKS != 0 ) #if ( ipconfigUSE_CALLBACKS != 0 )
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 0 ); BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 0 );
#else #else
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 ); BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
@ -180,31 +188,36 @@ void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void vDNS_callback( const char *pcName, void *pvSearchID, uint32_t ulIPAddress ) static void vDNS_callback( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{ {
char pcBuf[16]; char pcBuf[ 16 ];
/* The DNS lookup has a result, or it has reached the time-out. */ /* The DNS lookup has a result, or it has reached the time-out. */
FreeRTOS_inet_ntoa( ulIPAddress, pcBuf ); FreeRTOS_inet_ntoa( ulIPAddress, pcBuf );
FreeRTOS_printf( ( "IP address of %s found: %s\n", pcName, pcBuf ) ); FreeRTOS_printf( ( "IP address of %s found: %s\n", pcName, pcBuf ) );
if( ulIPAddressFound == 0ul ) if( ulIPAddressFound == 0ul )
{ {
ulIPAddressFound = ulIPAddress; ulIPAddressFound = ulIPAddress;
} }
/* For testing: in case DNS doen't respond, still try some NTP server
with a known IP-address. */ /* For testing: in case DNS doesn't respond, still try some NTP server
* with a known IP-address. */
if( ulIPAddressFound == 0ul ) if( ulIPAddressFound == 0ul )
{ {
ulIPAddressFound = FreeRTOS_inet_addr_quick( 184, 105, 182, 7 ); ulIPAddressFound = FreeRTOS_inet_addr_quick( 184, 105, 182, 7 );
/* ulIPAddressFound = FreeRTOS_inet_addr_quick( 103, 242, 70, 4 ); */ /* ulIPAddressFound = FreeRTOS_inet_addr_quick( 103, 242, 70, 4 ); */
} }
xStatus = EStatusAsking; xStatus = EStatusAsking;
vSignalTask(); vSignalTask();
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvSwapFields( struct SNtpPacket *pxPacket) static void prvSwapFields( struct SNtpPacket * pxPacket )
{ {
/* NTP messages are big-endian */ /* NTP messages are big-endian */
pxPacket->rootDelay = FreeRTOS_htonl( pxPacket->rootDelay ); pxPacket->rootDelay = FreeRTOS_htonl( pxPacket->rootDelay );
@ -224,9 +237,9 @@ static void prvSwapFields( struct SNtpPacket *pxPacket)
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvNTPPacketInit( ) static void prvNTPPacketInit()
{ {
memset (&xNTPPacket, '\0', sizeof( xNTPPacket ) ); memset( &xNTPPacket, '\0', sizeof( xNTPPacket ) );
xNTPPacket.flags = 0xDB; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */ xNTPPacket.flags = 0xDB; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */
xNTPPacket.poll = 10; /* 10 means 1 << 10 = 1024 seconds */ xNTPPacket.poll = 10; /* 10 means 1 << 10 = 1024 seconds */
@ -235,7 +248,7 @@ static void prvNTPPacketInit( )
xNTPPacket.rootDispersion = 0x0008CAC8; /* 0x0008CAC8 = 8.7912 seconds */ xNTPPacket.rootDispersion = 0x0008CAC8; /* 0x0008CAC8 = 8.7912 seconds */
/* use the recorded NTP time */ /* use the recorded NTP time */
time_t uxSecs = FreeRTOS_time( NULL );/* apTime may be NULL, returns seconds */ time_t uxSecs = FreeRTOS_time( NULL ); /* apTime may be NULL, returns seconds */
xNTPPacket.referenceTimestamp.seconds = uxSecs; /* Current time */ xNTPPacket.referenceTimestamp.seconds = uxSecs; /* Current time */
xNTPPacket.transmitTimestamp.seconds = uxSecs + 3; xNTPPacket.transmitTimestamp.seconds = uxSecs + 3;
@ -254,7 +267,7 @@ static void prvReadTime( struct SNtpPacket * pxPacket )
time_t uxCurrentSeconds; time_t uxCurrentSeconds;
time_t uxCurrentMS; time_t uxCurrentMS;
const char *pcTimeUnit; const char * pcTimeUnit;
int32_t ilDiff; int32_t ilDiff;
TickType_t uxTravelTime; TickType_t uxTravelTime;
@ -268,10 +281,10 @@ static void prvReadTime( struct SNtpPacket * pxPacket )
uxCurrentSeconds += uxCurrentMS / 1000; uxCurrentSeconds += uxCurrentMS / 1000;
uxCurrentMS = uxCurrentMS % 1000; uxCurrentMS = uxCurrentMS % 1000;
// Get the last time recorded /* Get the last time recorded */
uxPreviousSeconds = FreeRTOS_get_secs_msec( &uxPreviousMS ); uxPreviousSeconds = FreeRTOS_get_secs_msec( &uxPreviousMS );
// Set the new time with precision in msec. */ /* Set the new time with precision in msec. * / */
FreeRTOS_set_secs_msec( &uxCurrentSeconds, &uxCurrentMS ); FreeRTOS_set_secs_msec( &uxCurrentSeconds, &uxCurrentMS );
if( uxCurrentSeconds >= uxPreviousSeconds ) if( uxCurrentSeconds >= uxPreviousSeconds )
@ -297,24 +310,25 @@ static void prvReadTime( struct SNtpPacket * pxPacket )
int32_t iPrevMS = 1000 * ( uxPreviousSeconds - ulLowest ) + uxPreviousMS; int32_t iPrevMS = 1000 * ( uxPreviousSeconds - ulLowest ) + uxPreviousMS;
ilDiff = iCurMS - iPrevMS; ilDiff = iCurMS - iPrevMS;
} }
uxCurrentSeconds -= iTimeZone; uxCurrentSeconds -= iTimeZone;
FreeRTOS_gmtime_r( &uxCurrentSeconds, &xTimeStruct ); FreeRTOS_gmtime_r( &uxCurrentSeconds, &xTimeStruct );
/* /*
378.067 [NTP client] NTP time: 9/11/2015 16:11:19.559 Diff -20 ms (289 ms) * 378.067 [NTP client] NTP time: 9/11/2015 16:11:19.559 Diff -20 ms (289 ms)
379.441 [NTP client] NTP time: 9/11/2015 16:11:20.933 Diff 0 ms (263 ms) * 379.441 [NTP client] NTP time: 9/11/2015 16:11:20.933 Diff 0 ms (263 ms)
*/ */
FreeRTOS_printf( ("NTP time: %d/%d/%02d %2d:%02d:%02d.%03u Diff %d %s (%lu ms)\n", FreeRTOS_printf( ( "NTP time: %d/%d/%02d %2d:%02d:%02d.%03u Diff %d %s (%lu ms)\n",
xTimeStruct.tm_mday, xTimeStruct.tm_mday,
xTimeStruct.tm_mon + 1, xTimeStruct.tm_mon + 1,
xTimeStruct.tm_year + 1900, xTimeStruct.tm_year + 1900,
xTimeStruct.tm_hour, xTimeStruct.tm_hour,
xTimeStruct.tm_min, xTimeStruct.tm_min,
xTimeStruct.tm_sec, xTimeStruct.tm_sec,
( unsigned )uxCurrentMS, ( unsigned ) uxCurrentMS,
( unsigned )ilDiff, ( unsigned ) ilDiff,
pcTimeUnit, pcTimeUnit,
uxTravelTime ) ); uxTravelTime ) );
@ -324,19 +338,24 @@ static void prvReadTime( struct SNtpPacket * pxPacket )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if( ipconfigUSE_CALLBACKS != 0 ) #if ( ipconfigUSE_CALLBACKS != 0 )
static BaseType_t xOnUDPReceive( Socket_t xSocket, void * pvData, size_t xLength, static BaseType_t xOnUDPReceive( Socket_t xSocket,
const struct freertos_sockaddr *pxFrom, const struct freertos_sockaddr *pxDest ) void * pvData,
size_t xLength,
const struct freertos_sockaddr * pxFrom,
const struct freertos_sockaddr * pxDest )
{ {
if( xLength >= sizeof( xNTPPacket ) ) if( xLength >= sizeof( xNTPPacket ) )
{ {
prvReadTime( ( struct SNtpPacket *)pvData ); prvReadTime( ( struct SNtpPacket * ) pvData );
if( xStatus != EStatusPause ) if( xStatus != EStatusPause )
{ {
xStatus = EStatusPause; xStatus = EStatusPause;
} }
} }
vSignalTask(); vSignalTask();
/* Tell the driver not to store the RX data */ /* Tell the driver not to store the RX data */
return 1; return 1;
@ -345,58 +364,63 @@ static void prvReadTime( struct SNtpPacket * pxPacket )
#endif /* ipconfigUSE_CALLBACKS != 0 */ #endif /* ipconfigUSE_CALLBACKS != 0 */
static void prvNTPTask( void *pvParameters ) static void prvNTPTask( void * pvParameters )
{ {
BaseType_t xServerIndex = 3; BaseType_t xServerIndex = 3;
struct freertos_sockaddr xAddress; struct freertos_sockaddr xAddress;
#if( ipconfigUSE_CALLBACKS != 0 )
#if ( ipconfigUSE_CALLBACKS != 0 )
F_TCP_UDP_Handler_t xHandler; F_TCP_UDP_Handler_t xHandler;
#endif /* ipconfigUSE_CALLBACKS != 0 */ #endif /* ipconfigUSE_CALLBACKS != 0 */
xStatus = EStatusLookup; xStatus = EStatusLookup;
#if( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 ) || ( ipconfigUSE_CALLBACKS != 0 ) #if ( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 ) || ( ipconfigUSE_CALLBACKS != 0 )
{ {
xNTPWakeupSem = xSemaphoreCreateBinary(); xNTPWakeupSem = xSemaphoreCreateBinary();
} }
#endif #endif
#if( ipconfigUSE_CALLBACKS != 0 ) #if ( ipconfigUSE_CALLBACKS != 0 )
{ {
memset( &xHandler, '\0', sizeof( xHandler ) ); memset( &xHandler, '\0', sizeof( xHandler ) );
xHandler.pxOnUDPReceive = xOnUDPReceive; xHandler.pxOnUDPReceive = xOnUDPReceive;
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_UDP_RECV_HANDLER, ( void * ) &xHandler, sizeof( xHandler ) ); FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_UDP_RECV_HANDLER, ( void * ) &xHandler, sizeof( xHandler ) );
} }
#endif #endif
#if( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 ) #if ( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 )
{ {
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_SET_SEMAPHORE, ( void * ) &xNTPWakeupSem, sizeof( xNTPWakeupSem ) ); FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_SET_SEMAPHORE, ( void * ) &xNTPWakeupSem, sizeof( xNTPWakeupSem ) );
} }
#endif #endif
for( ; ; ) for( ; ; )
{ {
switch( xStatus ) switch( xStatus )
{ {
case EStatusLookup: case EStatusLookup:
if( ( ulIPAddressFound == 0ul ) || ( ulIPAddressFound == ~0ul ) ) if( ( ulIPAddressFound == 0ul ) || ( ulIPAddressFound == ~0ul ) )
{ {
if( ++xServerIndex == sizeof( pcTimeServers ) / sizeof( pcTimeServers[ 0 ] ) ) if( ++xServerIndex == sizeof( pcTimeServers ) / sizeof( pcTimeServers[ 0 ] ) )
{ {
xServerIndex = 0; xServerIndex = 0;
} }
FreeRTOS_printf( ( "Looking up server '%s'\n", pcTimeServers[ xServerIndex ] ) ); FreeRTOS_printf( ( "Looking up server '%s'\n", pcTimeServers[ xServerIndex ] ) );
FreeRTOS_gethostbyname_a( pcTimeServers[ xServerIndex ], vDNS_callback, (void *)NULL, 1200 ); FreeRTOS_gethostbyname_a( pcTimeServers[ xServerIndex ], vDNS_callback, ( void * ) NULL, 1200 );
} }
else else
{ {
xStatus = EStatusAsking; xStatus = EStatusAsking;
} }
break; break;
case EStatusAsking: case EStatusAsking:
{ {
char pcBuf[16]; char pcBuf[ 16 ];
prvNTPPacketInit( ); prvNTPPacketInit();
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{ {
@ -418,8 +442,8 @@ struct freertos_sockaddr xAddress;
pcBuf, pcBuf,
FreeRTOS_ntohs( xAddress.sin_port ) ) ); FreeRTOS_ntohs( xAddress.sin_port ) ) );
uxSendTime = xTaskGetTickCount( ); uxSendTime = xTaskGetTickCount();
FreeRTOS_sendto( xUDPSocket, ( void * )&xNTPPacket, sizeof( xNTPPacket ), 0, &xAddress, sizeof( xAddress ) ); FreeRTOS_sendto( xUDPSocket, ( void * ) &xNTPPacket, sizeof( xNTPPacket ), 0, &xAddress, sizeof( xAddress ) );
} }
break; break;
@ -430,7 +454,7 @@ struct freertos_sockaddr xAddress;
break; break;
} }
#if( ipconfigUSE_CALLBACKS != 0 ) #if ( ipconfigUSE_CALLBACKS != 0 )
{ {
xSemaphoreTake( xNTPWakeupSem, 5000 ); xSemaphoreTake( xNTPWakeupSem, 5000 );
} }
@ -441,29 +465,34 @@ struct freertos_sockaddr xAddress;
xAddressSize = sizeof( xAddress ); xAddressSize = sizeof( xAddress );
xReturned = FreeRTOS_recvfrom( xUDPSocket, ( void * ) cRecvBuffer, sizeof( cRecvBuffer ), 0, &xAddress, &xAddressSize ); xReturned = FreeRTOS_recvfrom( xUDPSocket, ( void * ) cRecvBuffer, sizeof( cRecvBuffer ), 0, &xAddress, &xAddressSize );
switch( xReturned ) switch( xReturned )
{ {
case 0: case 0:
case -pdFREERTOS_ERRNO_EAGAIN: case -pdFREERTOS_ERRNO_EAGAIN:
case -pdFREERTOS_ERRNO_EINTR: case -pdFREERTOS_ERRNO_EINTR:
break; break;
default: default:
if( xReturned < sizeof( xNTPPacket ) ) if( xReturned < sizeof( xNTPPacket ) )
{ {
FreeRTOS_printf( ( "FreeRTOS_recvfrom: returns %ld\n", xReturned ) ); FreeRTOS_printf( ( "FreeRTOS_recvfrom: returns %ld\n", xReturned ) );
} }
else else
{ {
prvReadTime( ( struct SNtpPacket *)cRecvBuffer ); prvReadTime( ( struct SNtpPacket * ) cRecvBuffer );
if( xStatus != EStatusPause ) if( xStatus != EStatusPause )
{ {
xStatus = EStatusPause; xStatus = EStatusPause;
} }
} }
break; break;
} }
} }
#endif #endif /* if ( ipconfigUSE_CALLBACKS != 0 ) */
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS+TCP V2.0.1 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -19,8 +19,9 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
#ifndef __FTPCMD_H__ #ifndef __FTPCMD_H__
@ -51,7 +52,7 @@
#define REPL_230 "230 User logged in, proceed.\r\n" #define REPL_230 "230 User logged in, proceed.\r\n"
#define REPL_250 "250 Requested file action okay, completed.\r\n" #define REPL_250 "250 Requested file action okay, completed.\r\n"
#define REPL_257 "257 %s created.\r\n" #define REPL_257 "257 %s created.\r\n"
// #define REPL_257_PWD "257 \"%s\" is current working dir.\r\n" /* #define REPL_257_PWD "257 \"%s\" is current working dir.\r\n" */
#define REPL_257_PWD "257 \"%s\"\r\n" #define REPL_257_PWD "257 \"%s\"\r\n"
#define REPL_331 "331 Only anonymous user is accepted.\r\n" #define REPL_331 "331 Only anonymous user is accepted.\r\n"
#define REPL_331_ANON "331 Anonymous login okay\r\n" #define REPL_331_ANON "331 Anonymous login okay\r\n"
@ -76,7 +77,8 @@
#define REPL_553 "553 Requested action not taken.\r\n" #define REPL_553 "553 Requested action not taken.\r\n"
#define REPL_553_READ_ONLY "553 Read-only file-system.\r\n" #define REPL_553_READ_ONLY "553 Read-only file-system.\r\n"
enum EFTPCommand { enum EFTPCommand
{
ECMD_USER, ECMD_USER,
ECMD_PASS, ECMD_PASS,
ECMD_ACCT, ECMD_ACCT,
@ -118,15 +120,16 @@ enum EFTPCommand {
ECMD_UNKNOWN, ECMD_UNKNOWN,
}; };
typedef struct xFTP_COMMAND { typedef struct xFTP_COMMAND
{
BaseType_t xCommandLength; BaseType_t xCommandLength;
const char pcCommandName[7]; const char pcCommandName[ 7 ];
const unsigned char ucCommandType; const unsigned char ucCommandType;
const unsigned char checkLogin; const unsigned char checkLogin;
const unsigned char checkNullArg; const unsigned char checkNullArg;
} FTPCommand_t; } FTPCommand_t;
#define FTP_CMD_COUNT (ECMD_UNKNOWN+1) #define FTP_CMD_COUNT ( ECMD_UNKNOWN + 1 )
extern const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ]; extern const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ];

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS+TCP V2.0.3 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -19,13 +19,15 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
#ifndef FREERTOS_HTTP_COMMANDS_H #ifndef FREERTOS_HTTP_COMMANDS_H
#define FREERTOS_HTTP_COMMANDS_H #define FREERTOS_HTTP_COMMANDS_H
enum { enum
{
WEB_REPLY_OK = 200, WEB_REPLY_OK = 200,
WEB_NO_CONTENT = 204, WEB_NO_CONTENT = 204,
WEB_BAD_REQUEST = 400, WEB_BAD_REQUEST = 400,
@ -36,7 +38,8 @@ enum {
WEB_INTERNAL_SERVER_ERROR = 500, WEB_INTERNAL_SERVER_ERROR = 500,
}; };
enum EWebCommand { enum EWebCommand
{
ECMD_GET, ECMD_GET,
ECMD_HEAD, ECMD_HEAD,
ECMD_POST, ECMD_POST,
@ -52,16 +55,14 @@ enum EWebCommand {
struct xWEB_COMMAND struct xWEB_COMMAND
{ {
BaseType_t xCommandLength; BaseType_t xCommandLength;
const char *pcCommandName; const char * pcCommandName;
const unsigned char ucCommandType; const unsigned char ucCommandType;
}; };
#define WEB_CMD_COUNT (ECMD_UNK+1) #define WEB_CMD_COUNT ( ECMD_UNK + 1 )
extern const struct xWEB_COMMAND xWebCommands[WEB_CMD_COUNT]; extern const struct xWEB_COMMAND xWebCommands[ WEB_CMD_COUNT ];
extern const char *webCodename (int aCode); extern const char * webCodename( int aCode );
#endif /* FREERTOS_HTTP_COMMANDS_H */ #endif /* FREERTOS_HTTP_COMMANDS_H */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS+TCP V2.0.3 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -19,72 +19,82 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
/* /*
Some code which is common to TCP servers like HTTP en FTP * Some code which is common to TCP servers like HTTP en FTP
*/ */
#ifndef FREERTOS_TCP_SERVER_H #ifndef FREERTOS_TCP_SERVER_H
#define FREERTOS_TCP_SERVER_H #define FREERTOS_TCP_SERVER_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY #ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY
#define FTP_SERVER_USES_RELATIVE_DIRECTORY 0 #define FTP_SERVER_USES_RELATIVE_DIRECTORY 0
#endif #endif
enum eSERVER_TYPE enum eSERVER_TYPE
{ {
eSERVER_NONE, eSERVER_NONE,
eSERVER_HTTP, eSERVER_HTTP,
eSERVER_FTP, eSERVER_FTP,
}; };
struct xFTP_CLIENT; struct xFTP_CLIENT;
#if( ipconfigFTP_HAS_RECEIVED_HOOK != 0 ) #if ( ipconfigFTP_HAS_RECEIVED_HOOK != 0 )
extern void vApplicationFTPReceivedHook( const char *pcFileName, uint32_t ulSize, struct xFTP_CLIENT *pxFTPClient ); extern void vApplicationFTPReceivedHook( const char * pcFileName,
extern void vFTPReplyMessage( struct xFTP_CLIENT *pxFTPClient, const char *pcMessage ); uint32_t ulSize,
#endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */ struct xFTP_CLIENT * pxFTPClient );
extern void vFTPReplyMessage( struct xFTP_CLIENT * pxFTPClient,
const char * pcMessage );
#endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 ) #if ( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
/*
* Function is called when a user name has been submitted. * Function is called when a user name has been submitted.
* The function may return a string such as: "331 Please enter your password" * The function may return a string such as: "331 Please enter your password"
* or return NULL to use the default reply. * or return NULL to use the default reply.
*/ */
extern const char *pcApplicationFTPUserHook( const char *pcUserName ); extern const char * pcApplicationFTPUserHook( const char * pcUserName );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */ #endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 ) #if ( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
/*
* Function is called when a password was received. * Function is called when a password was received.
* Return positive value to allow the user * Return positive value to allow the user
*/ */
extern BaseType_t xApplicationFTPPasswordHook( const char *pcUserName, const char *pcPassword ); extern BaseType_t xApplicationFTPPasswordHook( const char * pcUserName,
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */ const char * pcPassword );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 ) #if ( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 )
/*
/*
* The FTP server is asking for user-specific properties * The FTP server is asking for user-specific properties
*/ */
typedef struct typedef struct
{ {
uint16_t usPortNumber; /* For reference only. Host-endian. */ uint16_t usPortNumber; /* For reference only. Host-endian. */
const char *pcRootDir; const char * pcRootDir;
BaseType_t xReadOnly; BaseType_t xReadOnly;
} }
FTPUserProperties_t; FTPUserProperties_t;
extern void vApplicationFTPUserPropertiesHook( const char *pcUserName, FTPUserProperties_t *pxProperties ); extern void vApplicationFTPUserPropertiesHook( const char * pcUserName,
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */ FTPUserProperties_t * pxProperties );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 ) #if ( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
/*
/*
* A GET request is received containing a special character, * A GET request is received containing a special character,
* usually a question mark. * usually a question mark.
* const char *pcURLData; // A request, e.g. "/request?limit=75" * const char *pcURLData; // A request, e.g. "/request?limit=75"
@ -92,34 +102,40 @@ struct xFTP_CLIENT;
* size_t uxBufferLength; // Size of the buffer * size_t uxBufferLength; // Size of the buffer
* *
*/ */
extern size_t uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, size_t uxBufferLength ); extern size_t uxApplicationHTTPHandleRequestHook( const char * pcURLData,
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */ char * pcBuffer,
size_t uxBufferLength );
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
struct xSERVER_CONFIG struct xSERVER_CONFIG
{ {
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */ enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
BaseType_t xPortNumber; /* e.g. 80, 8080, 21 */ BaseType_t xPortNumber; /* e.g. 80, 8080, 21 */
BaseType_t xBackLog; /* e.g. 10, maximum number of connected TCP clients */ BaseType_t xBackLog; /* e.g. 10, maximum number of connected TCP clients */
const char * const pcRootDir; /* Treat this directory as the root directory */ const char * const pcRootDir; /* Treat this directory as the root directory */
}; };
struct xTCP_SERVER; struct xTCP_SERVER;
typedef struct xTCP_SERVER TCPServer_t; typedef struct xTCP_SERVER TCPServer_t;
TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount ); TCPServer_t * FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG * pxConfigs,
void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime ); BaseType_t xCount );
void FreeRTOS_TCPServerWork( TCPServer_t * pxServer,
TickType_t xBlockingTime );
#if( ipconfigSUPPORT_SIGNALS != 0 ) #if ( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select().
The two functions below provide a possibility to interrupt
the call to select(). After the interruption, resume
by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer );
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken );
#endif
#ifdef __cplusplus /* FreeRTOS_TCPServerWork() calls select().
* The two functions below provide a possibility to interrupt
* the call to select(). After the interruption, resume
* by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t * pxServer );
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t * pxServer,
BaseType_t * pxHigherPriorityTaskWoken );
#endif
#ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif /* FREERTOS_TCP_SERVER_H */ #endif /* FREERTOS_TCP_SERVER_H */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS+TCP V2.0.3 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -19,13 +19,14 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
/* /*
Some code which is common to TCP servers like HTTP and FTP * Some code which is common to TCP servers like HTTP and FTP
*/ */
#ifndef FREERTOS_SERVER_PRIVATE_H #ifndef FREERTOS_SERVER_PRIVATE_H
#define FREERTOS_SERVER_PRIVATE_H #define FREERTOS_SERVER_PRIVATE_H
@ -63,19 +64,18 @@ typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
#define TCP_CLIENT_FIELDS \ #define TCP_CLIENT_FIELDS \
enum eSERVER_TYPE eType; \ enum eSERVER_TYPE eType; \
struct xTCP_SERVER *pxParent; \ struct xTCP_SERVER * pxParent; \
Socket_t xSocket; \ Socket_t xSocket; \
const char *pcRootDir; \ const char * pcRootDir; \
FTCPWorkFunction fWorkFunction; \ FTCPWorkFunction fWorkFunction; \
FTCPDeleteFunction fDeleteFunction; \ FTCPDeleteFunction fDeleteFunction; \
struct xTCP_CLIENT *pxNextClient struct xTCP_CLIENT * pxNextClient
typedef struct xTCP_CLIENT typedef struct xTCP_CLIENT
{ {
/* This define contains fields which must come first within each of the client structs */ /* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS; TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */ /* --- Keep at the top --- */
} TCPClient_t; } TCPClient_t;
struct xHTTP_CLIENT struct xHTTP_CLIENT
@ -84,18 +84,21 @@ struct xHTTP_CLIENT
TCP_CLIENT_FIELDS; TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */ /* --- Keep at the top --- */
const char *pcUrlData; const char * pcUrlData;
const char *pcRestData; const char * pcRestData;
char pcCurrentFilename[ ffconfigMAX_FILENAME ]; char pcCurrentFilename[ ffconfigMAX_FILENAME ];
size_t uxBytesLeft; size_t uxBytesLeft;
FF_FILE *pxFileHandle; FF_FILE * pxFileHandle;
union { union
struct { {
struct
{
uint32_t uint32_t
bReplySent : 1; bReplySent : 1;
}; };
uint32_t ulFlags; uint32_t ulFlags;
} bits; }
bits;
}; };
typedef struct xHTTP_CLIENT HTTPClient_t; typedef struct xHTTP_CLIENT HTTPClient_t;
@ -116,14 +119,16 @@ struct xFTP_CLIENT
BaseType_t xTransType; BaseType_t xTransType;
BaseType_t xDirCount; BaseType_t xDirCount;
FF_FindData_t xFindData; FF_FindData_t xFindData;
FF_FILE *pxReadHandle; FF_FILE * pxReadHandle;
FF_FILE *pxWriteHandle; FF_FILE * pxWriteHandle;
char pcCurrentDir[ ffconfigMAX_FILENAME ]; char pcCurrentDir[ ffconfigMAX_FILENAME ];
char pcFileName[ ffconfigMAX_FILENAME ]; char pcFileName[ ffconfigMAX_FILENAME ];
char pcConnectionAck[ 128 ]; char pcConnectionAck[ 128 ];
char pcClientAck[ 128 ]; char pcClientAck[ 128 ];
union { union
struct { {
struct
{
uint32_t uint32_t
bHelloSent : 1, bHelloSent : 1,
bLoggedIn : 1, bLoggedIn : 1,
@ -132,9 +137,12 @@ struct xFTP_CLIENT
bReadOnly : 1; bReadOnly : 1;
}; };
uint32_t ulFTPFlags; uint32_t ulFTPFlags;
} bits; }
union { bits;
struct { union
{
struct
{
uint32_t uint32_t
bIsListen : 1, /* pdTRUE for passive data connections (using list()). */ bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */ bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
@ -143,19 +151,26 @@ struct xFTP_CLIENT
bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */ bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
}; };
uint32_t ulConnFlags; uint32_t ulConnFlags;
} bits1; }
bits1;
}; };
typedef struct xFTP_CLIENT FTPClient_t; typedef struct xFTP_CLIENT FTPClient_t;
BaseType_t xHTTPClientWork( TCPClient_t *pxClient ); BaseType_t xHTTPClientWork( TCPClient_t * pxClient );
BaseType_t xFTPClientWork( TCPClient_t *pxClient ); BaseType_t xFTPClientWork( TCPClient_t * pxClient );
void vHTTPClientDelete( TCPClient_t *pxClient ); void vHTTPClientDelete( TCPClient_t * pxClient );
void vFTPClientDelete( TCPClient_t *pxClient ); void vFTPClientDelete( TCPClient_t * pxClient );
BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName ); BaseType_t xMakeAbsolute( struct xFTP_CLIENT * pxClient,
BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName ); char * pcBuffer,
BaseType_t xBufferLength,
const char * pcFileName );
BaseType_t xMakeRelative( FTPClient_t * pxClient,
char * pcBuffer,
BaseType_t xBufferLength,
const char * pcFileName );
struct xTCP_SERVER struct xTCP_SERVER
{ {
@ -165,21 +180,22 @@ struct xTCP_SERVER
/* A buffer to access the file system: read or write data. */ /* A buffer to access the file system: read or write data. */
char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ]; char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
#if( ipconfigUSE_FTP != 0 ) #if ( ipconfigUSE_FTP != 0 )
char pcNewDir[ ffconfigMAX_FILENAME ]; char pcNewDir[ ffconfigMAX_FILENAME ];
#endif #endif
#if( ipconfigUSE_HTTP != 0 ) #if ( ipconfigUSE_HTTP != 0 )
char pcContentsType[40]; /* Space for the msg: "text/javascript" */ char pcContentsType[ 40 ]; /* Space for the msg: "text/javascript" */
char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */ char pcExtraContents[ 40 ]; /* Space for the msg: "Content-Length: 346500" */
#endif #endif
BaseType_t xServerCount; BaseType_t xServerCount;
TCPClient_t *pxClients; TCPClient_t * pxClients;
struct xSERVER struct xSERVER
{ {
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */ enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
const char *pcRootDir; const char * pcRootDir;
Socket_t xSocket; Socket_t xSocket;
} xServers[ 1 ]; }
xServers[ 1 ];
}; };
#endif /* FREERTOS_SERVER_PRIVATE_H */ #endif /* FREERTOS_SERVER_PRIVATE_H */

View file

@ -1,6 +1,30 @@
// /*
// ntpClient.h * FreeRTOS V202212.00
// * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* ntpClient.h */
#ifndef __NTPCLIENT_H__ #ifndef __NTPCLIENT_H__
@ -18,7 +42,8 @@ typedef union _SNtpFlags SNtpFlags;
/** /**
* 64-bit NTP timestamp. * 64-bit NTP timestamp.
*/ */
struct __attribute__ ((__packed__)) _SNtpTimestamp { struct __attribute__( ( __packed__ ) ) _SNtpTimestamp
{
/** Number of seconds passed since Jan 1 1900, in big-endian format. */ /** Number of seconds passed since Jan 1 1900, in big-endian format. */
quint32 seconds; quint32 seconds;
@ -27,39 +52,41 @@ struct __attribute__ ((__packed__)) _SNtpTimestamp {
}; };
typedef struct _SNtpTimestamp SNtpTimestamp; typedef struct _SNtpTimestamp SNtpTimestamp;
/** /**
* Mandatory part of an NTP packet * Mandatory part of an NTP packet
*/ */
struct SNtpPacket { struct SNtpPacket
{
/** Flags. */ /** Flags. */
unsigned char flags; // value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 unsigned char flags; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */
/** Stratum of the clock. */ /** Stratum of the clock. */
quint8 stratum; // value 0 : unspecified quint8 stratum; /* value 0 : unspecified */
/** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */ /** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
qint8 poll; // 10 means 1 << 10 = 1024 seconds qint8 poll; /* 10 means 1 << 10 = 1024 seconds */
/** Precision of the clock, in log2 seconds. Note that the value is signed. */ /** Precision of the clock, in log2 seconds. Note that the value is signed. */
qint8 precision; // 0xFA = 250 = 0.015625 seconds qint8 precision; /* 0xFA = 250 = 0.015625 seconds */
/** Round trip time to the primary reference source, in NTP short format. */ /** Round trip time to the primary reference source, in NTP short format. */
qint32 rootDelay; // 0x5D2E = 23854 or (23854/65535)= 0.3640 sec qint32 rootDelay; /* 0x5D2E = 23854 or (23854/65535)= 0.3640 sec */
/** Nominal error relative to the primary reference source. */ /** Nominal error relative to the primary reference source. */
qint32 rootDispersion; // 0x0008 CAC8 = 8.7912 seconds qint32 rootDispersion; /* 0x0008 CAC8 = 8.7912 seconds */
/** Reference identifier (either a 4 character string or an IP address). */ /** Reference identifier (either a 4 character string or an IP address). */
qint8 referenceID[4]; // or just 0000 qint8 referenceID[ 4 ]; /* or just 0000 */
/** The time at which the clock was last set or corrected. */ /** The time at which the clock was last set or corrected. */
SNtpTimestamp referenceTimestamp; // Current time SNtpTimestamp referenceTimestamp; /* Current time */
/** The time at which the request departed the client for the server. */ /** The time at which the request departed the client for the server. */
SNtpTimestamp originateTimestamp; // Keep 0 SNtpTimestamp originateTimestamp; /* Keep 0 */
/** The time at which the request arrived at the server. */ /** The time at which the request arrived at the server. */
SNtpTimestamp receiveTimestamp; // Keep 0 SNtpTimestamp receiveTimestamp; /* Keep 0 */
/** The time at which the reply departed the server for client. */ /** The time at which the reply departed the server for client. */
SNtpTimestamp transmitTimestamp; SNtpTimestamp transmitTimestamp;

View file

@ -1,11 +1,34 @@
/* /*
* A simple demo for NTP using FreeRTOS+TCP * FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/ */
#ifndef NTPDEMO_H #ifndef NTPDEMO_H
#define NTPDEMO_H #define NTPDEMO_H
void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ); void vStartNTPTask( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority );
#endif #endif

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -56,44 +56,55 @@
/* /*
* Print out information on a single file. * Print out information on a single file.
*/ */
static void prvCreateFileInfoString( char *pcBuffer, F_FIND *pxFindStruct ); static void prvCreateFileInfoString( char * pcBuffer,
F_FIND * pxFindStruct );
/* /*
* Copies an existing file into a newly created file. * Copies an existing file into a newly created file.
*/ */
static BaseType_t prvPerformCopy( const char *pcSourceFile, static BaseType_t prvPerformCopy( const char * pcSourceFile,
int32_t lSourceFileLength, int32_t lSourceFileLength,
const char *pcDestinationFile, const char * pcDestinationFile,
char *pxWriteBuffer, char * pxWriteBuffer,
size_t xWriteBufferLen ); size_t xWriteBufferLen );
/* /*
* Implements the DIR command. * Implements the DIR command.
*/ */
static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDIRCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the CD command. * Implements the CD command.
*/ */
static BaseType_t prvCDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvCDCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the DEL command. * Implements the DEL command.
*/ */
static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDELCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the TYPE command. * Implements the TYPE command.
*/ */
static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvTYPECommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the COPY command. * Implements the COPY command.
*/ */
static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvCOPYCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* Structure that defines the DIR command line command, which lists all the /* Structure that defines the DIR command line command, which lists all the
files in the current directory. */ * files in the current directory. */
static const CLI_Command_Definition_t xDIR = static const CLI_Command_Definition_t xDIR =
{ {
"dir", /* The command string to type. */ "dir", /* The command string to type. */
@ -103,7 +114,7 @@ static const CLI_Command_Definition_t xDIR =
}; };
/* Structure that defines the CD command line command, which changes the /* Structure that defines the CD command line command, which changes the
working directory. */ * working directory. */
static const CLI_Command_Definition_t xCD = static const CLI_Command_Definition_t xCD =
{ {
"cd", /* The command string to type. */ "cd", /* The command string to type. */
@ -113,7 +124,7 @@ static const CLI_Command_Definition_t xCD =
}; };
/* Structure that defines the TYPE command line command, which prints the /* Structure that defines the TYPE command line command, which prints the
contents of a file to the console. */ * contents of a file to the console. */
static const CLI_Command_Definition_t xTYPE = static const CLI_Command_Definition_t xTYPE =
{ {
"type", /* The command string to type. */ "type", /* The command string to type. */
@ -154,14 +165,16 @@ void vRegisterFileSystemCLICommands( void )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvTYPECommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn = pdTRUE; BaseType_t xParameterStringLength, xReturn = pdTRUE;
static F_FILE *pxFile = NULL; static F_FILE * pxFile = NULL;
int iChar; int iChar;
size_t xByte; size_t xByte;
size_t xColumns = 50U; size_t xColumns = 50U;
/* Ensure there is always a null terminator after each character written. */ /* Ensure there is always a null terminator after each character written. */
memset( pcWriteBuffer, 0x00, xWriteBufferLen ); memset( pcWriteBuffer, 0x00, xWriteBufferLen );
@ -173,7 +186,7 @@ size_t xColumns = 50U;
if( xWriteBufferLen < xColumns ) if( xWriteBufferLen < xColumns )
{ {
/* Ensure the loop that uses xColumns as an end condition does not /* Ensure the loop that uses xColumns as an end condition does not
write off the end of the buffer. */ * write off the end of the buffer. */
xColumns = xWriteBufferLen; xColumns = xWriteBufferLen;
} }
@ -218,7 +231,7 @@ size_t xColumns = 50U;
if( pxFile == NULL ) if( pxFile == NULL )
{ {
/* Either the file was not opened, or all the data from the file has /* Either the file was not opened, or all the data from the file has
been returned and the file is now closed. */ * been returned and the file is now closed. */
xReturn = pdFALSE; xReturn = pdFALSE;
} }
@ -228,12 +241,14 @@ size_t xColumns = 50U;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvCDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvCDCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength; BaseType_t xParameterStringLength;
unsigned char ucReturned; unsigned char ucReturned;
size_t xStringLength; size_t xStringLength;
/* Obtain the parameter string. */ /* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter pcParameter = FreeRTOS_CLIGetParameter
@ -266,11 +281,13 @@ size_t xStringLength;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDIRCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
static F_FIND *pxFindStruct = NULL; static F_FIND * pxFindStruct = NULL;
unsigned char ucReturned; unsigned char ucReturned;
BaseType_t xReturn = pdFALSE; BaseType_t xReturn = pdFALSE;
/* This assumes pcWriteBuffer is long enough. */ /* This assumes pcWriteBuffer is long enough. */
( void ) pcCommandString; ( void ) pcCommandString;
@ -282,7 +299,7 @@ BaseType_t xReturn = pdFALSE;
if( pxFindStruct == NULL ) if( pxFindStruct == NULL )
{ {
/* This is the first time this function has been executed since the Dir /* This is the first time this function has been executed since the Dir
command was run. Create the find structure. */ * command was run. Create the find structure. */
pxFindStruct = ( F_FIND * ) pvPortMalloc( sizeof( F_FIND ) ); pxFindStruct = ( F_FIND * ) pvPortMalloc( sizeof( F_FIND ) );
if( pxFindStruct != NULL ) if( pxFindStruct != NULL )
@ -307,7 +324,7 @@ BaseType_t xReturn = pdFALSE;
else else
{ {
/* The find struct has already been created. Find the next file in /* The find struct has already been created. Find the next file in
the directory. */ * the directory. */
ucReturned = f_findnext( pxFindStruct ); ucReturned = f_findnext( pxFindStruct );
if( ucReturned == F_NO_ERROR ) if( ucReturned == F_NO_ERROR )
@ -332,11 +349,13 @@ BaseType_t xReturn = pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDELCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength; BaseType_t xParameterStringLength;
unsigned char ucReturned; unsigned char ucReturned;
/* This function assumes xWriteBufferLen is large enough! */ /* This function assumes xWriteBufferLen is large enough! */
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
@ -370,11 +389,13 @@ unsigned char ucReturned;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvCOPYCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
char *pcSourceFile, *pcDestinationFile; char * pcSourceFile, * pcDestinationFile;
BaseType_t xParameterStringLength; BaseType_t xParameterStringLength;
long lSourceLength, lDestinationLength = 0; long lSourceLength, lDestinationLength = 0;
/* Obtain the name of the destination file. */ /* Obtain the name of the destination file. */
pcDestinationFile = ( char * ) FreeRTOS_CLIGetParameter pcDestinationFile = ( char * ) FreeRTOS_CLIGetParameter
@ -420,7 +441,7 @@ long lSourceLength, lDestinationLength = 0;
} }
/* Continue only if the source file exists and the destination file does /* Continue only if the source file exists and the destination file does
not exist. */ * not exist. */
if( ( lSourceLength != 0 ) && ( lDestinationLength == 0 ) ) if( ( lSourceLength != 0 ) && ( lDestinationLength == 0 ) )
{ {
if( prvPerformCopy( pcSourceFile, lSourceLength, pcDestinationFile, pcWriteBuffer, xWriteBufferLen ) == pdPASS ) if( prvPerformCopy( pcSourceFile, lSourceLength, pcDestinationFile, pcWriteBuffer, xWriteBufferLen ) == pdPASS )
@ -439,15 +460,15 @@ long lSourceLength, lDestinationLength = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvPerformCopy( const char *pcSourceFile, static BaseType_t prvPerformCopy( const char * pcSourceFile,
int32_t lSourceFileLength, int32_t lSourceFileLength,
const char *pcDestinationFile, const char * pcDestinationFile,
char *pxWriteBuffer, char * pxWriteBuffer,
size_t xWriteBufferLen ) size_t xWriteBufferLen )
{ {
int32_t lBytesRead = 0, lBytesToRead, lBytesRemaining; int32_t lBytesRead = 0, lBytesToRead, lBytesRemaining;
F_FILE *pxFile; F_FILE * pxFile;
BaseType_t xReturn = pdPASS; BaseType_t xReturn = pdPASS;
/* NOTE: Error handling has been omitted for clarity. */ /* NOTE: Error handling has been omitted for clarity. */
@ -457,7 +478,7 @@ BaseType_t xReturn = pdPASS;
lBytesRemaining = lSourceFileLength - lBytesRead; lBytesRemaining = lSourceFileLength - lBytesRead;
/* How many bytes should be read this time around the loop. Can't /* How many bytes should be read this time around the loop. Can't
read more bytes than will fit into the buffer. */ * read more bytes than will fit into the buffer. */
if( lBytesRemaining > ( long ) xWriteBufferLen ) if( lBytesRemaining > ( long ) xWriteBufferLen )
{ {
lBytesToRead = ( long ) xWriteBufferLen; lBytesToRead = ( long ) xWriteBufferLen;
@ -468,9 +489,10 @@ BaseType_t xReturn = pdPASS;
} }
/* Open the source file, seek past the data that has already been /* Open the source file, seek past the data that has already been
read from the file, read the next block of data, then close the * read from the file, read the next block of data, then close the
file again so the destination file can be opened. */ * file again so the destination file can be opened. */
pxFile = f_open( pcSourceFile, "r" ); pxFile = f_open( pcSourceFile, "r" );
if( pxFile != NULL ) if( pxFile != NULL )
{ {
f_seek( pxFile, lBytesRead, F_SEEK_SET ); f_seek( pxFile, lBytesRead, F_SEEK_SET );
@ -484,8 +506,9 @@ BaseType_t xReturn = pdPASS;
} }
/* Open the destination file and write the block of data to the end of /* Open the destination file and write the block of data to the end of
the file. */ * the file. */
pxFile = f_open( pcDestinationFile, "a" ); pxFile = f_open( pcDestinationFile, "a" );
if( pxFile != NULL ) if( pxFile != NULL )
{ {
f_write( pxWriteBuffer, lBytesToRead, 1, pxFile ); f_write( pxWriteBuffer, lBytesToRead, 1, pxFile );
@ -504,10 +527,11 @@ BaseType_t xReturn = pdPASS;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvCreateFileInfoString( char *pcBuffer, F_FIND *pxFindStruct ) static void prvCreateFileInfoString( char * pcBuffer,
F_FIND * pxFindStruct )
{ {
const char *pcWritableFile = "writable file", *pcReadOnlyFile = "read only file", *pcDirectory = "directory"; const char * pcWritableFile = "writable file", * pcReadOnlyFile = "read only file", * pcDirectory = "directory";
const char * pcAttrib; const char * pcAttrib;
/* Point pcAttrib to a string that describes the file. */ /* Point pcAttrib to a string that describes the file. */
if( ( pxFindStruct->attr & F_ATTR_DIR ) != 0 ) if( ( pxFindStruct->attr & F_ATTR_DIR ) != 0 )
@ -524,6 +548,6 @@ const char * pcAttrib;
} }
/* Create a string that includes the file name, the file size and the /* Create a string that includes the file name, the file size and the
attributes string. */ * attributes string. */
sprintf( pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, ( int ) pxFindStruct->filesize ); sprintf( pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, ( int ) pxFindStruct->filesize );
} }

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,16 +20,16 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
/****************************************************************************** /******************************************************************************
* *
* https://www.FreeRTOS.org/cli * https://www.FreeRTOS.org/cli
* *
******************************************************************************/ ******************************************************************************/
/* FreeRTOS includes. */ /* FreeRTOS includes. */
@ -61,41 +61,53 @@ void vRegisterSampleCLICommands( void );
/* /*
* Implements the task-stats command. * Implements the task-stats command.
*/ */
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the run-time-stats command. * Implements the run-time-stats command.
*/ */
#if( configGENERATE_RUN_TIME_STATS == 1 ) #if ( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif /* configGENERATE_RUN_TIME_STATS */ #endif /* configGENERATE_RUN_TIME_STATS */
/* /*
* Implements the echo-three-parameters command. * Implements the echo-three-parameters command.
*/ */
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the echo-parameters command. * Implements the echo-parameters command.
*/ */
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the "query heap" command. * Implements the "query heap" command.
*/ */
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 ) #if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvQueryHeapCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif #endif
/* /*
* Implements the "trace start" and "trace stop" commands; * Implements the "trace start" and "trace stop" commands;
*/ */
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 ) #if ( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif #endif
/* Structure that defines the "task-stats" command line command. This generates /* Structure that defines the "task-stats" command line command. This generates
a table that gives information on each task in the system. */ * a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats = static const CLI_Command_Definition_t xTaskStats =
{ {
"task-stats", /* The command string to type. */ "task-stats", /* The command string to type. */
@ -105,8 +117,8 @@ static const CLI_Command_Definition_t xTaskStats =
}; };
/* Structure that defines the "echo_3_parameters" command line command. This /* Structure that defines the "echo_3_parameters" command line command. This
takes exactly three parameters that the command simply echos back one at a * takes exactly three parameters that the command simply echos back one at a
time. */ * time. */
static const CLI_Command_Definition_t xThreeParameterEcho = static const CLI_Command_Definition_t xThreeParameterEcho =
{ {
"echo-3-parameters", "echo-3-parameters",
@ -116,8 +128,8 @@ static const CLI_Command_Definition_t xThreeParameterEcho =
}; };
/* Structure that defines the "echo_parameters" command line command. This /* Structure that defines the "echo_parameters" command line command. This
takes a variable number of parameters that the command simply echos back one at * takes a variable number of parameters that the command simply echos back one at
a time. */ * a time. */
static const CLI_Command_Definition_t xParameterEcho = static const CLI_Command_Definition_t xParameterEcho =
{ {
"echo-parameters", "echo-parameters",
@ -126,9 +138,10 @@ static const CLI_Command_Definition_t xParameterEcho =
-1 /* The user can enter any number of commands. */ -1 /* The user can enter any number of commands. */
}; };
#if( configGENERATE_RUN_TIME_STATS == 1 ) #if ( configGENERATE_RUN_TIME_STATS == 1 )
/* Structure that defines the "run-time-stats" command line command. This
generates a table that shows how much run time each task has */ /* Structure that defines the "run-time-stats" command line command. This
* generates a table that shows how much run time each task has */
static const CLI_Command_Definition_t xRunTimeStats = static const CLI_Command_Definition_t xRunTimeStats =
{ {
"run-time-stats", /* The command string to type. */ "run-time-stats", /* The command string to type. */
@ -138,7 +151,7 @@ static const CLI_Command_Definition_t xParameterEcho =
}; };
#endif /* configGENERATE_RUN_TIME_STATS */ #endif /* configGENERATE_RUN_TIME_STATS */
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 ) #if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
/* Structure that defines the "query_heap" command line command. */ /* Structure that defines the "query_heap" command line command. */
static const CLI_Command_Definition_t xQueryHeap = static const CLI_Command_Definition_t xQueryHeap =
{ {
@ -150,8 +163,9 @@ static const CLI_Command_Definition_t xParameterEcho =
#endif /* configQUERY_HEAP_COMMAND */ #endif /* configQUERY_HEAP_COMMAND */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
/* Structure that defines the "trace" command line command. This takes a single
parameter, which can be either "start" or "stop". */ /* Structure that defines the "trace" command line command. This takes a single
* parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartStopTrace = static const CLI_Command_Definition_t xStartStopTrace =
{ {
"trace", "trace",
@ -170,19 +184,19 @@ void vRegisterSampleCLICommands( void )
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho ); FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
FreeRTOS_CLIRegisterCommand( &xParameterEcho ); FreeRTOS_CLIRegisterCommand( &xParameterEcho );
#if( configGENERATE_RUN_TIME_STATS == 1 ) #if ( configGENERATE_RUN_TIME_STATS == 1 )
{ {
FreeRTOS_CLIRegisterCommand( &xRunTimeStats ); FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
} }
#endif #endif
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 ) #if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
{ {
FreeRTOS_CLIRegisterCommand( &xQueryHeap ); FreeRTOS_CLIRegisterCommand( &xQueryHeap );
} }
#endif #endif
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 ) #if ( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
{ {
FreeRTOS_CLIRegisterCommand( &xStartStopTrace ); FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
} }
@ -190,14 +204,16 @@ void vRegisterSampleCLICommands( void )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *const pcHeader = " State Priority Stack #\r\n************************************************\r\n"; const char * const pcHeader = " State Priority Stack #\r\n************************************************\r\n";
BaseType_t xSpacePadding; BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -207,8 +223,9 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer ); pcWriteBuffer += strlen( pcWriteBuffer );
/* Minus three for the null terminator and half the number of characters in /* Minus three for the null terminator and half the number of characters in
"Task" so the column lines up with the centre of the heading. */ * "Task" so the column lines up with the centre of the heading. */
configASSERT( configMAX_TASK_NAME_LEN > 3 ); configASSERT( configMAX_TASK_NAME_LEN > 3 );
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ ) for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{ {
/* Add a space to align columns after the task's name. */ /* Add a space to align columns after the task's name. */
@ -218,22 +235,25 @@ BaseType_t xSpacePadding;
/* Ensure always terminated. */ /* Ensure always terminated. */
*pcWriteBuffer = 0x00; *pcWriteBuffer = 0x00;
} }
strcpy( pcWriteBuffer, pcHeader ); strcpy( pcWriteBuffer, pcHeader );
vTaskList( pcWriteBuffer + strlen( pcHeader ) ); vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 ) #if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvQueryHeapCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -241,23 +261,25 @@ BaseType_t xSpacePadding;
sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() ); sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
#endif /* configINCLUDE_QUERY_HEAP */ #endif /* configINCLUDE_QUERY_HEAP */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if( configGENERATE_RUN_TIME_STATS == 1 ) #if ( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n"; const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
BaseType_t xSpacePadding; BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -267,9 +289,9 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer ); pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the /* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the * length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of * number of characters in "Task" so the column lines up with the centre of
the heading. */ * the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ ) for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{ {
/* Add a space to align columns after the task's name. */ /* Add a space to align columns after the task's name. */
@ -284,22 +306,24 @@ BaseType_t xSpacePadding;
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) ); vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
#endif /* configGENERATE_RUN_TIME_STATS */ #endif /* configGENERATE_RUN_TIME_STATS */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0; static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -307,15 +331,15 @@ static UBaseType_t uxParameterNumber = 0;
if( uxParameterNumber == 0 ) if( uxParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" ); sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
uxParameterNumber = 1U; uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -338,11 +362,11 @@ static UBaseType_t uxParameterNumber = 0;
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
if( uxParameterNumber == 3U ) if( uxParameterNumber == 3U )
{ {
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
xReturn = pdFALSE; xReturn = pdFALSE;
uxParameterNumber = 0; uxParameterNumber = 0;
} }
@ -358,15 +382,17 @@ static UBaseType_t uxParameterNumber = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0; static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -374,15 +400,15 @@ static UBaseType_t uxParameterNumber = 0;
if( uxParameterNumber == 0 ) if( uxParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" ); sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
uxParameterNumber = 1U; uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -410,7 +436,7 @@ static UBaseType_t uxParameterNumber = 0;
else else
{ {
/* No more parameters were found. Make sure the write buffer does /* No more parameters were found. Make sure the write buffer does
not contain a valid string. */ * not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00; pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */ /* No more data to return. */
@ -427,14 +453,16 @@ static UBaseType_t uxParameterNumber = 0;
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength; BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -472,7 +500,7 @@ static UBaseType_t uxParameterNumber = 0;
} }
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -46,15 +46,15 @@
/* Dimensions the buffer into which input characters are placed. */ /* Dimensions the buffer into which input characters are placed. */
#define cmdMAX_INPUT_SIZE 50 #define cmdMAX_INPUT_SIZE 50
/* Dimentions a buffer to be used by the UART driver, if the UART driver uses a /* Dimensions a buffer to be used by the UART driver, if the UART driver uses a
buffer at all. */ * buffer at all. */
#define cmdQUEUE_LENGTH 25 #define cmdQUEUE_LENGTH 25
/* DEL acts as a backspace. */ /* DEL acts as a backspace. */
#define cmdASCII_DEL ( 0x7F ) #define cmdASCII_DEL ( 0x7F )
/* The maximum time to wait for the mutex that guards the UART to become /* The maximum time to wait for the mutex that guards the UART to become
available. */ * available. */
#define cmdMAX_MUTEX_WAIT pdMS_TO_TICKS( 300 ) #define cmdMAX_MUTEX_WAIT pdMS_TO_TICKS( 300 )
#ifndef configCLI_BAUD_RATE #ifndef configCLI_BAUD_RATE
@ -66,8 +66,9 @@ available. */
/* /*
* The task that implements the command console processing. * The task that implements the command console processing.
*/ */
static void prvUARTCommandConsoleTask( void *pvParameters ); static void prvUARTCommandConsoleTask( void * pvParameters );
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority ); void vUARTCommandConsoleStart( uint16_t usStackSize,
UBaseType_t uxPriority );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -77,7 +78,7 @@ static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute th
static const char * const pcNewLine = "\r\n"; static const char * const pcNewLine = "\r\n";
/* Used to guard access to the UART in case messages are sent to the UART from /* Used to guard access to the UART in case messages are sent to the UART from
more than one task. */ * more than one task. */
static SemaphoreHandle_t xTxMutex = NULL; static SemaphoreHandle_t xTxMutex = NULL;
/* The handle to the UART port, which is not used by all ports. */ /* The handle to the UART port, which is not used by all ports. */
@ -85,7 +86,8 @@ static xComPortHandle xPort = 0;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority ) void vUARTCommandConsoleStart( uint16_t usStackSize,
UBaseType_t uxPriority )
{ {
/* Create the semaphore used to access the UART Tx. */ /* Create the semaphore used to access the UART Tx. */
xTxMutex = xSemaphoreCreateMutex(); xTxMutex = xSemaphoreCreateMutex();
@ -101,20 +103,20 @@ void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvUARTCommandConsoleTask( void *pvParameters ) static void prvUARTCommandConsoleTask( void * pvParameters )
{ {
signed char cRxedChar; signed char cRxedChar;
uint8_t ucInputIndex = 0; uint8_t ucInputIndex = 0;
char *pcOutputString; char * pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ]; static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
BaseType_t xReturned; BaseType_t xReturned;
xComPortHandle xPort; xComPortHandle xPort;
( void ) pvParameters; ( void ) pvParameters;
/* Obtain the address of the output buffer. Note there is no mutual /* Obtain the address of the output buffer. Note there is no mutual
exclusion on this buffer as it is assumed only one command console interface * exclusion on this buffer as it is assumed only one command console interface
will be used at any one time. */ * will be used at any one time. */
pcOutputString = FreeRTOS_CLIGetOutputBuffer(); pcOutputString = FreeRTOS_CLIGetOutputBuffer();
/* Initialise the UART. */ /* Initialise the UART. */
@ -123,12 +125,14 @@ xComPortHandle xPort;
/* Send the welcome message. */ /* Send the welcome message. */
vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) ); vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );
for( ;; ) for( ; ; )
{ {
/* Wait for the next character. The while loop is used in case /* Wait for the next character. The while loop is used in case
INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will * INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
be a genuine block time rather than an infinite block time. */ * be a genuine block time rather than an infinite block time. */
while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS ); while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS )
{
}
/* Ensure exclusive access to the UART Tx. */ /* Ensure exclusive access to the UART Tx. */
if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS ) if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
@ -137,13 +141,13 @@ xComPortHandle xPort;
xSerialPutChar( xPort, cRxedChar, portMAX_DELAY ); xSerialPutChar( xPort, cRxedChar, portMAX_DELAY );
/* Was it the end of the line? */ /* Was it the end of the line? */
if( cRxedChar == '\n' || cRxedChar == '\r' ) if( ( cRxedChar == '\n' ) || ( cRxedChar == '\r' ) )
{ {
/* Just to space the output from the input. */ /* Just to space the output from the input. */
vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) ); vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) );
/* See if the command is empty, indicating that the last command /* See if the command is empty, indicating that the last command
is to be executed again. */ * is to be executed again. */
if( ucInputIndex == 0 ) if( ucInputIndex == 0 )
{ {
/* Copy the last command back into the input string. */ /* Copy the last command back into the input string. */
@ -151,9 +155,9 @@ xComPortHandle xPort;
} }
/* Pass the received command to the command interpreter. The /* Pass the received command to the command interpreter. The
command interpreter is called repeatedly until it returns * command interpreter is called repeatedly until it returns
pdFALSE (indicating there is no more output) as it might * pdFALSE (indicating there is no more output) as it might
generate more than one string. */ * generate more than one string. */
do do
{ {
/* Get the next output string from the command interpreter. */ /* Get the next output string from the command interpreter. */
@ -161,13 +165,12 @@ xComPortHandle xPort;
/* Write the generated string to the UART. */ /* Write the generated string to the UART. */
vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) ); vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) );
} while( xReturned != pdFALSE ); } while( xReturned != pdFALSE );
/* All the strings generated by the input command have been /* All the strings generated by the input command have been
sent. Clear the input string ready to receive the next command. * sent. Clear the input string ready to receive the next command.
Remember the command that was just processed first in case it is * Remember the command that was just processed first in case it is
to be processed again. */ * to be processed again. */
strcpy( cLastInputString, cInputString ); strcpy( cLastInputString, cInputString );
ucInputIndex = 0; ucInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
@ -183,7 +186,7 @@ xComPortHandle xPort;
else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) ) else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
{ {
/* Backspace was pressed. Erase the last character in the /* Backspace was pressed. Erase the last character in the
string - if any. */ * string - if any. */
if( ucInputIndex > 0 ) if( ucInputIndex > 0 )
{ {
ucInputIndex--; ucInputIndex--;
@ -193,8 +196,8 @@ xComPortHandle xPort;
else else
{ {
/* A character was entered. Add it to the string entered so /* A character was entered. Add it to the string entered so
far. When a \n is entered the complete string will be * far. When a \n is entered the complete string will be
passed to the command interpreter. */ * passed to the command interpreter. */
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) ) if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
{ {
if( ucInputIndex < cmdMAX_INPUT_SIZE ) if( ucInputIndex < cmdMAX_INPUT_SIZE )
@ -222,4 +225,3 @@ void vOutputString( const char * const pcMessage )
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -24,12 +24,12 @@
* *
*/ */
/****************************************************************************** /******************************************************************************
* *
* See the following URL for information on the commands defined in this file: * See the following URL for information on the commands defined in this file:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml * https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
* *
******************************************************************************/ ******************************************************************************/
/* FreeRTOS includes. */ /* FreeRTOS includes. */
@ -45,24 +45,30 @@
#include "FreeRTOS_CLI.h" #include "FreeRTOS_CLI.h"
/* FreeRTOS+UDP includes, just to make the stats available to the CLI /* FreeRTOS+UDP includes, just to make the stats available to the CLI
commands. */ * commands. */
#include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_Sockets.h" #include "FreeRTOS_Sockets.h"
/* /*
* Defines a command that prints out IP address information. * Defines a command that prints out IP address information.
*/ */
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that prints out the gathered demo debug stats. * Defines a command that prints out the gathered demo debug stats.
*/ */
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that sends an ICMP ping request to an IP address. * Defines a command that sends an ICMP ping request to an IP address.
*/ */
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* Structure that defines the "ip-config" command line command. */ /* Structure that defines the "ip-config" command line command. */
static const CLI_Command_Definition_t xIPConfig = static const CLI_Command_Definition_t xIPConfig =
@ -86,9 +92,9 @@ static const CLI_Command_Definition_t xIPConfig =
#if ipconfigSUPPORT_OUTGOING_PINGS == 1 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
/* Structure that defines the "ping" command line command. This takes an IP /* Structure that defines the "ping" command line command. This takes an IP
address or host name and (optionally) the number of bytes to ping as * address or host name and (optionally) the number of bytes to ping as
parameters. */ * parameters. */
static const CLI_Command_Definition_t xPing = static const CLI_Command_Definition_t xPing =
{ {
"ping", "ping",
@ -123,7 +129,9 @@ void vRegisterUDPCLICommands( void )
#if ipconfigSUPPORT_OUTGOING_PINGS == 1 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
char * pcParameter; char * pcParameter;
BaseType_t lParameterStringLength, xReturn; BaseType_t lParameterStringLength, xReturn;
@ -132,8 +140,8 @@ void vRegisterUDPCLICommands( void )
char cBuffer[ 16 ]; char cBuffer[ 16 ];
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -171,7 +179,7 @@ void vRegisterUDPCLICommands( void )
configASSERT( pcParameter ); configASSERT( pcParameter );
/* Attempt to obtain the IP address. If the first character is not a /* Attempt to obtain the IP address. If the first character is not a
digit, assume the host name has been passed in. */ * digit, assume the host name has been passed in. */
if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) ) if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
{ {
ulIPAddress = FreeRTOS_inet_addr( pcParameter ); ulIPAddress = FreeRTOS_inet_addr( pcParameter );
@ -214,15 +222,17 @@ void vRegisterUDPCLICommands( void )
#if configINCLUDE_DEMO_DEBUG_STATS != 0 #if configINCLUDE_DEMO_DEBUG_STATS != 0
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
static BaseType_t xIndex = -1; static BaseType_t xIndex = -1;
extern xExampleDebugStatEntry_t xIPTraceValues[]; extern xExampleDebugStatEntry_t xIPTraceValues[];
BaseType_t xReturn; BaseType_t xReturn;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -250,22 +260,24 @@ void vRegisterUDPCLICommands( void )
#endif /* configINCLUDE_DEMO_DEBUG_STATS */ #endif /* configINCLUDE_DEMO_DEBUG_STATS */
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
static BaseType_t xIndex = 0; static BaseType_t xIndex = 0;
BaseType_t xReturn; BaseType_t xReturn;
uint32_t ulAddress; uint32_t ulAddress;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
switch( xIndex ) switch( xIndex )
{ {
case 0 : case 0:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else #else
@ -276,7 +288,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 1 : case 1:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else #else
@ -287,7 +299,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 2 : case 2:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else #else
@ -298,7 +310,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 3 : case 3:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else #else
@ -309,7 +321,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
default : default:
ulAddress = 0; ulAddress = 0;
sprintf( pcWriteBuffer, "\r\n\r\n" ); sprintf( pcWriteBuffer, "\r\n\r\n" );
xReturn = pdFALSE; xReturn = pdFALSE;
@ -325,4 +337,3 @@ uint32_t ulAddress;
return xReturn; return xReturn;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -83,17 +83,17 @@ static void prvVerifyDemoFileUsing_f_getc( void );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* A buffer used to both create content to write to disk, and read content back /* A buffer used to both create content to write to disk, and read content back
from a disk. Note there is no mutual exclusion on this buffer. */ * from a disk. Note there is no mutual exclusion on this buffer. */
static char cRAMBuffer[ fsRAM_BUFFER_SIZE ]; static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
/* Names of directories that are created. */ /* Names of directories that are created. */
static const char *pcRoot = "/", *pcDirectory1 = "SUB1", *pcDirectory2 = "SUB2", *pcFullPath = "/SUB1/SUB2"; static const char * pcRoot = "/", * pcDirectory1 = "SUB1", * pcDirectory2 = "SUB2", * pcFullPath = "/SUB1/SUB2";
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vCreateAndVerifySampleFiles( void ) void vCreateAndVerifySampleFiles( void )
{ {
unsigned char ucStatus; unsigned char ucStatus;
/* First create the volume. */ /* First create the volume. */
ucStatus = f_initvolume( ram_initfunc ); ucStatus = f_initvolume( ram_initfunc );
@ -117,7 +117,7 @@ unsigned char ucStatus;
prvCreateDemoFileUsing_f_putc(); prvCreateDemoFileUsing_f_putc();
/* Read back and verify the file created by /* Read back and verify the file created by
prvCreateDemoFileUsing_f_putc(). */ * prvCreateDemoFileUsing_f_putc(). */
prvVerifyDemoFileUsing_f_getc(); prvVerifyDemoFileUsing_f_getc();
} }
} }
@ -125,22 +125,22 @@ unsigned char ucStatus;
static void prvCreateDemoFilesUsing_f_write( void ) static void prvCreateDemoFilesUsing_f_write( void )
{ {
BaseType_t xFileNumber, xWriteNumber; BaseType_t xFileNumber, xWriteNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ]; char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5; const BaseType_t xMaxFiles = 5;
long lItemsWritten; long lItemsWritten;
F_FILE *pxFile; F_FILE * pxFile;
/* Create xMaxFiles files. Each created file will be /* Create xMaxFiles files. Each created file will be
( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled * ( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
with a different repeating character. */ * with a different repeating character. */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ ) for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{ {
/* Generate a file name. */ /* Generate a file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber ); sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and /* Obtain the current working directory and print out the file name and
the directory into which the file is being written. */ * the directory into which the file is being written. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file, creating the file if it does not already exist. */ /* Open the file, creating the file if it does not already exist. */
@ -148,12 +148,12 @@ F_FILE *pxFile;
configASSERT( pxFile ); configASSERT( pxFile );
/* Fill the RAM buffer with data that will be written to the file. This /* Fill the RAM buffer with data that will be written to the file. This
is just a repeating ascii character that indicates the file number. */ * is just a repeating ascii character that indicates the file number. */
memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE ); memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
/* Write the RAM buffer to the opened file a number of times. The /* Write the RAM buffer to the opened file a number of times. The
number of times the RAM buffer is written to the file depends on the * number of times the RAM buffer is written to the file depends on the
file number, so the length of each created file will be different. */ * file number, so the length of each created file will be different. */
for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ ) for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
{ {
lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile ); lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
@ -168,21 +168,21 @@ F_FILE *pxFile;
static void prvVerifyDemoFileUsing_f_read( void ) static void prvVerifyDemoFileUsing_f_read( void )
{ {
BaseType_t xFileNumber, xReadNumber; BaseType_t xFileNumber, xReadNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ]; char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5; const BaseType_t xMaxFiles = 5;
long lItemsRead, lChar; long lItemsRead, lChar;
F_FILE *pxFile; F_FILE * pxFile;
/* Read back the files that were created by /* Read back the files that were created by
prvCreateDemoFilesUsing_f_write(). */ * prvCreateDemoFilesUsing_f_write(). */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ ) for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{ {
/* Generate the file name. */ /* Generate the file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber ); sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and /* Obtain the current working directory and print out the file name and
the directory from which the file is being read. */ * the directory from which the file is being read. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file for reading. */ /* Open the file for reading. */
@ -190,7 +190,7 @@ F_FILE *pxFile;
configASSERT( pxFile ); configASSERT( pxFile );
/* Read the file into the RAM buffer, checking the file contents are as /* Read the file into the RAM buffer, checking the file contents are as
expected. The size of the file depends on the file number. */ * expected. The size of the file depends on the file number. */
for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ ) for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
{ {
/* Start with the RAM buffer clear. */ /* Start with the RAM buffer clear. */
@ -200,8 +200,8 @@ F_FILE *pxFile;
configASSERT( lItemsRead == 1 ); configASSERT( lItemsRead == 1 );
/* Check the RAM buffer is filled with the expected data. Each /* Check the RAM buffer is filled with the expected data. Each
file contains a different repeating ascii character that indicates * file contains a different repeating ascii character that indicates
the number of the file. */ * the number of the file. */
for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ ) for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
{ {
configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) ); configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
@ -216,10 +216,10 @@ F_FILE *pxFile;
static void prvCreateDemoFileUsing_f_putc( void ) static void prvCreateDemoFileUsing_f_putc( void )
{ {
unsigned char ucReturn; unsigned char ucReturn;
int iByte, iReturned; int iByte, iReturned;
F_FILE *pxFile; F_FILE * pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ]; char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Obtain and print out the working directory. */ /* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
@ -240,7 +240,7 @@ char cFileName[ fsMAX_FILE_NAME_LEN ];
configASSERT( ucReturn == F_NO_ERROR ); configASSERT( ucReturn == F_NO_ERROR );
/* Move into the directory just created - now two directories down from /* Move into the directory just created - now two directories down from
the root. */ * the root. */
ucReturn = f_chdir( pcDirectory2 ); ucReturn = f_chdir( pcDirectory2 );
configASSERT( ucReturn == F_NO_ERROR ); configASSERT( ucReturn == F_NO_ERROR );
@ -252,11 +252,11 @@ char cFileName[ fsMAX_FILE_NAME_LEN ];
sprintf( cFileName, "%s.txt", pcDirectory2 ); sprintf( cFileName, "%s.txt", pcDirectory2 );
/* Print out the file name and the directory into which the file is being /* Print out the file name and the directory into which the file is being
written. */ * written. */
pxFile = f_open( cFileName, "w" ); pxFile = f_open( cFileName, "w" );
/* Create a file 1 byte at a time. The file is filled with incrementing /* Create a file 1 byte at a time. The file is filled with incrementing
ascii characters starting from '0'. */ * ascii characters starting from '0'. */
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ ) for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
{ {
iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile ); iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
@ -278,10 +278,10 @@ char cFileName[ fsMAX_FILE_NAME_LEN ];
static void prvVerifyDemoFileUsing_f_getc( void ) static void prvVerifyDemoFileUsing_f_getc( void )
{ {
unsigned char ucReturn; unsigned char ucReturn;
int iByte, iReturned; int iByte, iReturned;
F_FILE *pxFile; F_FILE * pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ]; char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Move into the directory in which the file was created. */ /* Move into the directory in which the file was created. */
ucReturn = f_chdir( pcFullPath ); ucReturn = f_chdir( pcFullPath );
@ -314,7 +314,3 @@ char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Obtain and print out the working directory. */ /* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
} }

View file

@ -24,12 +24,12 @@
* *
*/ */
/****************************************************************************** /******************************************************************************
* *
* See the following URL for information on the commands defined in this file: * See the following URL for information on the commands defined in this file:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml * https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
* *
******************************************************************************/ ******************************************************************************/
/* FreeRTOS includes. */ /* FreeRTOS includes. */
@ -45,7 +45,7 @@
#include "FreeRTOS_CLI.h" #include "FreeRTOS_CLI.h"
/* FreeRTOS+UDP includes, just to make the stats available to the CLI /* FreeRTOS+UDP includes, just to make the stats available to the CLI
commands. */ * commands. */
#include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_Sockets.h" #include "FreeRTOS_Sockets.h"
@ -57,43 +57,59 @@ commands. */
/* /*
* Implements the run-time-stats command. * Implements the run-time-stats command.
*/ */
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the task-stats command. * Implements the task-stats command.
*/ */
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the echo-three-parameters command. * Implements the echo-three-parameters command.
*/ */
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the echo-parameters command. * Implements the echo-parameters command.
*/ */
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that prints out IP address information. * Defines a command that prints out IP address information.
*/ */
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that prints out the gathered demo debug stats. * Defines a command that prints out the gathered demo debug stats.
*/ */
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that sends an ICMP ping request to an IP address. * Defines a command that sends an ICMP ping request to an IP address.
*/ */
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the "trace start" and "trace stop" commands; * Implements the "trace start" and "trace stop" commands;
*/ */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif #endif
/* Structure that defines the "ip-config" command line command. */ /* Structure that defines the "ip-config" command line command. */
@ -117,7 +133,7 @@ static const CLI_Command_Definition_t xIPConfig =
#endif /* configINCLUDE_DEMO_DEBUG_STATS */ #endif /* configINCLUDE_DEMO_DEBUG_STATS */
/* Structure that defines the "run-time-stats" command line command. This /* Structure that defines the "run-time-stats" command line command. This
generates a table that shows how much run time each task has */ * generates a table that shows how much run time each task has */
static const CLI_Command_Definition_t xRunTimeStats = static const CLI_Command_Definition_t xRunTimeStats =
{ {
"run-time-stats", /* The command string to type. */ "run-time-stats", /* The command string to type. */
@ -127,7 +143,7 @@ static const CLI_Command_Definition_t xRunTimeStats =
}; };
/* Structure that defines the "task-stats" command line command. This generates /* Structure that defines the "task-stats" command line command. This generates
a table that gives information on each task in the system. */ * a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats = static const CLI_Command_Definition_t xTaskStats =
{ {
"task-stats", /* The command string to type. */ "task-stats", /* The command string to type. */
@ -137,8 +153,8 @@ static const CLI_Command_Definition_t xTaskStats =
}; };
/* Structure that defines the "echo_3_parameters" command line command. This /* Structure that defines the "echo_3_parameters" command line command. This
takes exactly three parameters that the command simply echos back one at a * takes exactly three parameters that the command simply echos back one at a
time. */ * time. */
static const CLI_Command_Definition_t xThreeParameterEcho = static const CLI_Command_Definition_t xThreeParameterEcho =
{ {
"echo-3-parameters", "echo-3-parameters",
@ -148,8 +164,8 @@ static const CLI_Command_Definition_t xThreeParameterEcho =
}; };
/* Structure that defines the "echo_parameters" command line command. This /* Structure that defines the "echo_parameters" command line command. This
takes a variable number of parameters that the command simply echos back one at * takes a variable number of parameters that the command simply echos back one at
a time. */ * a time. */
static const CLI_Command_Definition_t xParameterEcho = static const CLI_Command_Definition_t xParameterEcho =
{ {
"echo-parameters", "echo-parameters",
@ -160,9 +176,9 @@ static const CLI_Command_Definition_t xParameterEcho =
#if ipconfigSUPPORT_OUTGOING_PINGS == 1 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
/* Structure that defines the "ping" command line command. This takes an IP /* Structure that defines the "ping" command line command. This takes an IP
address or host name and (optionally) the number of bytes to ping as * address or host name and (optionally) the number of bytes to ping as
parameters. */ * parameters. */
static const CLI_Command_Definition_t xPing = static const CLI_Command_Definition_t xPing =
{ {
"ping", "ping",
@ -174,8 +190,9 @@ static const CLI_Command_Definition_t xParameterEcho =
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */ #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
/* Structure that defines the "trace" command line command. This takes a single
parameter, which can be either "start" or "stop". */ /* Structure that defines the "trace" command line command. This takes a single
* parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartStopTrace = static const CLI_Command_Definition_t xStartStopTrace =
{ {
"trace", "trace",
@ -204,19 +221,21 @@ void vRegisterCLICommands( void )
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */ #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
FreeRTOS_CLIRegisterCommand( & xStartStopTrace ); FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
#endif #endif
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *const pcHeader = " State\tPriority\tStack\t#\r\n************************************************\r\n"; const char * const pcHeader = " State\tPriority\tStack\t#\r\n************************************************\r\n";
BaseType_t xSpacePadding; BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -226,9 +245,9 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer ); pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the /* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the * length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of * number of characters in "Task" so the column lines up with the centre of
the heading. */ * the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ ) for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{ {
/* Add a space to align columns after the task's name. */ /* Add a space to align columns after the task's name. */
@ -238,23 +257,26 @@ BaseType_t xSpacePadding;
/* Ensure always terminated. */ /* Ensure always terminated. */
*pcWriteBuffer = 0x00; *pcWriteBuffer = 0x00;
} }
strcpy( pcWriteBuffer, pcHeader ); strcpy( pcWriteBuffer, pcHeader );
vTaskList( pcWriteBuffer + strlen( pcHeader ) ); vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n"; const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
BaseType_t xSpacePadding; BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -264,9 +286,9 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer ); pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the /* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the * length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of * number of characters in "Task" so the column lines up with the centre of
the heading. */ * the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ ) for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{ {
/* Add a space to align columns after the task's name. */ /* Add a space to align columns after the task's name. */
@ -281,20 +303,22 @@ BaseType_t xSpacePadding;
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) ); vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -302,15 +326,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" ); sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -333,11 +357,11 @@ static BaseType_t lParameterNumber = 0;
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
if( lParameterNumber == 3L ) if( lParameterNumber == 3L )
{ {
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
xReturn = pdFALSE; xReturn = pdFALSE;
lParameterNumber = 0L; lParameterNumber = 0L;
} }
@ -353,15 +377,17 @@ static BaseType_t lParameterNumber = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -369,15 +395,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" ); sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -405,7 +431,7 @@ static BaseType_t lParameterNumber = 0;
else else
{ {
/* No more parameters were found. Make sure the write buffer does /* No more parameters were found. Make sure the write buffer does
not contain a valid string. */ * not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00; pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */ /* No more data to return. */
@ -422,7 +448,9 @@ static BaseType_t lParameterNumber = 0;
#if ipconfigSUPPORT_OUTGOING_PINGS == 1 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
char * pcParameter; char * pcParameter;
BaseType_t lParameterStringLength, xReturn; BaseType_t lParameterStringLength, xReturn;
@ -431,8 +459,8 @@ static BaseType_t lParameterNumber = 0;
char cBuffer[ 16 ]; char cBuffer[ 16 ];
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -470,7 +498,7 @@ static BaseType_t lParameterNumber = 0;
configASSERT( pcParameter ); configASSERT( pcParameter );
/* Attempt to obtain the IP address. If the first character is not a /* Attempt to obtain the IP address. If the first character is not a
digit, assume the host name has been passed in. */ * digit, assume the host name has been passed in. */
if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) ) if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
{ {
ulIPAddress = FreeRTOS_inet_addr( pcParameter ); ulIPAddress = FreeRTOS_inet_addr( pcParameter );
@ -513,15 +541,17 @@ static BaseType_t lParameterNumber = 0;
#if configINCLUDE_DEMO_DEBUG_STATS != 0 #if configINCLUDE_DEMO_DEBUG_STATS != 0
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
static BaseType_t xIndex = -1; static BaseType_t xIndex = -1;
extern xExampleDebugStatEntry_t xIPTraceValues[]; extern xExampleDebugStatEntry_t xIPTraceValues[];
BaseType_t xReturn; BaseType_t xReturn;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -549,22 +579,24 @@ static BaseType_t lParameterNumber = 0;
#endif /* configINCLUDE_DEMO_DEBUG_STATS */ #endif /* configINCLUDE_DEMO_DEBUG_STATS */
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
static BaseType_t xIndex = 0; static BaseType_t xIndex = 0;
BaseType_t xReturn; BaseType_t xReturn;
uint32_t ulAddress; uint32_t ulAddress;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
switch( xIndex ) switch( xIndex )
{ {
case 0 : case 0:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else #else
@ -575,7 +607,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 1 : case 1:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else #else
@ -586,7 +618,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 2 : case 2:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else #else
@ -597,7 +629,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
case 3 : case 3:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints ); FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else #else
@ -608,7 +640,7 @@ uint32_t ulAddress;
xIndex++; xIndex++;
break; break;
default : default:
ulAddress = 0; ulAddress = 0;
sprintf( pcWriteBuffer, "\r\n\r\n" ); sprintf( pcWriteBuffer, "\r\n\r\n" );
xReturn = pdFALSE; xReturn = pdFALSE;
@ -627,14 +659,16 @@ uint32_t ulAddress;
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength; BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -672,7 +706,7 @@ uint32_t ulAddress;
} }
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,13 +20,15 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
#ifndef UDP_COMMAND_INTERPRETER_H #ifndef UDP_COMMAND_INTERPRETER_H
#define UDP_COMMAND_INTERPRETER_H #define UDP_COMMAND_INTERPRETER_H
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority ); void vStartUDPCommandInterpreterTask( uint16_t usStackSize,
uint32_t ulPort,
UBaseType_t uxPriority );
#endif /* UDP_COMMAND_INTERPRETER_H */ #endif /* UDP_COMMAND_INTERPRETER_H */

View file

@ -54,7 +54,7 @@
/* /*
* The task that runs FreeRTOS+CLI. * The task that runs FreeRTOS+CLI.
*/ */
void vUDPCommandInterpreterTask( void *pvParameters ); void vUDPCommandInterpreterTask( void * pvParameters );
/* /*
* Open and configure the UDP socket. * Open and configure the UDP socket.
@ -63,7 +63,9 @@ static xSocket_t prvOpenUDPServerSocket( uint16_t usPort );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority ) void vStartUDPCommandInterpreterTask( uint16_t usStackSize,
uint32_t ulPort,
UBaseType_t uxPriority )
{ {
xTaskCreate( vUDPCommandInterpreterTask, "CLI", usStackSize, ( void * ) ulPort, uxPriority, NULL ); xTaskCreate( vUDPCommandInterpreterTask, "CLI", usStackSize, ( void * ) ulPort, uxPriority, NULL );
} }
@ -74,27 +76,27 @@ void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBa
* interpreter. In this case a UDP port is used. See the URL in the comments * interpreter. In this case a UDP port is used. See the URL in the comments
* within main.c for the location of the online documentation. * within main.c for the location of the online documentation.
*/ */
void vUDPCommandInterpreterTask( void *pvParameters ) void vUDPCommandInterpreterTask( void * pvParameters )
{ {
long lBytes, lByte; long lBytes, lByte;
signed char cInChar, cInputIndex = 0; signed char cInChar, cInputIndex = 0;
static char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ]; static char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ];
BaseType_t xMoreDataToFollow; BaseType_t xMoreDataToFollow;
struct freertos_sockaddr xClient; struct freertos_sockaddr xClient;
socklen_t xClientAddressLength = 0; /* This is required as a parameter to maintain the sendto() Berkeley sockets API - but it is not actually used so can take any value. */ socklen_t xClientAddressLength = 0; /* This is required as a parameter to maintain the sendto() Berkeley sockets API - but it is not actually used so can take any value. */
xSocket_t xSocket; xSocket_t xSocket;
/* Just to prevent compiler warnings. */ /* Just to prevent compiler warnings. */
( void ) pvParameters; ( void ) pvParameters;
/* Attempt to open the socket. The port number is passed in the task /* Attempt to open the socket. The port number is passed in the task
parameter. The strange casting is to remove compiler warnings on 32-bit * parameter. The strange casting is to remove compiler warnings on 32-bit
machines. */ * machines. */
xSocket = prvOpenUDPServerSocket( ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL ); xSocket = prvOpenUDPServerSocket( ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL );
if( xSocket != FREERTOS_INVALID_SOCKET ) if( xSocket != FREERTOS_INVALID_SOCKET )
{ {
for( ;; ) for( ; ; )
{ {
/* Wait for incoming data on the opened socket. */ /* Wait for incoming data on the opened socket. */
lBytes = FreeRTOS_recvfrom( xSocket, ( void * ) cLocalBuffer, sizeof( cLocalBuffer ), 0, &xClient, &xClientAddressLength ); lBytes = FreeRTOS_recvfrom( xSocket, ( void * ) cLocalBuffer, sizeof( cLocalBuffer ), 0, &xClient, &xClientAddressLength );
@ -103,6 +105,7 @@ xSocket_t xSocket;
{ {
/* Process each received byte in turn. */ /* Process each received byte in turn. */
lByte = 0; lByte = 0;
while( lByte < lBytes ) while( lByte < lBytes )
{ {
/* The next character in the input buffer. */ /* The next character in the input buffer. */
@ -110,30 +113,29 @@ xSocket_t xSocket;
lByte++; lByte++;
/* Newline characters are taken as the end of the command /* Newline characters are taken as the end of the command
string. */ * string. */
if( cInChar == '\n' ) if( cInChar == '\n' )
{ {
/* Process the input string received prior to the /* Process the input string received prior to the
newline. */ * newline. */
do do
{ {
/* Pass the string to FreeRTOS+CLI. */ /* Pass the string to FreeRTOS+CLI. */
xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE ); xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE );
/* Send the output generated by the command's /* Send the output generated by the command's
implementation. */ * implementation. */
FreeRTOS_sendto( xSocket, cOutputString, strlen( cOutputString ), 0, &xClient, xClientAddressLength ); FreeRTOS_sendto( xSocket, cOutputString, strlen( cOutputString ), 0, &xClient, xClientAddressLength );
} while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */ } while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */
/* All the strings generated by the command processing /* All the strings generated by the command processing
have been sent. Clear the input string ready to receive * have been sent. Clear the input string ready to receive
the next command. */ * the next command. */
cInputIndex = 0; cInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
/* Transmit a spacer, just to make the command console /* Transmit a spacer, just to make the command console
easier to read. */ * easier to read. */
FreeRTOS_sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, &xClient, xClientAddressLength ); FreeRTOS_sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, &xClient, xClientAddressLength );
} }
else else
@ -141,12 +143,12 @@ xSocket_t xSocket;
if( cInChar == '\r' ) if( cInChar == '\r' )
{ {
/* Ignore the character. Newlines are used to /* Ignore the character. Newlines are used to
detect the end of the input string. */ * detect the end of the input string. */
} }
else if( cInChar == '\b' ) else if( cInChar == '\b' )
{ {
/* Backspace was pressed. Erase the last character /* Backspace was pressed. Erase the last character
in the string - if any. */ * in the string - if any. */
if( cInputIndex > 0 ) if( cInputIndex > 0 )
{ {
cInputIndex--; cInputIndex--;
@ -156,8 +158,8 @@ xSocket_t xSocket;
else else
{ {
/* A character was entered. Add it to the string /* A character was entered. Add it to the string
entered so far. When a \n is entered the complete * entered so far. When a \n is entered the complete
string will be passed to the command interpreter. */ * string will be passed to the command interpreter. */
if( cInputIndex < cmdMAX_INPUT_SIZE ) if( cInputIndex < cmdMAX_INPUT_SIZE )
{ {
cInputString[ cInputIndex ] = cInChar; cInputString[ cInputIndex ] = cInChar;
@ -179,11 +181,12 @@ xSocket_t xSocket;
static xSocket_t prvOpenUDPServerSocket( uint16_t usPort ) static xSocket_t prvOpenUDPServerSocket( uint16_t usPort )
{ {
struct freertos_sockaddr xServer; struct freertos_sockaddr xServer;
xSocket_t xSocket = FREERTOS_INVALID_SOCKET; xSocket_t xSocket = FREERTOS_INVALID_SOCKET;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET)
if( xSocket != FREERTOS_INVALID_SOCKET )
{ {
/* Zero out the server structure. */ /* Zero out the server structure. */
memset( ( void * ) &xServer, 0x00, sizeof( xServer ) ); memset( ( void * ) &xServer, 0x00, sizeof( xServer ) );
@ -202,5 +205,3 @@ xSocket_t xSocket = FREERTOS_INVALID_SOCKET;
return xSocket; return xSocket;
} }

View file

@ -26,12 +26,12 @@
/****************************************************************************** /******************************************************************************
* *
* See the following web page for essential TwoEchoClient.c usage and * See the following web page for essential TwoEchoClient.c usage and
* configuration details: * configuration details:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml * https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml
* *
******************************************************************************/ ******************************************************************************/
/* Standard includes. */ /* Standard includes. */
@ -51,28 +51,30 @@
#define echoTINY_DELAY ( ( TickType_t ) 2 ) #define echoTINY_DELAY ( ( TickType_t ) 2 )
/* The echo tasks create a socket, send out a number of echo requests /* The echo tasks create a socket, send out a number of echo requests
(listening for each echo reply), then close the socket again before * (listening for each echo reply), then close the socket again before
starting over. This delay is used between each iteration to ensure the * starting over. This delay is used between each iteration to ensure the
network does not get too congested. */ * network does not get too congested. */
#define echoLOOP_DELAY ( ( TickType_t ) 250 / portTICK_RATE_MS ) #define echoLOOP_DELAY ( ( TickType_t ) 250 / portTICK_RATE_MS )
#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 #if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
/* When the trace recorder code is included user events are generated to
mark the sending and receiving of the echoed data (only in the zero copy /* When the trace recorder code is included user events are generated to
task. */ * mark the sending and receiving of the echoed data (only in the zero copy
* task. */
#define echoMARK_SEND_IN_TRACE_BUFFER( x ) vTraceUserEvent( x ) #define echoMARK_SEND_IN_TRACE_BUFFER( x ) vTraceUserEvent( x )
traceLabel xZeroCopySendEvent, xZeroCopyReceiveEvent; traceLabel xZeroCopySendEvent, xZeroCopyReceiveEvent;
#else #else
/* When the trace recorder code is not included just #define away the call
to post the user event. */ /* When the trace recorder code is not included just #define away the call
* to post the user event. */
#define echoMARK_SEND_IN_TRACE_BUFFER( x ) #define echoMARK_SEND_IN_TRACE_BUFFER( x )
#define xZeroCopySendEvent 0 #define xZeroCopySendEvent 0
#define xZeroCopyReceiveEvent 0 #define xZeroCopyReceiveEvent 0
#endif #endif
/* The echo server is assumed to be on port 7, which is the standard echo /* The echo server is assumed to be on port 7, which is the standard echo
protocol port. */ * protocol port. */
#define echoECHO_PORT ( 7 ) #define echoECHO_PORT ( 7 )
/* /*
@ -80,11 +82,11 @@ protocol port. */
* port number 7. prvEchoClientTask() uses the standard interface. * port number 7. prvEchoClientTask() uses the standard interface.
* prvZeroCopyEchoClientTask() uses the zero copy interface. * prvZeroCopyEchoClientTask() uses the zero copy interface.
*/ */
static void prvEchoClientTask( void *pvParameters ); static void prvEchoClientTask( void * pvParameters );
static void prvZeroCopyEchoClientTask( void *pvParameters ); static void prvZeroCopyEchoClientTask( void * pvParameters );
/* The receive timeout is set shorter when the windows simulator is used /* The receive timeout is set shorter when the windows simulator is used
because simulated time is slower than real time. */ * because simulated time is slower than real time. */
#ifdef _WINDOWS_ #ifdef _WINDOWS_
const TickType_t xReceiveTimeOut = 50 / portTICK_RATE_MS; const TickType_t xReceiveTimeOut = 50 / portTICK_RATE_MS;
#else #else
@ -93,7 +95,8 @@ because simulated time is slower than real time. */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vStartEchoClientTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ) void vStartEchoClientTasks( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority )
{ {
/* Create the echo client task that does not use the zero copy interface. */ /* Create the echo client task that does not use the zero copy interface. */
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */ xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
@ -113,22 +116,22 @@ void vStartEchoClientTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvEchoClientTask( void *pvParameters ) static void prvEchoClientTask( void * pvParameters )
{ {
xSocket_t xSocket; xSocket_t xSocket;
struct freertos_sockaddr xEchoServerAddress; struct freertos_sockaddr xEchoServerAddress;
char cTxString[ 25 ], cRxString[ 25 ]; /* Make sure the stack is large enough to hold these. Turn on stack overflow checking during debug to be sure. */ char cTxString[ 25 ], cRxString[ 25 ]; /* Make sure the stack is large enough to hold these. Turn on stack overflow checking during debug to be sure. */
int32_t lLoopCount = 0UL; int32_t lLoopCount = 0UL;
const int32_t lMaxLoopCount = 50; const int32_t lMaxLoopCount = 50;
volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL; volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL;
uint32_t xAddressLength = sizeof( xEchoServerAddress ); uint32_t xAddressLength = sizeof( xEchoServerAddress );
/* Remove compiler warning about unused parameters. */ /* Remove compiler warning about unused parameters. */
( void ) pvParameters; ( void ) pvParameters;
/* Echo requests are sent to the echo server. The address of the echo /* Echo requests are sent to the echo server. The address of the echo
server is configured by the constants configECHO_SERVER_ADDR0 to * server is configured by the constants configECHO_SERVER_ADDR0 to
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */ * configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT ); xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
@ -149,14 +152,14 @@ uint32_t xAddressLength = sizeof( xEchoServerAddress );
xEchoServerAddress.sin_family = FREERTOS_AF_INET; xEchoServerAddress.sin_family = FREERTOS_AF_INET;
for( ;; ) for( ; ; )
{ {
/* Create a socket. */ /* Create a socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
configASSERT( xSocket != FREERTOS_INVALID_SOCKET ); configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
/* Set a time out so a missing reply does not cause the task to block /* Set a time out so a missing reply does not cause the task to block
indefinitely. */ * indefinitely. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
/* Send a number of echo requests. */ /* Send a number of echo requests. */
@ -166,29 +169,29 @@ uint32_t xAddressLength = sizeof( xEchoServerAddress );
sprintf( cTxString, "Message number %u\r\n", ( unsigned int ) ulTxCount ); sprintf( cTxString, "Message number %u\r\n", ( unsigned int ) ulTxCount );
/* Send the string to the socket. ulFlags is set to 0, so the zero /* Send the string to the socket. ulFlags is set to 0, so the zero
copy interface is not used. That means the data from cTxString is * copy interface is not used. That means the data from cTxString is
copied into a network buffer inside FreeRTOS_sendto(), and cTxString * copied into a network buffer inside FreeRTOS_sendto(), and cTxString
can be reused as soon as FreeRTOS_sendto() has returned. 1 is added * can be reused as soon as FreeRTOS_sendto() has returned. 1 is added
to ensure the NULL string terminator is sent as part of the message. */ * to ensure the NULL string terminator is sent as part of the message. */
FreeRTOS_sendto( xSocket, /* The socket being sent to. */ FreeRTOS_sendto( xSocket, /* The socket being sent to. */
( void * ) cTxString, /* The data being sent. */ ( void * ) cTxString, /* The data being sent. */
strlen( cTxString ) + 1,/* The length of the data being sent. */ strlen( cTxString ) + 1, /* The length of the data being sent. */
0, /* ulFlags with the FREERTOS_ZERO_COPY bit clear. */ 0, /* ulFlags with the FREERTOS_ZERO_COPY bit clear. */
&xEchoServerAddress, /* The destination address. */ &xEchoServerAddress, /* The destination address. */
sizeof( xEchoServerAddress ) ); sizeof( xEchoServerAddress ) );
/* Keep a count of how many echo requests have been transmitted so /* Keep a count of how many echo requests have been transmitted so
it can be compared to the number of echo replies received. It would * it can be compared to the number of echo replies received. It would
be expected to loose at least one to an ARP message the first time * be expected to loose at least one to an ARP message the first time
the connection is created. */ * the connection is created. */
ulTxCount++; ulTxCount++;
/* Receive data echoed back to the socket. ulFlags is zero, so the /* Receive data echoed back to the socket. ulFlags is zero, so the
zero copy option is not being used and the received data will be * zero copy option is not being used and the received data will be
copied into the buffer pointed to by cRxString. xAddressLength is * copied into the buffer pointed to by cRxString. xAddressLength is
not actually used (at the time of writing this comment, anyway) by * not actually used (at the time of writing this comment, anyway) by
FreeRTOS_recvfrom(), but is set appropriately in case future * FreeRTOS_recvfrom(), but is set appropriately in case future
versions do use it. */ * versions do use it. */
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) ); memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
FreeRTOS_recvfrom( xSocket, /* The socket being received from. */ FreeRTOS_recvfrom( xSocket, /* The socket being received from. */
cRxString, /* The buffer into which the received data will be written. */ cRxString, /* The buffer into which the received data will be written. */
@ -203,10 +206,10 @@ uint32_t xAddressLength = sizeof( xEchoServerAddress );
/* The echo reply was received without error. */ /* The echo reply was received without error. */
ulRxCount++; ulRxCount++;
} }
}; }
/* Pause for a short while to ensure the network is not too /* Pause for a short while to ensure the network is not too
congested. */ * congested. */
vTaskDelay( echoLOOP_DELAY ); vTaskDelay( echoLOOP_DELAY );
/* Close this socket before looping back to create another. */ /* Close this socket before looping back to create another. */
@ -215,27 +218,27 @@ uint32_t xAddressLength = sizeof( xEchoServerAddress );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvZeroCopyEchoClientTask( void *pvParameters ) static void prvZeroCopyEchoClientTask( void * pvParameters )
{ {
xSocket_t xSocket; xSocket_t xSocket;
struct freertos_sockaddr xEchoServerAddress; struct freertos_sockaddr xEchoServerAddress;
static char cTxString[ 40 ]; static char cTxString[ 40 ];
int32_t lLoopCount = 0UL; int32_t lLoopCount = 0UL;
volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL; volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL;
uint32_t xAddressLength = sizeof( xEchoServerAddress ); uint32_t xAddressLength = sizeof( xEchoServerAddress );
int32_t lReturned; int32_t lReturned;
uint8_t *pucUDPPayloadBuffer; uint8_t * pucUDPPayloadBuffer;
const int32_t lMaxLoopCount = 50; const int32_t lMaxLoopCount = 50;
const char * const pcStringToSend = "Zero copy message number"; const char * const pcStringToSend = "Zero copy message number";
/* The buffer is large enough to hold the string, a number, and the string terminator. */ /* The buffer is large enough to hold the string, a number, and the string terminator. */
const size_t xBufferLength = strlen( pcStringToSend ) + 15; const size_t xBufferLength = strlen( pcStringToSend ) + 15;
#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 #if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
{ {
/* When the trace recorder code is included user events are generated to /* When the trace recorder code is included user events are generated to
mark the sending and receiving of the echoed data (only in the zero copy * mark the sending and receiving of the echoed data (only in the zero copy
task). */ * task). */
xZeroCopySendEvent = xTraceOpenLabel( "ZeroCopyTx" ); xZeroCopySendEvent = xTraceOpenLabel( "ZeroCopyTx" );
xZeroCopyReceiveEvent = xTraceOpenLabel( "ZeroCopyRx" ); xZeroCopyReceiveEvent = xTraceOpenLabel( "ZeroCopyRx" );
} }
@ -245,12 +248,12 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
( void ) pvParameters; ( void ) pvParameters;
/* Delay for a little while to ensure the task is out of synch with the /* Delay for a little while to ensure the task is out of synch with the
other echo task implemented above. */ * other echo task implemented above. */
vTaskDelay( echoLOOP_DELAY >> 1 ); vTaskDelay( echoLOOP_DELAY >> 1 );
/* Echo requests are sent to the echo server. The address of the echo /* Echo requests are sent to the echo server. The address of the echo
server is configured by the constants configECHO_SERVER_ADDR0 to * server is configured by the constants configECHO_SERVER_ADDR0 to
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */ * configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT ); xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
@ -271,42 +274,42 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
xEchoServerAddress.sin_family = FREERTOS_AF_INET; xEchoServerAddress.sin_family = FREERTOS_AF_INET;
for( ;; ) for( ; ; )
{ {
/* Create a socket. */ /* Create a socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
configASSERT( xSocket != FREERTOS_INVALID_SOCKET ); configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
/* Set a time out so a missing reply does not cause the task to block /* Set a time out so a missing reply does not cause the task to block
indefinitely. */ * indefinitely. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
/* Send a number of echo requests. */ /* Send a number of echo requests. */
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ ) for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
{ {
/* This task is going to send using the zero copy interface. The /* This task is going to send using the zero copy interface. The
data being sent is therefore written directly into a buffer that is * data being sent is therefore written directly into a buffer that is
passed by reference into the FreeRTOS_sendto() function. First * passed by reference into the FreeRTOS_sendto() function. First
obtain a buffer of adequate size from the IP stack. Although a max * obtain a buffer of adequate size from the IP stack. Although a max
delay is used, the actual delay will be capped to * delay is used, the actual delay will be capped to
ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence the test to ensure a buffer * ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence the test to ensure a buffer
was actually obtained. */ * was actually obtained. */
pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xBufferLength, portMAX_DELAY ); pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xBufferLength, portMAX_DELAY );
if( pucUDPPayloadBuffer != NULL ) if( pucUDPPayloadBuffer != NULL )
{ {
/* A buffer was successfully obtained. Create the string that is /* A buffer was successfully obtained. Create the string that is
sent to the echo server. Note the string is written directly * sent to the echo server. Note the string is written directly
into the buffer obtained from the IP stack. */ * into the buffer obtained from the IP stack. */
sprintf( ( char * ) pucUDPPayloadBuffer, "%s %u\r\n", "Zero copy message number", ( unsigned int ) ulTxCount ); sprintf( ( char * ) pucUDPPayloadBuffer, "%s %u\r\n", "Zero copy message number", ( unsigned int ) ulTxCount );
/* Also copy the string into a local buffer so it can be compared /* Also copy the string into a local buffer so it can be compared
with the string that is later received back from the echo server. */ * with the string that is later received back from the echo server. */
strcpy( cTxString, ( char * ) pucUDPPayloadBuffer ); strcpy( cTxString, ( char * ) pucUDPPayloadBuffer );
/* Pass the buffer into the send function. ulFlags has the /* Pass the buffer into the send function. ulFlags has the
FREERTOS_ZERO_COPY bit set so the IP stack will take control of * FREERTOS_ZERO_COPY bit set so the IP stack will take control of
the buffer, rather than copy data out of the buffer. */ * the buffer, rather than copy data out of the buffer. */
echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopySendEvent ); echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopySendEvent );
lReturned = FreeRTOS_sendto( xSocket, /* The socket being sent to. */ lReturned = FreeRTOS_sendto( xSocket, /* The socket being sent to. */
( void * ) pucUDPPayloadBuffer, /* The buffer being passed into the IP stack. */ ( void * ) pucUDPPayloadBuffer, /* The buffer being passed into the IP stack. */
@ -318,37 +321,37 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
if( lReturned == 0 ) if( lReturned == 0 )
{ {
/* The send operation failed, so this task is still /* The send operation failed, so this task is still
responsible for the buffer obtained from the IP stack. To * responsible for the buffer obtained from the IP stack. To
ensure the buffer is not lost it must either be used again, * ensure the buffer is not lost it must either be used again,
or, as in this case, returned to the IP stack using * or, as in this case, returned to the IP stack using
FreeRTOS_ReleaseUDPPayloadBuffer(). pucUDPPayloadBuffer can * FreeRTOS_ReleaseUDPPayloadBuffer(). pucUDPPayloadBuffer can
be safely re-used to receive from the socket below once the * be safely re-used to receive from the socket below once the
buffer has been returned to the stack. */ * buffer has been returned to the stack. */
FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer ); FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer );
} }
else else
{ {
/* The send was successful so the IP stack is now managing /* The send was successful so the IP stack is now managing
the buffer pointed to by pucUDPPayloadBuffer, and the IP * the buffer pointed to by pucUDPPayloadBuffer, and the IP
stack will return the buffer once it has been sent. * stack will return the buffer once it has been sent.
pucUDPPayloadBuffer can be safely re-used to receive from * pucUDPPayloadBuffer can be safely re-used to receive from
the socket below. */ * the socket below. */
} }
/* Keep a count of how many echo requests have been transmitted /* Keep a count of how many echo requests have been transmitted
so it can be compared to the number of echo replies received. * so it can be compared to the number of echo replies received.
It would be expected to loose at least one to an ARP message the * It would be expected to loose at least one to an ARP message the
first time the connection is created. */ * first time the connection is created. */
ulTxCount++; ulTxCount++;
/* Receive data on the socket. ulFlags has the zero copy bit set /* Receive data on the socket. ulFlags has the zero copy bit set
(FREERTOS_ZERO_COPY) indicating to the stack that a reference to * (FREERTOS_ZERO_COPY) indicating to the stack that a reference to
the received data should be passed out to this task using the * the received data should be passed out to this task using the
second parameter to the FreeRTOS_recvfrom() call. When this is * second parameter to the FreeRTOS_recvfrom() call. When this is
done the IP stack is no longer responsible for releasing the * done the IP stack is no longer responsible for releasing the
buffer, and the task *must* return the buffer to the stack when * buffer, and the task *must* return the buffer to the stack when
it is no longer needed. By default the receive block time is * it is no longer needed. By default the receive block time is
portMAX_DELAY. */ * portMAX_DELAY. */
echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopyReceiveEvent ); echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopyReceiveEvent );
lReturned = FreeRTOS_recvfrom( xSocket, /* The socket to receive from. */ lReturned = FreeRTOS_recvfrom( xSocket, /* The socket to receive from. */
( void * ) &pucUDPPayloadBuffer, /* pucUDPPayloadBuffer will be set to point to the buffer that already contains the received data. */ ( void * ) &pucUDPPayloadBuffer, /* pucUDPPayloadBuffer will be set to point to the buffer that already contains the received data. */
@ -360,7 +363,7 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
if( lReturned > 0 ) if( lReturned > 0 )
{ {
/* Compare the string sent to the echo server with the string /* Compare the string sent to the echo server with the string
received back from the echo server. */ * received back from the echo server. */
if( strcmp( ( char * ) pucUDPPayloadBuffer, cTxString ) == 0 ) if( strcmp( ( char * ) pucUDPPayloadBuffer, cTxString ) == 0 )
{ {
/* The strings matched. */ /* The strings matched. */
@ -368,14 +371,14 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
} }
/* The buffer that contains the data passed out of the stack /* The buffer that contains the data passed out of the stack
*must* be returned to the stack. */ * must* be returned to the stack. */
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer ); FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
} }
} }
} }
/* Pause for a short while to ensure the network is not too /* Pause for a short while to ensure the network is not too
congested. */ * congested. */
vTaskDelay( echoLOOP_DELAY ); vTaskDelay( echoLOOP_DELAY );
/* Close this socket before looping back to create another. */ /* Close this socket before looping back to create another. */
@ -383,4 +386,3 @@ const size_t xBufferLength = strlen( pcStringToSend ) + 15;
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -32,6 +32,7 @@
* to send to and receive from an echo server. The other task uses the zero * to send to and receive from an echo server. The other task uses the zero
* copy interface to send to and receive from an echo server. * copy interface to send to and receive from an echo server.
*/ */
void vStartEchoClientTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ); void vStartEchoClientTasks( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority );
#endif /* TWO_ECHO_CLIENTS_H */ #endif /* TWO_ECHO_CLIENTS_H */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -43,7 +43,7 @@
#include "DemoIPTrace.h" #include "DemoIPTrace.h"
/* It is possible to remove the trace macros using the /* It is possible to remove the trace macros using the
configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */ * configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
#if configINCLUDE_DEMO_DEBUG_STATS == 1 #if configINCLUDE_DEMO_DEBUG_STATS == 1
/* /*
@ -53,18 +53,20 @@ configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
* number of network buffers that were available during the execution of the * number of network buffers that were available during the execution of the
* stack). * stack).
*/ */
static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount ); static void prvStoreLowest( uint32_t * pulCurrentValue,
uint32_t ulCount );
/* /*
* Each row in the xIPTraceValues[] table contains a pointer to a function that * Each row in the xIPTraceValues[] table contains a pointer to a function that
* updates the value for that row. Rows that simply increment an event count * updates the value for that row. Rows that simply increment an event count
* point to this function. * point to this function.
*/ */
static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount ); static void prvIncrementEventCount( uint32_t * pulCurrentValue,
uint32_t ulCount );
xExampleDebugStatEntry_t xIPTraceValues[] = xExampleDebugStatEntry_t xIPTraceValues[] =
{ {
/* Comment out array entries to remove individual trace items. */ /* Comment out array entries to remove individual trace items. */
{ iptraceID_NETWORK_INTERFACE_RECEIVE, ( const uint8_t * const ) "Packets received by the network interface", prvIncrementEventCount, 0 }, { iptraceID_NETWORK_INTERFACE_RECEIVE, ( const uint8_t * const ) "Packets received by the network interface", prvIncrementEventCount, 0 },
@ -72,11 +74,11 @@ xExampleDebugStatEntry_t xIPTraceValues[] =
{ iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 }, { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 },
{ iptraceID_NETWORK_BUFFER_OBTAINED, ( const uint8_t * const ) "Lowest ever available network buffers", prvStoreLowest, 0xffffUL }, { iptraceID_NETWORK_BUFFER_OBTAINED, ( const uint8_t * const ) "Lowest ever available network buffers", prvStoreLowest, 0xffffUL },
{ iptraceID_NETWORK_EVENT_RECEIVED, ( const uint8_t * const ) "Lowest ever free space in network event queue", prvStoreLowest, 0xffffUL }, { iptraceID_NETWORK_EVENT_RECEIVED, ( const uint8_t * const ) "Lowest ever free space in network event queue", prvStoreLowest, 0xffffUL },
{ iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 }, { iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer", prvIncrementEventCount, 0 },
{ iptraceID_ARP_TABLE_ENTRY_EXPIRED, ( const uint8_t * const ) "Count of expired ARP entries", prvIncrementEventCount, 0 }, { iptraceID_ARP_TABLE_ENTRY_EXPIRED, ( const uint8_t * const ) "Count of expired ARP entries", prvIncrementEventCount, 0 },
{ iptraceID_FAILED_TO_CREATE_SOCKET, ( const uint8_t * const ) "Count of failures to create a socket", prvIncrementEventCount, 0 }, { iptraceID_FAILED_TO_CREATE_SOCKET, ( const uint8_t * const ) "Count of failures to create a socket", prvIncrementEventCount, 0 },
{ iptraceID_RECVFROM_DISCARDING_BYTES, ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes", prvIncrementEventCount, 0 }, { iptraceID_RECVFROM_DISCARDING_BYTES, ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes", prvIncrementEventCount, 0 },
{ iptraceID_ETHERNET_RX_EVENT_LOST, ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 }, { iptraceID_ETHERNET_RX_EVENT_LOST, ( const uint8_t * const ) "Count of lost Ethernet Rx events (event queue full?)", prvIncrementEventCount, 0 },
{ iptraceID_STACK_TX_EVENT_LOST, ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)", prvIncrementEventCount, 0 }, { iptraceID_STACK_TX_EVENT_LOST, ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)", prvIncrementEventCount, 0 },
{ ipconfigID_BIND_FAILED, ( const uint8_t * const ) "Count of failed calls to bind()", prvIncrementEventCount, 0 }, { ipconfigID_BIND_FAILED, ( const uint8_t * const ) "Count of failed calls to bind()", prvIncrementEventCount, 0 },
{ iptraceID_RECVFROM_TIMEOUT, ( const uint8_t * const ) "Count of receive timeouts", prvIncrementEventCount, 0 }, { iptraceID_RECVFROM_TIMEOUT, ( const uint8_t * const ) "Count of receive timeouts", prvIncrementEventCount, 0 },
@ -85,25 +87,26 @@ xExampleDebugStatEntry_t xIPTraceValues[] =
{ iptraceID_NO_BUFFER_FOR_SENDTO, ( const uint8_t * const ) "Count of failed transmits due to timeout", prvIncrementEventCount, 0 }, { iptraceID_NO_BUFFER_FOR_SENDTO, ( const uint8_t * const ) "Count of failed transmits due to timeout", prvIncrementEventCount, 0 },
{ iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, ( const uint8_t * const ) "Number of times task had to wait to obtain a DMA Tx descriptor", prvIncrementEventCount, 0 }, { iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, ( const uint8_t * const ) "Number of times task had to wait to obtain a DMA Tx descriptor", prvIncrementEventCount, 0 },
{ iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, ( const uint8_t * const ) "Failed to notify select group", prvIncrementEventCount, 0 } { iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, ( const uint8_t * const ) "Failed to notify select group", prvIncrementEventCount, 0 }
}; };
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xExampleDebugStatEntries( void ) BaseType_t xExampleDebugStatEntries( void )
{ {
/* Return the number of entries in the xIPTraceValues[] table. */ /* Return the number of entries in the xIPTraceValues[] table. */
return ( BaseType_t ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) ); return ( BaseType_t ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue ) void vExampleDebugStatUpdate( uint8_t ucIdentifier,
{ uint32_t ulValue )
BaseType_t xIndex; {
const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ); BaseType_t xIndex;
const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t );
/* Update an entry in the xIPTraceValues[] table. Each row in the table /* Update an entry in the xIPTraceValues[] table. Each row in the table
includes a pointer to a function that performs the actual update. This * includes a pointer to a function that performs the actual update. This
function just executes the update function from that table row. */ * function just executes the update function from that table row. */
for( xIndex = 0; xIndex < xEntries; xIndex++ ) for( xIndex = 0; xIndex < xEntries; xIndex++ )
{ {
if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier ) if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier )
@ -114,36 +117,34 @@ const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStat
} }
configASSERT( xIndex != xEntries ); configASSERT( xIndex != xEntries );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount ) static void prvIncrementEventCount( uint32_t * pulCurrentValue,
{ uint32_t ulCount )
{
/* Each row in the xIPTraceValues[] table contains a pointer to a function /* Each row in the xIPTraceValues[] table contains a pointer to a function
that updates the value for that row. Rows that simply increment an event * that updates the value for that row. Rows that simply increment an event
count point to this function. */ * count point to this function. */
( void ) ulCount; ( void ) ulCount;
( *pulCurrentValue )++; ( *pulCurrentValue )++;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount ) static void prvStoreLowest( uint32_t * pulCurrentValue,
{ uint32_t ulCount )
{
/* Each row in the xIPTraceValues[] table contains a pointer to a function /* Each row in the xIPTraceValues[] table contains a pointer to a function
that updates the value for that row. Rows that latch the lowest value * that updates the value for that row. Rows that latch the lowest value
point to this function (for example, this function can be used to latch * point to this function (for example, this function can be used to latch
the lowest number of network buffers that were available during the * the lowest number of network buffers that were available during the
execution of the stack). */ * execution of the stack). */
if( ulCount < *pulCurrentValue ) if( ulCount < *pulCurrentValue )
{ {
*pulCurrentValue = ulCount; *pulCurrentValue = ulCount;
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */ #endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -34,7 +34,8 @@
#ifndef DEMO_IP_TRACE_MACROS_H #ifndef DEMO_IP_TRACE_MACROS_H
#define DEMO_IP_TRACE_MACROS_H #define DEMO_IP_TRACE_MACROS_H
typedef void ( *vTraceAction_t )( uint32_t *, uint32_t ); typedef void ( * vTraceAction_t )( uint32_t *,
uint32_t );
/* Type that defines each statistic being gathered. */ /* Type that defines each statistic being gathered. */
typedef struct ExampleDebugStatEntry typedef struct ExampleDebugStatEntry
@ -46,12 +47,13 @@ typedef struct ExampleDebugStatEntry
} xExampleDebugStatEntry_t; } xExampleDebugStatEntry_t;
/* Unique identifiers used to locate the entry for each trace macro in the /* Unique identifiers used to locate the entry for each trace macro in the
xIPTraceValues[] table defined in DemoIPTrace.c. */ * xIPTraceValues[] table defined in DemoIPTrace.c. */
#define iptraceID_NETWORK_INTERFACE_RECEIVE 0 #define iptraceID_NETWORK_INTERFACE_RECEIVE 0
#define iptraceID_NETWORK_INTERFACE_TRANSMIT 1 #define iptraceID_NETWORK_INTERFACE_TRANSMIT 1
#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2 #define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2
/* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto /* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto
demo. */ * demo. */
#define iptraceID_NETWORK_BUFFER_OBTAINED 3 #define iptraceID_NETWORK_BUFFER_OBTAINED 3
#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4 #define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4
#define iptraceID_NETWORK_EVENT_RECEIVED 5 #define iptraceID_NETWORK_EVENT_RECEIVED 5
@ -70,15 +72,16 @@ demo. */
#define iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP 18 #define iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP 18
/* It is possible to remove the trace macros using the /* It is possible to remove the trace macros using the
configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */ * configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
#if configINCLUDE_DEMO_DEBUG_STATS == 1 #if configINCLUDE_DEMO_DEBUG_STATS == 1
/* The trace macro definitions themselves. Any trace macros left undefined /* The trace macro definitions themselves. Any trace macros left undefined
will default to be empty macros. */ * will default to be empty macros. */
#define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) ) #define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) )
#define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) ) #define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) )
#define iptraceNETWORK_EVENT_RECEIVED( eEvent ) { \ #define iptraceNETWORK_EVENT_RECEIVED( eEvent ) \
{ \
uint16_t usSpace; \ uint16_t usSpace; \
usSpace = ( uint16_t ) uxQueueMessagesWaiting( xNetworkEventQueue ); \ usSpace = ( uint16_t ) uxQueueMessagesWaiting( xNetworkEventQueue ); \
/* Minus one as an event was removed before the space was queried. */ \ /* Minus one as an event was removed before the space was queried. */ \
@ -103,12 +106,13 @@ configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
#define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 ) #define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 )
#define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 ) #define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 )
/* /*
* The function that updates a line in the xIPTraceValues table. * The function that updates a line in the xIPTraceValues table.
*/ */
void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue ); void vExampleDebugStatUpdate( uint8_t ucIdentifier,
uint32_t ulValue );
/* /*
* Returns the number of entries in the xIPTraceValues table. * Returns the number of entries in the xIPTraceValues table.
*/ */
BaseType_t xExampleDebugStatEntries( void ); BaseType_t xExampleDebugStatEntries( void );
@ -117,4 +121,3 @@ configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
#endif /* DEMO_IP_TRACE_MACROS_H */ #endif /* DEMO_IP_TRACE_MACROS_H */

View file

@ -193,7 +193,6 @@ void vLoggingInit( BaseType_t xLogToStdout,
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */ #endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xPrintUDPAddress.sin_family = FREERTOS_AF_INET; xPrintUDPAddress.sin_family = FREERTOS_AF_INET;
} }
/* If a disk file or stdout are to be used then Win32 system calls will /* If a disk file or stdout are to be used then Win32 system calls will
@ -549,8 +548,8 @@ static void prvLogToFile( const char * pcMessage,
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vPlatformInitLogging(void) void vPlatformInitLogging( void )
{ {
vLoggingInit(pdTRUE, pdFALSE, pdFALSE, 0U, 0U); vLoggingInit( pdTRUE, pdFALSE, pdFALSE, 0U, 0U );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -636,6 +636,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
#ifdef democonfigUSE_AWS_IOT_CORE_BROKER #ifdef democonfigUSE_AWS_IOT_CORE_BROKER
#if defined( democonfigCLIENT_USERNAME ) #if defined( democonfigCLIENT_USERNAME )
/* /*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect * When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443. * to AWS IoT Core with Custom Authentication on port 443.
@ -651,6 +652,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn." #error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */ #endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */ #else /* if !defined( democonfigCLIENT_USERNAME ) */
/* /*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using * Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication. * x509 Certificate Authentication.

View file

@ -41,7 +41,7 @@
* @brief Cellular library log configuration. * @brief Cellular library log configuration.
* *
* Cellular library use CellularLogLevel macro for logging. * Cellular library use CellularLogLevel macro for logging.
* The prototye of these logging function is similar with printf with return type ignored. * The prototype of these logging function is similar with printf with return type ignored.
* *
*/ */

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386 VisualStudioVersion = 16.0.32929.386

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386 VisualStudioVersion = 16.0.32929.386

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386 VisualStudioVersion = 16.0.32929.386

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -48,31 +48,41 @@ static void prvSaveTraceFile( void );
* Defines a command that returns a table showing the state of each task at the * Defines a command that returns a table showing the state of each task at the
* time the command is called. * time the command is called.
*/ */
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that returns a table showing how much time each task has * Defines a command that returns a table showing how much time each task has
* spent in the Running state. * spent in the Running state.
*/ */
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that expects exactly three parameters. Each of the three * Defines a command that expects exactly three parameters. Each of the three
* parameter are echoed back one at a time. * parameter are echoed back one at a time.
*/ */
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that can take a variable number of parameters. Each * Defines a command that can take a variable number of parameters. Each
* parameter is echoes back one at a time. * parameter is echoes back one at a time.
*/ */
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Defines a command that starts/stops events being recorded for offline viewing * Defines a command that starts/stops events being recorded for offline viewing
* in FreeRTOS+Trace. * in FreeRTOS+Trace.
*/ */
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* Structure that defines the "run-time-stats" command line command. */ /* Structure that defines the "run-time-stats" command line command. */
static const CLI_Command_Definition_t xRunTimeStats = static const CLI_Command_Definition_t xRunTimeStats =
@ -93,8 +103,8 @@ static const CLI_Command_Definition_t xTaskStats =
}; };
/* Structure that defines the "echo_3_parameters" command line command. This /* Structure that defines the "echo_3_parameters" command line command. This
takes exactly three parameters that the command simply echos back one at a * takes exactly three parameters that the command simply echos back one at a
time. */ * time. */
static const CLI_Command_Definition_t xThreeParameterEcho = static const CLI_Command_Definition_t xThreeParameterEcho =
{ {
"echo_3_parameters", "echo_3_parameters",
@ -104,8 +114,8 @@ static const CLI_Command_Definition_t xThreeParameterEcho =
}; };
/* Structure that defines the "echo_parameters" command line command. This /* Structure that defines the "echo_parameters" command line command. This
takes a variable number of parameters that the command simply echos back one at * takes a variable number of parameters that the command simply echos back one at
a time. */ * a time. */
static const CLI_Command_Definition_t xParameterEcho = static const CLI_Command_Definition_t xParameterEcho =
{ {
"echo_parameters", "echo_parameters",
@ -115,7 +125,7 @@ static const CLI_Command_Definition_t xParameterEcho =
}; };
/* Structure that defines the "trace" command line command. This takes a single /* Structure that defines the "trace" command line command. This takes a single
parameter, which can be either "start" or "stop". */ * parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartTrace = static const CLI_Command_Definition_t xStartTrace =
{ {
"trace", "trace",
@ -137,13 +147,15 @@ void vRegisterCLICommands( void )
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n"; const char * const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -153,18 +165,20 @@ const char *const pcHeader = "Task State Priority Stack #\r\n********
vTaskList( pcWriteBuffer + strlen( pcHeader ) ); vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n"; const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -174,20 +188,22 @@ const char * const pcHeader = "Task Abs Time % Time\r\n*********
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) ); vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength, xReturn; BaseType_t lParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -195,15 +211,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" ); sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -226,11 +242,11 @@ static BaseType_t lParameterNumber = 0;
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
if( lParameterNumber == 3L ) if( lParameterNumber == 3L )
{ {
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
xReturn = pdFALSE; xReturn = pdFALSE;
lParameterNumber = 0L; lParameterNumber = 0L;
} }
@ -246,15 +262,17 @@ static BaseType_t lParameterNumber = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength, xReturn; BaseType_t lParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -262,15 +280,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" ); sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -298,7 +316,7 @@ static BaseType_t lParameterNumber = 0;
else else
{ {
/* No more parameters were found. Make sure the write buffer does /* No more parameters were found. Make sure the write buffer does
not contain a valid string. */ * not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00; pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */ /* No more data to return. */
@ -313,14 +331,16 @@ static BaseType_t lParameterNumber = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength; BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -361,16 +381,16 @@ BaseType_t lParameterStringLength;
} }
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvSaveTraceFile( void ) static void prvSaveTraceFile( void )
{ {
FILE* pxOutputFile; FILE * pxOutputFile;
fopen_s( &pxOutputFile, "Trace.dump", "wb"); fopen_s( &pxOutputFile, "Trace.dump", "wb" );
if( pxOutputFile != NULL ) if( pxOutputFile != NULL )
{ {
@ -383,4 +403,3 @@ FILE* pxOutputFile;
printf( "\r\nFailed to create trace dump file\r\n" ); printf( "\r\nFailed to create trace dump file\r\n" );
} }
} }

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386 VisualStudioVersion = 16.0.32929.386

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -34,37 +34,37 @@
* *
* Also note that it is assumed this demo is going to be used for short periods * Also note that it is assumed this demo is going to be used for short periods
* of time only, and therefore timer overflows are not handled. * of time only, and therefore timer overflows are not handled.
*/ */
/* FreeRTOS includes. */ /* FreeRTOS includes. */
#include <FreeRTOS.h> #include <FreeRTOS.h>
/* Variables used in the creation of the run time stats time base. Run time /* Variables used in the creation of the run time stats time base. Run time
stats record how much time each task spends in the Running state. */ * stats record how much time each task spends in the Running state. */
static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundedthMillisecond = 0LL; static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundredthMillisecond = 0LL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vConfigureTimerForRunTimeStats( void ) void vConfigureTimerForRunTimeStats( void )
{ {
LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue; LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue;
/* Initialise the variables used to create the run time stats time base. /* Initialise the variables used to create the run time stats time base.
Run time stats record how much time each task spends in the Running * Run time stats record how much time each task spends in the Running
state. */ * state. */
if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 ) if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 )
{ {
llTicksPerHundedthMillisecond = 1; llTicksPerHundredthMillisecond = 1;
} }
else else
{ {
/* How many times does the performance counter increment in 1/100th /* How many times does the performance counter increment in 1/100th
millisecond. */ * millisecond. */
llTicksPerHundedthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL; llTicksPerHundredthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL;
/* What is the performance counter value now, this will be subtracted /* What is the performance counter value now, this will be subtracted
from readings taken at run time. */ * from readings taken at run time. */
QueryPerformanceCounter( &liInitialRunTimeValue ); QueryPerformanceCounter( &liInitialRunTimeValue );
llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart; llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart;
} }
@ -73,25 +73,25 @@ LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue;
unsigned long ulGetRunTimeCounterValue( void ) unsigned long ulGetRunTimeCounterValue( void )
{ {
LARGE_INTEGER liCurrentCount; LARGE_INTEGER liCurrentCount;
unsigned long ulReturn; unsigned long ulReturn;
/* What is the performance counter value now? */ /* What is the performance counter value now? */
QueryPerformanceCounter( &liCurrentCount ); QueryPerformanceCounter( &liCurrentCount );
/* Subtract the performance counter value reading taken when the /* Subtract the performance counter value reading taken when the
application started to get a count from that reference point, then * application started to get a count from that reference point, then
scale to (simulated) 1/100ths of a millisecond. */ * scale to (simulated) 1/100ths of a millisecond. */
if( llTicksPerHundedthMillisecond == 0 ) if( llTicksPerHundredthMillisecond == 0 )
{ {
/* The trace macros can call this function before the kernel has been /* The trace macros can call this function before the kernel has been
started, in which case llTicksPerHundedthMillisecond will not have been * started, in which case llTicksPerHundredthMillisecond will not have been
initialised. */ * initialised. */
ulReturn = 0; ulReturn = 0;
} }
else else
{ {
ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundedthMillisecond ); ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundredthMillisecond );
} }
return ulReturn; return ulReturn;

View file

@ -1,4 +1,4 @@
/******************************************************************************* /*******************************************************************************
* Trace Recorder Library for Tracealyzer v4.1.4 * Trace Recorder Library for Tracealyzer v4.1.4
* Percepio AB, www.percepio.com * Percepio AB, www.percepio.com
* *
@ -46,13 +46,13 @@
******************************************************************************/ ******************************************************************************/
#ifndef TRC_CONFIG_H #ifndef TRC_CONFIG_H
#define TRC_CONFIG_H #define TRC_CONFIG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "trcDefines.h" #include "trcDefines.h"
/****************************************************************************** /******************************************************************************
* Include of processor header file * Include of processor header file
@ -61,7 +61,7 @@ extern "C" {
* required at least for the ARM Cortex-M port, that uses the ARM CMSIS API. * required at least for the ARM Cortex-M port, that uses the ARM CMSIS API.
* Try that in case of build problems. Otherwise, remove the #error line below. * Try that in case of build problems. Otherwise, remove the #error line below.
*****************************************************************************/ *****************************************************************************/
//#error "Trace Recorder: Please include your processor's header file here and remove this line." /*#error "Trace Recorder: Please include your processor's header file here and remove this line." */
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_HARDWARE_PORT * Configuration Macro: TRC_CFG_HARDWARE_PORT
@ -81,7 +81,7 @@ extern "C" {
* See trcHardwarePort.h for available ports and information on how to * See trcHardwarePort.h for available ports and information on how to
* define your own port, if not already present. * define your own port, if not already present.
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_Win32 #define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_Win32
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_RECORDER_MODE * Configuration Macro: TRC_CFG_RECORDER_MODE
@ -97,7 +97,7 @@ extern "C" {
* TRC_RECORDER_MODE_SNAPSHOT * TRC_RECORDER_MODE_SNAPSHOT
* TRC_RECORDER_MODE_STREAMING * TRC_RECORDER_MODE_STREAMING
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT #define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT
/****************************************************************************** /******************************************************************************
* TRC_CFG_FREERTOS_VERSION * TRC_CFG_FREERTOS_VERSION
@ -123,7 +123,7 @@ extern "C" {
* TRC_FREERTOS_VERSION_10_3_1 If using FreeRTOS v10.3.1 * TRC_FREERTOS_VERSION_10_3_1 If using FreeRTOS v10.3.1
* TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0 or later * TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0 or later
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_0 #define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_0
/******************************************************************************* /*******************************************************************************
* TRC_CFG_SCHEDULING_ONLY * TRC_CFG_SCHEDULING_ONLY
@ -135,9 +135,9 @@ extern "C" {
* *
* Default value is 0 (= include additional events). * Default value is 0 (= include additional events).
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_SCHEDULING_ONLY 0 #define TRC_CFG_SCHEDULING_ONLY 0
/****************************************************************************** /******************************************************************************
* TRC_CFG_INCLUDE_MEMMANG_EVENTS * TRC_CFG_INCLUDE_MEMMANG_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
@ -147,9 +147,9 @@ extern "C" {
* *
* Default value is 1. * Default value is 1.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1 #define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1
/****************************************************************************** /******************************************************************************
* TRC_CFG_INCLUDE_USER_EVENTS * TRC_CFG_INCLUDE_USER_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
@ -172,91 +172,91 @@ extern "C" {
* *
* Default value is 1. * Default value is 1.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_USER_EVENTS 1 #define TRC_CFG_INCLUDE_USER_EVENTS 1
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_ISR_TRACING * TRC_CFG_INCLUDE_ISR_TRACING
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If this is zero (0), the code for recording Interrupt Service Routines is * If this is zero (0), the code for recording Interrupt Service Routines is
* excluded, in order to reduce code size. This means that any calls to * excluded, in order to reduce code size. This means that any calls to
* vTraceStoreISRBegin/vTraceStoreISREnd will be ignored. * vTraceStoreISRBegin/vTraceStoreISREnd will be ignored.
* This does not completely disable ISR tracing, in cases where an ISR is * This does not completely disable ISR tracing, in cases where an ISR is
* calling a traced kernel service. These events will still be recorded and * calling a traced kernel service. These events will still be recorded and
* show up in anonymous ISR instances in Tracealyzer, with names such as * show up in anonymous ISR instances in Tracealyzer, with names such as
* "ISR sending to <queue name>". * "ISR sending to <queue name>".
* To disable such tracing, please refer to vTraceSetFilterGroup and * To disable such tracing, please refer to vTraceSetFilterGroup and
* vTraceSetFilterMask. * vTraceSetFilterMask.
* *
* Default value is 1. * Default value is 1.
* *
* Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin * Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin
* and vTraceStoreISREnd in your interrupt handlers. * and vTraceStoreISREnd in your interrupt handlers.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_ISR_TRACING 1 #define TRC_CFG_INCLUDE_ISR_TRACING 1
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_READY_EVENTS * TRC_CFG_INCLUDE_READY_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If one (1), events are recorded when tasks enter scheduling state "ready". * If one (1), events are recorded when tasks enter scheduling state "ready".
* This allows Tracealyzer to show the initial pending time before tasks enter * This allows Tracealyzer to show the initial pending time before tasks enter
* the execution state, and present accurate response times. * the execution state, and present accurate response times.
* If zero (0), "ready events" are not created, which allows for recording * If zero (0), "ready events" are not created, which allows for recording
* longer traces in the same amount of RAM. * longer traces in the same amount of RAM.
* *
* Default value is 1. * Default value is 1.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_READY_EVENTS 1 #define TRC_CFG_INCLUDE_READY_EVENTS 1
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_OSTICK_EVENTS * TRC_CFG_INCLUDE_OSTICK_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If this is one (1), events will be generated whenever the OS clock is * If this is one (1), events will be generated whenever the OS clock is
* increased. If zero (0), OS tick events are not generated, which allows for * increased. If zero (0), OS tick events are not generated, which allows for
* recording longer traces in the same amount of RAM. * recording longer traces in the same amount of RAM.
* *
* Default value is 1. * Default value is 1.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_OSTICK_EVENTS 1 #define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS * TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If this is zero (0), the trace will exclude any "event group" events. * If this is zero (0), the trace will exclude any "event group" events.
* *
* Default value is 0 (excluded) since dependent on event_groups.c * Default value is 0 (excluded) since dependent on event_groups.c
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 0 #define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 0
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_TIMER_EVENTS * TRC_CFG_INCLUDE_TIMER_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If this is zero (0), the trace will exclude any Timer events. * If this is zero (0), the trace will exclude any Timer events.
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_TIMER_EVENTS 1 #define TRC_CFG_INCLUDE_TIMER_EVENTS 1
/***************************************************************************** /*****************************************************************************
* TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS * TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
* *
* Macro which should be defined as either zero (0) or one (1). * Macro which should be defined as either zero (0) or one (1).
* *
* If this is zero (0), the trace will exclude any "pending function call" * If this is zero (0), the trace will exclude any "pending function call"
* events, such as xTimerPendFunctionCall(). * events, such as xTimerPendFunctionCall().
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1 #define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS * Configuration Macro: TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
@ -268,9 +268,9 @@ extern "C" {
* *
* Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10) * Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 0 #define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 0
/****************************************************************************** /******************************************************************************
* TRC_CFG_ENABLE_STACK_MONITOR * TRC_CFG_ENABLE_STACK_MONITOR
* *
* If enabled (1), the recorder periodically reports the unused stack space of * If enabled (1), the recorder periodically reports the unused stack space of
@ -280,9 +280,9 @@ extern "C" {
* In snapshot mode, the TzCtrl task is only used for stack monitoring and is * In snapshot mode, the TzCtrl task is only used for stack monitoring and is
* not created unless this is enabled. * not created unless this is enabled.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_ENABLE_STACK_MONITOR 0 #define TRC_CFG_ENABLE_STACK_MONITOR 0
/****************************************************************************** /******************************************************************************
* TRC_CFG_STACK_MONITOR_MAX_TASKS * TRC_CFG_STACK_MONITOR_MAX_TASKS
* *
* Macro which should be defined as a non-zero integer value. * Macro which should be defined as a non-zero integer value.
@ -292,9 +292,9 @@ extern "C" {
* *
* Default value is 10. * Default value is 10.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_STACK_MONITOR_MAX_TASKS 10 #define TRC_CFG_STACK_MONITOR_MAX_TASKS 10
/****************************************************************************** /******************************************************************************
* TRC_CFG_STACK_MONITOR_MAX_REPORTS * TRC_CFG_STACK_MONITOR_MAX_REPORTS
* *
* Macro which should be defined as a non-zero integer value. * Macro which should be defined as a non-zero integer value.
@ -313,9 +313,9 @@ extern "C" {
* *
* Default value is 1. * Default value is 1.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_STACK_MONITOR_MAX_REPORTS 1 #define TRC_CFG_STACK_MONITOR_MAX_REPORTS 1
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_PRIORITY * Configuration Macro: TRC_CFG_CTRL_TASK_PRIORITY
* *
* The scheduling priority of the Tracealyzer Control (TzCtrl) task. * The scheduling priority of the Tracealyzer Control (TzCtrl) task.
@ -331,9 +331,9 @@ extern "C" {
* not created if stack monitoring is disabled. TRC_CFG_CTRL_TASK_PRIORITY should * not created if stack monitoring is disabled. TRC_CFG_CTRL_TASK_PRIORITY should
* be low, to avoid disturbing any time-sensitive tasks. * be low, to avoid disturbing any time-sensitive tasks.
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_CTRL_TASK_PRIORITY 1 #define TRC_CFG_CTRL_TASK_PRIORITY 1
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_DELAY * Configuration Macro: TRC_CFG_CTRL_TASK_DELAY
* *
* The delay between loops of the TzCtrl task (see TRC_CFG_CTRL_TASK_PRIORITY), * The delay between loops of the TzCtrl task (see TRC_CFG_CTRL_TASK_PRIORITY),
@ -344,15 +344,15 @@ extern "C" {
* increases the CPU load of TzCtrl somewhat, but may improve the performance of * increases the CPU load of TzCtrl somewhat, but may improve the performance of
* of the trace streaming, especially if the trace buffer is small. * of the trace streaming, especially if the trace buffer is small.
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_CTRL_TASK_DELAY 10 #define TRC_CFG_CTRL_TASK_DELAY 10
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_STACK_SIZE * Configuration Macro: TRC_CFG_CTRL_TASK_STACK_SIZE
* *
* The stack size of the Tracealyzer Control (TzCtrl) task. * The stack size of the Tracealyzer Control (TzCtrl) task.
* See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl. * See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl.
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_CTRL_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define TRC_CFG_CTRL_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
/******************************************************************************* /*******************************************************************************
* Configuration Macro: TRC_CFG_RECORDER_BUFFER_ALLOCATION * Configuration Macro: TRC_CFG_RECORDER_BUFFER_ALLOCATION
@ -370,7 +370,7 @@ extern "C" {
* The custom mode allows you to control how and where the allocation is made, * The custom mode allows you to control how and where the allocation is made,
* for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer(). * for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC #define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC
/****************************************************************************** /******************************************************************************
* TRC_CFG_MAX_ISR_NESTING * TRC_CFG_MAX_ISR_NESTING
@ -385,7 +385,7 @@ extern "C" {
* *
* Default value: 8 * Default value: 8
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_MAX_ISR_NESTING 8 #define TRC_CFG_MAX_ISR_NESTING 8
/****************************************************************************** /******************************************************************************
* TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND * TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND
@ -395,19 +395,19 @@ extern "C" {
* traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from * traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from
* other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED. * other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED.
*****************************************************************************/ *****************************************************************************/
#define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND TRC_ACKNOWLEDGED /* 0 or TRC_ACKNOWLEDGED */ #define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND TRC_ACKNOWLEDGED /* 0 or TRC_ACKNOWLEDGED */
#define TRC_CFG_RECORDER_DATA_ATTRIBUTE #define TRC_CFG_RECORDER_DATA_ATTRIBUTE
/* Specific configuration, depending on Streaming/Snapshot mode */ /* Specific configuration, depending on Streaming/Snapshot mode */
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) #if ( TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT )
#include "trcSnapshotConfig.h" #include "trcSnapshotConfig.h"
#elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) #elif ( TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING )
#include "trcStreamingConfig.h" #include "trcStreamingConfig.h"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TRC_CONFIG_H */ #endif /* _TRC_CONFIG_H */

View file

@ -11,11 +11,11 @@
*/ */
#ifndef TRC_KERNEL_PORT_CONFIG_H #ifndef TRC_KERNEL_PORT_CONFIG_H
#define TRC_KERNEL_PORT_CONFIG_H #define TRC_KERNEL_PORT_CONFIG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
* @def TRC_CFG_RECORDER_MODE * @def TRC_CFG_RECORDER_MODE
@ -30,7 +30,7 @@ extern "C" {
* TRC_RECORDER_MODE_SNAPSHOT * TRC_RECORDER_MODE_SNAPSHOT
* TRC_RECORDER_MODE_STREAMING * TRC_RECORDER_MODE_STREAMING
*/ */
#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT #define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT
/** /**
* @def TRC_CFG_FREERTOS_VERSION * @def TRC_CFG_FREERTOS_VERSION
@ -56,7 +56,7 @@ extern "C" {
* TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0 * TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0
* TRC_FREERTOS_VERSION_10_4_1 If using FreeRTOS v10.4.1 or later * TRC_FREERTOS_VERSION_10_4_1 If using FreeRTOS v10.4.1 or later
*/ */
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_1 #define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_1
/** /**
* @def TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS * @def TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
@ -66,7 +66,7 @@ extern "C" {
* *
* Default value is 0 (excluded) since dependent on event_groups.c * Default value is 0 (excluded) since dependent on event_groups.c
*/ */
#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 0 #define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 0
/** /**
* @def TRC_CFG_INCLUDE_TIMER_EVENTS * @def TRC_CFG_INCLUDE_TIMER_EVENTS
@ -76,7 +76,7 @@ extern "C" {
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*/ */
#define TRC_CFG_INCLUDE_TIMER_EVENTS 1 #define TRC_CFG_INCLUDE_TIMER_EVENTS 1
/** /**
* @def TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS * @def TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
@ -87,7 +87,7 @@ extern "C" {
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*/ */
#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1 #define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1
/** /**
* @def TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS * @def TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
@ -98,7 +98,7 @@ extern "C" {
* *
* Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10) * Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
*/ */
#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 0 #define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 0
/** /**
* @def TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND * @def TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND
@ -107,10 +107,10 @@ extern "C" {
* traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from * traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from
* other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED. * other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED.
*/ */
#define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND 0 /* TRC_ACKNOWLEDGED */ #define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND 0 /* TRC_ACKNOWLEDGED */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* TRC_KERNEL_PORT_CONFIG_H */ #endif /* TRC_KERNEL_PORT_CONFIG_H */

View file

@ -9,11 +9,11 @@
*/ */
#ifndef TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H #ifndef TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#define TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H #define TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
* @def TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE... * @def TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...
@ -36,15 +36,15 @@ extern "C" {
* check the actual usage by selecting View menu -> Trace Details -> * check the actual usage by selecting View menu -> Trace Details ->
* Resource Usage -> Object Table. * Resource Usage -> Object Table.
*/ */
#define TRC_CFG_NTASK 150 #define TRC_CFG_NTASK 150
#define TRC_CFG_NISR 90 #define TRC_CFG_NISR 90
#define TRC_CFG_NQUEUE 90 #define TRC_CFG_NQUEUE 90
#define TRC_CFG_NSEMAPHORE 90 #define TRC_CFG_NSEMAPHORE 90
#define TRC_CFG_NMUTEX 90 #define TRC_CFG_NMUTEX 90
#define TRC_CFG_NTIMER 250 #define TRC_CFG_NTIMER 250
#define TRC_CFG_NEVENTGROUP 90 #define TRC_CFG_NEVENTGROUP 90
#define TRC_CFG_NSTREAMBUFFER 50 #define TRC_CFG_NSTREAMBUFFER 50
#define TRC_CFG_NMESSAGEBUFFER 50 #define TRC_CFG_NMESSAGEBUFFER 50
/** /**
* @def TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ... * @def TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...
@ -52,18 +52,18 @@ extern "C" {
* kernel objects, such as tasks and queues. If longer names are used, they will * kernel objects, such as tasks and queues. If longer names are used, they will
* be truncated when stored in the recorder. * be truncated when stored in the recorder.
*/ */
#define TRC_CFG_NAME_LEN_TASK 15 #define TRC_CFG_NAME_LEN_TASK 15
#define TRC_CFG_NAME_LEN_ISR 15 #define TRC_CFG_NAME_LEN_ISR 15
#define TRC_CFG_NAME_LEN_QUEUE 15 #define TRC_CFG_NAME_LEN_QUEUE 15
#define TRC_CFG_NAME_LEN_SEMAPHORE 15 #define TRC_CFG_NAME_LEN_SEMAPHORE 15
#define TRC_CFG_NAME_LEN_MUTEX 15 #define TRC_CFG_NAME_LEN_MUTEX 15
#define TRC_CFG_NAME_LEN_TIMER 15 #define TRC_CFG_NAME_LEN_TIMER 15
#define TRC_CFG_NAME_LEN_EVENTGROUP 15 #define TRC_CFG_NAME_LEN_EVENTGROUP 15
#define TRC_CFG_NAME_LEN_STREAMBUFFER 15 #define TRC_CFG_NAME_LEN_STREAMBUFFER 15
#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 15 #define TRC_CFG_NAME_LEN_MESSAGEBUFFER 15
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H */ #endif /* TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H */

View file

@ -46,8 +46,8 @@
#ifndef TRC_SNAPSHOT_CONFIG_H #ifndef TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_CONFIG_H #define TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_MODE_RING_BUFFER (0x01) #define TRC_SNAPSHOT_MODE_RING_BUFFER ( 0x01 )
#define TRC_SNAPSHOT_MODE_STOP_WHEN_FULL (0x02) #define TRC_SNAPSHOT_MODE_STOP_WHEN_FULL ( 0x02 )
/****************************************************************************** /******************************************************************************
* TRC_CFG_SNAPSHOT_MODE * TRC_CFG_SNAPSHOT_MODE
@ -151,8 +151,8 @@
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_SYMBOL_TABLE_SIZE 5000 #define TRC_CFG_SYMBOL_TABLE_SIZE 5000
#if (TRC_CFG_SYMBOL_TABLE_SIZE == 0) #if ( TRC_CFG_SYMBOL_TABLE_SIZE == 0 )
#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!" #error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"
#endif #endif
/****************************************************************************** /******************************************************************************
@ -320,7 +320,7 @@
* *
* // Finds the existing UB channel * // Finds the existing UB channel
* vTracePrintF(chn2, "%Z: %d", value2); * vTracePrintF(chn2, "%Z: %d", value2);
*
******************************************************************************/ ******************************************************************************/
#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0 #define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -58,16 +58,16 @@ static SOCKET prvOpenUDPSocket( void );
* interpreter. In this case a UDP port is used. See the URL in the comments * interpreter. In this case a UDP port is used. See the URL in the comments
* within main.c for the location of the online documentation. * within main.c for the location of the online documentation.
*/ */
void vUDPCommandInterpreterTask( void *pvParameters ) void vUDPCommandInterpreterTask( void * pvParameters )
{ {
long lBytes, lByte; long lBytes, lByte;
signed char cInChar, cInputIndex = 0; signed char cInChar, cInputIndex = 0;
static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ]; static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ];
BaseType_t xMoreDataToFollow; BaseType_t xMoreDataToFollow;
volatile int iErrorCode = 0; volatile int iErrorCode = 0;
struct sockaddr_in xClient; struct sockaddr_in xClient;
int xClientAddressLength = sizeof( struct sockaddr_in ); int xClientAddressLength = sizeof( struct sockaddr_in );
SOCKET xSocket; SOCKET xSocket;
/* Just to prevent compiler warnings. */ /* Just to prevent compiler warnings. */
( void ) pvParameters; ( void ) pvParameters;
@ -77,7 +77,7 @@ SOCKET xSocket;
if( xSocket != INVALID_SOCKET ) if( xSocket != INVALID_SOCKET )
{ {
for( ;; ) for( ; ; )
{ {
/* Wait for incoming data on the opened socket. */ /* Wait for incoming data on the opened socket. */
lBytes = recvfrom( xSocket, cLocalBuffer, sizeof( cLocalBuffer ), 0, ( struct sockaddr * ) &xClient, &xClientAddressLength ); lBytes = recvfrom( xSocket, cLocalBuffer, sizeof( cLocalBuffer ), 0, ( struct sockaddr * ) &xClient, &xClientAddressLength );
@ -85,13 +85,14 @@ SOCKET xSocket;
if( lBytes == SOCKET_ERROR ) if( lBytes == SOCKET_ERROR )
{ {
/* Something went wrong, but it is not handled by this simple /* Something went wrong, but it is not handled by this simple
example. */ * example. */
iErrorCode = WSAGetLastError(); iErrorCode = WSAGetLastError();
} }
else else
{ {
/* Process each received byte in turn. */ /* Process each received byte in turn. */
lByte = 0; lByte = 0;
while( lByte < lBytes ) while( lByte < lBytes )
{ {
/* The next character in the input buffer. */ /* The next character in the input buffer. */
@ -99,30 +100,29 @@ SOCKET xSocket;
lByte++; lByte++;
/* Newline characters are taken as the end of the command /* Newline characters are taken as the end of the command
string. */ * string. */
if( cInChar == '\n' ) if( cInChar == '\n' )
{ {
/* Process the input string received prior to the /* Process the input string received prior to the
newline. */ * newline. */
do do
{ {
/* Pass the string to FreeRTOS+CLI. */ /* Pass the string to FreeRTOS+CLI. */
xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE ); xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE );
/* Send the output generated by the command's /* Send the output generated by the command's
implementation. */ * implementation. */
sendto( xSocket, cOutputString, strlen( cOutputString ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength ); sendto( xSocket, cOutputString, strlen( cOutputString ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength );
} while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */ } while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */
/* All the strings generated by the command processing /* All the strings generated by the command processing
have been sent. Clear the input string ready to receive * have been sent. Clear the input string ready to receive
the next command. */ * the next command. */
cInputIndex = 0; cInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
/* Transmit a spacer, just to make the command console /* Transmit a spacer, just to make the command console
easier to read. */ * easier to read. */
sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength ); sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength );
} }
else else
@ -130,12 +130,12 @@ SOCKET xSocket;
if( cInChar == '\r' ) if( cInChar == '\r' )
{ {
/* Ignore the character. Newlines are used to /* Ignore the character. Newlines are used to
detect the end of the input string. */ * detect the end of the input string. */
} }
else if( cInChar == '\b' ) else if( cInChar == '\b' )
{ {
/* Backspace was pressed. Erase the last character /* Backspace was pressed. Erase the last character
in the string - if any. */ * in the string - if any. */
if( cInputIndex > 0 ) if( cInputIndex > 0 )
{ {
cInputIndex--; cInputIndex--;
@ -145,8 +145,8 @@ SOCKET xSocket;
else else
{ {
/* A character was entered. Add it to the string /* A character was entered. Add it to the string
entered so far. When a \n is entered the complete * entered so far. When a \n is entered the complete
string will be passed to the command interpreter. */ * string will be passed to the command interpreter. */
if( cInputIndex < cmdMAX_INPUT_SIZE ) if( cInputIndex < cmdMAX_INPUT_SIZE )
{ {
cInputString[ cInputIndex ] = cInChar; cInputString[ cInputIndex ] = cInChar;
@ -168,10 +168,10 @@ SOCKET xSocket;
static SOCKET prvOpenUDPSocket( void ) static SOCKET prvOpenUDPSocket( void )
{ {
WSADATA xWSAData; WSADATA xWSAData;
WORD wVersionRequested; WORD wVersionRequested;
struct sockaddr_in xServer; struct sockaddr_in xServer;
SOCKET xSocket = INVALID_SOCKET; SOCKET xSocket = INVALID_SOCKET;
wVersionRequested = MAKEWORD( 2, 2 ); wVersionRequested = MAKEWORD( 2, 2 );
@ -183,7 +183,8 @@ SOCKET xSocket = INVALID_SOCKET;
else else
{ {
xSocket = socket( AF_INET, SOCK_DGRAM, 0 ); xSocket = socket( AF_INET, SOCK_DGRAM, 0 );
if( xSocket == INVALID_SOCKET)
if( xSocket == INVALID_SOCKET )
{ {
fprintf( stderr, "Could not create socket.\n" ); fprintf( stderr, "Could not create socket.\n" );
WSACleanup(); WSACleanup();
@ -216,5 +217,3 @@ SOCKET xSocket = INVALID_SOCKET;
return xSocket; return xSocket;
} }

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Resource Files"> <Filter Include="Resource Files">

View file

@ -88,12 +88,12 @@
#define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY ) #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
/* The rate at which data is sent to the queue. The (simulated) 250ms value is /* The rate at which data is sent to the queue. The (simulated) 250ms value is
converted to ticks using the portTICK_RATE_MS constant. */ * converted to ticks using the portTICK_RATE_MS constant. */
#define mainQUEUE_SEND_FREQUENCY_MS ( 250 / portTICK_RATE_MS ) #define mainQUEUE_SEND_FREQUENCY_MS ( 250 / portTICK_RATE_MS )
/* The number of items the queue can hold. This is 1 as the receive task /* The number of items the queue can hold. This is 1 as the receive task
will remove items as they are added, meaning the send task should always find * will remove items as they are added, meaning the send task should always find
the queue empty. */ * the queue empty. */
#define mainQUEUE_LENGTH ( 1 ) #define mainQUEUE_LENGTH ( 1 )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -102,13 +102,13 @@ the queue empty. */
* The queue send and receive tasks as described in the comments at the top of * The queue send and receive tasks as described in the comments at the top of
* this file. * this file.
*/ */
static void prvQueueReceiveTask( void *pvParameters ); static void prvQueueReceiveTask( void * pvParameters );
static void prvQueueSendTask( void *pvParameters ); static void prvQueueSendTask( void * pvParameters );
/* /*
* The task that implements the UDP command interpreter using FreeRTOS+CLI. * The task that implements the UDP command interpreter using FreeRTOS+CLI.
*/ */
extern void vUDPCommandInterpreterTask( void *pvParameters ); extern void vUDPCommandInterpreterTask( void * pvParameters );
/* /*
* Register commands that can be used with FreeRTOS+CLI through the UDP socket. * Register commands that can be used with FreeRTOS+CLI through the UDP socket.
@ -123,21 +123,21 @@ static xQueueHandle xQueue = NULL;
int main( void ) int main( void )
{ {
const uint32_t ulLongTime_ms = 250UL; const uint32_t ulLongTime_ms = 250UL;
/* Initialise the trace recorder and create the label used to post user /* Initialise the trace recorder and create the label used to post user
events to the trace recording on each tick interrupt. */ * events to the trace recording on each tick interrupt. */
vTraceEnable( TRC_START ); vTraceEnable( TRC_START );
/* Create the queue used to pass messages from the queue send task to the /* Create the queue used to pass messages from the queue send task to the
queue receive task. */ * queue receive task. */
xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) ); xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
/* Give the queue a name for the FreeRTOS+Trace log. */ /* Give the queue a name for the FreeRTOS+Trace log. */
vTraceSetQueueName( xQueue, "DemoQ" ); vTraceSetQueueName( xQueue, "DemoQ" );
/* Start the two tasks as described in the comments at the top of this /* Start the two tasks as described in the comments at the top of this
file. */ * file. */
xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */ xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
"Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */ "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. Not actually used as a stack in the Win32 simulator port. */ configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. Not actually used as a stack in the Win32 simulator port. */
@ -148,7 +148,7 @@ const uint32_t ulLongTime_ms = 250UL;
xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL ); xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
/* Create the task that handles the CLI on a UDP port. The port number /* Create the task that handles the CLI on a UDP port. The port number
is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */ * is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
xTaskCreate( vUDPCommandInterpreterTask, "CLI", configMINIMAL_STACK_SIZE, NULL, mainUDP_CLI_TASK_PRIORITY, NULL ); xTaskCreate( vUDPCommandInterpreterTask, "CLI", configMINIMAL_STACK_SIZE, NULL, mainUDP_CLI_TASK_PRIORITY, NULL );
/* Register commands with the FreeRTOS+CLI command interpreter. */ /* Register commands with the FreeRTOS+CLI command interpreter. */
@ -158,22 +158,22 @@ const uint32_t ulLongTime_ms = 250UL;
vTaskStartScheduler(); vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following /* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then * line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or * there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the * timer tasks to be created. See the memory management section on the
FreeRTOS web site for more details (this is standard text that is not * FreeRTOS web site for more details (this is standard text that is not
really applicable to the Win32 simulator port). */ * really applicable to the Win32 simulator port). */
for( ;; ) for( ; ; )
{ {
Sleep( ulLongTime_ms ); Sleep( ulLongTime_ms );
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvQueueSendTask( void *pvParameters ) static void prvQueueSendTask( void * pvParameters )
{ {
TickType_t xNextWakeTime; TickType_t xNextWakeTime;
const unsigned long ulValueToSend = 100UL; const unsigned long ulValueToSend = 100UL;
/* Remove warning about unused parameters. */ /* Remove warning about unused parameters. */
( void ) pvParameters; ( void ) pvParameters;
@ -181,39 +181,39 @@ const unsigned long ulValueToSend = 100UL;
/* Initialise xNextWakeTime - this only needs to be done once. */ /* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount(); xNextWakeTime = xTaskGetTickCount();
for( ;; ) for( ; ; )
{ {
/* Place this task in the blocked state until it is time to run again. /* Place this task in the blocked state until it is time to run again.
While in the Blocked state this task will not consume any CPU time. */ * While in the Blocked state this task will not consume any CPU time. */
vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS ); vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
/* Send to the queue - causing the queue receive task to unblock and /* Send to the queue - causing the queue receive task to unblock and
write a message to the display. 0 is used as the block time so the * write a message to the display. 0 is used as the block time so the
sending operation will not block - it shouldn't need to block as the * sending operation will not block - it shouldn't need to block as the
queue should always be empty at this point in the code, and it is an * queue should always be empty at this point in the code, and it is an
error if it is not. */ * error if it is not. */
xQueueSend( xQueue, &ulValueToSend, 0U ); xQueueSend( xQueue, &ulValueToSend, 0U );
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvQueueReceiveTask( void *pvParameters ) static void prvQueueReceiveTask( void * pvParameters )
{ {
unsigned long ulReceivedValue; unsigned long ulReceivedValue;
/* Remove warning about unused parameters. */ /* Remove warning about unused parameters. */
( void ) pvParameters; ( void ) pvParameters;
for( ;; ) for( ; ; )
{ {
/* Wait until something arrives in the queue - this task will block /* Wait until something arrives in the queue - this task will block
indefinitely provided INCLUDE_vTaskSuspend is set to 1 in * indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
FreeRTOSConfig.h. */ * FreeRTOSConfig.h. */
xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY ); xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
/* To get here something must have been received from the queue, but /* To get here something must have been received from the queue, but
is it the expected value? If it is, write the message to the * is it the expected value? If it is, write the message to the
display before looping back to block on the queue again. */ * display before looping back to block on the queue again. */
if( ulReceivedValue == 100UL ) if( ulReceivedValue == 100UL )
{ {
printf( "Message received!\r\n" ); printf( "Message received!\r\n" );
@ -225,11 +225,11 @@ unsigned long ulReceivedValue;
void vApplicationIdleHook( void ) void vApplicationIdleHook( void )
{ {
const unsigned long ulMSToSleep = 5; const unsigned long ulMSToSleep = 5;
/* This function is called on each cycle of the idle task if /* This function is called on each cycle of the idle task if
configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU * configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
load. */ * load. */
Sleep( ulMSToSleep ); Sleep( ulMSToSleep );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -248,5 +248,5 @@ uint32_t uiTraceTimerGetFrequency( void )
uint32_t uiTraceTimerGetValue( void ) uint32_t uiTraceTimerGetValue( void )
{ {
return ( xTaskGetTickCount() - ulEntryTime ); return( xTaskGetTickCount() - ulEntryTime );
} }

View file

@ -1,17 +1,18 @@
/* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION /* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION
UTILITY. DO NOT MODIFY. * UTILITY. DO NOT MODIFY.
*
* Generated by configuration utility version 2.0
*/
Generated by configuration utility version 2.0
*/
/** @file /** @file
*/ */
#include <redconf.h> #include <redconf.h>
#include <redtypes.h> #include <redtypes.h>
#include <redmacs.h> #include <redmacs.h>
#include <redvolume.h> #include <redvolume.h>
const VOLCONF gaRedVolConf[REDCONF_VOLUME_COUNT] = const VOLCONF gaRedVolConf[ REDCONF_VOLUME_COUNT ] =
{ {
{ 512U, 65536U, false, 256U, 0U, "" } { 512U, 65536U, false, 256U, 0U, "" }
}; };

View file

@ -1,10 +1,11 @@
/* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION /* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION
UTILITY. DO NOT MODIFY. * UTILITY. DO NOT MODIFY.
*
* Generated by configuration utility version 2.0
*/
Generated by configuration utility version 2.0
*/
/** @file /** @file
*/ */
#ifndef REDCONF_H #ifndef REDCONF_H
#define REDCONF_H #define REDCONF_H
@ -93,7 +94,7 @@
#define RedStrNCpyUnchecked strncpy #define RedStrNCpyUnchecked strncpy
#define REDCONF_TRANSACT_DEFAULT (( RED_TRANSACT_CREAT | RED_TRANSACT_MKDIR | RED_TRANSACT_RENAME | RED_TRANSACT_LINK | RED_TRANSACT_UNLINK | RED_TRANSACT_FSYNC | RED_TRANSACT_CLOSE | RED_TRANSACT_VOLFULL | RED_TRANSACT_UMOUNT ) & RED_TRANSACT_MASK) #define REDCONF_TRANSACT_DEFAULT ( ( RED_TRANSACT_CREAT | RED_TRANSACT_MKDIR | RED_TRANSACT_RENAME | RED_TRANSACT_LINK | RED_TRANSACT_UNLINK | RED_TRANSACT_FSYNC | RED_TRANSACT_CLOSE | RED_TRANSACT_VOLFULL | RED_TRANSACT_UMOUNT ) & RED_TRANSACT_MASK )
#define REDCONF_IMAP_INLINE 0 #define REDCONF_IMAP_INLINE 0
@ -109,4 +110,4 @@
#define RED_CONFIG_MINCOMPAT_VER 0x1000200U #define RED_CONFIG_MINCOMPAT_VER 0x1000200U
#endif #endif /* ifndef REDCONF_H */

View file

@ -1,84 +1,86 @@
/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- /* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
*
* Copyright (c) 2014-2015 Datalight, Inc.
* All Rights Reserved Worldwide.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; use version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
Copyright (c) 2014-2015 Datalight, Inc.
All Rights Reserved Worldwide.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; use version 2 of the License.
This program is distributed in the hope that it will be useful,
but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Businesses and individuals that for commercial or other reasons cannot /* Businesses and individuals that for commercial or other reasons cannot
comply with the terms of the GPLv2 license may obtain a commercial license * comply with the terms of the GPLv2 license may obtain a commercial license
before incorporating Reliance Edge into proprietary software for * before incorporating Reliance Edge into proprietary software for
distribution in any form. Visit http://www.datalight.com/reliance-edge for * distribution in any form. Visit http://www.datalight.com/reliance-edge for
more information. * more information.
*/ */
/** @file /** @file
@brief Defines basic types used by Reliance Edge. * @brief Defines basic types used by Reliance Edge.
*
The following types *must* be defined by this header, either directly (using * The following types *must* be defined by this header, either directly (using
typedef) or indirectly (by including other headers, such as the C99 headers * typedef) or indirectly (by including other headers, such as the C99 headers
stdint.h and stdbool.h): * stdint.h and stdbool.h):
*
- bool: Boolean type, capable of storing true (1) or false (0) * - bool: Boolean type, capable of storing true (1) or false (0)
- uint8_t: Unsigned 8-bit integer * - uint8_t: Unsigned 8-bit integer
- int8_t: Signed 8-bit integer * - int8_t: Signed 8-bit integer
- uint16_t: Unsigned 16-bit integer * - uint16_t: Unsigned 16-bit integer
- int16_t: Signed 16-bit integer * - int16_t: Signed 16-bit integer
- uint32_t: Unsigned 32-bit integer * - uint32_t: Unsigned 32-bit integer
- int32_t: Signed 32-bit integer * - int32_t: Signed 32-bit integer
- uint64_t: Unsigned 64-bit integer * - uint64_t: Unsigned 64-bit integer
- int64_t: Signed 64-bit integer * - int64_t: Signed 64-bit integer
- uintptr_t: Unsigned integer capable of storing a pointer, preferably the * - uintptr_t: Unsigned integer capable of storing a pointer, preferably the
same size as pointers themselves. * same size as pointers themselves.
*
These types deliberately use the same names as the standard C99 types, so * These types deliberately use the same names as the standard C99 types, so
that if the C99 headers stdint.h and stdbool.h are available, they may be * that if the C99 headers stdint.h and stdbool.h are available, they may be
included here. * included here.
*
If the user application defines similar types, those may be reused. For * If the user application defines similar types, those may be reused. For
example, suppose there is an application header apptypes.h which defines * example, suppose there is an application header apptypes.h which defines
types with a similar purpose but different names. That header could be * types with a similar purpose but different names. That header could be
reused to define the types Reliance Edge needs: * reused to define the types Reliance Edge needs:
*
~~~{.c} * ~~~{.c}
#include <apptypes.h> #include <apptypes.h>
*
typedef BOOL bool; * typedef BOOL bool;
typedef BYTE uint8_t; * typedef BYTE uint8_t;
typedef INT8 int8_t; * typedef INT8 int8_t;
// And so on... * // And so on...
~~~ * ~~~
*
If there are neither C99 headers nor suitable types in application headers, * If there are neither C99 headers nor suitable types in application headers,
this header should be populated with typedefs that define the required types * this header should be populated with typedefs that define the required types
in terms of the standard C types. This requires knowledge of the size of * in terms of the standard C types. This requires knowledge of the size of
the C types on the target hardware (e.g., how big is an "int" or a pointer). * the C types on the target hardware (e.g., how big is an "int" or a pointer).
Below is an example which assumes the target has 8-bit chars, 16-bit shorts, * Below is an example which assumes the target has 8-bit chars, 16-bit shorts,
32-bit ints, 32-bit pointers, and 64-bit long longs: * 32-bit ints, 32-bit pointers, and 64-bit long longs:
*
~~~{.c} * ~~~{.c}
typedef int bool; * typedef int bool;
typedef unsigned char uint8_t; * typedef unsigned char uint8_t;
typedef signed char int8_t; * typedef signed char int8_t;
typedef unsigned short uint16_t; * typedef unsigned short uint16_t;
typedef short int16_t; * typedef short int16_t;
typedef unsigned int uint32_t; * typedef unsigned int uint32_t;
typedef int int32_t; * typedef int int32_t;
typedef unsigned long long uint64_t; * typedef unsigned long long uint64_t;
typedef long long int64_t; * typedef long long int64_t;
typedef uint32_t uintptr_t; * typedef uint32_t uintptr_t;
~~~ * ~~~
*/ */
#ifndef REDTYPES_H #ifndef REDTYPES_H
#define REDTYPES_H #define REDTYPES_H
@ -98,13 +100,12 @@ typedef unsigned __int64 uint64_t; /**< @brief Unsigned 64-bit integer. */
typedef __int64 int64_t; /**< @brief Signed 64-bit integer. */ typedef __int64 int64_t; /**< @brief Signed 64-bit integer. */
/** @brief Unsigned integer capable of storing a pointer. /** @brief Unsigned integer capable of storing a pointer.
*/ */
#ifdef _WIN64 #ifdef _WIN64
typedef uint64_t uintptr_t; typedef uint64_t uintptr_t;
#else #else
typedef uint32_t uintptr_t; typedef uint32_t uintptr_t;
#endif #endif
#endif #endif /* ifndef REDTYPES_H */

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -42,8 +42,8 @@
#define fsRAM_BUFFER_SIZE 200 #define fsRAM_BUFFER_SIZE 200
/* The volume prefix is an empty string, for convenience since there is only one /* The volume prefix is an empty string, for convenience since there is only one
volume in this demo. * volume in this demo.
*/ */
#define fsVOLUME_NAME "" #define fsVOLUME_NAME ""
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -69,17 +69,17 @@ static void prvVerifyDemoFiles( void );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* A buffer used to both create content to write to disk, and read content back /* A buffer used to both create content to write to disk, and read content back
from a disk. Note there is no mutual exclusion on this buffer. */ * from a disk. Note there is no mutual exclusion on this buffer. */
static char cRAMBuffer[ fsRAM_BUFFER_SIZE ]; static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
/* Names of directories that are created. */ /* Names of directories that are created. */
static const char *pcDirectory1 = "/SUB1", *pcDirectory2 = "/SUB1/SUB2"; static const char * pcDirectory1 = "/SUB1", * pcDirectory2 = "/SUB1/SUB2";
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vCreateAndVerifySampleFiles( void ) void vCreateAndVerifySampleFiles( void )
{ {
int32_t lStatus; int32_t lStatus;
/* First initialize the Reliance Edge driver. */ /* First initialize the Reliance Edge driver. */
lStatus = red_init(); lStatus = red_init();
@ -109,45 +109,45 @@ int32_t lStatus;
static void prvCreateDemoFiles( void ) static void prvCreateDemoFiles( void )
{ {
BaseType_t xFileNumber, xWriteNumber; BaseType_t xFileNumber, xWriteNumber;
char cFilePath[ 64 ]; char cFilePath[ 64 ];
const BaseType_t xMaxFiles = 5; const BaseType_t xMaxFiles = 5;
uint32_t ulEventMask; uint32_t ulEventMask;
int32_t lBytesWritten, lFildes, lStatus; int32_t lBytesWritten, lFildes, lStatus;
int iByte; int iByte;
/* Save the current transaction point settings. */ /* Save the current transaction point settings. */
lStatus = red_gettransmask( fsVOLUME_NAME, &ulEventMask ); lStatus = red_gettransmask( fsVOLUME_NAME, &ulEventMask );
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
/* Disable automatic transaction points so that all of the files can be /* Disable automatic transaction points so that all of the files can be
created in one atomic operation. */ * created in one atomic operation. */
lStatus = red_settransmask( fsVOLUME_NAME, RED_TRANSACT_MANUAL ); lStatus = red_settransmask( fsVOLUME_NAME, RED_TRANSACT_MANUAL );
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
/* Create xMaxFiles files. Each created file will be /* Create xMaxFiles files. Each created file will be
( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled * ( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
with a different repeating character. */ * with a different repeating character. */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ ) for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{ {
/* Generate a file name. */ /* Generate a file name. */
sprintf( cFilePath, "/root%03d.txt", xFileNumber ); sprintf( cFilePath, "/root%03d.txt", xFileNumber );
/* Print out the file name and the directory into which the file is /* Print out the file name and the directory into which the file is
being written. */ * being written. */
printf( "Creating file %s\r\n", cFilePath ); printf( "Creating file %s\r\n", cFilePath );
/* Open the file, creating the file if it does not already exist. */ /* Open the file, creating the file if it does not already exist. */
lFildes = red_open( cFilePath, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY ); lFildes = red_open( cFilePath, RED_O_CREAT | RED_O_TRUNC | RED_O_WRONLY );
configASSERT( lFildes != -1 ); configASSERT( lFildes != -1 );
/* Fill the RAM buffer with data that will be written to the file. This /* Fill the RAM buffer with data that will be written to the file. This
is just a repeating ascii character that indicates the file number. */ * is just a repeating ascii character that indicates the file number. */
memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE ); memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
/* Write the RAM buffer to the opened file a number of times. The /* Write the RAM buffer to the opened file a number of times. The
number of times the RAM buffer is written to the file depends on the * number of times the RAM buffer is written to the file depends on the
file number, so the length of each created file will be different. */ * file number, so the length of each created file will be different. */
for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ ) for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
{ {
lBytesWritten = red_write( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE ); lBytesWritten = red_write( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE );
@ -160,7 +160,7 @@ int iByte;
} }
/* Commit a transaction point, atomically adding the set of files to the /* Commit a transaction point, atomically adding the set of files to the
transacted state. */ * transacted state. */
lStatus = red_transact( fsVOLUME_NAME ); lStatus = red_transact( fsVOLUME_NAME );
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
@ -180,13 +180,13 @@ int iByte;
sprintf( cFilePath, "%s/file.txt", pcDirectory2 ); sprintf( cFilePath, "%s/file.txt", pcDirectory2 );
/* Print out the file name and the directory into which the file is being /* Print out the file name and the directory into which the file is being
written. */ * written. */
printf( "Writing file %s\r\n", cFilePath ); printf( "Writing file %s\r\n", cFilePath );
lFildes = red_open( cFilePath, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY ); lFildes = red_open( cFilePath, RED_O_CREAT | RED_O_TRUNC | RED_O_WRONLY );
/* Write the file. It is filled with incrementing ascii characters starting /* Write the file. It is filled with incrementing ascii characters starting
from '0'. */ * from '0'. */
for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ ) for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ )
{ {
cRAMBuffer[ iByte ] = ( char ) ( ( int ) '0' + iByte ); cRAMBuffer[ iByte ] = ( char ) ( ( int ) '0' + iByte );
@ -200,7 +200,7 @@ int iByte;
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
/* Commit a transaction point, atomically adding the set of files and /* Commit a transaction point, atomically adding the set of files and
directories to the transacted state. */ * directories to the transacted state. */
lStatus = red_transact( fsVOLUME_NAME ); lStatus = red_transact( fsVOLUME_NAME );
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
@ -212,12 +212,12 @@ int iByte;
static void prvVerifyDemoFiles( void ) static void prvVerifyDemoFiles( void )
{ {
BaseType_t xFileNumber, xReadNumber; BaseType_t xFileNumber, xReadNumber;
char cFilePath[ 64 ]; char cFilePath[ 64 ];
const BaseType_t xMaxFiles = 5; const BaseType_t xMaxFiles = 5;
long lChar; long lChar;
int32_t lBytesRead, lFildes, lStatus; int32_t lBytesRead, lFildes, lStatus;
int iByte; int iByte;
/* Read back the files that were created by prvCreateDemoFiles(). */ /* Read back the files that were created by prvCreateDemoFiles(). */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ ) for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
@ -226,7 +226,7 @@ int iByte;
sprintf( cFilePath, "/root%03d.txt", xFileNumber ); sprintf( cFilePath, "/root%03d.txt", xFileNumber );
/* Print out the file name and the directory from which the file is /* Print out the file name and the directory from which the file is
being read. */ * being read. */
printf( "Reading file %s\r\n", cFilePath ); printf( "Reading file %s\r\n", cFilePath );
/* Open the file for reading. */ /* Open the file for reading. */
@ -234,7 +234,7 @@ int iByte;
configASSERT( lFildes != -1 ); configASSERT( lFildes != -1 );
/* Read the file into the RAM buffer, checking the file contents are as /* Read the file into the RAM buffer, checking the file contents are as
expected. The size of the file depends on the file number. */ * expected. The size of the file depends on the file number. */
for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ ) for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
{ {
/* Start with the RAM buffer clear. */ /* Start with the RAM buffer clear. */
@ -244,8 +244,8 @@ int iByte;
configASSERT( lBytesRead == fsRAM_BUFFER_SIZE ); configASSERT( lBytesRead == fsRAM_BUFFER_SIZE );
/* Check the RAM buffer is filled with the expected data. Each /* Check the RAM buffer is filled with the expected data. Each
file contains a different repeating ascii character that indicates * file contains a different repeating ascii character that indicates
the number of the file. */ * the number of the file. */
for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ ) for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
{ {
configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) ); configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
@ -261,7 +261,7 @@ int iByte;
sprintf( cFilePath, "%s/file.txt", pcDirectory2 ); sprintf( cFilePath, "%s/file.txt", pcDirectory2 );
/* Print out the file name and the directory from which the file is being /* Print out the file name and the directory from which the file is being
read. */ * read. */
printf( "Reading file %s\r\n", cFilePath ); printf( "Reading file %s\r\n", cFilePath );
/* This time the file is opened for reading. */ /* This time the file is opened for reading. */
@ -282,7 +282,3 @@ int iByte;
lStatus = red_close( lFildes ); lStatus = red_close( lFildes );
configASSERT( lStatus == 0 ); configASSERT( lStatus == 0 );
} }

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386 VisualStudioVersion = 16.0.32929.386

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="Source Files">

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -34,37 +34,37 @@
* *
* Also note that it is assumed this demo is going to be used for short periods * Also note that it is assumed this demo is going to be used for short periods
* of time only, and therefore timer overflows are not handled. * of time only, and therefore timer overflows are not handled.
*/ */
/* FreeRTOS includes. */ /* FreeRTOS includes. */
#include <FreeRTOS.h> #include <FreeRTOS.h>
/* Variables used in the creation of the run time stats time base. Run time /* Variables used in the creation of the run time stats time base. Run time
stats record how much time each task spends in the Running state. */ * stats record how much time each task spends in the Running state. */
static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundedthMillisecond = 0LL; static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundredthMillisecond = 0LL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vConfigureTimerForRunTimeStats( void ) void vConfigureTimerForRunTimeStats( void )
{ {
LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue; LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue;
/* Initialise the variables used to create the run time stats time base. /* Initialise the variables used to create the run time stats time base.
Run time stats record how much time each task spends in the Running * Run time stats record how much time each task spends in the Running
state. */ * state. */
if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 ) if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 )
{ {
llTicksPerHundedthMillisecond = 1; llTicksPerHundredthMillisecond = 1;
} }
else else
{ {
/* How many times does the performance counter increment in 1/100th /* How many times does the performance counter increment in 1/100th
millisecond. */ * millisecond. */
llTicksPerHundedthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL; llTicksPerHundredthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL;
/* What is the performance counter value now, this will be subtracted /* What is the performance counter value now, this will be subtracted
from readings taken at run time. */ * from readings taken at run time. */
QueryPerformanceCounter( &liInitialRunTimeValue ); QueryPerformanceCounter( &liInitialRunTimeValue );
llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart; llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart;
} }
@ -73,16 +73,16 @@ LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue;
unsigned long ulGetRunTimeCounterValue( void ) unsigned long ulGetRunTimeCounterValue( void )
{ {
LARGE_INTEGER liCurrentCount; LARGE_INTEGER liCurrentCount;
unsigned long ulReturn; unsigned long ulReturn;
/* What is the performance counter value now? */ /* What is the performance counter value now? */
QueryPerformanceCounter( &liCurrentCount ); QueryPerformanceCounter( &liCurrentCount );
/* Subtract the performance counter value reading taken when the /* Subtract the performance counter value reading taken when the
application started to get a count from that reference point, then * application started to get a count from that reference point, then
scale to (simulated) 1/100ths of a millisecond. */ * scale to (simulated) 1/100ths of a millisecond. */
ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundedthMillisecond ); ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundredthMillisecond );
return ulReturn; return ulReturn;
} }

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,16 +20,16 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
/****************************************************************************** /******************************************************************************
* *
* See the following URL for information on the commands defined in this file: * See the following URL for information on the commands defined in this file:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml * https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
* *
******************************************************************************/ ******************************************************************************/
/* FreeRTOS includes. */ /* FreeRTOS includes. */
@ -52,32 +52,42 @@
/* /*
* Implements the run-time-stats command. * Implements the run-time-stats command.
*/ */
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the task-stats command. * Implements the task-stats command.
*/ */
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the echo-three-parameters command. * Implements the echo-three-parameters command.
*/ */
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the echo-parameters command. * Implements the echo-parameters command.
*/ */
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* /*
* Implements the "trace start" and "trace stop" commands; * Implements the "trace start" and "trace stop" commands;
*/ */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ); static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif #endif
/* Structure that defines the "run-time-stats" command line command. This /* Structure that defines the "run-time-stats" command line command. This
generates a table that shows how much run time each task has */ * generates a table that shows how much run time each task has */
static const CLI_Command_Definition_t xRunTimeStats = static const CLI_Command_Definition_t xRunTimeStats =
{ {
"run-time-stats", /* The command string to type. */ "run-time-stats", /* The command string to type. */
@ -87,7 +97,7 @@ static const CLI_Command_Definition_t xRunTimeStats =
}; };
/* Structure that defines the "task-stats" command line command. This generates /* Structure that defines the "task-stats" command line command. This generates
a table that gives information on each task in the system. */ * a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats = static const CLI_Command_Definition_t xTaskStats =
{ {
"task-stats", /* The command string to type. */ "task-stats", /* The command string to type. */
@ -97,8 +107,8 @@ static const CLI_Command_Definition_t xTaskStats =
}; };
/* Structure that defines the "echo_3_parameters" command line command. This /* Structure that defines the "echo_3_parameters" command line command. This
takes exactly three parameters that the command simply echos back one at a * takes exactly three parameters that the command simply echos back one at a
time. */ * time. */
static const CLI_Command_Definition_t xThreeParameterEcho = static const CLI_Command_Definition_t xThreeParameterEcho =
{ {
"echo-3-parameters", "echo-3-parameters",
@ -108,8 +118,8 @@ static const CLI_Command_Definition_t xThreeParameterEcho =
}; };
/* Structure that defines the "echo_parameters" command line command. This /* Structure that defines the "echo_parameters" command line command. This
takes a variable number of parameters that the command simply echos back one at * takes a variable number of parameters that the command simply echos back one at
a time. */ * a time. */
static const CLI_Command_Definition_t xParameterEcho = static const CLI_Command_Definition_t xParameterEcho =
{ {
"echo-parameters", "echo-parameters",
@ -119,8 +129,9 @@ static const CLI_Command_Definition_t xParameterEcho =
}; };
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
/* Structure that defines the "trace" command line command. This takes a single
parameter, which can be either "start" or "stop". */ /* Structure that defines the "trace" command line command. This takes a single
* parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartStopTrace = static const CLI_Command_Definition_t xStartStopTrace =
{ {
"trace", "trace",
@ -140,21 +151,23 @@ void vRegisterSampleCLICommands( void )
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho ); FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
FreeRTOS_CLIRegisterCommand( &xParameterEcho ); FreeRTOS_CLIRegisterCommand( &xParameterEcho );
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 ) #if ( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
{ {
FreeRTOS_CLIRegisterCommand( & xStartStopTrace ); FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
} }
#endif #endif
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n"; const char * const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -164,18 +177,20 @@ const char *const pcHeader = "Task State Priority Stack #\r\n********
vTaskList( pcWriteBuffer + strlen( pcHeader ) ); vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n"; const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -185,20 +200,22 @@ const char * const pcHeader = "Task Abs Time % Time\r\n*********
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) ); vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -206,15 +223,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" ); sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -237,11 +254,11 @@ static BaseType_t lParameterNumber = 0;
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) ); strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
if( lParameterNumber == 3L ) if( lParameterNumber == 3L )
{ {
/* If this is the last of the three parameters then there are no more /* If this is the last of the three parameters then there are no more
strings to return after this one. */ * strings to return after this one. */
xReturn = pdFALSE; xReturn = pdFALSE;
lParameterNumber = 0L; lParameterNumber = 0L;
} }
@ -257,15 +274,17 @@ static BaseType_t lParameterNumber = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t xParameterStringLength, xReturn; BaseType_t xParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0; static BaseType_t lParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -273,15 +292,15 @@ static BaseType_t lParameterNumber = 0;
if( lParameterNumber == 0 ) if( lParameterNumber == 0 )
{ {
/* The first time the function is called after the command has been /* The first time the function is called after the command has been
entered just a header string is returned. */ * entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" ); sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed /* Next time the function is called the first parameter will be echoed
back. */ * back. */
lParameterNumber = 1L; lParameterNumber = 1L;
/* There is more data to be returned as no parameters have been echoed /* There is more data to be returned as no parameters have been echoed
back yet. */ * back yet. */
xReturn = pdPASS; xReturn = pdPASS;
} }
else else
@ -309,7 +328,7 @@ static BaseType_t lParameterNumber = 0;
else else
{ {
/* No more parameters were found. Make sure the write buffer does /* No more parameters were found. Make sure the write buffer does
not contain a valid string. */ * not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00; pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */ /* No more data to return. */
@ -326,14 +345,16 @@ static BaseType_t lParameterNumber = 0;
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{ {
const char *pcParameter; const char * pcParameter;
BaseType_t lParameterStringLength; BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the /* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes 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. */ * write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString; ( void ) pcCommandString;
( void ) xWriteBufferLen; ( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer ); configASSERT( pcWriteBuffer );
@ -371,7 +392,7 @@ static BaseType_t lParameterNumber = 0;
} }
/* There is no more data to return after this single string, so return /* There is no more data to return after this single string, so return
pdFALSE. */ * pdFALSE. */
return pdFALSE; return pdFALSE;
} }

View file

@ -1,6 +1,6 @@
/* /*
* FreeRTOS V202212.00 * FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of * 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 * this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
* https://www.FreeRTOS.org * https://www.FreeRTOS.org
* https://aws.amazon.com/freertos * https://github.com/FreeRTOS
* *
*/ */
@ -66,16 +66,16 @@ static SOCKET prvOpenUDPSocket( void );
* demo runs in a simulated environment on a Windows PC. See the URL in the * demo runs in a simulated environment on a Windows PC. See the URL in the
* comments within main.c for the location of the online documentation. * comments within main.c for the location of the online documentation.
*/ */
void vUDPCommandInterpreterTask( void *pvParameters ) void vUDPCommandInterpreterTask( void * pvParameters )
{ {
long lBytes, lByte; long lBytes, lByte;
signed char cInChar, cInputIndex = 0; signed char cInChar, cInputIndex = 0;
static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ]; static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ];
BaseType_t xMoreDataToFollow; BaseType_t xMoreDataToFollow;
volatile int iErrorCode = 0; volatile int iErrorCode = 0;
struct sockaddr_in xClient; struct sockaddr_in xClient;
int xClientAddressLength = sizeof( struct sockaddr_in ); int xClientAddressLength = sizeof( struct sockaddr_in );
SOCKET xSocket; SOCKET xSocket;
/* Just to prevent compiler warnings. */ /* Just to prevent compiler warnings. */
( void ) pvParameters; ( void ) pvParameters;
@ -85,7 +85,7 @@ SOCKET xSocket;
if( xSocket != INVALID_SOCKET ) if( xSocket != INVALID_SOCKET )
{ {
for( ;; ) for( ; ; )
{ {
/* Wait for incoming data on the opened socket. */ /* Wait for incoming data on the opened socket. */
lBytes = recvfrom( xSocket, cLocalBuffer, sizeof( cLocalBuffer ), 0, ( struct sockaddr * ) &xClient, &xClientAddressLength ); lBytes = recvfrom( xSocket, cLocalBuffer, sizeof( cLocalBuffer ), 0, ( struct sockaddr * ) &xClient, &xClientAddressLength );
@ -93,13 +93,14 @@ SOCKET xSocket;
if( lBytes == SOCKET_ERROR ) if( lBytes == SOCKET_ERROR )
{ {
/* Something went wrong, but it is not handled by this simple /* Something went wrong, but it is not handled by this simple
example. */ * example. */
iErrorCode = WSAGetLastError(); iErrorCode = WSAGetLastError();
} }
else else
{ {
/* Process each received byte in turn. */ /* Process each received byte in turn. */
lByte = 0; lByte = 0;
while( lByte < lBytes ) while( lByte < lBytes )
{ {
/* The next character in the input buffer. */ /* The next character in the input buffer. */
@ -107,30 +108,29 @@ SOCKET xSocket;
lByte++; lByte++;
/* Newline characters are taken as the end of the command /* Newline characters are taken as the end of the command
string. */ * string. */
if( cInChar == '\n' ) if( cInChar == '\n' )
{ {
/* Process the input string received prior to the /* Process the input string received prior to the
newline. */ * newline. */
do do
{ {
/* Pass the string to FreeRTOS+CLI. */ /* Pass the string to FreeRTOS+CLI. */
xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE ); xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE );
/* Send the output generated by the command's /* Send the output generated by the command's
implementation. */ * implementation. */
sendto( xSocket, cOutputString, strlen( cOutputString ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength ); sendto( xSocket, cOutputString, strlen( cOutputString ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength );
} while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */ } while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */
/* All the strings generated by the command processing /* All the strings generated by the command processing
have been sent. Clear the input string ready to receive * have been sent. Clear the input string ready to receive
the next command. */ * the next command. */
cInputIndex = 0; cInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
/* Transmit a spacer, just to make the command console /* Transmit a spacer, just to make the command console
easier to read. */ * easier to read. */
sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength ); sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, ( SOCKADDR * ) &xClient, xClientAddressLength );
} }
else else
@ -138,12 +138,12 @@ SOCKET xSocket;
if( cInChar == '\r' ) if( cInChar == '\r' )
{ {
/* Ignore the character. Newlines are used to /* Ignore the character. Newlines are used to
detect the end of the input string. */ * detect the end of the input string. */
} }
else if( ( cInChar == '\b' ) || ( cInChar == cmdASCII_DEL ) ) else if( ( cInChar == '\b' ) || ( cInChar == cmdASCII_DEL ) )
{ {
/* Backspace was pressed. Erase the last character /* Backspace was pressed. Erase the last character
in the string - if any. */ * in the string - if any. */
if( cInputIndex > 0 ) if( cInputIndex > 0 )
{ {
cInputIndex--; cInputIndex--;
@ -153,8 +153,8 @@ SOCKET xSocket;
else else
{ {
/* A character was entered. Add it to the string /* A character was entered. Add it to the string
entered so far. When a \n is entered the complete * entered so far. When a \n is entered the complete
string will be passed to the command interpreter. */ * string will be passed to the command interpreter. */
if( cInputIndex < cmdMAX_INPUT_SIZE ) if( cInputIndex < cmdMAX_INPUT_SIZE )
{ {
cInputString[ cInputIndex ] = cInChar; cInputString[ cInputIndex ] = cInChar;
@ -176,10 +176,10 @@ SOCKET xSocket;
static SOCKET prvOpenUDPSocket( void ) static SOCKET prvOpenUDPSocket( void )
{ {
WSADATA xWSAData; WSADATA xWSAData;
WORD wVersionRequested; WORD wVersionRequested;
struct sockaddr_in xServer; struct sockaddr_in xServer;
SOCKET xSocket = INVALID_SOCKET; SOCKET xSocket = INVALID_SOCKET;
wVersionRequested = MAKEWORD( 2, 2 ); wVersionRequested = MAKEWORD( 2, 2 );
@ -191,7 +191,8 @@ SOCKET xSocket = INVALID_SOCKET;
else else
{ {
xSocket = socket( AF_INET, SOCK_DGRAM, 0 ); xSocket = socket( AF_INET, SOCK_DGRAM, 0 );
if( xSocket == INVALID_SOCKET)
if( xSocket == INVALID_SOCKET )
{ {
fprintf( stderr, "Could not create socket.\n" ); fprintf( stderr, "Could not create socket.\n" );
WSACleanup(); WSACleanup();
@ -224,5 +225,3 @@ SOCKET xSocket = INVALID_SOCKET;
return xSocket; return xSocket;
} }

View file

@ -25,12 +25,12 @@
*/ */
/****************************************************************************** /******************************************************************************
* *
* This demo is described on the following web page: * This demo is described on the following web page:
* TODO: This link describes the FAT version of this demo. * TODO: This link describes the FAT version of this demo.
* https://www.FreeRTOS.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml * https://www.FreeRTOS.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
* *
******************************************************************************/ ******************************************************************************/
/* Standard includes. */ /* Standard includes. */
#include <stdio.h> #include <stdio.h>
@ -60,7 +60,7 @@ extern void vRegisterFileSystemCLICommands( void );
/* /*
* The task that implements the UDP command interpreter using FreeRTOS+CLI. * The task that implements the UDP command interpreter using FreeRTOS+CLI.
*/ */
extern void vUDPCommandInterpreterTask( void *pvParameters ); extern void vUDPCommandInterpreterTask( void * pvParameters );
/* /*
* Creates and verifies different files on the volume, demonstrating the use of * Creates and verifies different files on the volume, demonstrating the use of
@ -71,27 +71,27 @@ extern void vCreateAndVerifySampleFiles( void );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* See http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml /* See http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
for instructions. */ * for instructions. */
int main( void ) int main( void )
{ {
const uint32_t ulLongTime_ms = 250UL; const uint32_t ulLongTime_ms = 250UL;
/* Initialise the drive and file system, then create a few example /* Initialise the drive and file system, then create a few example
files. The output from this function just goes to the stdout window, * files. The output from this function just goes to the stdout window,
allowing the output to be viewed when the UDP command console is not * allowing the output to be viewed when the UDP command console is not
connected. */ * connected. */
vCreateAndVerifySampleFiles(); vCreateAndVerifySampleFiles();
/* Register generic commands with the FreeRTOS+CLI command interpreter. */ /* Register generic commands with the FreeRTOS+CLI command interpreter. */
vRegisterSampleCLICommands(); vRegisterSampleCLICommands();
/* Register file system related commands with the FreeRTOS+CLI command /* Register file system related commands with the FreeRTOS+CLI command
interpreter. */ * interpreter. */
vRegisterFileSystemCLICommands(); vRegisterFileSystemCLICommands();
/* Create the task that handles the CLI on a UDP port. The port number /* Create the task that handles the CLI on a UDP port. The port number
is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */ * is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
xTaskCreate( vUDPCommandInterpreterTask, /* The function that implements the command interpreter IO handling. */ xTaskCreate( vUDPCommandInterpreterTask, /* The function that implements the command interpreter IO handling. */
"CLI", /* The name of the task - just to assist debugging. */ "CLI", /* The name of the task - just to assist debugging. */
configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */ configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */
@ -102,12 +102,12 @@ const uint32_t ulLongTime_ms = 250UL;
vTaskStartScheduler(); vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following /* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then * line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or * there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the * timer tasks to be created. See the memory management section on the
FreeRTOS web site for more details (this is standard text that is not * FreeRTOS web site for more details (this is standard text that is not
really applicable to the Win32 simulator port). */ * really applicable to the Win32 simulator port). */
for( ;; ) for( ; ; )
{ {
Sleep( ulLongTime_ms ); Sleep( ulLongTime_ms );
} }
@ -116,11 +116,11 @@ const uint32_t ulLongTime_ms = 250UL;
void vApplicationIdleHook( void ) void vApplicationIdleHook( void )
{ {
const unsigned long ulMSToSleep = 5; const unsigned long ulMSToSleep = 5;
/* This function is called on each cycle of the idle task if /* This function is called on each cycle of the idle task if
configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU * configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
load. */ * load. */
Sleep( ulMSToSleep ); Sleep( ulMSToSleep );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -128,19 +128,19 @@ const unsigned long ulMSToSleep = 5;
void vApplicationMallocFailedHook( void ) void vApplicationMallocFailedHook( void )
{ {
/* vApplicationMallocFailedHook() will only be called if /* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails. * function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue, * pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the * timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the * demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
size of the heap available to pvPortMalloc() is defined by * size of the heap available to pvPortMalloc() is defined by
configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() * configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
API function can be used to query the size of free heap space that remains * API function can be used to query the size of free heap space that remains
(although it does not provide information on how the remaining heap might * (although it does not provide information on how the remaining heap might
be fragmented). */ * be fragmented). */
taskDISABLE_INTERRUPTS(); taskDISABLE_INTERRUPTS();
for( ;; );
for( ; ; )
{
}
} }

View file

@ -130,21 +130,21 @@ extern void vAssertCalled( const char * const pcFileName,
#if ( projCOVERAGE_TEST == 1 ) #if ( projCOVERAGE_TEST == 1 )
/* Insert NOPs in empty decision paths to ensure both true and false paths /* Insert NOPs in empty decision paths to ensure both true and false paths
* are being tested. */ * are being tested. */
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" ) #define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
/* Ensure the tick count overflows during the coverage test. */ /* Ensure the tick count overflows during the coverage test. */
#define configINITIAL_TICK_COUNT 0xffffd800UL #define configINITIAL_TICK_COUNT 0xffffd800UL
/* Allows tests of trying to allocate more than the heap has free. */ /* Allows tests of trying to allocate more than the heap has free. */
#define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_MALLOC_FAILED_HOOK 0
/* To test builds that remove the static qualifier for debug builds. */ /* To test builds that remove the static qualifier for debug builds. */
#define portREMOVE_STATIC_QUALIFIER #define portREMOVE_STATIC_QUALIFIER
#else /* if ( projCOVERAGE_TEST == 1 ) */ #else /* if ( projCOVERAGE_TEST == 1 ) */
/* It is a good idea to define configASSERT() while developing. configASSERT() /* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. Don't define * uses the same semantics as the standard C assert() macro. Don't define
* configASSERT() when performing code coverage tests though, as it is not * configASSERT() when performing code coverage tests though, as it is not
* intended to asserts() to fail, some some code is intended not to run if no * intended to asserts() to fail, some some code is intended not to run if no
@ -153,7 +153,7 @@ extern void vAssertCalled( const char * const pcFileName,
#define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_MALLOC_FAILED_HOOK 0
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */ /* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
#include "trcRecorder.h" #include "trcRecorder.h"
#endif /* if ( projCOVERAGE_TEST == 1 ) */ #endif /* if ( projCOVERAGE_TEST == 1 ) */

View file

@ -196,7 +196,7 @@
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
FreeRTOS_listen( xListeningSocket, xBacklog ); FreeRTOS_listen( xListeningSocket, xBacklog );
for( ;; ) for( ; ; )
{ {
/* Wait for a client to connect. */ /* Wait for a client to connect. */
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize ); xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
@ -235,7 +235,7 @@
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
for( ;; ) for( ; ; )
{ {
/* Zero out the receive array so there is NULL at the end of the string /* Zero out the receive array so there is NULL at the end of the string
* when it is printed out. */ * when it is printed out. */

View file

@ -416,5 +416,5 @@
return eDHCPContinue; return eDHCPContinue;
} }
#endif #endif /* if ( ( ipconfigUSE_TCP == 1 ) && ( ipconfigUSE_DHCP_HOOK != 0 ) ) */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -31,9 +31,8 @@
* Create the TCP echo client tasks. This is the version where an echo request * Create the TCP echo client tasks. This is the version where an echo request
* is made from the same task that listens for the echo reply. * is made from the same task that listens for the echo reply.
*/ */
void vStartTCPEchoClientTasks_SingleTasks( size_t uxTaskStackSize, UBaseType_t uxTaskPriority ); void vStartTCPEchoClientTasks_SingleTasks( size_t uxTaskStackSize,
UBaseType_t uxTaskPriority );
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ); BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void );
#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */ #endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */

Some files were not shown because too many files have changed in this diff Show more