Dependencies:   mbed

Committer:
nucho
Date:
Fri Jul 29 11:20:55 2011 +0000
Revision:
0:a70ea71286b6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:a70ea71286b6 1 /**
nucho 0:a70ea71286b6 2 * RTno_Template.pde
nucho 0:a70ea71286b6 3 * RTno is RT-middleware and arduino.
nucho 0:a70ea71286b6 4 *
nucho 0:a70ea71286b6 5 * Using RTno, arduino device can communicate any RT-components
nucho 0:a70ea71286b6 6 * through the RTno-proxy component which is launched in PC.
nucho 0:a70ea71286b6 7 * Connect arduino with USB, and program with RTno library.
nucho 0:a70ea71286b6 8 * You do not have to define any protocols to establish communication
nucho 0:a70ea71286b6 9 * between arduino and PC.
nucho 0:a70ea71286b6 10 *
nucho 0:a70ea71286b6 11 * Using RTno, you must not define the function "setup" and "loop".
nucho 0:a70ea71286b6 12 * Those functions are automatically defined in the RTno libarary.
nucho 0:a70ea71286b6 13 * You, developers, must define following functions:
nucho 0:a70ea71286b6 14 * int onInitialize(void);
nucho 0:a70ea71286b6 15 * int onActivated(void);
nucho 0:a70ea71286b6 16 * int onDeactivated(void);
nucho 0:a70ea71286b6 17 * int onExecute(void);
nucho 0:a70ea71286b6 18 * int onError(void);
nucho 0:a70ea71286b6 19 * int onReset(void);
nucho 0:a70ea71286b6 20 * These functions are spontaneously called by the RTno-proxy
nucho 0:a70ea71286b6 21 * RT-component which is launched in the PC.
nucho 0:a70ea71286b6 22 * @author Yuki Suga
nucho 0:a70ea71286b6 23 * This code is written/distributed for public-domain.
nucho 0:a70ea71286b6 24 */
nucho 0:a70ea71286b6 25
nucho 0:a70ea71286b6 26 #include "RTno.h"
nucho 0:a70ea71286b6 27 #include "mbed.h"
nucho 0:a70ea71286b6 28 /**
nucho 0:a70ea71286b6 29 * This function is called at first.
nucho 0:a70ea71286b6 30 * conf._default.baudrate: baudrate of serial communication
nucho 0:a70ea71286b6 31 * exec_cxt.periodic.type: reserved but not used.
nucho 0:a70ea71286b6 32 */
nucho 0:a70ea71286b6 33 void rtcconf(void) {
nucho 0:a70ea71286b6 34 conf._default.baudrate = 115200;
nucho 0:a70ea71286b6 35 exec_cxt.periodic.type = ProxySynchronousExecutionContext;
nucho 0:a70ea71286b6 36 }
nucho 0:a70ea71286b6 37
nucho 0:a70ea71286b6 38
nucho 0:a70ea71286b6 39 /**
nucho 0:a70ea71286b6 40 * Declaration Division:
nucho 0:a70ea71286b6 41 *
nucho 0:a70ea71286b6 42 * DataPort and Data Buffer should be placed here.
nucho 0:a70ea71286b6 43 *
nucho 0:a70ea71286b6 44 * available data types are as follows:
nucho 0:a70ea71286b6 45 * TimedLong
nucho 0:a70ea71286b6 46 * TimedDouble
nucho 0:a70ea71286b6 47 * TimedFloat
nucho 0:a70ea71286b6 48 * TimedLongSeq
nucho 0:a70ea71286b6 49 * TimedDoubleSeq
nucho 0:a70ea71286b6 50 * TimedFloatSeq
nucho 0:a70ea71286b6 51 *
nucho 0:a70ea71286b6 52 * Please refer following comments. If you need to use some ports,
nucho 0:a70ea71286b6 53 * uncomment the line you want to declare.
nucho 0:a70ea71286b6 54 **/
nucho 0:a70ea71286b6 55 //TimedLong in0;
nucho 0:a70ea71286b6 56 //InPort in0In("in0", in0);
nucho 0:a70ea71286b6 57 //TimedLongSeq in0;
nucho 0:a70ea71286b6 58 //InPort in0In("in0", in0);
nucho 0:a70ea71286b6 59
nucho 0:a70ea71286b6 60 //TimedLong out0;
nucho 0:a70ea71286b6 61 //OutPort out0Out("out0", out0);
nucho 0:a70ea71286b6 62 //TimedLongSeq out0;
nucho 0:a70ea71286b6 63 //OutPort out0Out("out0", out0);
nucho 0:a70ea71286b6 64
nucho 0:a70ea71286b6 65
nucho 0:a70ea71286b6 66 //////////////////////////////////////////
nucho 0:a70ea71286b6 67 // on_initialize
nucho 0:a70ea71286b6 68 //
nucho 0:a70ea71286b6 69 // This function is called in the initialization
nucho 0:a70ea71286b6 70 // sequence. The sequence is triggered by the
nucho 0:a70ea71286b6 71 // PC. When the RTnoRTC is launched in the PC,
nucho 0:a70ea71286b6 72 // then, this function is remotely called
nucho 0:a70ea71286b6 73 // through the USB cable.
nucho 0:a70ea71286b6 74 // In on_initialize, usually DataPorts are added.
nucho 0:a70ea71286b6 75 //
nucho 0:a70ea71286b6 76 //////////////////////////////////////////
nucho 0:a70ea71286b6 77 int RTno::onInitialize() {
nucho 0:a70ea71286b6 78 /* Data Ports are added in this section.
nucho 0:a70ea71286b6 79 addInPort(&in0In);
nucho 0:a70ea71286b6 80 addInPort(&in1In);
nucho 0:a70ea71286b6 81 addOutPort(&out0Out);
nucho 0:a70ea71286b6 82 addOutPort(&out1Out);
nucho 0:a70ea71286b6 83 */
nucho 0:a70ea71286b6 84
nucho 0:a70ea71286b6 85 // Some initialization (like port direction setting)
nucho 0:a70ea71286b6 86 // pinMode(LED, OUTPUT);
nucho 0:a70ea71286b6 87 return RTC_OK;
nucho 0:a70ea71286b6 88 }
nucho 0:a70ea71286b6 89
nucho 0:a70ea71286b6 90 ////////////////////////////////////////////
nucho 0:a70ea71286b6 91 // on_activated
nucho 0:a70ea71286b6 92 // This function is called when the RTnoRTC
nucho 0:a70ea71286b6 93 // is activated. When the activation, the RTnoRTC
nucho 0:a70ea71286b6 94 // sends message to call this function remotely.
nucho 0:a70ea71286b6 95 // If this function is failed (return value
nucho 0:a70ea71286b6 96 // is RTC_ERROR), RTno will enter ERROR condition.
nucho 0:a70ea71286b6 97 ////////////////////////////////////////////
nucho 0:a70ea71286b6 98 int RTno::onActivated() {
nucho 0:a70ea71286b6 99 // Write here initialization code.
nucho 0:a70ea71286b6 100
nucho 0:a70ea71286b6 101 return RTC_OK;
nucho 0:a70ea71286b6 102 }
nucho 0:a70ea71286b6 103
nucho 0:a70ea71286b6 104 /////////////////////////////////////////////
nucho 0:a70ea71286b6 105 // on_deactivated
nucho 0:a70ea71286b6 106 // This function is called when the RTnoRTC
nucho 0:a70ea71286b6 107 // is deactivated.
nucho 0:a70ea71286b6 108 /////////////////////////////////////////////
nucho 0:a70ea71286b6 109 int RTno::onDeactivated()
nucho 0:a70ea71286b6 110 {
nucho 0:a70ea71286b6 111 // Write here finalization code.
nucho 0:a70ea71286b6 112
nucho 0:a70ea71286b6 113 return RTC_OK;
nucho 0:a70ea71286b6 114 }
nucho 0:a70ea71286b6 115
nucho 0:a70ea71286b6 116 //////////////////////////////////////////////
nucho 0:a70ea71286b6 117 // This function is repeatedly called when the
nucho 0:a70ea71286b6 118 // RTno is in the ACTIVE condition.
nucho 0:a70ea71286b6 119 // If this function is failed (return value is
nucho 0:a70ea71286b6 120 // RTC_ERROR), RTno immediately enter into the
nucho 0:a70ea71286b6 121 // ERROR condition.r
nucho 0:a70ea71286b6 122 //////////////////////////////////////////////
nucho 0:a70ea71286b6 123 int RTno::onExecute() {
nucho 0:a70ea71286b6 124
nucho 0:a70ea71286b6 125 /**
nucho 0:a70ea71286b6 126 * Usage of InPort with premitive type.
nucho 0:a70ea71286b6 127 if(in0In.isNew()) {
nucho 0:a70ea71286b6 128 in0In.read();
nucho 0:a70ea71286b6 129 long data = in0.data;
nucho 0:a70ea71286b6 130 }
nucho 0:a70ea71286b6 131 */
nucho 0:a70ea71286b6 132
nucho 0:a70ea71286b6 133 /**
nucho 0:a70ea71286b6 134 * Usage of InPort with sequence type
nucho 0:a70ea71286b6 135 if(in0In.isNew(&in1In)) {
nucho 0:a70ea71286b6 136 in0In.read();
nucho 0:a70ea71286b6 137 for(int i = 0;i < in0.data.length;i++) {
nucho 0:a70ea71286b6 138 long data_buffer = in0.data[i];
nucho 0:a70ea71286b6 139 }
nucho 0:a70ea71286b6 140 }
nucho 0:a70ea71286b6 141 */
nucho 0:a70ea71286b6 142
nucho 0:a70ea71286b6 143 /**
nucho 0:a70ea71286b6 144 * Usage of OutPort with primitive type.
nucho 0:a70ea71286b6 145 out0.data = 3.14159;
nucho 0:a70ea71286b6 146 out0Out.write();
nucho 0:a70ea71286b6 147 */
nucho 0:a70ea71286b6 148
nucho 0:a70ea71286b6 149 /**
nucho 0:a70ea71286b6 150 * Usage of OutPort with sequence type.
nucho 0:a70ea71286b6 151 out0.data.length(3);
nucho 0:a70ea71286b6 152 out0.data[0] = 1.1;
nucho 0:a70ea71286b6 153 out0.data[1] = 2.2;
nucho 0:a70ea71286b6 154 out0.data[2] = 3.3;
nucho 0:a70ea71286b6 155 out0Out.write();
nucho 0:a70ea71286b6 156 */
nucho 0:a70ea71286b6 157
nucho 0:a70ea71286b6 158 return RTC_OK;
nucho 0:a70ea71286b6 159 }
nucho 0:a70ea71286b6 160
nucho 0:a70ea71286b6 161
nucho 0:a70ea71286b6 162 //////////////////////////////////////
nucho 0:a70ea71286b6 163 // on_error
nucho 0:a70ea71286b6 164 // This function is repeatedly called when
nucho 0:a70ea71286b6 165 // the RTno is in the ERROR condition.
nucho 0:a70ea71286b6 166 // The ERROR condition can be recovered,
nucho 0:a70ea71286b6 167 // when the RTno is reset.
nucho 0:a70ea71286b6 168 ///////////////////////////////////////
nucho 0:a70ea71286b6 169 int RTno::onError()
nucho 0:a70ea71286b6 170 {
nucho 0:a70ea71286b6 171 return RTC_OK;
nucho 0:a70ea71286b6 172 }
nucho 0:a70ea71286b6 173
nucho 0:a70ea71286b6 174 ////////////////////////////////////////
nucho 0:a70ea71286b6 175 // This function is called when
nucho 0:a70ea71286b6 176 // the RTno is reset. If on_reset is
nucho 0:a70ea71286b6 177 // succeeded, the RTno will enter into
nucho 0:a70ea71286b6 178 // the INACTIVE condition. If failed
nucho 0:a70ea71286b6 179 // (return value is RTC_ERROR), RTno
nucho 0:a70ea71286b6 180 // will stay in ERROR condition.ec
nucho 0:a70ea71286b6 181 ///////////////////////////////////////
nucho 0:a70ea71286b6 182 int RTno::onReset()
nucho 0:a70ea71286b6 183 {
nucho 0:a70ea71286b6 184 return RTC_OK;
nucho 0:a70ea71286b6 185 }