{"id":13411210,"url":"https://github.com/simonjwright/multiplexed-io","last_synced_at":"2025-03-14T16:34:12.711Z","repository":{"id":135312563,"uuid":"55594454","full_name":"simonjwright/multiplexed-io","owner":"simonjwright","description":"Demos of multiplexed digital I/O for AdaPilot","archived":false,"fork":false,"pushed_at":"2016-10-18T15:46:25.000Z","size":293,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T16:55:22.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ada","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonjwright.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-04-06T09:48:13.000Z","updated_at":"2016-04-06T09:51:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"c34779a7-2f98-47f0-b80a-d788aee5b126","html_url":"https://github.com/simonjwright/multiplexed-io","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonjwright%2Fmultiplexed-io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonjwright%2Fmultiplexed-io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonjwright%2Fmultiplexed-io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonjwright%2Fmultiplexed-io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonjwright","download_url":"https://codeload.github.com/simonjwright/multiplexed-io/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243610958,"owners_count":20319059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:12.175Z","updated_at":"2025-03-14T16:34:12.340Z","avatar_url":"https://github.com/simonjwright.png","language":"Ada","funding_links":[],"categories":["Hardware and Embedded"],"sub_categories":["Drivers"],"readme":"# multiplexed-io\n\nThis contains explorations, for\n[AdaPilot](http://adapilot.likeabird.eu), of implementing drivers for\nthe AdaRacer MCU, using the Ravenscar profile of Ada 2012 from\n[AdaCore](http://libre.adacore.com) and device bindings generated\nusing [SVD2Ada](https://github.com/AdaCore/svd2ada).\n\nThe structure corresponds to that proposed for the main AdaPilot repository.\n\n## Proof\n\nOf particular interest is how \"near the metal\" we can get code that\ncan be processed by\n[SPARK GPL](http://libre.adacore.com/tools/spark-gpl-edition/) (2016).\n\nThe [Ada Drivers Library](https://github.com/AdaCore/Ada_Drivers_Library) imposes quite a lot of code between applications and the hardware, and that code is not in SPARK ([nor is a move in this direction planned](https://github.com/AdaCore/Ada_Drivers_Library/issues/13)).\n\nThe code here provides minimal layers between applications and hardware.\n\n### Volatility\n\nA major problem is dealing with _volatile_ objects.\n\nThe device bindings declare registers as `Volatile_Full_Access`, which allows you to write code like\n\n       bitfield_of_component := value;\n\nwhich looks great, but under the hood GNAT implements this as\n\n       local_variable := register;\n       bitfield_of_local_variable := value;\n       register := local_variable;\n\nand suffers the usual concurrency-related problems. The only apparent solution to the *gnatprove* issue (not, of course, to the underlying concurrency vulnerability) is to mark the subprograms that have to modify device registers as being out of SPARK (`pragma SPARK_Mode (Off);`), and supply alternative reasoning to justify the code (I haven't done this :-).\n\n## Concurrent access\n\nWe have two devices using SPI2, the BARO (MS5611) and the FRAM (FM25V02). It is absolutely vital that they don't interfere with each other.\n\nOne approach would be to arrange a schedule so that each device is given its own time slot(s). That would be fine for the MS5611 on its own - bearing in mind that it requires two accesses to perform a measurement, the first to start the process and the second to fetch the result, which must occur after an interval depending on the measurement precision (9 ms for the highest precision). However the purpose of the FRAM is to store application parameters and checkpoint data, which might be quite hard to schedule with the MS5611.\n\nHere, I've used an Ada protected object. Writing a command and its parameter, and retrieving the associated data, is performed within one protected action, so that other Ada tasks that try to access the same SPI will be blocked. One might want to arrange that these activities take place at a lower priority than others (RMA scheduling, perhaps), and there's the protected object's [ceiling priority](http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-D-3.html) to organise also (the default is `System.Priority'Last`, i.e. the highest priority).\n\nTiming remains to be done.\n\n## GNAT Project Files\n\nEach component directory has three [GNAT Project](http://docs.adacore.com/gprbuild-docs/html/gprbuild_ug.html) (`.gpr`) files (actually, the `test` directory breaks this to some extent):\n\n  * \u003ctt\u003e\u003ci\u003ecomponent\u003c/i\u003e_build.gpr\u003c/tt\u003e calls \u003ctt\u003e\u003ci\u003ecomponent\u003c/i\u003e.gpr\u003c/tt\u003e to build this component for the selected RTS (and MCU),\n  * \u003ctt\u003e\u003ci\u003ecomponent\u003c/i\u003e.gpr\u003c/tt\u003e builds the component, calling in the GPRs of other components as required,\n  * \u003ctt\u003e\u003ci\u003ecomponent\u003c/i\u003e_gnatprove.gpr\u003c/tt\u003e is for use with *gnatprove*.\n\nThe RTS/MCU selection supports building either\n\n  * for the AdaRacer platform (with the scenario variable `RTS` set to, or left at, its default (`adaracer`)), using the `ravenscar-sfp-adaracer` runtime,\n  * for the [STM32F4Discovery](http://www.st.com/content/ccc/resource/technical/document/data_brief/09/71/8c/4e/e4/da/4b/fa/DM00037955.pdf/files/DM00037955.pdf/jcr:content/translations/en.DM00037955.pdf) kit (with the scenario variable `RTS` set to `stm32f4`), using the `ravenscar-sfp-stm32f4` runtime.\n\nThe reason for a separate \u003ctt\u003e\u003ci\u003ecomponent\u003c/i\u003e_gnatprove.gpr\u003c/tt\u003e is that *gnatprove* doesn't understand runtime or target settings within a GPR; proof is essentially platform-independent, so it's OK to use the host runtime.\n\n## Device variants\n\nAdaRacer uses two of the six SPI peripherals on STM32F42[79] MCUs, which means that there is considerable commonality between the code for SPI1 and SPI2. Trying to address this using a generic resulted in a lot of problems at the proof stage, so instead this work uses template processing with \u003ci\u003e[gnatprep](https://gcc.gnu.org/onlinedocs/gnat_ugn/Preprocessing-with-gnatprep.html#17)\u003c/i\u003e.\n\nPreprocessing is triggered by `make sources`, and the results have been checked into the repository; see `drivers/spi/`, `drivers/spi1`, and `drivers/spi2`.\n\nGNAT has a facility to [integrate preprocessing](https://gcc.gnu.org/onlinedocs/gnat_ugn/Integrated-Preprocessing.html#18), but it seems unlikely that this will work well with *gnatprove*.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonjwright%2Fmultiplexed-io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonjwright%2Fmultiplexed-io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonjwright%2Fmultiplexed-io/lists"}