Skip to content

Commit ac4db5e

Browse files
committed
Example project updated
1 parent 1ddd43e commit ac4db5e

7 files changed

+89
-41
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ CPPWARN = -Wall -Wextra
185185
#
186186

187187
# List all default C defines here, like -D_DEBUG=1
188-
DDEFS = -DPORT_INT_REQUIRED_STACK=128
188+
DDEFS = -DPORT_INT_REQUIRED_STACK=256
189189

190190
# List all default ASM defines here, like -D_DEBUG=1
191191
DADEFS =
@@ -208,7 +208,7 @@ DLIBS = -lm
208208
#
209209

210210
# List all user C define here, like -D_DEBUG=1
211-
UDEFS += -DR2MW_TEST -DR2P_MODULE_NAME='"$(R2P_MODULE_NAME)"'
211+
UDEFS += -DR2MW_TEST -DR2P_USE_BRIDGE_MODE=1 -DR2P_ITERATE_PUBSUB=0
212212

213213
# Define ASM defines here
214214
UADEFS +=

R2P_IMU_test_mw (OpenOCD, Flash and Run).launch

+1-1
Large diffs are not rendered by default.

R2P_IMU_test_mw (Run only).launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
3333
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
3434
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
35-
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;signature-infop-r2p::Bootloader::app_threadf_wrapper-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;datap-tailp-impl-r2p::StaticQueue&amp;lt;r2p::BaseSubscriber&amp;gt;-subp_queue-r2p::DebugSubscriber::fetch_dequeue-(cast)&quot; val=&quot;r2p::BaseSubscriber *&quot;/&gt;&lt;content id=&quot;datap-headp-impl-r2p::StaticQueue&amp;lt;r2p::BaseSubscriber&amp;gt;-subp_queue-r2p::DebugSubscriber::fetch_dequeue-(cast)&quot; val=&quot;r2p::BaseSubscriber *&quot;/&gt;&lt;content id=&quot;datap-entryp-r2p::StaticQueue_impl::get_head-(cast)&quot; val=&quot;DebugSubscriber*&quot;/&gt;&lt;content id=&quot;p_state-tp-chEvtSignalI-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;freeadr-null-start_apps-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;checksum-record-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;offset-record-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;base-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;end-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;start-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmend-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmstart-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;ramend-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;ramstart-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;MSR-can-can-RTCAND--(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;flags-rtcan_lld_tx_cb-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;data-msg_p-pwm123_cb-(cast)&quot; val=&quot;uint16_t *&quot;/&gt;&lt;content id=&quot;data[7]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[6]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[5]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[4]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[3]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[2]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[1]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[0]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;p_epending-threads[4]-threads--(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;ewmask-p_u-ctp-chEvtWaitAny-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;mask-chEvtWaitAny-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;ewmask-p_u-tp-chEvtSignalI-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;chp-cfgp-ldrProcess-(cast)&quot; val=&quot;SerialDriver *&quot;/&gt;&lt;content id=&quot;freeadr-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmadr-infos[0]-infos-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmlen-infos[0]-infos-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;datap-headp-impl-topics-null-main-(cast)&quot; val=&quot;r2p::Topic *&quot;/&gt;&lt;/contentList&gt;"/>
35+
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;boot_mode_magic-null-main-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;rebooted_magic-null-main-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;datap-headp-impl-topics-null-main-(cast)&quot; val=&quot;r2p::Topic *&quot;/&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmlen-infos[0]-infos-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmadr-infos[0]-infos-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;freeadr-null-_idle_thread-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;chp-cfgp-ldrProcess-(cast)&quot; val=&quot;SerialDriver *&quot;/&gt;&lt;content id=&quot;ewmask-p_u-tp-chEvtSignalI-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;mask-chEvtWaitAny-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;ewmask-p_u-ctp-chEvtWaitAny-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;p_epending-threads[4]-threads--(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;data[0]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[1]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[2]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[3]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[4]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[5]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[6]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data[7]-data-msg_p-pwm123_cb-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;data-msg_p-pwm123_cb-(cast)&quot; val=&quot;uint16_t *&quot;/&gt;&lt;content id=&quot;flags-rtcan_lld_tx_cb-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;MSR-can-can-RTCAND--(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;ramstart-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;ramend-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmstart-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;pgmend-cfgp-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;start-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;end-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;base-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;offset-record-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;checksum-record-process_ihex-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;freeadr-null-start_apps-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;p_state-tp-chEvtSignalI-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;datap-entryp-r2p::StaticQueue_impl::get_head-(cast)&quot; val=&quot;DebugSubscriber*&quot;/&gt;&lt;content id=&quot;datap-headp-impl-r2p::StaticQueue&amp;lt;r2p::BaseSubscriber&amp;gt;-subp_queue-r2p::DebugSubscriber::fetch_dequeue-(cast)&quot; val=&quot;r2p::BaseSubscriber *&quot;/&gt;&lt;content id=&quot;datap-tailp-impl-r2p::StaticQueue&amp;lt;r2p::BaseSubscriber&amp;gt;-subp_queue-r2p::DebugSubscriber::fetch_dequeue-(cast)&quot; val=&quot;r2p::BaseSubscriber *&quot;/&gt;&lt;content id=&quot;signature-infop-r2p::Bootloader::app_threadf_wrapper-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
3636
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;globalVariableList/&gt;&#10;"/>
3737
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList/&gt;&#10;"/>
3838
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>

board.c

+30-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const PALConfig pal_default_config =
3232
{VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
3333
{VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
3434
{VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
35-
{VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
36-
{VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
3735
};
3836
#endif
3937

@@ -55,3 +53,33 @@ void boardInit(void) {
5553
// AFIO->MAPR |= AFIO_MAPR_CAN_REMAP_REMAP2;
5654
AFIO->MAPR |= AFIO_MAPR_I2C1_REMAP;
5755
}
56+
57+
58+
void * led2gpio(unsigned led_id) {
59+
60+
switch (led_id) {
61+
case 1:
62+
case 2:
63+
case 3:
64+
case 4:
65+
return LED_GPIO;
66+
}
67+
68+
chSysHalt();
69+
}
70+
71+
unsigned led2pin(unsigned led_id) {
72+
73+
switch (led_id) {
74+
case 1:
75+
return LED1;
76+
case 2:
77+
return LED2;
78+
case 3:
79+
return LED3;
80+
case 4:
81+
return LED4;
82+
}
83+
84+
chSysHalt();
85+
}

board.h

+9-19
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
/*
2929
* Board identifier.
3030
*/
31-
#define BOARD_R2D_IMU_MODULE
32-
#define BOARD_NAME "R2D IMU module"
31+
#define BOARD_R2P_IMU_MODULE
32+
#define BOARD_NAME "R2P IMU module"
3333

3434
/*
3535
* Board frequencies.
@@ -46,13 +46,17 @@
4646
* IO pins assignments.
4747
*/
4848
#define LED_GPIO GPIOB
49+
#define LED1_GPIO GPIOB
4950
#define LED1 12
51+
#define LED2_GPIO GPIOB
5052
#define LED2 13
53+
#define LED3_GPIO GPIOB
5154
#define LED3 14
55+
#define LED4_GPIO GPIOB
5256
#define LED4 15
5357

54-
//#define SERIAL_DRIVER SD1
5558
#define SERIAL_DRIVER SD2
59+
//#define GPS_SERIAL_DRIVER SD2
5660
#define SPI_DRIVER SPID1
5761
#define I2C_DRIVER I2CD1
5862

@@ -146,27 +150,13 @@
146150
#define VAL_GPIOCCRH 0x88888888 /* PC15...PC8 */
147151
#define VAL_GPIOCODR 0xFFFFFFFF
148152

149-
/*
150-
* Port D setup.
151-
* Everything input with pull-up except:
152-
*/
153-
#define VAL_GPIODCRL 0x88888888 /* PD7...PD0 */
154-
#define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
155-
#define VAL_GPIODODR 0xFFFFFFFF
156-
157-
/*
158-
* Port E setup.
159-
* Everything input with pull-up except:
160-
*/
161-
#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
162-
#define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
163-
#define VAL_GPIOEODR 0xFFFFFFFF
164-
165153
#if !defined(_FROM_ASM_)
166154
#ifdef __cplusplus
167155
extern "C" {
168156
#endif
169157
void boardInit(void);
158+
void * led2gpio(unsigned led_id);
159+
unsigned led2pin(unsigned led_id);
170160
#ifdef __cplusplus
171161
}
172162
#endif

board.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ BOARDSRC = ./board.c
44
# Required include directories
55
BOARDINC = .
66

7-
# R"P module name
8-
R2P_MODULE_NAME = IMU_0
7+
# R2P module name
8+
R2P_MODULE_NAME = IMU_GW
99

main.cpp

+44-14
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@
1212
#include <r2p/NamingTraits.hpp>
1313
#include <r2p/Bootloader.hpp>
1414
#include <r2p/transport/DebugTransport.hpp>
15+
#include <r2p/transport/RTCANTransport.hpp>
16+
17+
#include <r2p/node/led.hpp>
18+
#include <r2p/msg/motor.hpp>
1519

1620
#include <cstdio>
1721
#include <cstdlib>
1822
#include <cstring>
1923

2024
#ifndef R2P_MODULE_NAME
21-
#define R2P_MODULE_NAME "R2PMODX"
25+
#define R2P_MODULE_NAME "IMU_GW"
26+
#endif
27+
28+
#ifndef DEBUGTRA
29+
#define DEBUGTRA 1
30+
#endif
31+
32+
#ifndef RTCANTRA
33+
#define RTCANTRA 1
2234
#endif
2335

2436

@@ -39,22 +51,36 @@ extern "C" {
3951

4052
#define BOOT_STACKLEN 1024
4153

42-
static WORKING_AREA(wa_info, 2048);
54+
#if R2P_USE_BRIDGE_MODE
55+
enum { PUBSUB_BUFFER_LENGTH = 16 };
56+
r2p::Middleware::PubSubStep pubsub_buf[PUBSUB_BUFFER_LENGTH];
57+
#endif
58+
59+
static WORKING_AREA(wa_info, 1024);
4360

44-
r2p::Middleware r2p::Middleware::instance(R2P_MODULE_NAME,
45-
"BOOT_"R2P_MODULE_NAME);
61+
r2p::Middleware r2p::Middleware::instance(
62+
R2P_MODULE_NAME, "BOOT_"R2P_MODULE_NAME
63+
#if R2P_USE_BRIDGE_MODE
64+
, pubsub_buf, PUBSUB_BUFFER_LENGTH
65+
#endif
66+
);
4667

4768
static WORKING_AREA(wa1, 1024);
4869
static WORKING_AREA(wa2, 1024);
4970
static WORKING_AREA(wa3, 1024);
5071

72+
#if DEBUGTRA
5173
static char dbgtra_namebuf[64];
52-
5374
static r2p::DebugTransport dbgtra("SD2", reinterpret_cast<BaseChannel *>(&SD2),
5475
dbgtra_namebuf);
55-
5676
static WORKING_AREA(wa_rx_dbgtra, 1024);
5777
static WORKING_AREA(wa_tx_dbgtra, 1024);
78+
#endif // DEBUGTRA
79+
80+
#if RTCANTRA
81+
static r2p::RTCANTransport rtcantra(RTCAND1);
82+
static RTCANConfig rtcan_config = { 1000000, 100, 60 };
83+
#endif // RTCANTRA
5884

5985
size_t num_msgs = 0;
6086
systime_t start_time, cur_time;
@@ -141,16 +167,12 @@ msg_t Thread3(void *) {
141167
}
142168

143169

144-
#include <r2p/BootMsg.hpp> // XXX
145-
146170
extern "C" {
147171
int main(void) {
148172

149173
halInit();
150174
chSysInit();
151175

152-
sdStart(&SD2, NULL);
153-
154176
r2p::Thread::set_priority(r2p::Thread::HIGHEST);
155177

156178
void *boot_stackp = NULL;
@@ -162,16 +184,24 @@ int main(void) {
162184
boot_stackp = stackp;
163185
}
164186

165-
r2p::Middleware::instance.pre_init(
187+
r2p::Middleware::instance.initialize(
166188
wa_info, sizeof(wa_info), r2p::Thread::LOWEST,
167189
boot_stackp, BOOT_STACKLEN, r2p::Thread::LOWEST
168190
);
169191

170-
dbgtra.initialize(wa_rx_dbgtra, sizeof(wa_rx_dbgtra), r2p::Thread::LOWEST + 11,
171-
wa_tx_dbgtra, sizeof(wa_tx_dbgtra), r2p::Thread::LOWEST + 10);
192+
#if DEBUGTRA
193+
sdStart(&SD2, NULL);
194+
dbgtra.initialize(wa_rx_dbgtra, sizeof(wa_rx_dbgtra), r2p::Thread::LOWEST + 11,
195+
wa_tx_dbgtra, sizeof(wa_tx_dbgtra), r2p::Thread::LOWEST + 10);
196+
#endif
197+
198+
#if RTCANTRA
199+
rtcantra.initialize(rtcan_config);
200+
#endif
172201

173-
r2p::Middleware::instance.post_init();
202+
r2p::Middleware::instance.start();
174203

204+
(void)wa1; (void)wa2; (void)wa3;
175205
// r2p::Thread::create_static(wa3, sizeof(wa3), r2p::Thread::NORMAL - 2, Thread3, NULL, "Thread3");
176206
// r2p::Thread::create_static(wa2, sizeof(wa2), r2p::Thread::NORMAL + 1, Thread2, NULL, "Thread2");
177207
// r2p::Thread::create_static(wa1, sizeof(wa1), r2p::Thread::NORMAL + 0, Thread1, NULL, "Thread1");

0 commit comments

Comments
 (0)