RTno is communicating library and framework which allows you to make your embedded device capable of communicating with RT-middleware world. RT-middleware is a platform software to realize Robotic system. In RTM, robots are developed by constructing robotics technologies\' elements (components) named RT-component. Therefore, the RTno helps you to create your own RT-component with your mbed and arduino. To know how to use your RTno device, visit here: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en To know about RT-middleware and RT-component, visit http://www.openrtm.org
Dependencies: EthernetInterface mbed-rtos
RTno.h@6:86d72601ff54, 2013-08-29 (annotated)
- Committer:
- ysuga
- Date:
- Thu Aug 29 05:26:09 2013 +0000
- Revision:
- 6:86d72601ff54
- Parent:
- 0:5f7bc45bc2e8
RTno updt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ysuga | 0:5f7bc45bc2e8 | 1 | #ifndef RTNO_HEADER_INCLUDED |
ysuga | 0:5f7bc45bc2e8 | 2 | #define RTNO_HEADER_INCLUDED |
ysuga | 0:5f7bc45bc2e8 | 3 | |
ysuga | 0:5f7bc45bc2e8 | 4 | /******************************************* |
ysuga | 0:5f7bc45bc2e8 | 5 | * RTno.h |
ysuga | 0:5f7bc45bc2e8 | 6 | * @author Yuki Suga |
ysuga | 0:5f7bc45bc2e8 | 7 | * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010. |
ysuga | 0:5f7bc45bc2e8 | 8 | * @license LGPLv3 |
ysuga | 0:5f7bc45bc2e8 | 9 | *****************************************/ |
ysuga | 0:5f7bc45bc2e8 | 10 | |
ysuga | 0:5f7bc45bc2e8 | 11 | |
ysuga | 0:5f7bc45bc2e8 | 12 | //#define BAUDRATE 19200 |
ysuga | 0:5f7bc45bc2e8 | 13 | |
ysuga | 0:5f7bc45bc2e8 | 14 | #define RTC_OK 0 |
ysuga | 0:5f7bc45bc2e8 | 15 | #define RTC_ERROR -1 |
ysuga | 0:5f7bc45bc2e8 | 16 | #define RTC_PRECONDITION_NOT_MET -2 |
ysuga | 0:5f7bc45bc2e8 | 17 | |
ysuga | 0:5f7bc45bc2e8 | 18 | |
ysuga | 0:5f7bc45bc2e8 | 19 | #define USE_UART_CONNECTION |
ysuga | 6:86d72601ff54 | 20 | //#define USE_ETHERNET_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 21 | #define USE_TIMER1_EC |
ysuga | 0:5f7bc45bc2e8 | 22 | |
ysuga | 0:5f7bc45bc2e8 | 23 | #include "mbed.h" |
ysuga | 0:5f7bc45bc2e8 | 24 | #include "BasicDataType.h" |
ysuga | 0:5f7bc45bc2e8 | 25 | #include "InPort.h" |
ysuga | 0:5f7bc45bc2e8 | 26 | #include "OutPort.h" |
ysuga | 0:5f7bc45bc2e8 | 27 | #include "rtcconf.h" |
ysuga | 0:5f7bc45bc2e8 | 28 | |
ysuga | 0:5f7bc45bc2e8 | 29 | #ifdef USE_UART_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 30 | #include "UART.h" |
ysuga | 0:5f7bc45bc2e8 | 31 | #endif |
ysuga | 0:5f7bc45bc2e8 | 32 | |
ysuga | 0:5f7bc45bc2e8 | 33 | #ifdef USE_ETHERNET_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 34 | #include "EtherTcp.h" |
ysuga | 6:86d72601ff54 | 35 | #include "EthernetInterface.h" |
ysuga | 0:5f7bc45bc2e8 | 36 | #endif |
ysuga | 0:5f7bc45bc2e8 | 37 | |
ysuga | 0:5f7bc45bc2e8 | 38 | #ifdef USE_TIMER1_EC |
ysuga | 0:5f7bc45bc2e8 | 39 | #include "Timer1ExecutionContext.h" |
ysuga | 0:5f7bc45bc2e8 | 40 | #endif |
ysuga | 0:5f7bc45bc2e8 | 41 | |
ysuga | 0:5f7bc45bc2e8 | 42 | #include "ProxySyncEC.h" |
ysuga | 0:5f7bc45bc2e8 | 43 | #define PACKET_BUFFER_SIZE 128 |
ysuga | 0:5f7bc45bc2e8 | 44 | |
ysuga | 0:5f7bc45bc2e8 | 45 | #define MAX_PORT 8 |
ysuga | 0:5f7bc45bc2e8 | 46 | |
ysuga | 0:5f7bc45bc2e8 | 47 | |
ysuga | 0:5f7bc45bc2e8 | 48 | // global variables for rtcconf |
ysuga | 0:5f7bc45bc2e8 | 49 | //extern volatile exec_cxt_str exec_cxt; |
ysuga | 0:5f7bc45bc2e8 | 50 | //extern config_str conf; |
ysuga | 0:5f7bc45bc2e8 | 51 | |
ysuga | 0:5f7bc45bc2e8 | 52 | // global functions |
ysuga | 0:5f7bc45bc2e8 | 53 | // RTno APIs |
ysuga | 0:5f7bc45bc2e8 | 54 | extern "C" { |
ysuga | 0:5f7bc45bc2e8 | 55 | void rtcconf(config_str& conf, exec_cxt_str& exec_cxt); |
ysuga | 0:5f7bc45bc2e8 | 56 | }; |
ysuga | 0:5f7bc45bc2e8 | 57 | |
ysuga | 0:5f7bc45bc2e8 | 58 | extern "C" { |
ysuga | 0:5f7bc45bc2e8 | 59 | void addInPort(InPortBase& inPort); |
ysuga | 0:5f7bc45bc2e8 | 60 | void addOutPort(OutPortBase& outPort); |
ysuga | 0:5f7bc45bc2e8 | 61 | } |
ysuga | 0:5f7bc45bc2e8 | 62 | |
ysuga | 0:5f7bc45bc2e8 | 63 | namespace RTno { |
ysuga | 0:5f7bc45bc2e8 | 64 | //extern "C" { |
ysuga | 0:5f7bc45bc2e8 | 65 | |
ysuga | 0:5f7bc45bc2e8 | 66 | // These call-back funcitons should be defined in user program code. |
ysuga | 0:5f7bc45bc2e8 | 67 | // Use RTno_template.pde to create your own project. |
ysuga | 0:5f7bc45bc2e8 | 68 | |
ysuga | 0:5f7bc45bc2e8 | 69 | /** |
ysuga | 0:5f7bc45bc2e8 | 70 | * onInitialize() |
ysuga | 0:5f7bc45bc2e8 | 71 | * This function is called when RTno is initialized. |
ysuga | 0:5f7bc45bc2e8 | 72 | * RTno is usually initialized when your device is turned on. |
ysuga | 0:5f7bc45bc2e8 | 73 | */ |
ysuga | 0:5f7bc45bc2e8 | 74 | int onInitialize(); |
ysuga | 0:5f7bc45bc2e8 | 75 | |
ysuga | 0:5f7bc45bc2e8 | 76 | /** |
ysuga | 0:5f7bc45bc2e8 | 77 | * onActivated() |
ysuga | 0:5f7bc45bc2e8 | 78 | * This function is called when RTno is activated only if RTno is RTC_INACTIVE condition. |
ysuga | 0:5f7bc45bc2e8 | 79 | * RTno is usually activated by RT System Editor or other tools for OpenRTM-aist. |
ysuga | 0:5f7bc45bc2e8 | 80 | */ |
ysuga | 0:5f7bc45bc2e8 | 81 | int onActivated(); |
ysuga | 0:5f7bc45bc2e8 | 82 | |
ysuga | 0:5f7bc45bc2e8 | 83 | /** |
ysuga | 0:5f7bc45bc2e8 | 84 | * onExecute() |
ysuga | 0:5f7bc45bc2e8 | 85 | * This function is periodically called when the RTno-proxy is RTC_ACTIVE condition. |
ysuga | 0:5f7bc45bc2e8 | 86 | */ |
ysuga | 0:5f7bc45bc2e8 | 87 | int onExecute(); |
ysuga | 0:5f7bc45bc2e8 | 88 | |
ysuga | 0:5f7bc45bc2e8 | 89 | /** |
ysuga | 0:5f7bc45bc2e8 | 90 | * onDeactivated() |
ysuga | 0:5f7bc45bc2e8 | 91 | * This function is called when RTno is deactivated only if RTno is RTC_ACTIVE condition. |
ysuga | 0:5f7bc45bc2e8 | 92 | * RTno is usually deactivated by RT System Editor or other tools for OpenRTM-aist. |
ysuga | 0:5f7bc45bc2e8 | 93 | */ |
ysuga | 0:5f7bc45bc2e8 | 94 | int onDeactivated(); |
ysuga | 0:5f7bc45bc2e8 | 95 | |
ysuga | 0:5f7bc45bc2e8 | 96 | /** |
ysuga | 0:5f7bc45bc2e8 | 97 | * onError |
ysuga | 0:5f7bc45bc2e8 | 98 | * This function is called when RTno is error only if RTno is in RTC_ERROR condition. |
ysuga | 0:5f7bc45bc2e8 | 99 | * [DANGEROUS] This function is periodically called in very short interval. |
ysuga | 0:5f7bc45bc2e8 | 100 | */ |
ysuga | 0:5f7bc45bc2e8 | 101 | int onError(); |
ysuga | 0:5f7bc45bc2e8 | 102 | |
ysuga | 0:5f7bc45bc2e8 | 103 | /** |
ysuga | 0:5f7bc45bc2e8 | 104 | * onReset |
ysuga | 0:5f7bc45bc2e8 | 105 | * This function is called when RTno is reset only if RTno is in RTC_ERROR condition. |
ysuga | 0:5f7bc45bc2e8 | 106 | * RTno is usually reset by RT System Editor or other tools for OpenRTM-aist. |
ysuga | 0:5f7bc45bc2e8 | 107 | */ |
ysuga | 0:5f7bc45bc2e8 | 108 | int onReset(); |
ysuga | 0:5f7bc45bc2e8 | 109 | //};// extern "C" |
ysuga | 0:5f7bc45bc2e8 | 110 | }; |
ysuga | 0:5f7bc45bc2e8 | 111 | |
ysuga | 0:5f7bc45bc2e8 | 112 | |
ysuga | 0:5f7bc45bc2e8 | 113 | #ifndef RTNO_SUBMODULE_DEFINE |
ysuga | 0:5f7bc45bc2e8 | 114 | |
ysuga | 0:5f7bc45bc2e8 | 115 | |
ysuga | 0:5f7bc45bc2e8 | 116 | void EC_setup(exec_cxt_str& exec_cxt) { |
ysuga | 0:5f7bc45bc2e8 | 117 | switch(exec_cxt.periodic.type) { |
ysuga | 0:5f7bc45bc2e8 | 118 | #ifdef USE_TIMER1_EC |
ysuga | 0:5f7bc45bc2e8 | 119 | case Timer1ExecutionContext: |
ysuga | 0:5f7bc45bc2e8 | 120 | Timer1EC_init(exec_cxt.periodic.rate); |
ysuga | 0:5f7bc45bc2e8 | 121 | break; |
ysuga | 0:5f7bc45bc2e8 | 122 | #endif // USE_TIMER1_EC |
ysuga | 0:5f7bc45bc2e8 | 123 | case ProxySynchronousExecutionContext: |
ysuga | 0:5f7bc45bc2e8 | 124 | default: |
ysuga | 0:5f7bc45bc2e8 | 125 | ProxySyncEC_init(); |
ysuga | 0:5f7bc45bc2e8 | 126 | break; |
ysuga | 0:5f7bc45bc2e8 | 127 | } |
ysuga | 0:5f7bc45bc2e8 | 128 | } |
ysuga | 0:5f7bc45bc2e8 | 129 | |
ysuga | 0:5f7bc45bc2e8 | 130 | |
ysuga | 0:5f7bc45bc2e8 | 131 | void Connection_setup(config_str& conf) { |
ysuga | 0:5f7bc45bc2e8 | 132 | switch(conf._default.connection_type) { |
ysuga | 0:5f7bc45bc2e8 | 133 | #ifdef USE_ETHERNET_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 134 | case ConnectionTypeEtherTcp: |
ysuga | 6:86d72601ff54 | 135 | EtherTcp_init(//(uint8_t*)&conf._default.mac_address, |
ysuga | 6:86d72601ff54 | 136 | conf._default.ip_address, |
ysuga | 6:86d72601ff54 | 137 | conf._default.default_gateway, |
ysuga | 6:86d72601ff54 | 138 | conf._default.subnet_mask, |
ysuga | 0:5f7bc45bc2e8 | 139 | conf._default.port); |
ysuga | 0:5f7bc45bc2e8 | 140 | break; |
ysuga | 0:5f7bc45bc2e8 | 141 | #endif // USE_ETHERNET_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 142 | #ifdef USE_UART_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 143 | case ConnectionTypeSerialUSB: |
ysuga | 0:5f7bc45bc2e8 | 144 | UART_init(0, conf._default.baudrate); |
ysuga | 0:5f7bc45bc2e8 | 145 | break; |
ysuga | 0:5f7bc45bc2e8 | 146 | case ConnectionTypeSerial1: |
ysuga | 0:5f7bc45bc2e8 | 147 | UART_init(1, conf._default.baudrate); |
ysuga | 0:5f7bc45bc2e8 | 148 | break; |
ysuga | 0:5f7bc45bc2e8 | 149 | case ConnectionTypeSerial2: |
ysuga | 0:5f7bc45bc2e8 | 150 | UART_init(2, conf._default.baudrate); |
ysuga | 0:5f7bc45bc2e8 | 151 | break; |
ysuga | 0:5f7bc45bc2e8 | 152 | case ConnectionTypeSerial3: |
ysuga | 0:5f7bc45bc2e8 | 153 | UART_init(3, conf._default.baudrate); |
ysuga | 0:5f7bc45bc2e8 | 154 | break; |
ysuga | 0:5f7bc45bc2e8 | 155 | #endif // USE_UART_CONNECTION |
ysuga | 0:5f7bc45bc2e8 | 156 | default: |
ysuga | 0:5f7bc45bc2e8 | 157 | break; |
ysuga | 0:5f7bc45bc2e8 | 158 | } |
ysuga | 0:5f7bc45bc2e8 | 159 | } |
ysuga | 0:5f7bc45bc2e8 | 160 | |
ysuga | 0:5f7bc45bc2e8 | 161 | void setup(); |
ysuga | 0:5f7bc45bc2e8 | 162 | void loop(); |
ysuga | 0:5f7bc45bc2e8 | 163 | |
ysuga | 0:5f7bc45bc2e8 | 164 | int main(void) { |
ysuga | 0:5f7bc45bc2e8 | 165 | setup(); |
ysuga | 0:5f7bc45bc2e8 | 166 | while(1) { |
ysuga | 0:5f7bc45bc2e8 | 167 | loop(); |
ysuga | 0:5f7bc45bc2e8 | 168 | } |
ysuga | 0:5f7bc45bc2e8 | 169 | } |
ysuga | 0:5f7bc45bc2e8 | 170 | |
ysuga | 0:5f7bc45bc2e8 | 171 | #endif |
ysuga | 0:5f7bc45bc2e8 | 172 | |
ysuga | 0:5f7bc45bc2e8 | 173 | #endif |
ysuga | 0:5f7bc45bc2e8 | 174 |