diff --git a/board/linker_template_gnu.ld b/board/linker_template_gnu.ld index f1f4c8c72..7195fdccf 100644 --- a/board/linker_template_gnu.ld +++ b/board/linker_template_gnu.ld @@ -78,15 +78,8 @@ SECTIONS _f_sdata = .; __SDATA_BEGIN__ = .; *(.sdata .sdata.* .gnu.linkonce.s.*) - _e_sdata = .; - _e_data = .; - } > REGION_RAM AT > REGION_ROM - - .bss (NOLOAD) : ALIGN(8) - { PROVIDE (__sbss_start = .); PROVIDE (___sbss_start = .); - _f_bss = .; _f_sbss = .; *(.dynsbss) *(.sbss .sbss.* .gnu.linkonce.sb.*) @@ -94,7 +87,13 @@ SECTIONS _e_sbss = .; PROVIDE (__sbss_end = .); PROVIDE (___sbss_end = .); + _e_sdata = .; + _e_data = .; + } > REGION_RAM AT > REGION_ROM + .bss (NOLOAD) : ALIGN(8) + { + _f_bss = .; *(.dynbss) *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) diff --git a/board/linker_template_mw.ld b/board/linker_template_mw.ld index e63571e54..bb63b6556 100644 --- a/board/linker_template_mw.ld +++ b/board/linker_template_mw.ld @@ -69,6 +69,7 @@ SECTIONS { _f_data = .; _f_sdata = .; *(.sdata) + *(.sbss) _e_sdata = .; *(TYPE data) } diff --git a/example/baremetal/openthread/cli/mbedtls-config.h b/example/baremetal/openthread/cli/mbedtls-config.h index 0b9693bd5..a6ceb5dba 100644 --- a/example/baremetal/openthread/cli/mbedtls-config.h +++ b/example/baremetal/openthread/cli/mbedtls-config.h @@ -33,6 +33,7 @@ #include #include #include +#include #if defined(_WIN32) #include @@ -189,7 +190,7 @@ __inline int windows_kernel_snprintf(char * s, size_t n, const char * format, .. //#define MBEDTLS_PLATFORM_TIME_ALT //#define MBEDTLS_PLATFORM_FPRINTF_ALT //#define MBEDTLS_PLATFORM_PRINTF_ALT -//#define MBEDTLS_PLATFORM_SNPRINTF_ALT +#define MBEDTLS_PLATFORM_SNPRINTF_ALT //#define MBEDTLS_PLATFORM_NV_SEED_ALT /** @@ -2557,7 +2558,7 @@ __inline int windows_kernel_snprintf(char * s, size_t n, const char * format, .. //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */ /* Note: your snprintf must correclty zero-terminate the buffer! */ -//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ +#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ diff --git a/example/baremetal/openthread/ncp/mbedtls-config.h b/example/baremetal/openthread/ncp/mbedtls-config.h index 0b9693bd5..a6ceb5dba 100644 --- a/example/baremetal/openthread/ncp/mbedtls-config.h +++ b/example/baremetal/openthread/ncp/mbedtls-config.h @@ -33,6 +33,7 @@ #include #include #include +#include #if defined(_WIN32) #include @@ -189,7 +190,7 @@ __inline int windows_kernel_snprintf(char * s, size_t n, const char * format, .. //#define MBEDTLS_PLATFORM_TIME_ALT //#define MBEDTLS_PLATFORM_FPRINTF_ALT //#define MBEDTLS_PLATFORM_PRINTF_ALT -//#define MBEDTLS_PLATFORM_SNPRINTF_ALT +#define MBEDTLS_PLATFORM_SNPRINTF_ALT //#define MBEDTLS_PLATFORM_NV_SEED_ALT /** @@ -2557,7 +2558,7 @@ __inline int windows_kernel_snprintf(char * s, size_t n, const char * format, .. //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */ /* Note: your snprintf must correclty zero-terminate the buffer! */ -//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ +#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ diff --git a/example/baremetal/secureshield/secret_normal/README.rst b/example/baremetal/secureshield/secret_normal/README.rst index 32687f07a..663fa6ba2 100644 --- a/example/baremetal/secureshield/secret_normal/README.rst +++ b/example/baremetal/secureshield/secret_normal/README.rst @@ -43,7 +43,7 @@ For nSIM, the commands to run this example are as follows: .. code-block:: console $ cd /example/baremetal/secureshield/secret_normal - $ gmake BOARD=nsim BD_VER=1506 CUR_CORE=arcemsecureshield TOOLCHAIN=mw run + $ gmake BOARD=nsim BD_VER=10 CUR_CORE=arcsem TOOLCHAIN=mw run For EMSK 2.2, the commands to run this example are as follows: diff --git a/example/baremetal/secureshield/secret_normal/makefile b/example/baremetal/secureshield/secret_normal/makefile index 15339c48d..f15c78f7a 100644 --- a/example/baremetal/secureshield/secret_normal/makefile +++ b/example/baremetal/secureshield/secret_normal/makefile @@ -9,7 +9,9 @@ BOARD ?= nsim CUR_CORE ?= arcsem -APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0 -DNTSHELL_USE_CMDS_ARC=0 +# secureshield doesn't support stack check now +APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0\ + -DNTSHELL_USE_CMDS_ARC=0 -DARC_FEATURE_STACK_CHECK=0 # # root dir of embARC diff --git a/example/baremetal/secureshield/secret_secure/README.rst b/example/baremetal/secureshield/secret_secure/README.rst index 853a53424..ec9bc51a7 100644 --- a/example/baremetal/secureshield/secret_secure/README.rst +++ b/example/baremetal/secureshield/secret_secure/README.rst @@ -42,7 +42,7 @@ For nSIM, the commands to run this example are as follows: .. code-block:: console $ cd /example/baremetal/secureshield/secret_secure - $ gmake BOARD=nsim BD_VER=1506 CUR_CORE=arcemsecureshield TOOLCHAIN=mw run + $ gmake BOARD=nsim BD_VER=10 CUR_CORE=arcsem TOOLCHAIN=mw run For EMSK 2.2, the commands to run this example are as follows: diff --git a/example/baremetal/secureshield/secret_secure/makefile b/example/baremetal/secureshield/secret_secure/makefile index fbceb093e..c6f1c08fc 100644 --- a/example/baremetal/secureshield/secret_secure/makefile +++ b/example/baremetal/secureshield/secret_secure/makefile @@ -9,7 +9,9 @@ BOARD ?= nsim CUR_CORE ?= arcsem -APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0 -DNTSHELL_USE_CMDS_ARC=0 +# secureshield doesn't support stack check now +APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0\ + -DNTSHELL_USE_CMDS_ARC=0 -DARC_FEATURE_STACK_CHECK=0 # # root dir of embARC diff --git a/example/baremetal/secureshield/secret_secure_sid/README.rst b/example/baremetal/secureshield/secret_secure_sid/README.rst index f97cc1212..4dcf2381c 100644 --- a/example/baremetal/secureshield/secret_secure_sid/README.rst +++ b/example/baremetal/secureshield/secret_secure_sid/README.rst @@ -44,7 +44,7 @@ For nSIM, the commands to run this example are as follows: .. code-block:: console $ cd /example/baremetal/secureshield/secret_secure_sid - $ gmake BOARD=nsim BD_VER=1506 CUR_CORE=arcemsecureshield TOOLCHAIN=mw run + $ gmake BOARD=nsim BD_VER=10 CUR_CORE=arcsem TOOLCHAIN=mw run For EMSK 2.3, the commands to run this example are as follows: diff --git a/example/baremetal/secureshield/secret_secure_sid/makefile b/example/baremetal/secureshield/secret_secure_sid/makefile index 7b6fd434e..dd6cbddf3 100644 --- a/example/baremetal/secureshield/secret_secure_sid/makefile +++ b/example/baremetal/secureshield/secret_secure_sid/makefile @@ -10,7 +10,9 @@ BOARD ?= nsim CUR_CORE = arcsem -APPL_DEFINES = -DNTSHELL_USE_CMDS_PERIPHERAL=0 -DNTSHELL_USE_CMDS_ARC=0 +# secureshield doesn't support stack check now +APPL_DEFINES = -DNTSHELL_USE_CMDS_PERIPHERAL=0 -DNTSHELL_USE_CMDS_ARC=0\ + -DARC_FEATURE_STACK_CHECK=0 # # root dir of embARC diff --git a/example/baremetal/secureshield/test_case/README.rst b/example/baremetal/secureshield/test_case/README.rst index 64ca23416..f1bb4612b 100644 --- a/example/baremetal/secureshield/test_case/README.rst +++ b/example/baremetal/secureshield/test_case/README.rst @@ -34,7 +34,7 @@ It is supported by nSIM. The commands to run this example are as follows: .. code-block:: console $ cd /example/baremetal/secureshield/test_case - $ gmake BOARD=nsim BD_VER=1506 CUR_CORE=arcemsecureshield TOOLCHAIN=mw run + $ gmake BOARD=nsim BD_VER=10 CUR_CORE=arcsem TOOLCHAIN=mw run Sample Output ============= diff --git a/example/baremetal/secureshield/test_case/makefile b/example/baremetal/secureshield/test_case/makefile index a8ce53a10..35f8d30a2 100644 --- a/example/baremetal/secureshield/test_case/makefile +++ b/example/baremetal/secureshield/test_case/makefile @@ -9,7 +9,9 @@ BOARD ?= nsim CUR_CORE ?= arcsem -APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0 -DNTSHELL_USE_CMDS_ARC=0 +# secureshield doesn't support stack check now +APPL_DEFINES = -DLIB_SECURESHIELD_OVERRIDES -DNTSHELL_USE_CMDS_PERIPHERAL=0\ + -DNTSHELL_USE_CMDS_ARC=0 -DARC_FEATURE_STACK_CHECK=0 # # root dir of embARC diff --git a/example/fatfs_test/main.c b/example/fatfs_test/main.c new file mode 100644 index 000000000..5a92142f2 --- /dev/null +++ b/example/fatfs_test/main.c @@ -0,0 +1,103 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior done permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#include "embARC.h" +#include "embARC_debug.h" + +#define DATA_SIZE 8192 +static FIL file; + +uint8_t data_write[DATA_SIZE]; +uint8_t data_read[DATA_SIZE]; + + +/** + * \brief Test hardware board without any peripheral + */ +int main(void) +{ + uint8_t res; + uint32_t i; + uint32_t rw_counter; + uint32_t done; + uint8_t *buf; + + EMBARC_PRINTF("test start\r\n"); + + for (i = 0; i < DATA_SIZE; i++) { + data_write[i] = 'a' + i % 26; + } + + res = f_open(&file, "test1.txt", FA_WRITE | FA_CREATE_ALWAYS); + + if (res) { + EMBARC_PRINTF("file open err\r\n"); + while (1); + } + + rw_counter = DATA_SIZE; + buf = data_write; + + while (rw_counter) { + res = f_write(&file, buf, rw_counter, &done); + + if (res) { + EMBARC_PRINTF("file write error :%d\r\n", res); + while (1); + } + rw_counter -= done; + buf += done; + EMBARC_PRINTF("%d bytes are written\r\n", done); + } + f_close(&file); + + res = f_open(&file, "test1.txt", FA_READ | FA_OPEN_EXISTING); + + if (res) { + EMBARC_PRINTF("file open err\r\n"); + while (1); + } + + rw_counter = DATA_SIZE; + buf = data_read; + + while (rw_counter) { + res = f_read(&file, buf, rw_counter, &done); + + if (res) { + EMBARC_PRINTF("file read error :%d\r\n", res); + while (1); + } + rw_counter -= done; + buf += done; + EMBARC_PRINTF("%d bytes are read\r\n", done); + } + + while (1); +} diff --git a/example/fatfs_test/makefile b/example/fatfs_test/makefile new file mode 100644 index 000000000..2bb854ab3 --- /dev/null +++ b/example/fatfs_test/makefile @@ -0,0 +1,24 @@ +# Application name +APPL ?= fatfs_test + +BOARD = iotdk +# +# root dir of embARC +# +EMBARC_ROOT = ../.. + +MID_SEL = common fatfs + +# application source dirs +APPL_CSRC_DIR = . +APPL_ASMSRC_DIR = . + +# application include dirs +APPL_INC_DIR = . + +# include current project makefile +COMMON_COMPILE_PREREQUISITES += makefile + +### Options above must be added before include options.mk ### +# include key embARC build system makefile +include $(EMBARC_ROOT)/options/options.mk \ No newline at end of file diff --git a/example/freertos/kernel_secure/README.rst b/example/freertos/kernel_secure/README.rst index 97ffdc39c..4e4f767cb 100644 --- a/example/freertos/kernel_secure/README.rst +++ b/example/freertos/kernel_secure/README.rst @@ -28,12 +28,21 @@ Detailed Description - Re-configure the EMSK 2.3 board to EM7D configuration. - run the following commands +For nSIM, the commands to run this example are as follows: + +.. code-block:: console + + $ cd /example/freertos/kernel_secure + $ gmake BOARD=nsim BD_VER=10 CUR_CORE=arcsem TOOLCHAIN=mw run + +For EMSK 2.3, the commands to run this example are as follows: + .. code-block:: console $ cd /example/freertos/kernel_secure $ make BOARD=emsk BD_VER=23 CUR_CORE=arcem7d TOOLCHAIN=gnu run -.. note:: This example is only valid for arc processors with SecureShield feature (Currently, emsk 2.3 arcem7d) +.. note:: This example is only valid for arc processors with SecureShield feature (Currently, emsk 2.3 arcem7d and nsim arcsem) Sample Output diff --git a/example/freertos/kernel_secure/makefile b/example/freertos/kernel_secure/makefile index 4878943c1..74aebcd74 100644 --- a/example/freertos/kernel_secure/makefile +++ b/example/freertos/kernel_secure/makefile @@ -20,6 +20,9 @@ EMBARC_ROOT = ../../.. LIB_SEL = secureshield MID_SEL = common +# secureshield doesn't support stack check now +APPL_DEFINES = -DARC_FEATURE_STACK_CHECK=0 + # application source dirs APPL_CSRC_DIR = . APPL_ASMSRC_DIR = . diff --git a/example/freertos/sec/mbedtls/dtls/client/README.rst b/example/freertos/sec/mbedtls/dtls/client/README.rst index 34fcb6797..7d853776e 100644 --- a/example/freertos/sec/mbedtls/dtls/client/README.rst +++ b/example/freertos/sec/mbedtls/dtls/client/README.rst @@ -18,7 +18,6 @@ Detailed Description * Extra Required Peripherals - Digilent PMOD WIFI(MRF24WG0MA) - - SD Card to store certification file, key file .. note:: EMSDP has board WiFi module, no need to use PMOD WiFI. @@ -39,16 +38,84 @@ Buidling and Running 2. In pc node or mbedtls dtls_server node, run the server application to listen. -3. Copy the ``tests`` dir in ``middleware/mbedtls`` into the SD card of secure server node, it will load CA file and key file. +3. Change SERVER_NAME and SERVER_ADDR in dtls_client.c to the dtls_server node's IP address. And build this application again. -4. Change SERVER_NAME and SERVER_ADDR in dtls_client.c to the dtls_server node's IP address. And build this application again. - -5. When initialization finished and network connected, run **main** in ntshell, it will try to do dtls communication. +4. When initialization finished and network connected, run **main** in ntshell, it will try to do dtls communication. Sample Output ============= .. code-block:: console - + ----------------------------------------------------------- + ____ _ ____ + | _ \ _____ _____ _ __ ___ __| | __ ) _ _ + | |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | + | __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | + |_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | + |___/ + _ _ ____ ____ + ___ _ __ ___ | |__ / \ | _ \ / ___| + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | + | __/ | | | | | |_) / ___ \| _ <| |___ + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| + ------------------------------------------------------------ + + embARC Build Time: Jan 23 2019, 10:57:51 + Compiler Version: Metaware, 4.2.1 Compatible Clang 6.0.1 (branches/release_60) + FatFS initialized successfully! + Start Init LWIP + ntshell command info(Information) was registered! + ntshell command main(Call main function) was registered! + ntshell command ls(List information about files) was registered! + ntshell command cd(Change the working directory) was registered! + ntshell command rm(Remove the file or the folder) was registered! + ntshell command mkdir(Create the directory) was registered! + ntshell command cat(Output file contents) was registered! + ntshell command cp(Copy source to destination) was registered! + ntshell command mv(Rename file or move file) was registered! + ntshell command pwd(Print the current working directory) was registered! + ntshell command cls(Clear the console output) was registered! + ntshell command touch(Create a file) was registered! + ntshell command ymodem(Ymodem file transfer protocol) was registered! + ntshell command disk(Operate the storge device) was registered! + ntshell command load(Load .bin/.hex file from SD card to ram at specified address) was registered! + ntshell command go(Run the program at the specified address) was registered! + NTShell Task StartUp + COM1>RS9113 MAC ADDRESS:00-00-00-00-00-00 + + Now trying to connect to WIFI hotspot, please wait about 30s! + RS9113 MAC ADDRESS:88-da-1a-0b-5e-4c + Link is UP! + + Now start get ip address using DHCP, Please wait about 30s! + + -----WIFI IP ADDRESS INFO----- + ipaddr 192.168.137.46 netmask 255.255.255.0 gw 192.168.137.1 + dns server 0 :192.168.137.1 + dns server 1 :0.0.0.0 + ----------------------------------- + WiFi connected + Please run NT-Shell command(main) to start your application. + main command may required some arguments, please refer to example's document. + main + + . Seeding the random number generator... ok + . Loading the CA root certificate ... ok (0 skipped) + . Connecting to udp/192.168.43.252/4433... ok + . Setting up the DTLS structure... ok + . Performing the SSL/TLS handshake... ok + . Verifying peer X.509 certificate... failed + ! The certificate Common Name (CN) does not match with the expected CN + ! The certificate is signed with an unacceptable hash. + + > Write to server: 9 bytes written + + Echo this + + < Read from server: 9 bytes read + + Echo this + + . Closing the connection... done diff --git a/example/freertos/sec/mbedtls/dtls/server/README.rst b/example/freertos/sec/mbedtls/dtls/server/README.rst index 61c66bb83..6e301e677 100644 --- a/example/freertos/sec/mbedtls/dtls/server/README.rst +++ b/example/freertos/sec/mbedtls/dtls/server/README.rst @@ -17,7 +17,6 @@ Detailed Description * Extra Required Peripherals - Digilent PMOD WIFI(MRF24WG0MA) - - SD Card to store certification file, key file .. note:: EMSDP has board WiFi module, no need to use PMOD WiFI. @@ -37,14 +36,95 @@ Buidling and Running cd /middleware/mbedtls sh apply_embarc_patch.sh +2. When initialization finished and network connected, run **main** in ntshell, it will try to do dtls communication. -2. Copy the ``tests`` dir in ``middleware/mbedtls`` into the SD card of secure server node, it will load CA file and key file. - -3. When initialization finished and network connected, run **main** in ntshell, it will try to do dtls communication. - -4. In pc node or mbedtls dtls_client node, run the client application to connect to the server node. +3. In pc node or mbedtls dtls_client node, run the client application to connect to the server node. Sample Output ============= -.. code-block:: console \ No newline at end of file +.. code-block:: console + + ----------------------------------------------------------- + ____ _ ____ + | _ \ _____ _____ _ __ ___ __| | __ ) _ _ + | |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | + | __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | + |_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | + |___/ + _ _ ____ ____ + ___ _ __ ___ | |__ / \ | _ \ / ___| + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | + | __/ | | | | | |_) / ___ \| _ <| |___ + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| + ------------------------------------------------------------ + + embARC Build Time: Jan 23 2019, 11:21:59 + Compiler Version: Metaware, 4.2.1 Compatible Clang 6.0.1 (branches/release_60) + FatFS initialized successfully! + Start Init LWIP + ntshell command info(Information) was registered! + ntshell command main(Call main function) was registered! + ntshell command ls(List information about files) was registered! + ntshell command cd(Change the working directory) was registered! + ntshell command rm(Remove the file or the folder) was registered! + ntshell command mkdir(Create the directory) was registered! + ntshell command cat(Output file contents) was registered! + ntshell command cp(Copy source to destination) was registered! + ntshell command mv(Rename file or move file) was registered! + ntshell command pwd(Print the current working directory) was registered! + ntshell command cls(Clear the console output) was registered! + ntshell command touch(Create a file) was registered! + ntshell command ymodem(Ymodem file transfer protocol) was registered! + ntshell command disk(Operate the storge device) was registered! + ntshell command load(Load .bin/.hex file from SD card to ram at specified address) was registered! + ntshell command go(Run the program at the specified address) was registered! + ntshell command spirw(Read/Write the image in spi flash for updating bootloader/application image) was registered! + ntshell command mload(Update firmware, read or write MCS file in the SPI flash) was registered! + NTShell Task StartUp + COM1> + Now trying to connect to WIFI hotspot, please wait about 30s! + MRF24G Device Information As Follows: + Device Type:2, ROM Ver:31, Patch Ver:7 + Connection Profile ID:1 + WF INIT SUCCESSFULL! + MRF24G MAC ADDRESS:00-1e-c0-0e-71-ac + WF_EVENT_CONNECTION_SUCCESSFUL + Link is UP! + + Now start get ip address using DHCP, Please wait about 30s! + + -----WIFI IP ADDRESS INFO----- + ipaddr 192.168.137.39 netmask 255.255.255.0 gw 192.168.137.1 + dns server 0 :192.168.137.1 + dns server 1 :0.0.0.0 + ----------------------------------- + WiFi connected + Please run NT-Shell command(main) to start your application. + main command may required some arguments, please refer to example's document. + main + + . Loading the server cert. and key... ok + . Bind on udp/*/4433 ... ok + . Seeding the random number generator... ok + . Setting up the DTLS data... ok + . Waiting for a remote connection ... ok + . Performing the DTLS handshake... hello verification requested + . Waiting for a remote connection ... ok + . Performing the DTLS handshake... ok + < Read from client: 9 bytes read + + Echo this + + > Write to client: 9 bytes written + + Echo this + + . Closing the connection... done + . Waiting for a remote connection ... ok + . Performing the DTLS handshake... failed + ! mbedtls_ssl_handshake returned -0x7900 + + Last error was: -30976 - SSL - Processing of the ClientHello handshake message failed + + . Waiting for a remote connection ... \ No newline at end of file diff --git a/example/freertos/sec/mbedtls/ssl/client2/README.rst b/example/freertos/sec/mbedtls/ssl/client2/README.rst index 936375954..5e26746ed 100644 --- a/example/freertos/sec/mbedtls/ssl/client2/README.rst +++ b/example/freertos/sec/mbedtls/ssl/client2/README.rst @@ -7,7 +7,7 @@ FreeRTOS mbed SSL Example: SSL Client Overview ******** -This example takes reference from mbedtls **ssL_client2 ** to test ssl client functionality. +This example takes reference from mbedtls **ssL_client2** to test ssl client functionality. Detailed Description @@ -18,7 +18,6 @@ Detailed Description * Extra Required Peripherals - Digilent PMOD WIFI(MRF24WG0MA) - - SD Card to store certification file, key file .. note:: EMSDP has board WiFi module, no need to use PMOD WiFI. @@ -43,10 +42,7 @@ commands 2. In pc node or mbedtls ssl server node, run the server application to listen. -3. Copy the ``tests`` dir in ``middleware/mbedtls`` into the SD card of secure -server node, it will load CA file and key file. - -4. Here the mbedtls ssl server node's ip address is 192.168.43.76, we can get +3. Here the mbedtls ssl server node's ip address is 192.168.43.76, we can get it from console output of uart. When initialization finished and network connected, run **main server_addr=192.168.43.76 auth_mode=optional** in ntshell, it will try to do ssl communication. @@ -54,4 +50,98 @@ ntshell, it will try to do ssl communication. Sample Output ============= -.. code-block:: console \ No newline at end of file +.. code-block:: console + + ----------------------------------------------------------- + ____ _ ____ + | _ \ _____ _____ _ __ ___ __| | __ ) _ _ + | |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | + | __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | + |_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | + |___/ + _ _ ____ ____ + ___ _ __ ___ | |__ / \ | _ \ / ___| + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | + | __/ | | | | | |_) / ___ \| _ <| |___ + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| + ------------------------------------------------------------ + + embARC Build Time: Jan 23 2019, 11:38:25 + Compiler Version: Metaware, 4.2.1 Compatible Clang 6.0.1 (branches/release_60) + FatFS initialized successfully! + Start Init LWIP + ntshell command info(Information) was registered! + ntshell command main(Call main function) was registered! + ntshell command ls(List information about files) was registered! + ntshell command cd(Change the working directory) was registered! + ntshell command rm(Remove the file or the folder) was registered! + ntshell command mkdir(Create the directory) was registered! + ntshell command cat(Output file contents) was registered! + ntshell command cp(Copy source to destination) was registered! + ntshell command mv(Rename file or move file) was registered! + ntshell command pwd(Print the current working directory) was registered! + ntshell command cls(Clear the console output) was registered! + ntshell command touch(Create a file) was registered! + ntshell command ymodem(Ymodem file transfer protocol) was registered! + ntshell command disk(Operate the storge device) was registered! + ntshell command load(Load .bin/.hex file from SD card to ram at specified address) was registered! + ntshell command go(Run the program at the specified address) was registered! + NTShell Task StartUp + COM1>RS9113 MAC ADDRESS:00-00-00-00-00-00 + + Now trying to connect to WIFI hotspot, please wait about 30s! + RS9113 MAC ADDRESS:88-da-1a-0b-5e-4c + Link is UP! + + Now start get ip address using DHCP, Please wait about 30s! + + -----WIFI IP ADDRESS INFO----- + ipaddr 192.168.137.46 netmask 255.255.255.0 gw 192.168.137.1 + dns server 0 :192.168.137.1 + dns server 1 :0.0.0.0 + ----------------------------------- + WiFi connected + Please run NT-Shell command(main) to start your application. + main command may required some arguments, please refer to example's document. + main server_addr=192.168.137.39 auth_mode=optional + + . Seeding the random number generator... ok + . Loading the CA root certificate ... ok (0 skipped) + . Loading the client cert. and key... ok + . Connecting to tcp/192.168.137.39/4433... ok + . Setting up the SSL/TLS structure... ok + . Performing the SSL/TLS handshake... ok + [ Protocol is TLSv1.2 ] + [ Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384 ] + [ Record expansion is 29 ] + [ Maximum fragment length is 16384 ] + . Verifying peer X.509 certificate... failed + ! The certificate validity has expired + ! The certificate Common Name (CN) does not match with the expected CN + ! The certificate validity starts in the future + + . Peer certificate information ... + cert. version : 3 + serial number : 09 + issuer name : C=NL, O=PolarSSL, CN=Polarssl Test EC CA + subject name : C=NL, O=PolarSSL, CN=localhost + issued on : 2013-09-24 15:52:04 + expires on : 2023-09-22 15:52:04 + signed using : ECDSA with SHA256 + EC key size : 256 bits + basic constraints : CA=false + + > Write to server: 34 bytes written in 1 fragments + + GET / HTTP/1.0 + Extra-header: + + + < Read from server: 152 bytes read + + HTTP/1.0 200 OK + Content-Type: text/html + +

mbed TLS Test Server

+

Successful connection using: TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384

+ . Closing the connection... done diff --git a/example/freertos/sec/mbedtls/ssl/server2/README.rst b/example/freertos/sec/mbedtls/ssl/server2/README.rst index 7403e5205..95fe8b181 100644 --- a/example/freertos/sec/mbedtls/ssl/server2/README.rst +++ b/example/freertos/sec/mbedtls/ssl/server2/README.rst @@ -7,7 +7,7 @@ FreeRTOS mbed SSL Example: SSL Server Overview ******** -This example takes reference from mbedtls **ssl_server2 ** to test ssl server +This example takes reference from mbedtls **ssl_server2** to test ssl server functionality. @@ -19,7 +19,6 @@ Detailed Description * Extra Required Peripherals - Digilent PMOD WIFI(MRF24WG0MA) - - SD Card to store certification file, key file .. note:: EMSDP has board WiFi module, no need to use PMOD WiFI. @@ -42,12 +41,100 @@ commands cd /middleware/mbedtls sh apply_embarc_patch.sh -2. Copy the ``tests`` dir in ``middleware/mbedtls`` into the SD card of secure -server node, it will load CA file and key file. - -3. When initialization finished and network connected, run **main auth_mode=optional** in ntshell, it will wait for ssl client to connect to it. +2. When initialization finished and network connected, run **main auth_mode=optional** in ntshell, it will wait for ssl client to connect to it. Sample Output ============= -.. code-block:: console \ No newline at end of file +.. code-block:: console + + ----------------------------------------------------------- + ____ _ ____ + | _ \ _____ _____ _ __ ___ __| | __ ) _ _ + | |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | + | __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | + |_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | + |___/ + _ _ ____ ____ + ___ _ __ ___ | |__ / \ | _ \ / ___| + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | + | __/ | | | | | |_) / ___ \| _ <| |___ + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| + ------------------------------------------------------------ + + embARC Build Time: Jan 23 2019, 11:35:42 + Compiler Version: Metaware, 4.2.1 Compatible Clang 6.0.1 (branches/release_60) + FatFS initialized successfully! + Start Init LWIP + ntshell command info(Information) was registered! + ntshell command main(Call main function) was registered! + ntshell command ls(List information about files) was registered! + ntshell command cd(Change the working directory) was registered! + ntshell command rm(Remove the file or the folder) was registered! + ntshell command mkdir(Create the directory) was registered! + ntshell command cat(Output file contents) was registered! + ntshell command cp(Copy source to destination) was registered! + ntshell command mv(Rename file or move file) was registered! + ntshell command pwd(Print the current working directory) was registered! + ntshell command cls(Clear the console output) was registered! + ntshell command touch(Create a file) was registered! + ntshell command ymodem(Ymodem file transfer protocol) was registered! + ntshell command disk(Operate the storge device) was registered! + ntshell command load(Load .bin/.hex file from SD card to ram at specified address) was registered! + ntshell command go(Run the program at the specified address) was registered! + ntshell command spirw(Read/Write the image in spi flash for updating bootloader/application image) was registered! + ntshell command mload(Update firmware, read or write MCS file in the SPI flash) was registered! + NTShell Task StartUp + COM1> + Now trying to connect to WIFI hotspot, please wait about 30s! + MRF24G Device Information As Follows: + Device Type:2, ROM Ver:31, Patch Ver:7 + Connection Profile ID:1 + WF INIT SUCCESSFULL! + MRF24G MAC ADDRESS:00-1e-c0-0e-71-ac + WF_EVENT_CONNECTION_FAILED + WF_EVENT_CONNECTION_SUCCESSFUL + Link is UP! + + Now start get ip address using DHCP, Please wait about 30s! + + -----WIFI IP ADDRESS INFO----- + ipaddr 192.168.137.39 netmask 255.255.255.0 gw 192.168.137.1 + dns server 0 :192.168.137.1 + dns server 1 :0.0.0.0 + ----------------------------------- + WiFi connected + Please run NT-Shell command(main) to start your application. + main command may required some arguments, please refer to example's document. + main + + . Seeding the random number generator... ok + . Loading the CA root certificate ... ok (0 skipped) + . Loading the server cert. and key... ok + . Bind on tcp://*:4433/ ... ok + . Setting up the SSL/TLS structure... ok + . Waiting for a remote connection ... ok + . Performing the SSL/TLS handshake... ok + [ Protocol is TLSv1.2 ] + [ Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384 ] + [ Record expansion is 29 ] + [ Maximum fragment length is 16384 ] + . Verifying peer X.509 certificate... failed + ! Certificate verification was skipped + + < Read from client: 34 bytes read + + GET / HTTP/1.0 + Extra-header: + + + > Write to client: 152 bytes written in 1 fragments + + HTTP/1.0 200 OK + Content-Type: text/html + +

mbed TLS Test Server

+

Successful connection using: TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384

+ + . Closing the connection... done + . Waiting for a remote connection ... diff --git a/example/freertos/stack_check/FreeRTOSConfig.h b/example/freertos/stack_check/FreeRTOSConfig.h new file mode 100644 index 000000000..77c7b88bb --- /dev/null +++ b/example/freertos/stack_check/FreeRTOSConfig.h @@ -0,0 +1,113 @@ +/* + FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 4 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 18 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 10 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/example/freertos/stack_check/main.c b/example/freertos/stack_check/main.c new file mode 100644 index 000000000..971ad4c11 --- /dev/null +++ b/example/freertos/stack_check/main.c @@ -0,0 +1,435 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +/** + * \defgroup EMBARC_APP_FREERTOS_KERNEL embARC FreeRTOS Kernel Example + * \ingroup EMBARC_APPS_TOTAL + * \ingroup EMBARC_APPS_OS_FREERTOS + * \brief embARC Example for testing FreeRTOS task switch and interrupt/exception handling + * + * \details + * ### Extra Required Tools + * + * ### Extra Required Peripherals + * + * ### Design Concept + * This example is designed to show the functionality of FreeRTOS. + * + * ### Usage Manual + * Test case for show how FreeRTOS is working by task switching and interrupt/exception processing. + * ![ScreenShot of freertos-demo under freertos](pic/images/example/emsk/emsk_freertos_demo.jpg) + * + * ### Extra Comments + * + */ + +/** + * \file + * \ingroup EMBARC_APP_FREERTOS_KERNEL + * \brief main source file of the freertos demo + */ + +/** + * \addtogroup EMBARC_APP_FREERTOS_KERNEL + * @{ + */ + +#include "embARC.h" +#include "embARC_debug.h" +#include + +static void task1(void *par); +static void task2(void *par); +static void trap_exception(void *p_excinf); +static void soft_interrupt(void *p_excinf); + +#ifdef INTNO_I2C0 + #define SWI_INTNO INTNO_I2C0 +#else + #define SWI_INTNO 20 +#endif + +#define TSK_PRIOR_HI (configMAX_PRIORITIES-1) +#define TSK_PRIOR_LO (configMAX_PRIORITIES-2) + +// Task IDs +static TaskHandle_t task1_handle = NULL; +static TaskHandle_t task2_handle = NULL; + +// Mutex IDs +static SemaphoreHandle_t mux1_id; + +// Semaphores +static SemaphoreHandle_t sem1_id; + +// Events +static EventGroupHandle_t evt1_cb; +#define EVENT_WAIT_BITS 0x00000001 + +// Queues +static QueueHandle_t dtq1_id; + +// Local parameters +static volatile unsigned int start = 0; +static unsigned int perf_id = 0xFF; + +//#define ENABLE_DETAILED_RESULT_OUTPUT + +// Change this macro if you want to run more or less times +#define MAX_SAMPLES 200 + +#define TASK_DELAY_MS 2 + +typedef struct _sample { + unsigned int t_measure; + unsigned int t_t2_t1; + unsigned int t_int_t1; + unsigned int t_t1_t2; + unsigned int t_t1_int; + unsigned int t_int_nest; + unsigned int t_nest_int; + unsigned int t_mux_rls; + unsigned int t_sem_snd; + unsigned int t_evt_snd; + unsigned int t_dtq_wri; +} sample; + + +static sample x; +static sample x_aver = {0}; + +static sample sample_array[MAX_SAMPLES]; +static int sample_count = 0; + +/** performance timer initialization */ +static void perf_init(unsigned int id) +{ + if (timer_start(id, TIMER_CTRL_NH, 0xFFFFFFFF) < 0) { + EMBARC_PRINTF("perf timer init failed\r\n"); + + while (1); + } + + perf_id = id; +} + +/** performance timer start */ +static void perf_start(void) +{ + if (timer_current(perf_id, (void *)(&start)) < 0) { + start = 0; + } +} + +/** performance timer end, and return the time passed */ +static unsigned int perf_end(void) +{ + unsigned int end = 0; + + if (timer_current(perf_id, (void *)(&end)) < 0) { + return 0; + } + + if (start < end) { + return (end - start); + } else { + return (0xFFFFFFFF - start + end); + } +} + +/** + * \brief call FreeRTOS API, create and start tasks + */ +int main(void) +{ + EMBARC_PRINTF("Benchmark CPU Frequency: %d Hz\r\n", BOARD_CPU_CLOCK); + EMBARC_PRINTF("Benchmark will run %d times, please wait about %d ms\r\n", MAX_SAMPLES, (TASK_DELAY_MS*MAX_SAMPLES)); + + // Register interrupts + int_handler_install(SWI_INTNO, (EXC_HANDLER)soft_interrupt); + //int_pri_set(SWI_INTNO, INT_PRI_MIN); + int_enable(SWI_INTNO); + + exc_handler_install(EXC_NO_TRAP, trap_exception); /*!< install the exception handler */ + + vTaskSuspendAll(); + + // Create Tasks + if (xTaskCreate(task1, "task1", 128, (void *)1, TSK_PRIOR_LO, &task1_handle) + != pdPASS) { /*!< FreeRTOS xTaskCreate() API function */ + EMBARC_PRINTF("create task1 error\r\n"); + return -1; + } + + if (xTaskCreate(task2, "task2", 128, (void *)2, TSK_PRIOR_HI, &task2_handle) + != pdPASS) { /*!< FreeRTOS xTaskCreate() API function */ + EMBARC_PRINTF("create task2 error\r\n"); + return -1; + } + + // Create Mutex + mux1_id = xSemaphoreCreateMutex(); + + // Create Semaphores + sem1_id = xSemaphoreCreateBinary(); + xSemaphoreGive(sem1_id); + + // Create Events + evt1_cb = xEventGroupCreate(); + + // Create Queues + dtq1_id = xQueueCreate(1, sizeof(uint32_t)); + + xTaskResumeAll(); + + vTaskSuspend(NULL); + vTaskSuspend(NULL); + + return 0; +} + + +/** + * \brief task1 in FreeRTOS + * \details Call vTaskDelayUntil() to execute task1 with a fixed period 1 second. + * \param[in] *par + */ +static void task1(void *par) +{ + uint32_t queue_data = 1; + TickType_t xLastExecutionTime; + volatile uint32_t data[32]; + xLastExecutionTime = xTaskGetTickCount(); /*!< initialize current tick */ + + for (queue_data = 1; queue_data < 32; queue_data++) { + data[queue_data] = queue_data; + } + while (1) { + //// 1-E: Task2 --> Task1 + x.t_t2_t1 = perf_end(); + //// 2-S: Task1 --> Int + perf_start(); + _arc_aux_write(AUX_IRQ_HINT, SWI_INTNO); /*!< activate soft_interrupt */ + //// 5-E: Int --> Task1 + x.t_int_t1 = perf_end(); + + // task delay, to control benchmark run speed + vTaskDelayUntil( &xLastExecutionTime, TASK_DELAY_MS); + // Task 1 acquire mutex first + xSemaphoreTake(mux1_id, portMAX_DELAY); + // Task 1 acquire semaphore first + xSemaphoreTake(sem1_id, portMAX_DELAY); + + //// 6-S: Task1 --> Task2 + perf_start(); + vTaskResume(task2_handle); + + //// 8-S: Mutex Release -> Mutex Acquire + perf_start(); + // Task 1 release mutex, task 2 acquire it + xSemaphoreGive(mux1_id); + + //// 9-S: Sem Post -> Sem Acquire + perf_start(); + // Task 1 post sem, task 2 acquire it + xSemaphoreGive(sem1_id); + + //// 10-S: Event Write -> Event Read + perf_start(); + // Task 1 write event, task 2 read it + xEventGroupSetBits(evt1_cb, EVENT_WAIT_BITS); + + //// 11-S: Queue Write -> Queue Read + perf_start(); + // Task 1 write queue, task 2 read it + xQueueSend(dtq1_id, (void *)(&queue_data), portMAX_DELAY); + queue_data ++; + } + +} + +/** + * \brief task2 in FreeRTOS + * \details Print information in task2 and suspend task2. + * \param[in] *par + */ +static void task2(void *par) +{ + //volatile uint32_t * ptr; + static uint32_t perf_times = 0; + uint32_t queue_data = 0; + perf_init(TIMER_1); + + //ptr = &queue_data; + + //ptr += 16; + + //*ptr = 10; + + while (1) { + //// 1-S: Task2 --> Task1 + perf_start(); + vTaskSuspend(task2_handle); /*!< suspend task2 */ + //// 6-E: Task1 --> Task2 + x.t_t1_t2 = perf_end(); + //// 7-S: Benchmark extra cost + perf_start(); + //// 7-E: Benchmark extra cost + x.t_measure = perf_end(); + + // Task 2 wait for task 1 release mutex + xSemaphoreTake(mux1_id, portMAX_DELAY); + //// 8-E: Mutex Release -> Mutex Acquire + x.t_mux_rls = perf_end(); + xSemaphoreGive(mux1_id); + + // Task 2 wait for task 1 release sem + xSemaphoreTake(sem1_id, portMAX_DELAY); + //// 9-E: Sem Post -> Sem Acquire + x.t_sem_snd = perf_end(); + xSemaphoreGive(sem1_id); + + // Task 2 wait for task 1 set event + xEventGroupWaitBits(evt1_cb, EVENT_WAIT_BITS, pdTRUE, pdFALSE, portMAX_DELAY); + + //// 10-E: Event Write -> Event Read + x.t_evt_snd = perf_end(); + + // Task 2 read queue + xQueueReceive(dtq1_id, (void *)(&queue_data), portMAX_DELAY); + //// 11-E: Queue Write -> Queue Read + x.t_dtq_wri = perf_end(); + + if (perf_times) { + if (sample_count < MAX_SAMPLES) { + sample_array[sample_count] = x; + } else { + /* Suspend task 1 */ + vTaskSuspend(task1_handle); + + for (int i = 0; i < MAX_SAMPLES; i ++) { + x_aver.t_measure += sample_array[i].t_measure; + x_aver.t_t2_t1 += sample_array[i].t_t2_t1; + x_aver.t_int_t1 += sample_array[i].t_int_t1; + x_aver.t_t1_t2 += sample_array[i].t_t1_t2; + x_aver.t_t1_int += sample_array[i].t_t1_int; + x_aver.t_int_nest += sample_array[i].t_int_nest; + x_aver.t_nest_int += sample_array[i].t_nest_int; + x_aver.t_mux_rls += sample_array[i].t_mux_rls; + x_aver.t_sem_snd += sample_array[i].t_sem_snd; + x_aver.t_evt_snd += sample_array[i].t_evt_snd; + x_aver.t_dtq_wri += sample_array[i].t_dtq_wri; + } + + x_aver.t_measure /= MAX_SAMPLES; + x_aver.t_t2_t1 /= MAX_SAMPLES; + x_aver.t_int_t1 /= MAX_SAMPLES; + x_aver.t_t1_t2 /= MAX_SAMPLES; + x_aver.t_t1_int /= MAX_SAMPLES; + x_aver.t_int_nest /= MAX_SAMPLES; + x_aver.t_nest_int /= MAX_SAMPLES; + x_aver.t_mux_rls /= MAX_SAMPLES; + x_aver.t_sem_snd /= MAX_SAMPLES; + x_aver.t_evt_snd /= MAX_SAMPLES; + x_aver.t_dtq_wri /= MAX_SAMPLES; + + EMBARC_PRINTF("\r\n"); + EMBARC_PRINTF("Average benchmark result list as follows:\r\n"); + EMBARC_PRINTF("extra measurement cost : %d cycles\r\n", x_aver.t_measure); + EMBARC_PRINTF("task2 -> task1 : %d cycles\r\n", x_aver.t_t2_t1); + EMBARC_PRINTF("task1 -> int : %d cycles\r\n", x_aver.t_t1_int); + EMBARC_PRINTF("int -> nest int : %d cycles\r\n", x_aver.t_int_nest); + EMBARC_PRINTF("nest int -> int : %d cycles\r\n", x_aver.t_nest_int); + EMBARC_PRINTF("int -> task1 : %d cycles\r\n", x_aver.t_int_t1); + EMBARC_PRINTF("task1 -> task2 : %d cycles\r\n", x_aver.t_t1_t2); + EMBARC_PRINTF("mux: tsk1 -> tsk2 : %d cycles\r\n", x_aver.t_mux_rls); + EMBARC_PRINTF("sem: tsk1 -> tsk2 : %d cycles\r\n", x_aver.t_sem_snd); + EMBARC_PRINTF("evt: tsk1 -> tsk2 : %d cycles\r\n", x_aver.t_evt_snd); + EMBARC_PRINTF("dtq: tsk1 -> tsk2 : %d cycles\r\n", x_aver.t_dtq_wri); + EMBARC_PRINTF("\r\n"); + +#ifdef ENABLE_DETAILED_RESULT_OUTPUT + EMBARC_PRINTF("Detailed benchmark result table list as follows:\r\n"); + EMBARC_PRINTF("t_measure t_t2_t1 t_t1_int t_int_nest t_nest_int t_int_t1 t_t1_t2 t_mux_rls t_sem_snd t_evt_snd t_dtq_wri\r\n"); + + for (int i = 0; i < MAX_SAMPLES; i ++) { + EMBARC_PRINTF("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n", \ + sample_array[i].t_measure, sample_array[i].t_t2_t1, \ + sample_array[i].t_t1_int, sample_array[i].t_int_nest, \ + sample_array[i].t_nest_int, sample_array[i].t_int_t1, \ + sample_array[i].t_t1_t2, sample_array[i].t_mux_rls, \ + sample_array[i].t_sem_snd, sample_array[i].t_evt_snd, \ + sample_array[i].t_dtq_wri); + } + +#endif + exit(0); /* Exit benchmark application */ + } + + sample_count ++; + } + + perf_times ++; + } +} + +/** + * \brief trap exception + * \details Call xTaskResumeFromISR() to resume task2 that can be called from within ISR. + * If resuming the task2 should result in a context switch, call vPortYieldFromIsr() to generate task switch request. + * \param[in] *p_excinf + */ +static void trap_exception(void *p_excinf) +{ + //// 3-E: Int --> Nest Int + x.t_int_nest = perf_end(); + //// 4-S: Nest Int --> Int + perf_start(); +} + +/** + * \brief soft interrupt + * \details Call trap_s instruction to raise the exception. + * \param[in] *p_excinf + */ +static void soft_interrupt(void *p_exinf) +{ + //// 2-E: Task1 --> Int + x.t_t1_int = perf_end(); + //// 3-S: Int --> Nest Int + perf_start(); + Asm("trap_s 1"); + //// 4-E: Nest Int --> Int + x.t_nest_int = perf_end(); + //// 5-S: Int --> Task1 + perf_start(); +} + +/** @} */ diff --git a/example/freertos/stack_check/makefile b/example/freertos/stack_check/makefile new file mode 100644 index 000000000..b9797aedf --- /dev/null +++ b/example/freertos/stack_check/makefile @@ -0,0 +1,26 @@ +# Application name +APPL ?= freertos_kernel + +# Selected OS +OS_SEL ?= freertos + +# +# root dir of embARC +# +EMBARC_ROOT = ../../.. + +MID_SEL = common + +# application source dirs +APPL_CSRC_DIR = . +APPL_ASMSRC_DIR = . + +# application include dirs +APPL_INC_DIR = . + +# include current project makefile +COMMON_COMPILE_PREREQUISITES += makefile + +### Options above must be added before include options.mk ### +# include key embARC build system makefile +include $(EMBARC_ROOT)/options/options.mk diff --git a/library/secureshield/board/secureshield_normal_template_gnu.ld b/library/secureshield/board/secureshield_normal_template_gnu.ld index 2a6ce7db3..65b5b3933 100644 --- a/library/secureshield/board/secureshield_normal_template_gnu.ld +++ b/library/secureshield/board/secureshield_normal_template_gnu.ld @@ -176,6 +176,15 @@ SECTIONS _f_sdata = .; __SDATA_BEGIN__ = .; *(BACKGROUND_RAM_OBJS_LIST .sdata BACKGROUND_RAM_OBJS_LIST .sdata.* BACKGROUND_RAM_OBJS_LIST .gnu.linkonce.s.*) + PROVIDE (__sbss_start = .); + PROVIDE (___sbss_start = .); + _f_sbss = .; + *(BACKGROUND_RAM_OBJS_LIST .dynsbss) + *(BACKGROUND_RAM_OBJS_LIST .sbss BACKGROUND_RAM_OBJS_LIST .sbss.* BACKGROUND_RAM_OBJS_LIST .gnu.linkonce.sb.*) + *(BACKGROUND_RAM_OBJS_LIST .scommon) + _e_sbss = .; + PROVIDE (__sbss_end = .); + PROVIDE (___sbss_end = .); _e_sdata = .; _e_data = .; _e_data_background_container = .; @@ -185,16 +194,7 @@ SECTIONS .bss (NOLOAD) : ALIGN(4) { _f_bss_background_container = .; - PROVIDE (__sbss_start = .); - PROVIDE (___sbss_start = .); _f_bss = .; - _f_sbss = .; - *(BACKGROUND_RAM_OBJS_LIST .dynsbss) - *(BACKGROUND_RAM_OBJS_LIST .sbss BACKGROUND_RAM_OBJS_LIST .sbss.* BACKGROUND_RAM_OBJS_LIST .gnu.linkonce.sb.*) - *(BACKGROUND_RAM_OBJS_LIST .scommon) - _e_sbss = .; - PROVIDE (__sbss_end = .); - PROVIDE (___sbss_end = .); *(BACKGROUND_RAM_OBJS_LIST .dynbss) *(BACKGROUND_RAM_OBJS_LIST .bss BACKGROUND_RAM_OBJS_LIST .bss.* BACKGROUND_RAM_OBJS_LIST .gnu.linkonce.b.*) *( COMMON) diff --git a/library/secureshield/board/secureshield_normal_template_mw.ld b/library/secureshield/board/secureshield_normal_template_mw.ld index 6c2f0063b..ac492a245 100644 --- a/library/secureshield/board/secureshield_normal_template_mw.ld +++ b/library/secureshield/board/secureshield_normal_template_mw.ld @@ -151,6 +151,7 @@ SECTIONS { _f_data = .; _f_sdata = .; *(.sdata) + *(.sbss) _e_sdata = .; *(TYPE data) } diff --git a/library/secureshield/board/secureshield_secure_template_gnu.ld b/library/secureshield/board/secureshield_secure_template_gnu.ld index b6e91e5ac..fc55e7434 100644 --- a/library/secureshield/board/secureshield_secure_template_gnu.ld +++ b/library/secureshield/board/secureshield_secure_template_gnu.ld @@ -56,14 +56,8 @@ SECTIONS { _f_sdata = .; __SDATA_BEGIN__ = .; *(.sdata .sdata.* .gnu.linkonce.s.*) - _e_sdata = .; - _e_data = .; - } > SECURE_RAM AT > SECURE_ROM - - .bss (NOLOAD) : ALIGN(4) { PROVIDE (__sbss_start = .); PROVIDE (___sbss_start = .); - _f_bss = .; _f_sbss = .; *(.dynsbss) *(.sbss .sbss.* .gnu.linkonce.sb.*) @@ -71,7 +65,12 @@ SECTIONS { _e_sbss = .; PROVIDE (__sbss_end = .); PROVIDE (___sbss_end = .); + _e_sdata = .; + _e_data = .; + } > SECURE_RAM AT > SECURE_ROM + .bss (NOLOAD) : ALIGN(4) { + _f_bss = .; *(.dynbss) *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) diff --git a/library/secureshield/board/secureshield_secure_template_mw.ld b/library/secureshield/board/secureshield_secure_template_mw.ld index 2d2c2d376..92a65e2b1 100644 --- a/library/secureshield/board/secureshield_secure_template_mw.ld +++ b/library/secureshield/board/secureshield_secure_template_mw.ld @@ -47,6 +47,7 @@ SECTIONS { _f_data = .; _f_sdata = .; *(.sdata) + *(.sbss) _e_sdata = .; *(TYPE data) }