{"id":22610362,"url":"https://github.com/klaxxon/rp2040os","last_synced_at":"2025-04-10T22:54:44.746Z","repository":{"id":144307068,"uuid":"337763034","full_name":"klaxxon/rp2040os","owner":"klaxxon","description":"Learning example for real-time OSes using the new RP2040","archived":false,"fork":false,"pushed_at":"2021-02-20T13:52:11.000Z","size":1589,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T22:54:39.586Z","etag":null,"topics":["embedded","os","pi","pico-sdk","raspberry","realtime","rp2040","rtos"],"latest_commit_sha":null,"homepage":"","language":"C","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/klaxxon.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-10T15:16:29.000Z","updated_at":"2025-02-22T12:30:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"af3ce852-3f44-4496-acf9-20ed3144c394","html_url":"https://github.com/klaxxon/rp2040os","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaxxon%2Frp2040os","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaxxon%2Frp2040os/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaxxon%2Frp2040os/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaxxon%2Frp2040os/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klaxxon","download_url":"https://codeload.github.com/klaxxon/rp2040os/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312172,"owners_count":21082638,"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":["embedded","os","pi","pico-sdk","raspberry","realtime","rp2040","rtos"],"created_at":"2024-12-08T16:06:44.304Z","updated_at":"2025-04-10T22:54:44.738Z","avatar_url":"https://github.com/klaxxon.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Raspberry Pi RP2040 Realtime OS \u003cbr/\u003e\n\u003cbr/\u003e\nLearning project to create a pre-emptive, real-time OS support\nfor the RP2040. Scheduler code is written in C to allow for easy\nexperimentation.  Current capabilities include: \u003cbr/\u003e\n\u003cbr/\u003e\nPre-emptive\u003cbr/\u003e\nThread priority\u003cbr/\u003e\nWaits/delays\u003cbr/\u003e\nCooperative yield\u003cbr/\u003e\nMutexes\u003cbr/\u003e\nStack checks (issues breakpoint)\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\nThe context switch times on the 125MHz Pico with four threads are:\u003cbr/\u003e\nNo optimizations \u003cbr/\u003e\n\u003ctable\u003e\n   \u003ctr\u003e\u003cth\u003e\u003c/th\u003e\u003cth\u003eContext Time\u003c/th\u003e\u003c/tr\u003e\n   \u003ctr\u003e\u003ctd\u003eNo stats collection:\u003c/td\u003e\u003ctd\u003e5.8 uS\u003c/td\u003e\u003c/tr\u003e\n   \u003ctr\u003e\u003ctd\u003eWith stats collecton:\u003c/td\u003e\u003ctd\u003e9.3 uS\u003c/td\u003e\u003c/tr\u003e\n   \u003ctr\u003e\u003ctd\u003eWith stats/stack checks:\u003c/td\u003e\u003ctd\u003e 9.9 uS\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003cbr/\u003e\nExample code has a simple \"top\" like output every two seconds to the serial port. The Ctx= values are the \npercentage of time spent in the context switch. Util= is the percentage of time spent in a thread and Idle=\npercent spent in one of the cores idle threads.\u003cbr/\u003e\nThe S or status indicator is simply: W-waiting, R-running, Z-zombied or thread returned.\u003cbr/\u003e\n\u003cpre\u003e\nWall time 0:56:38\nCPU0 Ctx=0.095%, Util=  1.229%  Idle= 98.771%\nCPU1 Ctx=0.074%, Util=  0.081%  Idle= 99.919%\nThrd   Name     S PRI  CPU     LastCPU\n   0 Red LED    W 100  0.001%  1\n   1 Green LED  W 100  0.011%  0\n   2 Report     R 255  1.115%  0\n   3 Spinner    Z 150  0.000%  0\n\u003c/pre\u003e\n\n\nThe current implementation consists of three files and a main example:\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cpre\u003e\nrp2040os.h    OS header\nrp2040os.c    Implementation in C\nfunc.s        Implementation function in assembly\nmain.c        Example\n\u003cbr/\u003e\n\u003c/pre\u003e\nA simple use case to kick off two threads:\u003cbr/\u003e\n\u003cpre\u003e\n#include \"rp2040.h\"\n\n\nstatic uint32_t blink1Stack[128];\nvoid blink1() {\n  while (true) {\n    setGPIO(LED_PIN1);\n    delayms(300);\n    clrGPIO(LED_PIN1);\n    delayms(300);\n  }\n}\n\nstatic uint32_t blink2Stack[128];\nvoid blink2() {\n  while (true) {\n    setGPIO(LED_PIN2);\n    delayms(300);\n    clrGPIO(LED_PIN2);\n    delayms(300);\n  }\n}\n\nint main() {\n  stdio_init_all(); \n  gpio_init(LED_PIN1);\n  gpio_set_dir(LED_PIN1, GPIO_OUT);\n  gpio_init(LED_PIN2);\n  gpio_set_dir(LED_PIN2, GPIO_OUT);\n  \n  addThread(\"Red LED\", blink1, blink1Stack, sizeof(blink1Stack), 100);\n  addThread(\"Green LED\", blink2, blink2Stack, sizeof(blink2Stack), 100);\n  setupSched(); // No return\n}\n\u003c/pre\u003e\n\u003cbr/\u003e\n### Stack sizes\u003cbr/\u003e\nBe aware that the more library functions you call, the more stack space you may require.  For example, using the printf function will require more than 256 32bit values in a stack to handle the functions memory requirements.  If the unit under test is attached to a debugger, the STACK_WATCH can be turned on and will trigger a BKPT (breakpoint) in the debugger if any of the stack guard values are modified, indicating a possible overflow condition.\u003cbr/\u003e\n\n\u003cbr/\u003e\n### osConfig.h\u003cbr/\u003e\nThis file lets you customize how the scheduler works.  By default, it is set to the RP2040 specifications or two cores.  Setting the USER_TASKS to \nthe correct amount for your application will minimize the amount of memory used.  Additional thread information such as naming, stats and stack monitoring also consume a little more memory, but can be very helpful with debugging.\u003cbr/\u003e\nThe CONTEXTSW_PIN can be used with an oscilloscope to see the context switches in real-time.\u003cbr/\u003e\n\n\n\n\n### Building\u003cbr/\u003e\nexport PICO_SDK_PATH=path to your pico-sdk\u003cbr/\u003e\nCopy the $PICO_SDK_PATH/external/pico_sdk_import.cmake into main directory.\u003cbr/\u003e\n\u003cpre\u003e\n$\u003e mkdir build\n$\u003e cd build\n$\u003e cmake .. -DCMAKE_BUILD_TYPE=Debug\n$\u003e make\n\u003c/pre\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaxxon%2Frp2040os","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklaxxon%2Frp2040os","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaxxon%2Frp2040os/lists"}