From 1b6a1368e0d80c55719374aab10261f1ff42a1de Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Mon, 22 Jul 2024 16:59:20 +0100 Subject: [PATCH] No longer requires cmake or ninja. Untested on hardware. --- .github/workflows/build-ferrocene.yml | 27 +-- .github/workflows/build.yml | 25 --- LICENSES/LicenseRef-Azure.txt | 249 -------------------------- build.sh | 10 +- demo-app/build.rs | 218 ++++++++++++++++++++-- demo-app/src/main.rs | 65 +++++++ demo-app/src/tx_low_level.S | 179 ------------------ 7 files changed, 275 insertions(+), 498 deletions(-) delete mode 100644 LICENSES/LicenseRef-Azure.txt delete mode 100644 demo-app/src/tx_low_level.S diff --git a/.github/workflows/build-ferrocene.yml b/.github/workflows/build-ferrocene.yml index c9b588b..ee50184 100644 --- a/.github/workflows/build-ferrocene.yml +++ b/.github/workflows/build-ferrocene.yml @@ -5,26 +5,6 @@ name: workflow-build-everything-ferrocene run-name: Build Everything with Ferrocene on: [push] jobs: - job-build-threadx-staticlib: - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v4 - with: - submodules: 'true' - - name: Install tools - run: | - sudo apt-get update -y && sudo apt-get -y install cmake gcc gcc-arm-none-eabi build-essential ninja-build - - name: Compile ThreadX for Cortex-M4 - run: | - cd threadx - cmake -Bbuild_m4 -GNinja -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake - cmake --build ./build_m4 - - name: Upload staticlib - uses: actions/upload-artifact@master - with: - name: threadx-cm4 - path: threadx/build_m4/libthreadx.a job-build-demo-app: runs-on: ubuntu-latest needs: job-build-threadx-staticlib @@ -37,13 +17,8 @@ jobs: uses: actions/checkout@v4 with: submodules: 'true' - - name: Download staticlib - uses: actions/download-artifact@master - with: - name: threadx-cm4 - path: threadx/build # Where build.rs expects it - name: Install Ferrocene - env: # Or as an environment variable + env: CRITICALUP_TOKEN: ${{ secrets.CRITICALUP_TOKEN }} run: | criticalup install diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7db193..5f05a1b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,26 +5,6 @@ name: workflow-build-everything run-name: Build Everything on: [push] jobs: - job-build-threadx-staticlib: - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v4 - with: - submodules: 'true' - - name: Install tools - run: | - sudo apt-get update -y && sudo apt-get -y install cmake gcc gcc-arm-none-eabi build-essential ninja-build - - name: Compile ThreadX for Cortex-M4 - run: | - cd threadx - cmake -Bbuild_m4 -GNinja -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake - cmake --build ./build_m4 - - name: Upload staticlib - uses: actions/upload-artifact@master - with: - name: threadx-cm4 - path: threadx/build_m4/libthreadx.a job-build-demo-app: runs-on: ubuntu-latest needs: job-build-threadx-staticlib @@ -40,11 +20,6 @@ jobs: uses: actions/checkout@v4 with: submodules: 'true' - - name: Download staticlib - uses: actions/download-artifact@master - with: - name: threadx-cm4 - path: threadx/build # Where build.rs expects it - name: Add rustup target run: | rustup target add thumbv7em-none-eabi diff --git a/LICENSES/LicenseRef-Azure.txt b/LICENSES/LicenseRef-Azure.txt deleted file mode 100644 index 6929d7e..0000000 --- a/LICENSES/LicenseRef-Azure.txt +++ /dev/null @@ -1,249 +0,0 @@ -MICROSOFT SOFTWARE LICENSE TERMS - -MICROSOFT AZURE RTOS - - -These license terms are an agreement between you and Microsoft Corporation (or -one of its affiliates). They apply to the software named above and any Microsoft -services or software updates (except to the extent such services or updates are -accompanied by new or additional terms, in which case those different terms -apply prospectively and do not alter your or Microsoft’s rights relating to -pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU -HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. - -1. INSTALLATION AND USE RIGHTS. - -a) General. You may (I) install, use and modify the software and (ii) install and use the included Microsoft -Applications (if any), each solely for internal development, testing and evaluation purposes. -Distribution or production use is governed by the license terms set forth in -Section 2. You may also obtain distribution or production use rights through a separate agreement with -Microsoft. - -b) Contributions. Microsoft welcomes contributions to this software. In the event -that you make a contribution to this software you will be required to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and -actually do, grant Microsoft the rights to use your contribution. For details, -visit https://cla.microsoft.com. - -c) Included Microsoft Applications. The software may include other Microsoft -applications which are governed by the licenses embedded in or made available -with those applications. - -d) Third Party Components. The software may include third party components with -separate legal notices or governed by other agreements, as may be described -within the software or in the ThirdPartyNotices file(s) accompanying the -software. - -e) Competitive Benchmarking. If you are a direct competitor, and you access or use -the software for purposes of competitive benchmarking, analysis, or intelligence -gathering, you waive as against Microsoft, its subsidiaries, and its affiliated -companies (including prospectively) any competitive use, access, and -benchmarking test restrictions in the terms governing your software to the -extent your terms of use are, or purport to be, more restrictive than -Microsoft’s terms. If you do not waive any such purported restrictions in the -terms governing your software, you are not allowed to access or use this -software, and will not do so. - -2. DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on -microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file -named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with -the software you have the following rights in and to the software solely when -used in combination with the hardware. In the event hardware is not listed in -the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2. - -a) Distribution and Production Use Rights. - -i. You may use the software in production (e.g. program the modified or unmodified -software to devices you own or control) and distribute (i.e. make available to -third parties) the modified or unmodified binary image produced from this code. - -ii. You may permit your device distributors or developers to copy and distribute the -binary image as programmed or to be programmed to your devices. - -iii. You may redistribute the unmodified or modified source to your device -distributors or developers. Modifications must be clearly marked. Any -redistribution in source code form must contain this license and any other -licenses that accompany the software. - -b) Requirements. For any code you distribute, you must: - -i. when distributed in binary form, except as embedded in a device, include with -such distribution the terms of this agreement; -ii. when distributed in source code form to distributors or developers of your -devices, include with such distribution the terms of this agreement; and -iii. indemnify, defend and hold harmless Microsoft from any claims, including claims arising from any High Risk Uses, and inclusive of attorneys’ fees, related to the distribution or use of your devices that include the software, except to the extent that any intellectual property claim is based solely on the unmodified software. - -c) Restrictions. You may not: -i. use or modify the software to create competing real time operating system -software; - -ii. remove any copyright notices or licenses contained in the software; - -iii. use Microsoft’s trademarks or trade dress in your application in any way that -suggests your device or application comes from or is endorsed by Microsoft; - -iv. transfer individual components, specific libraries, classes, functions or code -fragments of the software separately for purposes unrelated to the software; or - -v. use or distribute the software in any way that would subject the software or -Microsoft’s intellectual property or technology to any other license terms. - -3. SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all -other rights. Unless applicable law gives you more rights despite this -limitation, you will not (and have no right to): - -a) remove, minimize, block, or modify any notices of Microsoft or its suppliers in -the software; - -b) use the software in any way that is against the law or to create or propagate -malware; or - -c) share, publish, distribute, or lease the software (except as permitted in -Section 2 above), or provide the software as a stand-alone offering for others -to use. - -4. DATA. This software may interact with other Microsoft products that collect data -that is transmitted to Microsoft. To learn more about how Microsoft processes -personal data we collect, please see the Microsoft Privacy Statement at -https://go.microsoft.com/fwlink/?LinkId=248681. - -5. EXPORT RESTRICTIONS. You must comply with all domestic and international export -laws and regulations that apply to the software, which include restrictions on -destinations, end users, and end use. For further information on export -restrictions, visit https://aka.ms/exporting. - -6. SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any -support services for the software. Any support provided is “as is”, “with all -faults”, and without warranty of any kind. - -7. UPDATES. Microsoft may periodically update the software. You may obtain updates -only from Microsoft or Microsoft-authorized sources. Updates may not include or -support all existing software features, services, or peripheral devices. - -8. TERMINATION. Without prejudice to any other rights, Microsoft may terminate this -agreement if you fail to comply with any of its terms or conditions. In such -event, you must destroy all copies of the software and all of its component -parts. - -9. ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for -supplements, updates, or third-party applications, is the entire agreement for -the software. To the extent you have entered into a separate agreement with -Microsoft relating specifically to the software, the terms in such agreement -shall control. - -10. APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in -the United States or Canada, the laws of the state or province where you live -(or, if a business, where your principal place of business is located) govern -the interpretation of this agreement, claims for its breach, and all other -claims (including consumer protection, unfair competition, and tort claims), -regardless of conflict of laws principles. If you acquired the software in any -other country, its laws apply. If U.S. federal jurisdiction exists, you and -Microsoft consent to exclusive jurisdiction and venue in the federal court in -King County, Washington for all disputes heard in court. If not, you and -Microsoft consent to exclusive jurisdiction and venue in the Superior Court of -King County, Washington for all disputes heard in court. - -11. CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal -rights. You may have other rights, including consumer rights, under the laws of -your state or country. Separate and apart from your relationship with Microsoft, -you may also have rights with respect to the party from which you acquired the -software. This agreement does not change those other rights if the laws of your -state or country do not permit it to do so. For example, if you acquired the -software in one of the below regions, or mandatory country law applies, then the -following provisions apply to you: - -a) Australia. You have statutory guarantees under the Australian Consumer Law and -nothing in this agreement is intended to affect those rights. - -b) Germany and Austria. - -i. Warranty. The properly licensed software will perform substantially as -described in any Microsoft materials that accompany the software. However, -Microsoft gives no contractual guarantee in relation to the licensed software. - -ii. Limitation of Liability. In case of intentional conduct, gross negligence, -claims based on the Product Liability Act, as well as, in case of death or -personal or physical injury, Microsoft is liable according to the statutory law. - - -Subject to the foregoing clause ii., Microsoft will only be liable for slight -negligence if Microsoft is in breach of such material contractual obligations, -the fulfillment of which facilitate the due performance of this agreement, the -breach of which would endanger the purpose of this agreement and the compliance -with which a party may constantly trust in (so-called "cardinal obligations"). -In other cases of slight negligence, Microsoft will not be liable for slight -negligence. -12. DISCLAIMER OF WARRANTY. -a) THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF -USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO -THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED -WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND -NON-INFRINGEMENT. -b) HIGH RISK USE DISCLAIMER. WARNING: THE SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE WHERE FAILURE OR FAULT OF ANY KIND OF THE SOFTWARE COULD RESULT IN DEATH OR SERIOUS BODILY INJURY, OR IN PHYSICAL OR ENVIRONMENTAL DAMAGE (“collectively High Risk Use”). Accordingly, You must design and implement your hardware and software such that, in the event of any interruption, defect, error, or other failure of the software, the safety of people, property, and the environment are not reduced below a level that is reasonable, appropriate, and legal, whether in general or for a specific industry. Your High Risk Use of the software is at Your own risk. - -13. LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING -DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM -MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT -RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, -INDIRECT, OR INCIDENTAL DAMAGES. - -This limitation applies to (a) anything related to the software, services, -content (including code) on third party Internet sites, or third party -applications; and (b) claims for breach of contract, warranty, guarantee, or -condition; strict liability, negligence, or other tort; or any other claim; in -each case to the extent permitted by applicable law. - -It also applies even if Microsoft knew or should have known about the -possibility of the damages. The above limitation or exclusion may not apply to -you because your state, province, or country may not allow the exclusion or -limitation of incidental, consequential, or other damages. - - Please note: As this software is distributed in Canada, some of the clauses in -this agreement are provided below in French. - -Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce -contrat sont fournies ci-dessous en français. - -EXONÉRATION DE GARANTIE. -a) Le logiciel visé par une licence est offert « tel quel -». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft -n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits -additionnels en vertu du droit local sur la protection des consommateurs, que ce -contrat ne peut modifier. La ou elles sont permises par le droit locale, les -garanties implicites de qualité marchande, d’adéquation à un usage particulier -et d’absence de contrefaçon sont exclues. -b) CLAUSE D’EXCLUSION DE RESPONSABILITÉ RELATIVE À L’UTILISATION À HAUT RISQUE. -AVERTISSEMENT: LE LOGICIEL N’EST PAS CONÇU OU DESTINÉ À ÊTRE UTILISÉ LORSQU’UNE -DÉFAILLANCE OU UN DÉFAUT DE QUELQUE NATURE QUE CE SOIT POURRAIT ENTRAÎNER LA -MORT OU DES BLESSURES CORPORELLES GRAVES, OU DES DOMMAGES PHYSIQUES OU -ENVIRONNEMENTAUX (« Utilisation à haut risque »). Par conséquent, vous devez concevoir et mettre en -œuvre votre équipement et votre logiciel de manière à ce que, en cas d’interruption, de défaut, d’erreur -ou de toute autre défaillance du logiciel, la sécurité des personnes, des biens et de l’environnement ne -soit pas réduite en dessous d’un niveau raisonnable, approprié et légal, que ce soit en général ou pour -un secteur spécifique. Votre utilisation à haut risque du logiciel est à vos propres risques. - -LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES -DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une -indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous -ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris -les dommages spéciaux, indirects ou accessoires et pertes de bénéfices. - -Cette limitation concerne: - -•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le -code) figurant sur des sites Internet tiers ou dans des programmes tiers; et - -•les réclamations au titre de violation de contrat ou de garantie, ou au titre -de responsabilité stricte, de négligence ou d’une autre faute dans la limite -autorisée par la loi en vigueur. - -Elle s’applique également, même si Microsoft connaissait ou devrait connaître -l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la -limitation de responsabilité pour les dommages indirects, accessoires ou de -quelque nature que ce soit, il se peut que la limitation ou l’exclusion -ci-dessus ne s’appliquera pas à votre égard. - -EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous -pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent -contrat ne modifie pas les droits que vous confèrent les lois de votre pays si -celles-ci ne le permettent pas. diff --git a/build.sh b/build.sh index 99aea8c..f318018 100755 --- a/build.sh +++ b/build.sh @@ -1,18 +1,12 @@ #!/bin/bash -# Builds the Cortex-M4 version of ThreadX, then builds a Rust -# application that links to it. +# Builds the various ThreadX demo apps. -# SPDX-FileCopyrightText: Copyright (c) 2023 Ferrous Systems +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems # SPDX-License-Identifier: MIT OR Apache-2.0 set -euo pipefail -pushd threadx -cmake -Bbuild -GNinja -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake . -cmake --build ./build -popd - pushd demo-app cargo build --release popd diff --git a/demo-app/build.rs b/demo-app/build.rs index 18a0c11..e5e17c2 100644 --- a/demo-app/build.rs +++ b/demo-app/build.rs @@ -5,6 +5,203 @@ use std::{env, error::Error, fs, path::PathBuf}; +static TX_PORT_FILES: &[&str] = &[ + "tx_thread_stack_build.S", + "tx_thread_schedule.S", + "tx_thread_system_return.S", + "tx_thread_context_save.S", + "tx_thread_context_restore.S", + "tx_thread_interrupt_control.S", + "tx_timer_interrupt.S", +]; + +static TX_COMMON_FILES: &[&str] = &[ + "tx_block_allocate.c", + "tx_block_pool_cleanup.c", + "tx_block_pool_create.c", + "tx_block_pool_delete.c", + "tx_block_pool_info_get.c", + "tx_block_pool_initialize.c", + "tx_block_pool_performance_info_get.c", + "tx_block_pool_performance_system_info_get.c", + "tx_block_pool_prioritize.c", + "tx_block_release.c", + "tx_byte_allocate.c", + "tx_byte_pool_cleanup.c", + "tx_byte_pool_create.c", + "tx_byte_pool_delete.c", + "tx_byte_pool_info_get.c", + "tx_byte_pool_initialize.c", + "tx_byte_pool_performance_info_get.c", + "tx_byte_pool_performance_system_info_get.c", + "tx_byte_pool_prioritize.c", + "tx_byte_pool_search.c", + "tx_byte_release.c", + "tx_event_flags_cleanup.c", + "tx_event_flags_create.c", + "tx_event_flags_delete.c", + "tx_event_flags_get.c", + "tx_event_flags_info_get.c", + "tx_event_flags_initialize.c", + "tx_event_flags_performance_info_get.c", + "tx_event_flags_performance_system_info_get.c", + "tx_event_flags_set.c", + "tx_event_flags_set_notify.c", + "tx_initialize_high_level.c", + "tx_initialize_kernel_enter.c", + "tx_initialize_kernel_setup.c", + "tx_mutex_cleanup.c", + "tx_mutex_create.c", + "tx_mutex_delete.c", + "tx_mutex_get.c", + "tx_mutex_info_get.c", + "tx_mutex_initialize.c", + "tx_mutex_performance_info_get.c", + "tx_mutex_performance_system_info_get.c", + "tx_mutex_prioritize.c", + "tx_mutex_priority_change.c", + "tx_mutex_put.c", + "tx_queue_cleanup.c", + "tx_queue_create.c", + "tx_queue_delete.c", + "tx_queue_flush.c", + "tx_queue_front_send.c", + "tx_queue_info_get.c", + "tx_queue_initialize.c", + "tx_queue_performance_info_get.c", + "tx_queue_performance_system_info_get.c", + "tx_queue_prioritize.c", + "tx_queue_receive.c", + "tx_queue_send.c", + "tx_queue_send_notify.c", + "tx_semaphore_ceiling_put.c", + "tx_semaphore_cleanup.c", + "tx_semaphore_create.c", + "tx_semaphore_delete.c", + "tx_semaphore_get.c", + "tx_semaphore_info_get.c", + "tx_semaphore_initialize.c", + "tx_semaphore_performance_info_get.c", + "tx_semaphore_performance_system_info_get.c", + "tx_semaphore_prioritize.c", + "tx_semaphore_put.c", + "tx_semaphore_put_notify.c", + "tx_thread_create.c", + "tx_thread_delete.c", + "tx_thread_entry_exit_notify.c", + "tx_thread_identify.c", + "tx_thread_info_get.c", + "tx_thread_initialize.c", + "tx_thread_performance_info_get.c", + "tx_thread_performance_system_info_get.c", + "tx_thread_preemption_change.c", + "tx_thread_priority_change.c", + "tx_thread_relinquish.c", + "tx_thread_reset.c", + "tx_thread_resume.c", + "tx_thread_shell_entry.c", + "tx_thread_sleep.c", + "tx_thread_stack_analyze.c", + "tx_thread_stack_error_handler.c", + "tx_thread_stack_error_notify.c", + "tx_thread_suspend.c", + "tx_thread_system_preempt_check.c", + "tx_thread_system_resume.c", + "tx_thread_system_suspend.c", + "tx_thread_terminate.c", + "tx_thread_time_slice.c", + "tx_thread_time_slice_change.c", + "tx_thread_timeout.c", + "tx_thread_wait_abort.c", + "tx_time_get.c", + "tx_time_set.c", + "tx_timer_activate.c", + "tx_timer_change.c", + "tx_timer_create.c", + "tx_timer_deactivate.c", + "tx_timer_delete.c", + "tx_timer_expiration_process.c", + "tx_timer_info_get.c", + "tx_timer_initialize.c", + "tx_timer_performance_info_get.c", + "tx_timer_performance_system_info_get.c", + "tx_timer_system_activate.c", + "tx_timer_system_deactivate.c", + "tx_timer_thread_entry.c", + "tx_trace_buffer_full_notify.c", + "tx_trace_enable.c", + "tx_trace_event_filter.c", + "tx_trace_event_unfilter.c", + "tx_trace_disable.c", + "tx_trace_initialize.c", + "tx_trace_interrupt_control.c", + "tx_trace_isr_enter_insert.c", + "tx_trace_isr_exit_insert.c", + "tx_trace_object_register.c", + "tx_trace_object_unregister.c", + "tx_trace_user_event_insert.c", + "txe_block_allocate.c", + "txe_block_pool_create.c", + "txe_block_pool_delete.c", + "txe_block_pool_info_get.c", + "txe_block_pool_prioritize.c", + "txe_block_release.c", + "txe_byte_allocate.c", + "txe_byte_pool_create.c", + "txe_byte_pool_delete.c", + "txe_byte_pool_info_get.c", + "txe_byte_pool_prioritize.c", + "txe_byte_release.c", + "txe_event_flags_create.c", + "txe_event_flags_delete.c", + "txe_event_flags_get.c", + "txe_event_flags_info_get.c", + "txe_event_flags_set.c", + "txe_event_flags_set_notify.c", + "txe_mutex_create.c", + "txe_mutex_delete.c", + "txe_mutex_get.c", + "txe_mutex_info_get.c", + "txe_mutex_prioritize.c", + "txe_mutex_put.c", + "txe_queue_create.c", + "txe_queue_delete.c", + "txe_queue_flush.c", + "txe_queue_front_send.c", + "txe_queue_info_get.c", + "txe_queue_prioritize.c", + "txe_queue_receive.c", + "txe_queue_send.c", + "txe_queue_send_notify.c", + "txe_semaphore_ceiling_put.c", + "txe_semaphore_create.c", + "txe_semaphore_delete.c", + "txe_semaphore_get.c", + "txe_semaphore_info_get.c", + "txe_semaphore_prioritize.c", + "txe_semaphore_put.c", + "txe_semaphore_put_notify.c", + "txe_thread_create.c", + "txe_thread_delete.c", + "txe_thread_entry_exit_notify.c", + "txe_thread_info_get.c", + "txe_thread_preemption_change.c", + "txe_thread_priority_change.c", + "txe_thread_relinquish.c", + "txe_thread_reset.c", + "txe_thread_resume.c", + "txe_thread_suspend.c", + "txe_thread_terminate.c", + "txe_thread_time_slice_change.c", + "txe_thread_wait_abort.c", + "txe_timer_activate.c", + "txe_timer_change.c", + "txe_timer_create.c", + "txe_timer_deactivate.c", + "txe_timer_delete.c", + "txe_timer_info_get.c", +]; + fn main() -> Result<(), Box> { let out_dir = PathBuf::from(env::var("OUT_DIR")?); let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); @@ -14,18 +211,17 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-link-search={}", out_dir.display()); println!("cargo:rerun-if-changed=memory.x"); - // Include our ThreadX static library - println!( - "cargo:rustc-link-search={}", - crate_dir.join("../threadx/build").display() - ); - println!("cargo:rustc-link-lib=static=threadx"); - - // Compile our assembly code + // Build our ThreadX static library + let tx_common_dir = crate_dir.join("../threadx/common/src"); + let tx_common_inc = crate_dir.join("../threadx/common/inc"); + let tx_port_dir = crate_dir.join("../threadx/ports/cortex_m4/gnu/src"); + let tx_port_inc = crate_dir.join("../threadx/ports/cortex_m4/gnu/inc"); cc::Build::new() - .file("src/tx_low_level.S") - .compile("tx_low_level"); - println!("cargo:rerun-if-changed=src/tx_low_level.S"); + .include(&tx_common_inc) + .include(&tx_port_inc) + .files(TX_PORT_FILES.iter().map(|&s| tx_port_dir.join(s))) + .files(TX_COMMON_FILES.iter().map(|&s| tx_common_dir.join(s))) + .compile("threadx"); Ok(()) } diff --git a/demo-app/src/main.rs b/demo-app/src/main.rs index 5de8ed8..be7cc90 100644 --- a/demo-app/src/main.rs +++ b/demo-app/src/main.rs @@ -180,3 +180,68 @@ fn main() -> ! { fn panic() -> ! { cortex_m::asm::udf() } + +#[no_mangle] +unsafe extern "C" fn __tx_SysTickHandler() { + extern "C" { + fn _tx_timer_interrupt(); + } + // Call into OS function (not in public API) + _tx_timer_interrupt(); + // Can do any extra work here +} + +const SYSTEM_CLOCK: u32 = 64_000_000; +const SYSTICK_CYCLES: u32 = (SYSTEM_CLOCK / 100) - 1; + +/// ThreadX call this low-level init function early on. +/// +/// We must setup SysTick, the heap pointer, the cycle counter, and various +/// interrupt priorities. +#[no_mangle] +unsafe extern "C" fn _tx_initialize_low_level() { + extern "C" { + static mut _tx_initialize_unused_memory: usize; + static __sheap: u8; + } + + // ThreadX requires interrupts be disable during init + cortex_m::interrupt::disable(); + + let mut p = cortex_m::Peripherals::take().unwrap(); + + // Initialise heap memory variable + let heap_ptr = core::ptr::addr_of_mut!(_tx_initialize_unused_memory); + let heap_start = core::ptr::addr_of!(__sheap) as usize + 4; + heap_ptr.write_volatile(heap_start); + + // Enable cycle counter + p.DCB.enable_trace(); + p.DWT.enable_cycle_counter(); + + // Enable the systick + p.SYST.set_reload(SYSTICK_CYCLES); + p.SYST.clear_current(); + p.SYST.enable_interrupt(); + p.SYST + .set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core); + p.SYST.enable_counter(); + + // Set up interrupt priorities + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::BusFault, 0); + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::UsageFault, 0); + p.SCB.set_priority( + cortex_m::peripheral::scb::SystemHandler::MemoryManagement, + 0, + ); + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::SVCall, 255); + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::PendSV, 0); + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::DebugMonitor, 0); + p.SCB + .set_priority(cortex_m::peripheral::scb::SystemHandler::SysTick, 64); +} diff --git a/demo-app/src/tx_low_level.S b/demo-app/src/tx_low_level.S deleted file mode 100644 index 32b0646..0000000 --- a/demo-app/src/tx_low_level.S +++ /dev/null @@ -1,179 +0,0 @@ -@/**************************************************************************/ -@/* */ -@/* Copyright (c) Microsoft Corporation. All rights reserved. */ -@/* */ -@/* This software is licensed under the Microsoft Software License */ -@/* Terms for Microsoft Azure RTOS. Full text of the license can be */ -@/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ -@/* and in the root directory of this software. */ -@/* SPDX-License-Identifier: LicenseRef-Azure */ -@/* */ -@/**************************************************************************/ -@ -@ -@/**************************************************************************/ -@/**************************************************************************/ -@/** */ -@/** ThreadX Component */ -@/** */ -@/** Initialize */ -@/** */ -@/**************************************************************************/ -@/**************************************************************************/ -@ -@ - .global _tx_thread_system_stack_ptr - .global _tx_initialize_unused_memory - .global __sheap - .global _tx_timer_interrupt - .global __vector_table - .global __tx_SysTickHandler @ SysTick - .global __tx_IntHandler @ Int 0 -@ -@ -SYSTEM_CLOCK = 64000000 -SYSTICK_CYCLES = ((SYSTEM_CLOCK / 100) -1) - - .text 32 - .align 4 - .syntax unified -@/**************************************************************************/ -@/* */ -@/* FUNCTION RELEASE */ -@/* */ -@/* _tx_initialize_low_level Cortex-M4/GNU */ -@/* 6.1 */ -@/* AUTHOR */ -@/* */ -@/* William E. Lamie, Microsoft Corporation */ -@/* */ -@/* DESCRIPTION */ -@/* */ -@/* This function is responsible for any low-level processor */ -@/* initialization, including setting up interrupt vectors, setting */ -@/* up a periodic timer interrupt source, saving the system stack */ -@/* pointer for use in ISR processing later, and finding the first */ -@/* available RAM memory address for tx_application_define. */ -@/* */ -@/* INPUT */ -@/* */ -@/* None */ -@/* */ -@/* OUTPUT */ -@/* */ -@/* None */ -@/* */ -@/* CALLS */ -@/* */ -@/* None */ -@/* */ -@/* CALLED BY */ -@/* */ -@/* _tx_initialize_kernel_enter ThreadX entry function */ -@/* */ -@/* RELEASE HISTORY */ -@/* */ -@/* DATE NAME DESCRIPTION */ -@/* */ -@/* 05-19-2020 William E. Lamie Initial Version 6.0 */ -@/* 09-30-2020 William E. Lamie Modified Comment(s), fixed */ -@/* GNU assembly comment, */ -@/* cleaned up whitespace, */ -@/* resulting in version 6.1 */ -@/* */ -@/**************************************************************************/ -@VOID _tx_initialize_low_level(VOID) -@{ - .global _tx_initialize_low_level - .thumb_func -_tx_initialize_low_level: -@ -@ /* Disable interrupts during ThreadX initialization. */ -@ - CPSID i -@ -@ /* Set base of available memory to end of non-initialised RAM area. */ -@ - LDR r0, =_tx_initialize_unused_memory @ Build address of unused memory pointer - LDR r1, =__sheap @ Build first free address - ADD r1, r1, #4 @ - STR r1, [r0] @ Setup first unused memory pointer -@ -@ /* Setup Vector Table Offset Register. */ -@ - MOV r0, #0xE000E000 @ Build address of NVIC registers - LDR r1, =__vector_table @ Pickup address of vector table - STR r1, [r0, #0xD08] @ Set vector table address -@ -@ /* Set system stack pointer from vector value. */ -@ - LDR r0, =_tx_thread_system_stack_ptr @ Build address of system stack pointer - LDR r1, =__vector_table @ Pickup address of vector table - LDR r1, [r1] @ Pickup reset stack pointer - STR r1, [r0] @ Save system stack pointer -@ -@ /* Enable the cycle count register. */ -@ - LDR r0, =0xE0001000 @ Build address of DWT register - LDR r1, [r0] @ Pickup the current value - ORR r1, r1, #1 @ Set the CYCCNTENA bit - STR r1, [r0] @ Enable the cycle count register -@ -@ /* Configure SysTick for 100Hz clock, or 16384 cycles if no reference. */ -@ - MOV r0, #0xE000E000 @ Build address of NVIC registers - LDR r1, =SYSTICK_CYCLES - STR r1, [r0, #0x14] @ Setup SysTick Reload Value - MOV r1, #0x7 @ Build SysTick Control Enable Value - STR r1, [r0, #0x10] @ Setup SysTick Control -@ -@ /* Configure handler priorities. */ -@ - LDR r1, =0x00000000 @ Rsrv, UsgF, BusF, MemM - STR r1, [r0, #0xD18] @ Setup System Handlers 4-7 Priority Registers - - LDR r1, =0xFF000000 @ SVCl, Rsrv, Rsrv, Rsrv - STR r1, [r0, #0xD1C] @ Setup System Handlers 8-11 Priority Registers - @ Note: SVC must be lowest priority, which is 0xFF - - LDR r1, =0x40FF0000 @ SysT, PnSV, Rsrv, DbgM - STR r1, [r0, #0xD20] @ Setup System Handlers 12-15 Priority Registers - @ Note: PnSV must be lowest priority, which is 0xFF - -@ -@ /* Return to caller. */ -@ - BX lr -@} -@ - -@ /* Generic interrupt handler template */ - .global __tx_IntHandler - .thumb_func -__tx_IntHandler: -@ VOID InterruptHandler (VOID) -@ { - PUSH {r0, lr} - -@ /* Do interrupt handler work here */ -@ /* BL .... */ - - POP {r0, lr} - BX LR -@ } - -@ /* System Tick timer interrupt handler */ - .global __tx_SysTickHandler - .global SysTick_Handler - .thumb_func -__tx_SysTickHandler: - .thumb_func -SysTick_Handler: -@ VOID TimerInterruptHandler (VOID) -@ { -@ - PUSH {r0, lr} - BL _tx_timer_interrupt - POP {r0, lr} - BX LR -@ }