Yuki Suga / RTnoV4

Dependencies:   EthernetInterface mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RTno.h Source File

RTno.h

00001 #ifndef RTNO_HEADER_INCLUDED
00002 #define RTNO_HEADER_INCLUDED
00003 
00004 /*******************************************
00005  * RTno.h
00006  * @author Yuki Suga
00007  * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
00008  * @license LGPLv3
00009  *****************************************/
00010 
00011 
00012 //#define BAUDRATE 19200
00013 
00014 #define RTC_OK 0
00015 #define RTC_ERROR -1
00016 #define RTC_PRECONDITION_NOT_MET -2
00017 
00018 
00019 #define USE_UART_CONNECTION
00020 //#define USE_ETHERNET_CONNECTION
00021 #define USE_TIMER1_EC
00022 
00023 #include "mbed.h"
00024 #include "BasicDataType.h"
00025 #include "InPort.h"
00026 #include "OutPort.h"
00027 #include "rtcconf.h"
00028 
00029 #ifdef USE_UART_CONNECTION
00030 #include "UART.h"
00031 #endif
00032 
00033 #ifdef USE_ETHERNET_CONNECTION
00034 #include "EtherTcp.h"
00035 #include "EthernetInterface.h"
00036 #endif
00037 
00038 #ifdef USE_TIMER1_EC
00039 #include "Timer1ExecutionContext.h"
00040 #endif
00041 
00042 #include "ProxySyncEC.h"
00043 #define PACKET_BUFFER_SIZE 128
00044 
00045 #define MAX_PORT 8
00046 
00047 
00048 // global variables for rtcconf
00049 //extern volatile exec_cxt_str exec_cxt;
00050 //extern config_str conf;
00051 
00052 // global functions
00053 // RTno APIs
00054 extern "C" {
00055   void rtcconf(config_str& conf, exec_cxt_str& exec_cxt);
00056 };
00057 
00058 extern "C" {
00059   void addInPort(InPortBase& inPort);
00060   void addOutPort(OutPortBase& outPort);
00061 }
00062 
00063 namespace RTno {
00064   //extern "C" {
00065 
00066   // These call-back funcitons should be defined in user program code.
00067   // Use RTno_template.pde to create your own project.
00068 
00069   /**
00070    * onInitialize()
00071    * This function is called when RTno is initialized.
00072    * RTno is usually initialized when your device is turned on.
00073    */
00074   int onInitialize();
00075 
00076   /**
00077    * onActivated()
00078    * This function is called when RTno is activated only if RTno is RTC_INACTIVE condition.
00079    * RTno is usually activated by RT System Editor or other tools for OpenRTM-aist.
00080    */
00081   int onActivated();
00082 
00083   /**
00084    * onExecute()
00085    * This function is periodically called when the RTno-proxy is RTC_ACTIVE condition.
00086    */
00087   int onExecute();
00088 
00089   /**
00090    * onDeactivated()
00091    * This function is called when RTno is deactivated only if RTno is RTC_ACTIVE condition.
00092    * RTno is usually deactivated by RT System Editor or other tools for OpenRTM-aist.
00093    */
00094   int onDeactivated();
00095 
00096   /**
00097    * onError
00098    * This function is called when RTno is error only if RTno is in RTC_ERROR condition.
00099    * [DANGEROUS] This function is periodically called in very short interval.
00100    */ 
00101  int onError();
00102 
00103   /**
00104    * onReset
00105    * This function is called when RTno is reset only if RTno is in RTC_ERROR condition.
00106    * RTno is usually reset by RT System Editor or other tools for OpenRTM-aist.
00107    */
00108   int onReset();
00109   //};// extern "C"
00110 };
00111 
00112 
00113 #ifndef RTNO_SUBMODULE_DEFINE
00114 
00115 
00116 void EC_setup(exec_cxt_str& exec_cxt) {
00117   switch(exec_cxt.periodic.type) {
00118 #ifdef USE_TIMER1_EC
00119   case Timer1ExecutionContext:
00120     Timer1EC_init(exec_cxt.periodic.rate);
00121     break;
00122 #endif // USE_TIMER1_EC
00123   case ProxySynchronousExecutionContext:
00124   default:
00125     ProxySyncEC_init();
00126     break;
00127   }
00128 }
00129 
00130 
00131 void Connection_setup(config_str& conf) {
00132   switch(conf._default.connection_type) {
00133 #ifdef USE_ETHERNET_CONNECTION
00134   case ConnectionTypeEtherTcp:
00135     EtherTcp_init(//(uint8_t*)&conf._default.mac_address,
00136           conf._default.ip_address,
00137           conf._default.default_gateway,
00138           conf._default.subnet_mask,
00139               conf._default.port);
00140     break;
00141 #endif // USE_ETHERNET_CONNECTION
00142 #ifdef USE_UART_CONNECTION
00143   case ConnectionTypeSerialUSB:
00144     UART_init(0, conf._default.baudrate);
00145     break;
00146   case ConnectionTypeSerial1:
00147     UART_init(1, conf._default.baudrate);
00148     break;
00149   case ConnectionTypeSerial2:
00150     UART_init(2, conf._default.baudrate);
00151     break;
00152   case ConnectionTypeSerial3:
00153     UART_init(3, conf._default.baudrate);
00154     break;
00155 #endif // USE_UART_CONNECTION
00156   default:
00157     break;
00158   }
00159 }
00160 
00161 void setup();
00162 void loop();
00163 
00164 int main(void) {
00165     setup();
00166     while(1) {
00167         loop();
00168     }
00169 }
00170 
00171 #endif
00172 
00173 #endif
00174