Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos
main_template.cpp
00001 // Set 1 if use this main program. 00002 // I recommend to copy and paste this template to your main.cpp. 00003 // And your main function in your main.cpp generated by server must be deleted. 00004 00005 #if 0 00006 #include "mbed.h" 00007 00008 /** 00009 * RTno_Template.pde 00010 * RTno is RT-middleware and arduino. 00011 * 00012 * Using RTno, arduino device can communicate any RT-components 00013 * through the RTno-proxy component which is launched in PC. 00014 * Connect arduino with USB, and program with RTno library. 00015 * You do not have to define any protocols to establish communication 00016 * between arduino and PC. 00017 * 00018 * Using RTno, you must not define the function "setup" and "loop". 00019 * Those functions are automatically defined in the RTno libarary. 00020 * You, developers, must define following functions: 00021 * int onInitialize(void); 00022 * int onActivated(void); 00023 * int onDeactivated(void); 00024 * int onExecute(void); 00025 * int onError(void); 00026 * int onReset(void); 00027 * These functions are spontaneously called by the RTno-proxy 00028 * RT-component which is launched in the PC. 00029 * @author Yuki Suga 00030 * This code is written/distributed for public-domain. 00031 */ 00032 00033 #include <RTno.h> 00034 00035 /** 00036 * This function is called at first. 00037 * conf._default.baudrate: baudrate of serial communication 00038 * exec_cxt.periodic.type: reserved but not used. 00039 */ 00040 void rtcconf(config_str& conf, exec_cxt_str& exec_cxt) { 00041 // If you want to use Serial Connection, configure below: 00042 conf._default.connection_type = ConnectionTypeSerialUSB; // USBTX & USBRX (In Windows, Driver must be updated.) 00043 //conf._default.connection_type = ConnectionTypeSerial1; // pin9=tx, pin10=rx 00044 //conf._default.connection_type = ConnectionTypeSerial2; // pin13=tx, pin14=rx 00045 //conf._default.connection_type = ConnectionTypeSerial3; // pin28=tx, pin27=rx 00046 conf._default.baudrate = 57600; // This value is required when you select ConnectionTypeSerial* 00047 00048 // If you want to use EthernetTCP, configure below: 00049 //conf._default.connection_type = ConnectionTypeEtherTcp; 00050 //conf._default.port = 23; 00051 //conf._default.mac_address = MACaddr(0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED); 00052 //conf._default.ip_address = IPaddr(192,168,42,100); 00053 //conf._default.subnet_mask = IPaddr(255,255,255,0); 00054 //conf._default.default_gateway = IPaddr(192,168,42,254); 00055 exec_cxt.periodic.type = ProxySynchronousExecutionContext; 00056 //exec_cxt.periodic.type = Timer1ExecutionContext; // onExecute is called by Timer1. Period must be specified by 'rate' option. 00057 exec_cxt.periodic.rate = 100; // [Hz] This option is indispensable when type is Timer*ExecutionContext. 00058 } 00059 00060 00061 /** 00062 * Declaration Division: 00063 * 00064 * DataPort and Data Buffer should be placed here. 00065 * 00066 * available data types are as follows: 00067 * TimedLong 00068 * TimedDouble 00069 * TimedFloat 00070 * TimedLongSeq 00071 * TimedDoubleSeq 00072 * TimedFloatSeq 00073 * 00074 * Please refer following comments. If you need to use some ports, 00075 * uncomment the line you want to declare. 00076 **/ 00077 TimedLong in0; 00078 InPort<TimedLong> in0In("in0", in0); 00079 ///TimedLong in1; 00080 //InPort<TimedLong> in1In("in1", in1); 00081 //TimedLongSeq in0; 00082 //InPort<TimedLongSeq> in0In("in0", in0); 00083 00084 TimedLong out0; 00085 OutPort<TimedLong> out0Out("out0", out0); 00086 //TimedLongSeq<TimedLongSeq> out0; 00087 //OutPort out0Out("out0", out0); 00088 00089 DigitalOut led1(LED1); 00090 DigitalOut led2(LED2); 00091 DigitalOut led3(LED3); 00092 DigitalOut led4(LED4); 00093 00094 DigitalIn sw1(p21); 00095 ////////////////////////////////////////// 00096 // on_initialize 00097 // 00098 // This function is called in the initialization 00099 // sequence. The sequence is triggered by the 00100 // PC. When the RTnoRTC is launched in the PC, 00101 // then, this function is remotely called 00102 // through the USB cable. 00103 // In on_initialize, usually DataPorts are added. 00104 // 00105 ////////////////////////////////////////// 00106 int RTno::onInitialize() { 00107 /* Data Ports are added in this section. 00108 00109 addInPort(in1In); 00110 addOutPort(out0Out); 00111 addOutPort(out1Out); 00112 */ 00113 00114 addInPort(in0In); 00115 //addInPort(in1In); 00116 addOutPort(out0Out); 00117 led1 = 1; 00118 led2 = 0; 00119 led3 = 0; 00120 led4 = 0; 00121 sw1.mode(PullUp); 00122 // Some initialization (like port direction setting) 00123 // int LED = 13; 00124 // pinMode(LED, OUTPUT); 00125 00126 return RTC_OK; 00127 } 00128 00129 //////////////////////////////////////////// 00130 // on_activated 00131 // This function is called when the RTnoRTC 00132 // is activated. When the activation, the RTnoRTC 00133 // sends message to call this function remotely. 00134 // If this function is failed (return value 00135 // is RTC_ERROR), RTno will enter ERROR condition. 00136 //////////////////////////////////////////// 00137 int RTno::onActivated() { 00138 // Write here initialization code. 00139 led2 = 1; 00140 led3 = 0; 00141 led4 = 0; 00142 return RTC_OK; 00143 } 00144 00145 ///////////////////////////////////////////// 00146 // on_deactivated 00147 // This function is called when the RTnoRTC 00148 // is deactivated. 00149 ///////////////////////////////////////////// 00150 int RTno::onDeactivated() 00151 { 00152 // Write here finalization code. 00153 led2 = 0; 00154 led3 = 0; 00155 led4 = 0; 00156 return RTC_OK; 00157 } 00158 00159 ////////////////////////////////////////////// 00160 // This function is repeatedly called when the 00161 // RTno is in the ACTIVE condition. 00162 // If this function is failed (return value is 00163 // RTC_ERROR), RTno immediately enter into the 00164 // ERROR condition.r 00165 ////////////////////////////////////////////// 00166 int RTno::onExecute() { 00167 /** 00168 * Usage of InPort with premitive type. 00169 */ 00170 if(in0In.isNew()) { 00171 in0In.read(); 00172 led4 = in0.data > 0 ? 1 : 0; 00173 } 00174 00175 //if(in1In.isNew()) { 00176 // in1In.read(); 00177 // led4 = in1.data; 00178 //} 00179 00180 /** 00181 * Usage of InPort with sequence type 00182 if(in0In.isNew(&in1In)) { 00183 in0In.read(); 00184 for(int i = 0;i < in0.data.length;i++) { 00185 long data_buffer = in0.data[i]; 00186 } 00187 } 00188 */ 00189 00190 /** 00191 * Usage of OutPort with primitive type. 00192 out0.data = 3.14159; 00193 out0Out.write(); 00194 */ 00195 out0.data = sw1; 00196 out0Out.write(); 00197 00198 /** 00199 * Usage of OutPort with sequence type. 00200 out0.data.length(3); 00201 out0.data[0] = 1.1; 00202 out0.data[1] = 2.2; 00203 out0.data[2] = 3.3; 00204 out0Out.write(); 00205 */ 00206 00207 return RTC_OK; 00208 } 00209 00210 00211 ////////////////////////////////////// 00212 // on_error 00213 // This function is repeatedly called when 00214 // the RTno is in the ERROR condition. 00215 // The ERROR condition can be recovered, 00216 // when the RTno is reset. 00217 /////////////////////////////////////// 00218 int RTno::onError() 00219 { 00220 return RTC_OK; 00221 } 00222 00223 //////////////////////////////////////// 00224 // This function is called when 00225 // the RTno is reset. If on_reset is 00226 // succeeded, the RTno will enter into 00227 // the INACTIVE condition. If failed 00228 // (return value is RTC_ERROR), RTno 00229 // will stay in ERROR condition.ec 00230 /////////////////////////////////////// 00231 int RTno::onReset() 00232 { 00233 return RTC_OK; 00234 } 00235 00236 00237 #endif
Generated on Fri Jul 22 2022 21:22:49 by
1.7.2