Quick and dirty port of scmRTOS demo to mbed 1768. scmRTOS is a small RTOS written using C++. Offers (static) processes, critical sections, mutexes, messages, channels.
main.cpp
00001 //****************************************************************************** 00002 //* 00003 //* FULLNAME: Single-Chip Microcontroller Real-Time Operating System 00004 //* 00005 //* NICKNAME: scmRTOS 00006 //* 00007 //* PROCESSOR: ARM Cortex-M3 00008 //* 00009 //* TOOLKIT: RVCT (ARM) 00010 //* 00011 //* PURPOSE: Port Test File 00012 //* 00013 //* Version: 3.10 00014 //* 00015 //* $Revision: 196 $ 00016 //* $Date:: 2010-09-09 #$ 00017 //* 00018 //* Copyright (c) 2003-2010, Harry E. Zhurov 00019 //* 00020 //* Permission is hereby granted, free of charge, to any person 00021 //* obtaining a copy of this software and associated documentation 00022 //* files (the "Software"), to deal in the Software without restriction, 00023 //* including without limitation the rights to use, copy, modify, merge, 00024 //* publish, distribute, sublicense, and/or sell copies of the Software, 00025 //* and to permit persons to whom the Software is furnished to do so, 00026 //* subject to the following conditions: 00027 //* 00028 //* The above copyright notice and this permission notice shall be included 00029 //* in all copies or substantial portions of the Software. 00030 //* 00031 //* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00032 //* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00033 //* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00034 //* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00035 //* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00036 //* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 00037 //* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00038 //* 00039 //* ================================================================= 00040 //* See http://scmrtos.sourceforge.net for documentation, latest 00041 //* information, license and contact details. 00042 //* ================================================================= 00043 //* 00044 //****************************************************************************** 00045 //* mbed port by Igor Skochinsky 00046 00047 #include <mbed.h> 00048 #include <scmRTOS.h> 00049 00050 //--------------------------------------------------------------------------- 00051 // 00052 // Process types 00053 // 00054 typedef OS::process<OS::pr0, 300> TProc1; 00055 typedef OS::process<OS::pr1, 300> TProc2; 00056 typedef OS::process<OS::pr2, 300> TProc3; 00057 //--------------------------------------------------------------------------- 00058 // 00059 // Process objects 00060 // 00061 TProc1 Proc1; 00062 TProc2 Proc2; 00063 TProc3 Proc3; 00064 //--------------------------------------------------------------------------- 00065 // 00066 // IO Pins 00067 // 00068 DigitalOut led1(LED1); 00069 DigitalOut led2(LED2); 00070 00071 //--------------------------------------------------------------------------- 00072 // 00073 // Event Flags to test 00074 // 00075 OS::TEventFlag ef; 00076 OS::TEventFlag timerEvent; 00077 00078 //--------------------------------------------------------------------------- 00079 // 00080 int main() 00081 { 00082 // configure IO pins 00083 led1.write(0); 00084 led2.write(0); 00085 00086 // run 00087 OS::Run(); 00088 } 00089 00090 //--------------------------------------------------------------------------- 00091 template<> OS_PROCESS void TProc1::Exec() 00092 { 00093 for(;;) 00094 { 00095 ef.Wait(); 00096 printf("e\n"); 00097 led1.write(0); 00098 } 00099 } 00100 00101 //--------------------------------------------------------------------------- 00102 template<> OS_PROCESS void TProc2::Exec() 00103 { 00104 for(;;) 00105 { 00106 timerEvent.Wait(); 00107 printf("t\n"); 00108 Sleep(5000); 00109 led2.write(0); 00110 } 00111 } 00112 00113 //--------------------------------------------------------------------------- 00114 template<> OS_PROCESS void TProc3::Exec() 00115 { 00116 for (;;) 00117 { 00118 led1.write(1); 00119 Sleep(5000); 00120 ef.Signal(); 00121 Sleep(5000); 00122 } 00123 } 00124 00125 //--------------------------------------------------------------------------- 00126 void OS::SystemTimerUserHook() 00127 { 00128 static int cnt=0; 00129 if (++cnt == 2000) 00130 { 00131 cnt = 0; 00132 led2.write(1); 00133 timerEvent.SignalISR(); 00134 } 00135 } 00136 00137 //--------------------------------------------------------------------------- 00138 void OS::IdleProcessUserHook() 00139 { 00140 __WFI(); 00141 } 00142 //-----------------------------------------------------------------------------
Generated on Tue Jul 12 2022 20:03:20 by 1.7.2