├── .clang_complete ├── .gitignore ├── .linter-clang-includes ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.ja.md ├── README.md ├── apps ├── blink │ ├── CMakeLists.txt │ └── blink.c ├── cam │ ├── CMakeLists.txt │ └── cam.c ├── cpp_test │ ├── CMakeLists.txt │ └── main.cpp ├── enet_test │ ├── CMakeLists.txt │ └── enet_test.c ├── hello_world │ ├── CMakeLists.txt │ └── hello_world.c ├── imu │ ├── CMakeLists.txt │ └── imu.c ├── led │ ├── CMakeLists.txt │ └── led.c ├── listener │ ├── CMakeLists.txt │ └── listener.c ├── listener_no_rosidl │ ├── CMakeLists.txt │ └── listener_no_rosidl.c ├── rx63n_gr_sakura_joystick │ ├── config_tcpudp.c │ └── joystick.c ├── rx63n_gr_sakura_listener │ ├── config_tcpudp.c │ └── listener_no_rosidl.c ├── rx63n_gr_sakura_talker │ ├── config_tcpudp.c │ └── talker_no_rosidl.c ├── rx63n_gr_sakura_tilt_ctrl │ ├── config_tcpudp.c │ └── tilt_ctrl.c ├── standalone_listen_for_n │ ├── CMakeLists.txt │ └── standalone_listen_for_n.c ├── standalone_talk_n │ ├── CMakeLists.txt │ └── standalone_talk_n.c ├── systime_test │ ├── CMakeLists.txt │ └── systime_test.c ├── talker │ ├── CMakeLists.txt │ └── talker.c ├── talker_no_rosidl │ ├── CMakeLists.txt │ └── talker_no_rosidl.c ├── talker_stm32_timer │ ├── CMakeLists.txt │ └── talker_stm32_timer.c ├── usb_cam │ ├── CMakeLists.txt │ ├── usb_cam.c │ └── usb_desc.c └── usb_test │ ├── CMakeLists.txt │ └── usb_test.c ├── disco.c ├── docs └── renesas_rx │ └── images │ ├── GR-SAKURA.png │ ├── csplus1.png │ ├── csplus10.png │ ├── csplus10_en.png │ ├── csplus11.png │ ├── csplus11_en.png │ ├── csplus12.png │ ├── csplus13.png │ ├── csplus14.png │ ├── csplus1_en.png │ ├── csplus2.png │ ├── csplus2_en.png │ ├── csplus3.png │ ├── csplus3_en.png │ ├── csplus4.png │ ├── csplus4_2.png │ ├── csplus4_2_en.png │ ├── csplus4_en.png │ ├── csplus5.png │ ├── csplus5_en.png │ ├── csplus6.png │ ├── csplus6_en.png │ ├── csplus7.png │ ├── csplus7_en.png │ ├── csplus8.png │ ├── csplus8_en.png │ ├── csplus9.png │ ├── csplus9_en.png │ ├── csplus_import1.png │ ├── csplus_import1_en.png │ ├── csplus_import2.png │ ├── csplus_import2_en.png │ ├── csplus_import3.png │ ├── csplus_import3_en.png │ ├── csplus_import4.png │ ├── csplus_import4_en.png │ ├── csplus_import5.png │ ├── csplus_import5_en.png │ ├── csplus_import6.png │ ├── csplus_import6_en.png │ ├── csplus_import7.png │ ├── csplus_import7_en.png │ ├── csplus_import8.png │ ├── csplus_import8_en.png │ ├── csplus_import9.png │ ├── csplus_import9_en.png │ ├── fdt1.png │ ├── fdt10.png │ ├── fdt10_en.png │ ├── fdt11.png │ ├── fdt11_en.png │ ├── fdt12.png │ ├── fdt12_en.png │ ├── fdt1_en.png │ ├── fdt2.png │ ├── fdt2_en.png │ ├── fdt3.png │ ├── fdt3_en.png │ ├── fdt4.png │ ├── fdt4_en.png │ ├── fdt5.png │ ├── fdt5_en.png │ ├── fdt6.png │ ├── fdt7.png │ ├── fdt7_en.png │ ├── fdt8.png │ ├── fdt8_en.png │ ├── fdt9.png │ ├── fdt9_en.png │ ├── reset_sw.png │ └── slide_sw3.png ├── freertps.c ├── id.c ├── include └── freertps │ ├── bswap.h │ ├── config.h │ ├── disco.h │ ├── freertps.h │ ├── id.h │ ├── locator.h │ ├── part.h │ ├── periph │ ├── cam.h │ ├── i2c.h │ ├── imu.h │ └── led.h │ ├── ports.h │ ├── psm.h │ ├── psm │ └── ser.h │ ├── pub.h │ ├── qos.h │ ├── sedp.h │ ├── spdp.h │ ├── sub.h │ ├── system.h │ ├── time.h │ ├── timer.h │ ├── type.h │ └── udp.h ├── package.xml ├── part.c ├── psm └── ser.c ├── pub.c ├── r2 └── mega_genmsg.py ├── ros2_demos ├── CMakeLists.txt ├── led_blink.cpp └── package.xml ├── rosmsg_apps └── rosmsg_talker │ ├── CMakeLists.txt │ └── rosmsg_talker.c ├── scripts └── task_runner ├── sedp.c ├── spdp.c ├── sub.c ├── systems ├── cortex_m_common │ └── cmsis │ │ ├── arm_common_tables.h │ │ ├── arm_const_structs.h │ │ ├── arm_math.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm3.h │ │ ├── core_cm4.h │ │ ├── core_cm7.h │ │ ├── core_cmFunc.h │ │ ├── core_cmInstr.h │ │ ├── core_cmSimd.h │ │ ├── core_sc000.h │ │ └── core_sc300.h ├── metal_common │ ├── CMakeLists.txt │ ├── arm_trap.c │ ├── bswap.c │ ├── delay.c │ ├── enet.c │ ├── metal │ │ ├── arm_trap.h │ │ ├── console.h │ │ ├── delay.h │ │ ├── enet.h │ │ ├── enet_config.h │ │ ├── enet_headers.h │ │ ├── metal.h │ │ ├── stack.h │ │ ├── systime.h │ │ └── usb.h │ ├── stack.c │ ├── stubs.c │ ├── system.c │ ├── udp.c │ └── usb.c ├── native-posix │ ├── CMakeLists.txt │ ├── bswap.c │ ├── fake_imu.c │ ├── fake_led.c │ ├── net.h │ ├── ser.c │ ├── system.c │ ├── time.c │ ├── toolchain.cmake │ └── udp.c ├── rx63n_gr_sakura │ ├── bswap.c │ ├── system.c │ ├── system_time.c │ └── system_udp.c ├── samv71_xplained_ultra-metal │ ├── 99-atmel-edbg.rules │ ├── CMakeLists.txt │ ├── README │ ├── cam.c │ ├── console.c │ ├── enet_mac.c │ ├── i2c.c │ ├── led.c │ ├── openocd.cfg │ ├── pin.c │ ├── pin.h │ ├── samv7 │ │ ├── component │ │ │ ├── component_acc.h │ │ │ ├── component_aes.h │ │ │ ├── component_afec.h │ │ │ ├── component_chipid.h │ │ │ ├── component_dacc.h │ │ │ ├── component_efc.h │ │ │ ├── component_gmac.h │ │ │ ├── component_gpbr.h │ │ │ ├── component_hsmci.h │ │ │ ├── component_icm.h │ │ │ ├── component_isi.h │ │ │ ├── component_matrix.h │ │ │ ├── component_mcan.h │ │ │ ├── component_mlb.h │ │ │ ├── component_pio.h │ │ │ ├── component_pmc.h │ │ │ ├── component_pwm.h │ │ │ ├── component_qspi.h │ │ │ ├── component_rstc.h │ │ │ ├── component_rswdt.h │ │ │ ├── component_rtc.h │ │ │ ├── component_rtt.h │ │ │ ├── component_sdramc.h │ │ │ ├── component_smc.h │ │ │ ├── component_spi.h │ │ │ ├── component_ssc.h │ │ │ ├── component_supc.h │ │ │ ├── component_tc.h │ │ │ ├── component_trng.h │ │ │ ├── component_twi.h │ │ │ ├── component_twihs.h │ │ │ ├── component_uart.h │ │ │ ├── component_uotghs.h │ │ │ ├── component_usart.h │ │ │ ├── component_usbhs.h │ │ │ ├── component_utmi.h │ │ │ ├── component_wdt.h │ │ │ └── component_xdmac.h │ │ ├── instance │ │ │ ├── instance_acc.h │ │ │ ├── instance_aes.h │ │ │ ├── instance_afec0.h │ │ │ ├── instance_afec1.h │ │ │ ├── instance_chipid.h │ │ │ ├── instance_dacc.h │ │ │ ├── instance_efc.h │ │ │ ├── instance_gmac.h │ │ │ ├── instance_gpbr.h │ │ │ ├── instance_hsmci.h │ │ │ ├── instance_icm.h │ │ │ ├── instance_isi.h │ │ │ ├── instance_matrix.h │ │ │ ├── instance_mcan0.h │ │ │ ├── instance_mcan1.h │ │ │ ├── instance_mlb.h │ │ │ ├── instance_pioa.h │ │ │ ├── instance_piob.h │ │ │ ├── instance_pioc.h │ │ │ ├── instance_piod.h │ │ │ ├── instance_pioe.h │ │ │ ├── instance_pmc.h │ │ │ ├── instance_pwm0.h │ │ │ ├── instance_pwm1.h │ │ │ ├── instance_qspi.h │ │ │ ├── instance_rstc.h │ │ │ ├── instance_rswdt.h │ │ │ ├── instance_rtc.h │ │ │ ├── instance_rtt.h │ │ │ ├── instance_sdramc.h │ │ │ ├── instance_smc.h │ │ │ ├── instance_spi0.h │ │ │ ├── instance_spi1.h │ │ │ ├── instance_ssc.h │ │ │ ├── instance_supc.h │ │ │ ├── instance_tc0.h │ │ │ ├── instance_tc1.h │ │ │ ├── instance_tc2.h │ │ │ ├── instance_tc3.h │ │ │ ├── instance_trng.h │ │ │ ├── instance_twihs0.h │ │ │ ├── instance_twihs1.h │ │ │ ├── instance_twihs2.h │ │ │ ├── instance_uart0.h │ │ │ ├── instance_uart1.h │ │ │ ├── instance_uart2.h │ │ │ ├── instance_uart3.h │ │ │ ├── instance_uart4.h │ │ │ ├── instance_usart0.h │ │ │ ├── instance_usart1.h │ │ │ ├── instance_usart2.h │ │ │ ├── instance_usbhs.h │ │ │ ├── instance_utmi.h │ │ │ ├── instance_wdt.h │ │ │ └── instance_xdmac.h │ │ ├── pio │ │ │ ├── pio_samv71j19.h │ │ │ ├── pio_samv71j20.h │ │ │ ├── pio_samv71j21.h │ │ │ ├── pio_samv71n19.h │ │ │ ├── pio_samv71n20.h │ │ │ ├── pio_samv71n21.h │ │ │ ├── pio_samv71q19.h │ │ │ ├── pio_samv71q20.h │ │ │ └── pio_samv71q21.h │ │ ├── samv71.h │ │ ├── samv71j19.h │ │ ├── samv71j20.h │ │ ├── samv71j21.h │ │ ├── samv71n19.h │ │ ├── samv71n20.h │ │ ├── samv71n21.h │ │ ├── samv71q19.h │ │ ├── samv71q20.h │ │ ├── samv71q21.h │ │ └── system_samv71.h │ ├── samv71q21.ld │ ├── startup.c │ ├── systime.c │ ├── time.c │ ├── toolchain.cmake │ ├── usb_mac.c │ └── vectors.c ├── stm3240g_eval-metal │ ├── CMakeLists.txt │ ├── console.c │ ├── enet_init_pins.c │ ├── flash.c │ ├── imu.c │ ├── led.c │ ├── openocd.cfg │ ├── systime.c │ ├── toolchain.cmake │ └── usb_fs_init_pins.c ├── stm32_common │ ├── CMakeLists.txt │ ├── cmake │ │ ├── stm32_common.cmake │ │ ├── stm32f4.cmake │ │ └── stm32f7.cmake │ ├── cmsis │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm3.h │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ ├── core_cm7.h │ │ ├── core_cmFunc.h │ │ ├── core_cmInstr.h │ │ ├── core_cmSimd.h │ │ ├── stm32f407xx.h │ │ ├── stm32f427xx.h │ │ └── stm32f746xx.h │ ├── enet_mac.c │ ├── enet_mac.h │ ├── flash.h │ ├── ld │ │ ├── stm32f4xx.ld │ │ └── stm32f746.ld │ ├── openocd │ │ ├── gdb_init_commands │ │ ├── olimex-arm-usb-tiny-h.cfg │ │ ├── stlink-v2-1.cfg │ │ ├── stm32f427.cfg │ │ └── stm32f7-disco.cfg │ ├── pin.c │ ├── pin.h │ ├── startup.c │ ├── startup.h │ ├── stm32f4_vectors.c │ ├── stm32f7_vectors.c │ ├── time_stm32.c │ └── timer.c ├── stm32f4_disco-metal │ ├── CMakeLists.txt │ ├── console.c │ ├── enet_init_pins.c │ ├── flash.c │ ├── imu.c │ ├── led.c │ ├── openocd.cfg │ ├── systime.c │ ├── toolchain.cmake │ └── usb_fs_init_pins.c └── stm32f7_disco-metal │ ├── CMakeLists.txt │ ├── console.c │ ├── enet_init_pins.c │ ├── flash.c │ ├── i2c.c │ ├── i2c.h │ ├── led.c │ ├── openocd.cfg │ ├── systime.c │ └── toolchain.cmake ├── tests ├── fake_imu │ ├── CMakeLists.txt │ ├── cmake │ │ └── add_executable_for_each_rmw_impl.cmake │ ├── fake_imu.cpp │ ├── imu_listener.cpp │ └── package.xml ├── standalone_talker_listener_tests.sh ├── talker_listener_test.cpp └── test_time.c ├── time.c ├── tiny └── notes ├── udp.c └── utils ├── Makefile ├── lightweightserial.cpp ├── lightweightserial.h └── main.cpp /.clang_complete: -------------------------------------------------------------------------------- 1 | -Iinclude -Iposix 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | bin 32 | *.swp 33 | build 34 | build.stm32 35 | -------------------------------------------------------------------------------- /.linter-clang-includes: -------------------------------------------------------------------------------- 1 | %p/include 2 | %p/posix 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SYSTEMS ?= native-posix \ 2 | stm32f7_disco-metal \ 3 | stm32f4_disco-metal \ 4 | stm3240g_eval-metal \ 5 | samv71_xplained_ultra-metal 6 | 7 | .PHONY: all clean $(SYSTEMS) 8 | all: utils/bin/console $(SYSTEMS) 9 | 10 | BUILT_SYSTEMS:=$(filter-out msgs,$(shell ls build)) 11 | BUILT_APPS:=$(foreach SYSTEM, $(BUILT_SYSTEMS), $(foreach APP, $(shell ls build/$(SYSTEM)/apps), $(APP)-$(SYSTEM))) 12 | PROGRAM_TARGETS:=$(foreach APP, $(BUILT_APPS), program-$(APP)) 13 | GDB_TARGETS:=$(foreach APP, $(BUILT_APPS), gdb-$(APP)) 14 | RESET_TARGETS:=$(foreach APP, $(BUILT_APPS), reset-$(APP)) 15 | GDB_SERVER_TARGETS:=$(foreach APP, $(BUILT_APPS), gdb_server-$(APP)) 16 | 17 | utils/bin/console: 18 | cd utils && make 19 | 20 | $(SYSTEMS): %: build/% 21 | @echo $@ 22 | cd build/$@ && cmake ../.. -DSYSTEM=$@ -Dfreertps_standalone=ON && make --no-print-directory 23 | 24 | build/%: 25 | mkdir -p $@ 26 | 27 | clean: 28 | -rm -rf build 29 | 30 | OPENOCD=/usr/local/bin/openocd -f stm32/openocd/stlink-v2-1.cfg -f stm32/openocd/stm32f7-disco.cfg 31 | IMAGE=build.stm32/examples/listener.bin 32 | IMAGE_START=0x08000000 33 | 34 | list-apps: 35 | @echo $(PROGRAM_TARGETS) 36 | 37 | genmsg: 38 | r2/mega_genmsg.py 39 | 40 | .PHONY: $(PROGRAM_TARGETS) $(RESET_TARGETS) $(GDB_SERVER_TARGETS) $(GDB_TARGETS) list-apps genmsg 41 | 42 | $(PROGRAM_TARGETS) : 43 | scripts/task_runner program $(subst program-,,$@) 44 | 45 | $(RESET_TARGETS) : 46 | scripts/task_runner reset $(subst reset-,,$@) 47 | 48 | $(GDB_SERVER_TARGETS) : 49 | scripts/task_runner gdb_server $(subst gdb_server-,,$@) 50 | 51 | $(GDB_TARGETS) : 52 | # this is really ugly. but we want to run gdb inside Make rather than 53 | # through task_runner (for now, at least) so the console works right 54 | PROGRAM=$(firstword $(subst -, ,$(subst gdb-,,$@))); SYSTEM=$(word 2,$(subst -, ,$(subst gdb-,,$@))); OS=$(word 3,$(subst -, ,$(subst gdb-,,$@))); echo $$SYSTEM-$$OS; arm-none-eabi-gdb build/$$SYSTEM-$$OS/apps/$$PROGRAM/$$PROGRAM.elf -x systems/stm32_common/openocd/gdb_init_commands 55 | 56 | # echo $$SYSTEM 57 | 58 | #$(echo $$SYSTEM 59 | #scripts/task_runner gdb $(subst gdb-,,$@) 60 | 61 | #: build/$(firstword 62 | 63 | #%-program: 64 | # @echo $* 65 | 66 | #dump_flash: 67 | # $(OPENOCD) -c "init; halt; flash banks; dump_image dump.bin $(IMAGE_START) 0x1000; reset run; shutdown" 68 | 69 | #gdb_server: 70 | # $(OPENOCD) -c "init; halt" 71 | 72 | #gdb: 73 | # arm-none-eabi-gdb build.stm32/examples/listener.elf -x stm32/openocd/gdb_init_commands 74 | 75 | #reset: 76 | # $(OPENOCD) -c "init; sleep 100; halt; sleep 100; reset run; sleep 100; shutdown" 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/README.md -------------------------------------------------------------------------------- /apps/blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(blink blink.c) 2 | -------------------------------------------------------------------------------- /apps/blink/blink.c: -------------------------------------------------------------------------------- 1 | // initial minimal program to sanity-check systems 2 | #include "freertps/periph/led.h" 3 | 4 | int main(int argc, char **argv) 5 | { 6 | led_init(); 7 | while (1) 8 | { 9 | for (volatile int i = 0; i < 2000000; i++); 10 | led_toggle(); 11 | } 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /apps/cam/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(cam cam.c) 2 | -------------------------------------------------------------------------------- /apps/cpp_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(cpp_test main.cpp) 2 | -------------------------------------------------------------------------------- /apps/cpp_test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | std::cout << "Hello, World!" << std::endl; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /apps/enet_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(enet_test enet_test.c) 2 | -------------------------------------------------------------------------------- /apps/enet_test/enet_test.c: -------------------------------------------------------------------------------- 1 | // minimal program to just sit there and send nonsense UDP while listening 2 | // for pings. intended for sanity-checking and debugging low-level ethernet 3 | #include 4 | #include 5 | #include "metal/systime.h" 6 | #include "metal/enet.h" 7 | #include "freertps/udp.h" 8 | 9 | #define TX_INTERVAL 1000000 10 | 11 | int main(int argc, char **argv) 12 | { 13 | enet_init(); 14 | __enable_irq(); 15 | printf("hello world\r\n"); 16 | uint32_t last_tx_time = 0; 17 | int tx_count = 0; 18 | while (1) 19 | { 20 | enet_process_rx_ring(); 21 | uint32_t t = systime_usecs(); 22 | if (t - last_tx_time > TX_INTERVAL) 23 | { 24 | last_tx_time = t; 25 | printf("tx %d %d\r\n", tx_count++, (int)t); 26 | uint8_t payload[8] = {0}; 27 | frudp_tx(0x6801a8c0, 5000, payload, sizeof(payload)); 28 | } 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /apps/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(hello_world hello_world.c) 2 | -------------------------------------------------------------------------------- /apps/hello_world/hello_world.c: -------------------------------------------------------------------------------- 1 | // initial minimal program to sanity-check systems 2 | #include 3 | #include "freertps/periph/led.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | led_init(); 8 | int hello_count = 0; 9 | led_off(); 10 | while (1) 11 | { 12 | for (volatile int i = 0; i < 2000000; i++); 13 | printf("hello, world! %d\r\n", hello_count++); 14 | } 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /apps/imu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(imu imu.c) 2 | -------------------------------------------------------------------------------- /apps/imu/imu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | #include 4 | #include "freertps/periph/imu.h" 5 | #include "freertps/timer.h" 6 | #include "sensor_msgs/imu.h" 7 | 8 | frudp_pub_t *g_pub = NULL; 9 | 10 | void timer_cb(void) 11 | { 12 | if (!g_pub) 13 | return; // startup race condition. not ready yet. hold your horses. wait. 14 | 15 | static float xyz[3]; 16 | if (!imu_poll_accels(xyz)) 17 | { 18 | printf("woah! couldn't poll the imu!\r\n"); 19 | return; 20 | } 21 | //printf("imu: [%+8.3f, %+8.3f, %+8.3f]\r\n", 22 | // xyz[0], xyz[1], xyz[2]); 23 | static int pub_count = 0; 24 | pub_count++; 25 | 26 | static struct sensor_msgs__imu imu_msg; 27 | static char *g_frame_id = "imu_frame"; 28 | 29 | imu_msg.header.stamp.sec = 1234; 30 | imu_msg.header.stamp.nanosec = 5678; 31 | imu_msg.header.frame_id = g_frame_id; 32 | imu_msg.orientation.x = 1 + pub_count; 33 | imu_msg.orientation.y = 2; 34 | imu_msg.orientation.z = 3; 35 | imu_msg.orientation.w = 4; 36 | imu_msg.angular_velocity.x = 5; 37 | imu_msg.angular_velocity.y = 6; 38 | imu_msg.angular_velocity.z = 7; 39 | imu_msg.linear_acceleration.x = xyz[0]; 40 | imu_msg.linear_acceleration.y = xyz[1]; 41 | imu_msg.linear_acceleration.z = xyz[2]; 42 | for (int i = 0; i < 9; i++) 43 | { 44 | imu_msg.orientation_covariance[i] = 11 + i; 45 | imu_msg.angular_velocity_covariance[i] = 20 + i; 46 | imu_msg.linear_acceleration_covariance[i] = 29 + i; 47 | } 48 | 49 | static uint8_t __attribute__((aligned(4))) cdr[512] = {0}; 50 | uint32_t cdr_len = serialize_sensor_msgs__imu(&imu_msg, cdr, sizeof(cdr)); 51 | freertps_publish(g_pub, (uint8_t *)cdr, cdr_len); 52 | } 53 | 54 | int main(int argc, char **argv) 55 | { 56 | imu_init(); 57 | freertps_system_init(); 58 | freertps_timer_set_freq(10, timer_cb); 59 | //freertps_timer_set_freq(1000, timer_cb); 60 | printf("hello, world!\r\n"); 61 | g_pub = freertps_create_pub("imu", sensor_msgs__imu__type.rtps_typename); 62 | frudp_disco_start(); 63 | while (freertps_system_ok()) 64 | { 65 | frudp_listen(1000000); 66 | frudp_disco_tick(); 67 | } 68 | frudp_fini(); 69 | return 0; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /apps/led/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(led led.c) 2 | -------------------------------------------------------------------------------- /apps/led/led.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | #include "freertps/periph/led.h" 4 | 5 | void led_cb(const void *msg) 6 | { 7 | uint8_t led = *((uint8_t *)msg); 8 | if (led & 0x1) 9 | led_on(); 10 | else 11 | led_off(); 12 | } 13 | 14 | int main(int argc, char **argv) 15 | { 16 | freertps_system_init(); 17 | freertps_create_sub("led", "std_msgs::msg::dds_::Bool_", led_cb); 18 | freertps_start(); 19 | while (freertps_system_ok()) 20 | { 21 | frudp_listen(1000000); 22 | frudp_disco_tick(); 23 | } 24 | frudp_fini(); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /apps/listener/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(listener listener.c) 2 | -------------------------------------------------------------------------------- /apps/listener/listener.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | 4 | void chatter_cb(const void *msg) 5 | { 6 | uint32_t str_len = *((uint32_t *)msg); 7 | char buf[128] = {0}; 8 | for (int i = 0; i < str_len && i < sizeof(buf)-1; i++) 9 | buf[i] = ((uint8_t *)msg)[4+i]; 10 | printf("I heard: [%s]\n", buf); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | printf("hello, world!\r\n"); 16 | freertps_system_init(); 17 | freertps_create_sub("chatter", 18 | "std_msgs::msg::dds_::String_", 19 | chatter_cb); 20 | freertps_start(); // all pubs/subs are created. let's start! 21 | while (freertps_system_ok()) 22 | { 23 | frudp_listen(1000000); 24 | frudp_disco_tick(); 25 | } 26 | frudp_fini(); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /apps/listener_no_rosidl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(listener_no_rosidl listener_no_rosidl.c) 2 | -------------------------------------------------------------------------------- /apps/listener_no_rosidl/listener_no_rosidl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | 4 | void chatter_cb(const void *msg) 5 | { 6 | uint32_t str_len = *((uint32_t *)msg); 7 | char buf[128] = {0}; 8 | for (int i = 0; i < str_len && i < sizeof(buf)-1; i++) 9 | buf[i] = ((uint8_t *)msg)[4+i]; 10 | printf("I heard: [%s]\n", buf); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | printf("hello, world!\r\n"); 16 | freertps_system_init(); 17 | freertps_create_sub("chatter", 18 | "std_msgs::msg::dds_::String_", 19 | chatter_cb); 20 | frudp_disco_start(); // we're alive now; announce ourselves to the world 21 | while (freertps_system_ok()) 22 | { 23 | frudp_listen(1000000); 24 | frudp_disco_tick(); 25 | } 26 | frudp_fini(); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /apps/rx63n_gr_sakura_listener/listener_no_rosidl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | 4 | void chatter_cb(const void *msg) 5 | { 6 | uint32_t str_len = *((uint32_t *)msg); 7 | char buf[128] = {0}; 8 | for (int i = 0; i < str_len && i < sizeof(buf)-1; i++) 9 | buf[i] = ((uint8_t *)msg)[4+i]; 10 | printf("I heard: [%s]\n", buf); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | printf("hello, world!\r\n"); 16 | freertps_system_init(); 17 | freertps_create_sub("chatter", 18 | "std_msgs::msg::dds_::String_", 19 | chatter_cb); 20 | frudp_disco_start(); // we're alive now; announce ourselves to the world 21 | while (freertps_system_ok()) 22 | { 23 | frudp_listen(0); 24 | frudp_disco_tick(); 25 | } 26 | frudp_fini(); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /apps/rx63n_gr_sakura_talker/talker_no_rosidl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertps/freertps.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | printf("hello, world!\r\n"); 8 | freertps_system_init(); 9 | frudp_pub_t *pub = freertps_create_pub( 10 | "chatter", "std_msgs::msg::dds_::String_"); 11 | frudp_disco_start(); 12 | int pub_count = 0; 13 | char msg[64] = {0}; 14 | while (freertps_system_ok()) 15 | { 16 | frudp_listen(0); 17 | frudp_disco_tick(); 18 | snprintf(&msg[4], sizeof(msg) - 4, "Hello World: %d", pub_count++); 19 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 20 | uint32_t *str_len_ptr = (uint32_t *)msg; 21 | *str_len_ptr = rtps_string_len; 22 | freertps_publish(pub, (uint8_t *)msg, rtps_string_len + 4); 23 | printf("sending: [%s]\r\n", &msg[4]); 24 | } 25 | frudp_fini(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /apps/standalone_listen_for_n/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(standalone_listen_for_n standalone_listen_for_n.c) 2 | -------------------------------------------------------------------------------- /apps/standalone_listen_for_n/standalone_listen_for_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertps/freertps.h" 4 | 5 | static int n_msg_recv = 0; // cue the raptors plz 6 | 7 | void chatter_cb(const void *msg) 8 | { 9 | uint32_t str_len = *((uint32_t *)msg); 10 | char buf[128] = {0}; 11 | for (int i = 0; i < str_len && i < sizeof(buf)-1; i++) 12 | buf[i] = ((uint8_t *)msg)[4+i]; 13 | printf("I heard: [%s]\n", buf); 14 | n_msg_recv++; 15 | } 16 | 17 | int main(int argc, char **argv) 18 | { 19 | if (argc < 3) 20 | { 21 | printf("usage: standalone_listen_for_n N TIMEOUT_SECONDS\n"); 22 | return 1; 23 | } 24 | const int target_n_msg_recv = atoi(argv[1]); 25 | const double max_seconds = atof(argv[2]); 26 | fr_time_t t_start = fr_time_now(); 27 | freertps_system_init(); 28 | freertps_create_sub("chatter", 29 | "std_msgs::msg::dds_::String_", 30 | chatter_cb); 31 | frudp_disco_start(); // we're alive now; announce ourselves to the world 32 | while (freertps_system_ok()) 33 | { 34 | frudp_listen(100000); 35 | frudp_disco_tick(); // stayin' alive FLOOR-TOM FLOOR-TOM CYMBAL-CRASH 36 | fr_time_t t = fr_time_now(); 37 | fr_duration_t dt = fr_time_diff(&t, &t_start); 38 | double dt_secs = fr_duration_double(&dt); 39 | if (n_msg_recv >= target_n_msg_recv || 40 | dt_secs > max_seconds) 41 | break; 42 | } 43 | frudp_fini(); 44 | bool success = n_msg_recv >= target_n_msg_recv; 45 | if (success) 46 | printf("HOORAY, I received all the messages.\n"); 47 | else 48 | printf("SADNESS, I didn't receive all the messages.\n"); 49 | return success ? 0 : 1; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /apps/standalone_talk_n/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(standalone_talk_n standalone_talk_n.c) 2 | -------------------------------------------------------------------------------- /apps/standalone_talk_n/standalone_talk_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "freertps/freertps.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | if (argc < 3) 9 | { 10 | printf("usage: standalone_talk_n N DT_SECS\n"); 11 | return 1; 12 | } 13 | printf("HELLO WORLD I WILL TALK AS REQUESTED BECAUSE I AM A ROBOT\r\n"); 14 | const int n_msg = atoi(argv[1]); 15 | const double target_dt = atof(argv[2]); 16 | printf("sending %d messages at %.3f-second intervals\n", n_msg, target_dt); 17 | freertps_system_init(); 18 | frudp_pub_t *pub = freertps_create_pub( 19 | "chatter", "std_msgs::msg::dds_::String_"); 20 | frudp_disco_start(); 21 | char msg[64] = {0}; 22 | for (int pub_count = 0; 23 | pub_count < n_msg && freertps_system_ok(); 24 | pub_count++) 25 | { 26 | frudp_listen(target_dt * 1000000); 27 | frudp_disco_tick(); 28 | snprintf(&msg[4], sizeof(msg) - 4, "Hello World: %d", pub_count); 29 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 30 | uint32_t *str_len_ptr = (uint32_t *)msg; 31 | *str_len_ptr = rtps_string_len; 32 | freertps_publish(pub, (uint8_t *)msg, rtps_string_len + 4); 33 | printf("sending: [%s]\r\n", &msg[4]); 34 | } 35 | frudp_fini(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /apps/systime_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(systime_test systime_test.c) 2 | -------------------------------------------------------------------------------- /apps/systime_test/systime_test.c: -------------------------------------------------------------------------------- 1 | // minimal program to print the system time to the console 2 | #include 3 | #include 4 | #include "metal/systime.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | while (1) 9 | { 10 | uint32_t waste_time = 200000 + rand() % 10000; 11 | for (volatile int i = 0; i < waste_time; i++); 12 | float f = 1.0e-6 * (float)systime_usecs(); 13 | printf("%.6f\r\n", (double)f); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /apps/talker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(talker talker.c) 2 | -------------------------------------------------------------------------------- /apps/talker/talker.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | #include "std_msgs/string.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | freertps_system_init(); 8 | frudp_pub_t *pub = freertps_create_pub 9 | ("chatter", 10 | std_msgs__string__type.rtps_typename); 11 | frudp_disco_start(); 12 | 13 | struct std_msgs__string msg; 14 | char data_buf[64] = {0}; 15 | msg.data = data_buf; 16 | 17 | uint8_t cdr[68] = {0}; 18 | 19 | int pub_count = 0; 20 | while (freertps_system_ok()) 21 | { 22 | frudp_listen(500000); 23 | frudp_disco_tick(); 24 | snprintf(msg.data, sizeof(data_buf), "Hello, world! %d", pub_count++); 25 | int cdr_len = serialize_std_msgs__string(&msg, cdr, sizeof(cdr)); 26 | freertps_publish(pub, cdr, cdr_len); 27 | printf("sending: [%s]\r\n", data_buf); 28 | } 29 | frudp_fini(); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /apps/talker_no_rosidl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(talker_no_rosidl talker_no_rosidl.c) 2 | -------------------------------------------------------------------------------- /apps/talker_no_rosidl/talker_no_rosidl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertps/freertps.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | printf("hello, world!\r\n"); 8 | freertps_system_init(); 9 | frudp_pub_t *pub = freertps_create_pub( 10 | "chatter", "std_msgs::msg::dds_::String_"); 11 | frudp_disco_start(); 12 | int pub_count = 0; 13 | char msg[64] = {0}; 14 | while (freertps_system_ok()) 15 | { 16 | frudp_listen(500000); 17 | frudp_disco_tick(); 18 | snprintf(&msg[4], sizeof(msg) - 4, "Hello World: %d", pub_count++); 19 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 20 | uint32_t *str_len_ptr = (uint32_t *)msg; 21 | *str_len_ptr = rtps_string_len; 22 | freertps_publish(pub, (uint8_t *)msg, rtps_string_len + 4); 23 | printf("sending: [%s]\r\n", &msg[4]); 24 | } 25 | frudp_fini(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /apps/talker_stm32_timer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(talker_stm32_timer talker_stm32_timer.c) 2 | -------------------------------------------------------------------------------- /apps/talker_stm32_timer/talker_stm32_timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | #include 4 | 5 | frudp_pub_t *g_pub = NULL; 6 | 7 | void tim5_vector(void) 8 | { 9 | TIM5->SR &= ~TIM_SR_UIF; // clear the update flag 10 | if (!g_pub) 11 | return; 12 | static char __attribute__((aligned(4))) msg[256] = {0}; 13 | static int pub_count = 0; 14 | snprintf(&msg[4], sizeof(msg), "Hello World: %d", pub_count++); 15 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 16 | *((uint32_t *)msg) = rtps_string_len; 17 | freertps_publish(g_pub, (uint8_t *)msg, rtps_string_len + 4); 18 | } 19 | 20 | int main(int argc, char **argv) 21 | { 22 | // set up TIM5 to be our tx timer 23 | RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; 24 | TIM5->PSC = 168000000 / 2 / 1000000 - 1; // microsecond resolution 25 | TIM5->ARR = 1000 - 1; // auto-reload @ 1000 Hz 26 | TIM5->EGR = TIM_EGR_UG; // load PSC immediately 27 | TIM5->CR1 = TIM_CR1_CEN; // start it counting 28 | TIM5->DIER = TIM_DIER_UIE; // enable update interrupt 29 | NVIC_SetPriority(TIM5_IRQn, 2); 30 | NVIC_EnableIRQ(TIM5_IRQn); 31 | 32 | printf("hello, world!\r\n"); 33 | freertps_system_init(); 34 | g_pub = freertps_create_pub 35 | ("chatter", "std_msgs::msg::dds_::String_"); 36 | while (freertps_system_ok()) 37 | { 38 | frudp_listen(1000000); 39 | frudp_disco_tick(); 40 | //printf("sending: [%s]\n", &msg[4]); 41 | } 42 | frudp_fini(); 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /apps/usb_cam/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(usb_cam usb_cam.c usb_desc.c) 2 | -------------------------------------------------------------------------------- /apps/usb_cam/usb_desc.c: -------------------------------------------------------------------------------- 1 | #include "metal/usb.h" 2 | 3 | const struct usb_device_desc g_usb_device_desc = 4 | { 5 | sizeof(struct usb_device_desc), 6 | METAL_USB_DESC_TYPE_DEVICE, 7 | METAL_USB_PROTO, 8 | METAL_USB_DEV_CLASS_CUSTOM, 9 | METAL_USB_DEV_SUBCLASS_CUSTOM, 10 | METAL_USB_DEV_PROTO_CUSTOM, 11 | METAL_USB_MAX_EP0_PKT_SIZE, 12 | METAL_USB_VID, 13 | 0x2601, 14 | METAL_USB_BCD_DEV, 15 | METAL_USB_NO_MFGR_STR, 16 | METAL_USB_NO_PROD_STR, 17 | METAL_USB_NO_SERIAL_STR 18 | }; 19 | 20 | void f(void) { } 21 | -------------------------------------------------------------------------------- /apps/usb_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(usb_test usb_test.c) 2 | -------------------------------------------------------------------------------- /apps/usb_test/usb_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "metal/systime.h" 3 | #include "metal/usb.h" 4 | #include "freertps/periph/led.h" 5 | 6 | #define TX_INTERVAL 1000000 7 | 8 | int main(int argc, char **argv) 9 | { 10 | usb_init(); 11 | __enable_irq(); 12 | uint32_t last_tx_time = 0; 13 | while (1) 14 | { 15 | uint32_t t = systime_usecs(); 16 | if (t - last_tx_time > TX_INTERVAL) 17 | { 18 | last_tx_time = t; 19 | led_toggle(); 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /disco.c: -------------------------------------------------------------------------------- 1 | #include "freertps/disco.h" 2 | #include "freertps/spdp.h" 3 | #include "freertps/sedp.h" 4 | 5 | uint8_t g_frudp_disco_tx_buf[FRUDP_DISCO_TX_BUFLEN]; 6 | uint16_t g_frudp_disco_tx_buf_wpos; 7 | 8 | frudp_part_t g_frudp_disco_parts[FRUDP_DISCO_MAX_PARTS]; 9 | int g_frudp_disco_num_parts = 0; 10 | 11 | //////////////////////////////////////////////////////////////// 12 | 13 | void frudp_disco_init(void) 14 | { 15 | FREERTPS_INFO("discovery init\r\n"); 16 | frudp_spdp_init(); 17 | frudp_sedp_init(); 18 | } 19 | 20 | void frudp_disco_start(void) 21 | { 22 | FREERTPS_INFO("discovery start\r\n"); 23 | frudp_spdp_start(); 24 | frudp_sedp_start(); 25 | } 26 | 27 | void frudp_disco_fini(void) 28 | { 29 | FREERTPS_INFO("discovery fini\r\n"); 30 | frudp_spdp_fini(); 31 | frudp_sedp_fini(); 32 | } 33 | 34 | void frudp_disco_tick(void) 35 | { 36 | frudp_spdp_tick(); 37 | frudp_sedp_tick(); 38 | } 39 | -------------------------------------------------------------------------------- /docs/renesas_rx/images/GR-SAKURA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/GR-SAKURA.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus1.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus10.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus10_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus10_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus11.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus11_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus11_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus12.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus13.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus14.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus1_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus1_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus2.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus2_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus2_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus3.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus3_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus3_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus4.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus4_2.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus4_2_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus4_2_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus4_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus4_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus5.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus5_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus5_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus6.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus6_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus6_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus7.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus7_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus7_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus8.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus8_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus8_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus9.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus9_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus9_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import1.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import1_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import1_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import2.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import2_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import2_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import3.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import3_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import3_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import4.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import4_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import4_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import5.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import5_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import5_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import6.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import6_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import6_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import7.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import7_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import7_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import8.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import8_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import8_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import9.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/csplus_import9_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/csplus_import9_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt1.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt10.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt10_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt10_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt11.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt11_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt11_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt12.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt12_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt12_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt1_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt1_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt2.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt2_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt2_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt3.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt3_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt3_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt4.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt4_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt4_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt5.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt5_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt5_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt6.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt7.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt7_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt7_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt8.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt8_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt8_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt9.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/fdt9_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/fdt9_en.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/reset_sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/reset_sw.png -------------------------------------------------------------------------------- /docs/renesas_rx/images/slide_sw3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/docs/renesas_rx/images/slide_sw3.png -------------------------------------------------------------------------------- /freertps.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertps/freertps.h" 4 | #include "freertps/udp.h" 5 | #include "freertps/sub.h" 6 | 7 | bool g_freertps_init_complete; 8 | 9 | void freertps_perish_if(bool b, const char *msg) 10 | { 11 | if (b) 12 | { 13 | FREERTPS_FATAL("%s\n", msg); 14 | #if __RX == 1 15 | while(1){} 16 | #else /* __RX == 1 */ 17 | exit(1); 18 | #endif /* __RX == 1 */ 19 | } 20 | } 21 | 22 | // todo: return something 23 | void freertps_create_sub(const char *topic_name, 24 | const char *type_name, 25 | freertps_msg_cb_t msg_cb) 26 | { 27 | // assume for now that we are only using UDP. in the future, this can 28 | // become smarter to handle when different (or multiple?) physical layer 29 | // are initialized 30 | frudp_add_user_sub(topic_name, type_name, msg_cb); 31 | //g_rtps_psm.create_sub(topic_name, type 32 | } 33 | 34 | frudp_pub_t *freertps_create_pub(const char *topic_name, 35 | const char *type_name) 36 | { 37 | // assume for now that we are only using UDP. in the future, this can 38 | // become smarter to handle when different (or multiple?) physical layers 39 | // are initialized 40 | return frudp_create_user_pub(topic_name, type_name); 41 | } 42 | 43 | bool freertps_publish(frudp_pub_t *pub, 44 | const uint8_t *msg, 45 | const uint32_t msg_len) 46 | { 47 | // todo: other physical layers... 48 | return frudp_publish_user_msg(pub, msg, msg_len); 49 | } 50 | 51 | void freertps_start(void) 52 | { 53 | // todo: other physical layers... 54 | frudp_disco_start(); 55 | } 56 | -------------------------------------------------------------------------------- /id.c: -------------------------------------------------------------------------------- 1 | #include "freertps/id.h" 2 | #include 3 | #include 4 | #include "freertps/bswap.h" 5 | 6 | static unsigned g_frudp_next_user_eid = 1; 7 | 8 | const frudp_guid_t g_frudp_guid_unknown = { .prefix = { .prefix = {0} }, 9 | .eid = { .u = 0 } }; 10 | 11 | const char *frudp_vendor(const frudp_vid_t vid) 12 | { 13 | switch (vid) 14 | { 15 | case 0x0101: return "RTI Connext"; 16 | case 0x0102: return "PrismTech OpenSplice"; 17 | case 0x0103: return "OCI OpenDDS"; 18 | case 0x0104: return "MilSoft"; 19 | case 0x0105: return "Gallium InterCOM"; 20 | case 0x0106: return "TwinOaks CoreDX"; 21 | case 0x0107: return "Lakota Technical Systems"; 22 | case 0x0108: return "ICOUP Consulting"; 23 | case 0x0109: return "ETRI"; 24 | case 0x010a: return "RTI Connext Micro"; 25 | case 0x010b: return "PrismTech Vortex Cafe"; 26 | case 0x010c: return "PrismTech Vortex Gateway"; 27 | case 0x010d: return "PrismTech Vortex Lite"; 28 | case 0x010e: return "Technicolor Qeo"; 29 | case 0x010f: return "eProsima"; 30 | case 0x0120: return "PrismTech Vortex Cloud"; 31 | case FREERTPS_VENDOR_ID: return "freertps"; 32 | default: return "unknown"; 33 | } 34 | } 35 | 36 | bool frudp_guid_prefix_identical(frudp_guid_prefix_t * const a, 37 | frudp_guid_prefix_t * const b) 38 | { 39 | for (int i = 0; i < FRUDP_GUID_PREFIX_LEN; i++) 40 | if (a->prefix[i] != b->prefix[i]) 41 | return false; 42 | return true; 43 | } 44 | 45 | bool frudp_guid_identical(const frudp_guid_t * const a, 46 | const frudp_guid_t * const b) 47 | { 48 | if (a->eid.u != b->eid.u) 49 | return false; 50 | for (int i = 0; i < FRUDP_GUID_PREFIX_LEN; i++) 51 | if (a->prefix.prefix[i] != b->prefix.prefix[i]) 52 | return false; 53 | return true; 54 | } 55 | 56 | void frudp_print_guid_prefix(const frudp_guid_prefix_t *p) 57 | { 58 | printf("%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x", 59 | (unsigned)p->prefix[0], 60 | (unsigned)p->prefix[1], 61 | (unsigned)p->prefix[2], 62 | (unsigned)p->prefix[3], 63 | (unsigned)p->prefix[4], 64 | (unsigned)p->prefix[5], 65 | (unsigned)p->prefix[6], 66 | (unsigned)p->prefix[7], 67 | (unsigned)p->prefix[8], 68 | (unsigned)p->prefix[9], 69 | (unsigned)p->prefix[10], 70 | (unsigned)p->prefix[11]); 71 | } 72 | 73 | void frudp_stuff_guid(frudp_guid_t *guid, 74 | const frudp_guid_prefix_t *prefix, 75 | const frudp_eid_t *id) 76 | { 77 | memcpy(&guid->prefix, prefix, sizeof(frudp_guid_prefix_t)); 78 | guid->eid = *id; 79 | } 80 | 81 | void frudp_print_guid(const frudp_guid_t *guid) 82 | { 83 | frudp_print_guid_prefix(&guid->prefix); 84 | printf(":%08x", (unsigned)freertps_htonl(guid->eid.u)); 85 | } 86 | 87 | frudp_eid_t frudp_create_user_id(const uint8_t entity_kind) 88 | { 89 | printf("frudp_create_user_id()\r\n"); 90 | frudp_eid_t eid; 91 | eid.s.kind = entity_kind; // entity kind must be set by caller of this functionmust be overwritten by FRUDP_ENTITY_KIND_USER_READER_NO_KEY; // has key? dunno 92 | eid.s.key[0] = 0; 93 | eid.s.key[1] = 0; // todo: >8 bit ID's 94 | eid.s.key[2] = g_frudp_next_user_eid++; 95 | return eid; 96 | } 97 | -------------------------------------------------------------------------------- /include/freertps/bswap.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_BSWAP_H 2 | #define FREERTPS_BSWAP_H 3 | 4 | #include 5 | 6 | // todo: something clever with inlining someday, if this matters 7 | uint32_t freertps_htonl(uint32_t u); 8 | uint16_t freertps_htons(uint16_t u); 9 | uint32_t freertps_ntohl(uint32_t u); 10 | uint16_t freertps_ntohs(uint16_t u); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /include/freertps/config.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_CONFIG_H 2 | #define FREERTPS_CONFIG_H 3 | 4 | #include 5 | #include "freertps/id.h" 6 | 7 | 8 | // default multicast group is 239.255.0.1 9 | #define FRUDP_DEFAULT_MCAST_GROUP 0xefff0001 10 | //#define FRUDP_DOMAIN_ID 0 11 | 12 | #define FRUDP_MAX_PUBS 5 13 | #define FRUDP_MAX_SUBS 5 14 | #define FRUDP_MAX_READERS 50 15 | #define FRUDP_MAX_WRITERS 50 16 | #define FRUDP_DISCO_MAX_PARTS 50 17 | 18 | #define FRUDP_MAX_TOPIC_NAME_LEN 128 19 | #define FRUDP_MAX_TYPE_NAME_LEN 128 20 | 21 | typedef struct 22 | { 23 | frudp_guid_prefix_t guid_prefix; 24 | int participant_id; 25 | uint32_t domain_id; 26 | uint32_t unicast_addr; 27 | } frudp_config_t; 28 | extern frudp_config_t g_frudp_config; 29 | 30 | #define VERBOSE_MSG_RX 31 | //#define VERBOSE_HEARTBEAT 32 | //#define VERBOSE_DATA 33 | //#define VERBOSE_ACKNACK 34 | //#define VERBOSE_GAP 35 | 36 | //#define VERBOSE_TX_ACKNACK 37 | //#define SEDP_VERBOSE 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/freertps/disco.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_DISCO_H 2 | #define FREERTPS_DISCO_H 3 | 4 | // this has a bunch of discovery-related debris 5 | 6 | #include 7 | #include "freertps/part.h" 8 | #include "freertps/config.h" 9 | 10 | #define FRUDP_PID_PAD 0x0000 11 | #define FRUDP_PID_SENTINEL 0x0001 12 | #define FRUDP_PID_PARTICIPANT_LEASE_DURATION 0x0002 13 | #define FRUDP_PID_TOPIC_NAME 0x0005 14 | #define FRUDP_PID_TYPE_NAME 0x0007 15 | #define FRUDP_PID_RELIABILITY 0x001a 16 | #define FRUDP_PID_PROTOCOL_VERSION 0x0015 17 | #define FRUDP_PID_VENDOR_ID 0x0016 18 | #define FRUDP_PID_RELIABILITY 0x001a 19 | #define FRUDP_PID_LIVELINESS 0x001b 20 | #define FRUDP_PID_DURABILITY 0x001d 21 | #define FRUDP_PID_PRESENTATION 0x0021 22 | #define FRUDP_PID_PARTITION 0x0029 23 | #define FRUDP_PID_DEFAULT_UNICAST_LOCATOR 0x0031 24 | #define FRUDP_PID_METATRAFFIC_UNICAST_LOCATOR 0x0032 25 | #define FRUDP_PID_METATRAFFIC_MULTICAST_LOCATOR 0x0033 26 | #define FRUDP_PID_HISTORY 0x0040 27 | #define FRUDP_PID_DEFAULT_MULTICAST_LOCATOR 0x0048 28 | #define FRUDP_PID_TRANSPORT_PRIORITY 0x0049 29 | #define FRUDP_PID_PARTICIPANT_GUID 0x0050 30 | #define FRUDP_PID_BUILTIN_ENDPOINT_SET 0x0058 31 | #define FRUDP_PID_PROPERTY_LIST 0x0059 32 | #define FRUDP_PID_ENDPOINT_GUID 0x005a 33 | #define FRUDP_PID_KEY_HASH 0x0070 34 | 35 | #define FRUDP_BUILTIN_EP_PARTICIPANT_ANNOUNCER 0x00000001 36 | #define FRUDP_BUILTIN_EP_PARTICIPANT_DETECTOR 0x00000002 37 | #define FRUDP_BUILTIN_EP_PUBLICATION_ANNOUNCER 0x00000004 38 | #define FRUDP_BUILTIN_EP_PUBLICATION_DETECTOR 0x00000008 39 | #define FRUDP_BUILTIN_EP_SUBSCRIPTION_ANNOUNCER 0x00000010 40 | #define FRUDP_BUILTIN_EP_SUBSCRIPTION_DETECTOR 0x00000020 41 | #define FRUDP_BUILTIN_EP_PARTICIPANT_PROXY_ANNOUNCER 0x00000040 42 | #define FRUDP_BUILTIN_EP_PARTICIPANT_PROXY_DETECTOR 0x00000080 43 | #define FRUDP_BUILTIN_EP_PARTICIPANT_STATE_ANNOUNCER 0x00000100 44 | #define FRUDP_BUILTIN_EP_PARTICIPANT_STATE_DETECTOR 0x00000200 45 | #define FRUDP_BUILTIN_EP_PARTICIPANT_MESSAGE_DATA_WRITER 0x00000400 46 | #define FRUDP_BUILTIN_EP_PARTICIPANT_MESSAGE_DATA_READER 0x00000800 47 | 48 | void frudp_disco_init(void); 49 | void frudp_disco_fini(void); 50 | 51 | void frudp_disco_start(void); /// must be called to kick off discovery 52 | void frudp_disco_tick(void); /// must be called periodically to broadcast SPDP 53 | 54 | #define FRUDP_DISCO_TX_BUFLEN 1536 55 | extern uint8_t g_frudp_disco_tx_buf[FRUDP_DISCO_TX_BUFLEN]; 56 | extern uint16_t g_frudp_disco_tx_buf_wpos; 57 | 58 | extern frudp_part_t g_frudp_disco_parts[FRUDP_DISCO_MAX_PARTS]; 59 | extern int g_frudp_disco_num_parts; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/freertps/freertps.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_H 2 | #define FREERTPS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | // NOTE: the prefix freertps_udp_ is too long to type, so it will often 11 | // be shortened to frudp_ 12 | 13 | typedef void (*freertps_msg_cb_t)(const void *msg); 14 | 15 | #include "freertps/udp.h" 16 | #include "freertps/config.h" 17 | #include "freertps/time.h" 18 | #include "freertps/ports.h" 19 | #include "freertps/locator.h" 20 | #include "freertps/disco.h" 21 | #include "freertps/bswap.h" 22 | #include "freertps/system.h" 23 | #include "freertps/pub.h" 24 | #include "freertps/sub.h" 25 | 26 | // maybe make this smarter someday 27 | #define FREERTPS_INFO(...) \ 28 | do { printf("freertps INFO : "); printf(__VA_ARGS__); } while (0) 29 | #define FREERTPS_ERROR(...) \ 30 | do { printf("freertps ERROR: "); printf(__VA_ARGS__); } while (0) 31 | #define FREERTPS_FATAL(...) \ 32 | do { printf("freertps FATAL: "); printf(__VA_ARGS__); } while (0) 33 | 34 | #ifdef __GNUC__ 35 | typedef union rtps_active_psms 36 | { 37 | uint32_t val; 38 | struct rtps_active_psms_mask 39 | { 40 | uint32_t udp : 1; 41 | uint32_t ser : 1; 42 | } s; 43 | } __attribute__((packed)) rtps_active_psms_t; 44 | #elif __RX == 1 45 | #pragma pack 46 | typedef union rtps_active_psms 47 | { 48 | uint32_t val; 49 | struct rtps_active_psms_mask 50 | { 51 | uint32_t udp : 1; 52 | uint32_t ser : 1; 53 | } s; 54 | } rtps_active_psms_t; 55 | #pragma unpack 56 | #endif /* __RX ==1 */ 57 | 58 | extern union rtps_active_psms g_rtps_active_psms; 59 | 60 | void freertps_create_sub(const char *topic_name, 61 | const char *type_name, 62 | freertps_msg_cb_t msg_cb); 63 | 64 | // todo: come up with a better way of holding onto publishers that is 65 | // agnostic to the physical layer 66 | frudp_pub_t *freertps_create_pub(const char *topic_name, 67 | const char *type_name); 68 | 69 | bool freertps_publish(frudp_pub_t *pub, 70 | const uint8_t *msg, 71 | const uint32_t msg_len); 72 | //void freertps_perish_if(bool b, const char *msg); 73 | 74 | extern bool g_freertps_init_complete; 75 | 76 | void freertps_start(void); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /include/freertps/id.h: -------------------------------------------------------------------------------- 1 | #ifndef FRUDP_ID_H 2 | #define FRUDP_ID_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __GNUC__ 8 | typedef union 9 | { 10 | struct 11 | { 12 | uint8_t key[3]; 13 | uint8_t kind; 14 | } s; 15 | uint32_t u; 16 | } __attribute__((packed)) frudp_eid_t; // entity ID 17 | #elif __RX == 1 18 | #pragma pack 19 | typedef union 20 | { 21 | struct 22 | { 23 | uint8_t key[3]; 24 | uint8_t kind; 25 | } s; 26 | uint32_t u; 27 | } frudp_eid_t; // entity ID 28 | #pragma unpack 29 | #endif /* __RX == 1 */ 30 | 31 | #define FRUDP_ENTITY_KIND_USER_WRITER_WITH_KEY 0x02 32 | #define FRUDP_ENTITY_KIND_USER_WRITER_NO_KEY 0x03 33 | #define FRUDP_ENTITY_KIND_USER_READER_NO_KEY 0x04 34 | #define FRUDP_ENTITY_KIND_USER_READER_WITH_KEY 0x07 35 | 36 | extern const frudp_eid_t g_frudp_eid_unknown; 37 | 38 | #define FRUDP_GUID_PREFIX_LEN 12 39 | typedef struct 40 | { 41 | uint8_t prefix[FRUDP_GUID_PREFIX_LEN]; 42 | } frudp_guid_prefix_t; 43 | 44 | #ifdef __GNUC__ 45 | typedef struct 46 | { 47 | frudp_guid_prefix_t prefix; 48 | frudp_eid_t eid; 49 | } __attribute__((packed)) frudp_guid_t; 50 | #elif __RX == 1 51 | #pragma pack 52 | typedef struct 53 | { 54 | frudp_guid_prefix_t prefix; 55 | frudp_eid_t eid; 56 | } frudp_guid_t; 57 | #pragma unpack 58 | #endif /* __RX == 1 */ 59 | extern const frudp_guid_t g_frudp_guid_unknown; 60 | 61 | bool frudp_guid_prefix_identical(frudp_guid_prefix_t * const a, 62 | frudp_guid_prefix_t * const b); 63 | 64 | bool frudp_guid_identical(const frudp_guid_t * const a, 65 | const frudp_guid_t * const b); 66 | 67 | void frudp_stuff_guid(frudp_guid_t *guid, 68 | const frudp_guid_prefix_t *prefix, 69 | const frudp_eid_t *id); 70 | 71 | ///////////////////////////////////////////////////////////////////////// 72 | // VENDOR ID STUFF 73 | // for now let's pretend that our vendor ID is 11311 in hex 74 | #define FREERTPS_VENDOR_ID 0x2C2F 75 | typedef uint16_t frudp_vid_t; 76 | const char *frudp_vendor(const frudp_vid_t vid); 77 | 78 | void frudp_print_guid_prefix(const frudp_guid_prefix_t *guid_prefix); 79 | void frudp_print_guid(const frudp_guid_t *guid); 80 | 81 | frudp_eid_t frudp_create_user_id(const uint8_t entity_kind); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/freertps/locator.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_LOCATOR_H 2 | #define FREERTPS_LOCATOR_H 3 | 4 | #include 5 | 6 | #define FRUDP_LOCATOR_KIND_INVALID -1 7 | #define FRUDP_LOCATOR_KIND_RESERVED 0 8 | #define FRUDP_LOCATOR_KIND_UDPV4 1 9 | #define FRUDP_LOCATOR_KIND_UDPV6 2 10 | 11 | #ifdef __GNUC__ 12 | typedef struct 13 | { 14 | int32_t kind; 15 | uint32_t port; 16 | union 17 | { 18 | uint8_t raw[16]; 19 | struct 20 | { 21 | uint8_t zeros[12]; 22 | uint32_t addr; 23 | } udp4; 24 | } addr; 25 | } __attribute__((packed)) frudp_locator_t; 26 | #elif __RX == 1 27 | #pragma pack 28 | typedef struct 29 | { 30 | int32_t kind; 31 | uint32_t port; 32 | union 33 | { 34 | uint8_t raw[16]; 35 | struct 36 | { 37 | uint8_t zeros[12]; 38 | uint32_t addr; 39 | } udp4; 40 | } addr; 41 | } frudp_locator_t; 42 | #pragma unpack 43 | #endif /* __RX == 1 */ 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/freertps/part.h: -------------------------------------------------------------------------------- 1 | #ifndef FRUDP_PART_H 2 | #define FRUDP_PART_H 3 | 4 | #include "freertps/udp.h" 5 | #include "freertps/locator.h" 6 | #include 7 | 8 | typedef struct 9 | { 10 | frudp_pver_t pver; 11 | frudp_vid_t vid; 12 | frudp_guid_prefix_t guid_prefix; 13 | bool expects_inline_qos; 14 | frudp_locator_t default_unicast_locator; 15 | frudp_locator_t default_multicast_locator; 16 | frudp_locator_t metatraffic_unicast_locator; 17 | frudp_locator_t metatraffic_multicast_locator; 18 | frudp_duration_t lease_duration; 19 | frudp_builtin_endpoint_set_t builtin_endpoints; 20 | } frudp_part_t; 21 | 22 | frudp_part_t *frudp_part_find(const frudp_guid_prefix_t *guid_prefix); 23 | bool frudp_part_create(void); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/freertps/periph/cam.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_CAM_H 2 | #define FREERTPS_CAM_H 3 | 4 | #include 5 | 6 | void cam_init(void); // image_cb_t cb, image_cb_t dma_cb); 7 | extern volatile uint8_t *g_cam_frame_buffer; 8 | 9 | typedef void (*cam_image_cb_t)(void); 10 | void cam_set_image_cb(cam_image_cb_t cb); 11 | 12 | void cam_start_image_capture(void); 13 | bool cam_image_ready(void); 14 | 15 | #if 0 16 | #define BUFFER_SIZE 0x2850 17 | static uint32_t __attribute__((unused)) aDST_Buffer[BUFFER_SIZE]; 18 | 19 | 20 | typedef enum{CAMERA_FRAMERATE_15FPS,CAMERA_FRAMERATE_30FPS} camera_framerate_t; 21 | typedef enum{CAMERA_COLOR_RGB_565,CAMERA_COLOR_RGB_555,CAMERA_COLOR_YUV} camera_colorspace_t; 22 | typedef enum{CAMERA_RESOLUTION_VGA,CAMERA_RESOLUTION_QVGA,CAMERA_RESOLUTION_QQVGA} camera_resolution_t; 23 | typedef enum{CAMERA_MODE_SNAPSHOT,CAMERA_MODE_CONTINUOUS} camera_mode_t; 24 | typedef enum{DATA_8_BITS,DATA_10_BITS,DATA_12_BITS,DATA_14_BITS} dcmi_data_width_t; 25 | typedef struct 26 | { 27 | camera_colorspace_t colorspace; 28 | camera_mode_t mode; 29 | camera_resolution_t resolution; 30 | camera_framerate_t framerate; 31 | // add other stuff which should be valid for any camera 32 | } __attribute__((packed)) camera_config_t; 33 | 34 | void camera_init(image_cb_t cb, image_cb_t dma_cb); 35 | void camera_reset(void); 36 | 37 | // generic function, make them weak ? 38 | void camera_set_framerate(camera_framerate_t framerate); 39 | void camera_set_color(camera_colorspace_t color_format); 40 | void camera_set_resolution(camera_resolution_t resolution); 41 | void camera_set_mode(camera_mode_t mode); 42 | void camera_set_nightmode(uint8_t mode); 43 | void camera_take_snapshot(void); 44 | void camera_increase_brightness(void); 45 | void camera_decrease_brightness(void); 46 | void camera_increase_contrast(void); 47 | void camera_decrease_contrast(void); 48 | 49 | // BSP Functions 50 | void camera_power_up(void); // Idem 51 | void camera_power_down(void); // Idem 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/freertps/periph/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_I2C_H 2 | #define FREERTPS_I2C_H 3 | 4 | #include 5 | #include 6 | 7 | bool i2c_init(void *i2c); 8 | 9 | bool i2c_read(void *i2c, uint8_t device_addr, 10 | uint8_t reg_addr, uint8_t len, uint8_t *buffer); 11 | 12 | bool i2c_write(void *i2c, uint8_t device_addr, 13 | uint8_t reg_addr, uint8_t len, uint8_t *buffer); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/freertps/periph/imu.h: -------------------------------------------------------------------------------- 1 | #ifndef IMU_H 2 | #define IMU_H 3 | 4 | #include 5 | 6 | void imu_init(void); 7 | bool imu_poll_accels(float *xyz); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/freertps/periph/led.h: -------------------------------------------------------------------------------- 1 | #ifndef LED_H 2 | #define LED_H 3 | 4 | // todo: extend this for multiple LEDs as well, maybe by using plurals, like 5 | // leds_on(uint32_t mask), etc. etc. 6 | 7 | void led_init(void); 8 | void led_on(void); 9 | void led_off(void); 10 | void led_toggle(void); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /include/freertps/ports.h: -------------------------------------------------------------------------------- 1 | #ifndef FRUDP_PORTS_H 2 | #define FRUDP_PORTS_H 3 | 4 | ///////////////////////////////////////////////////////////////////// 5 | // A FEW CONSTANTS FROM THE SPEC 6 | ///////////////////////////////////////////////////////////////////// 7 | 8 | #define FRUDP_PORT_PB 7400 9 | #define FRUDP_PORT_DG 250 10 | #define FRUDP_PORT_PG 2 11 | #define FRUDP_PORT_D0 0 12 | #define FRUDP_PORT_D1 10 13 | #define FRUDP_PORT_D2 1 14 | #define FRUDP_PORT_D3 11 15 | 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/freertps/psm.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_PSM_H 2 | #define FREERTPS_PSM_H 3 | 4 | #include "freertps/pub.h" 5 | 6 | typedef bool (*rtps_psm_init_func_t)(void); 7 | typedef void (*rtps_psm_disco_func_t)(void); 8 | typedef frudp_pub_t *(*rtps_psm_create_pub_func_t)( 9 | const char *topic_name, const char *type_name); 10 | typedef void (*rtps_psm_create_sub_func_t)( 11 | const char *topic_name, const char *type_name, freertps_msg_cb_t msg_cb); 12 | typedef void (*rtps_psm_pub_func_t)( 13 | void *pub, const uint8_t *msg, const uint32_t msg_len); 14 | 15 | struct rtps_psm 16 | { 17 | rtps_psm_init_func_t init; 18 | rtps_psm_disco_func_t disco; 19 | rtps_psm_create_pub_func_t create_pub; 20 | rtps_psm_create_sub_func_t create_sub; 21 | rtps_psm_pub_func_t pub; 22 | }; 23 | 24 | extern struct rtps_psm g_rtps_psm; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/freertps/psm/ser.h: -------------------------------------------------------------------------------- 1 | #ifndef RTPS_PSM_SER 2 | #define RTPS_PSM_SER 3 | 4 | void rtps_ser_init(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/freertps/pub.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_PUB_H 2 | #define FREERTPS_PUB_H 3 | 4 | #include "freertps/udp.h" 5 | #include "freertps/id.h" 6 | #include "freertps/config.h" 7 | #include "freertps/part.h" 8 | #include 9 | 10 | typedef struct 11 | { 12 | const char *topic_name; 13 | const char *type_name; 14 | frudp_eid_t writer_eid; 15 | frudp_sn_t max_tx_sn_avail; 16 | frudp_sn_t min_tx_sn_avail; 17 | uint32_t num_data_submsgs; 18 | frudp_submsg_data_t **data_submsgs; 19 | uint32_t next_submsg_idx; 20 | frudp_sn_t next_sn; 21 | bool reliable; 22 | } frudp_pub_t; 23 | 24 | extern frudp_pub_t g_frudp_pubs[FRUDP_MAX_PUBS]; 25 | extern uint32_t g_frudp_num_pubs; 26 | 27 | ////////////////////////////////////////////////////////////// 28 | 29 | typedef struct 30 | { 31 | frudp_guid_t reader_guid; 32 | frudp_eid_t writer_eid; 33 | } frudp_writer_t; // currently only supports best-effort connections 34 | 35 | extern frudp_writer_t g_frudp_writers[FRUDP_MAX_WRITERS]; 36 | extern uint32_t g_frudp_num_writers; 37 | 38 | ////////////////////////////////////////////////////////////// 39 | 40 | frudp_pub_t *frudp_create_pub(const char *topic_name, 41 | const char *type_name, 42 | const frudp_eid_t writer_id, 43 | frudp_submsg_data_t **data_submsgs, 44 | const uint32_t num_data_submsgs); 45 | 46 | void frudp_publish(frudp_pub_t *publication, 47 | frudp_submsg_data_t *submsg); 48 | 49 | bool frudp_publish_user_msg(frudp_pub_t *publication, 50 | const uint8_t *msg, const uint32_t msg_len); 51 | 52 | bool frudp_publish_user_msg_frag( 53 | frudp_pub_t *publication, 54 | const uint32_t frag_num, 55 | const uint8_t *frag, 56 | const uint32_t frag_len, 57 | const uint32_t frag_used_len, 58 | const uint32_t msg_len); 59 | 60 | frudp_pub_t *frudp_pub_from_writer_id(const frudp_eid_t id); 61 | 62 | void frudp_pub_rx_acknack(frudp_pub_t *pub, 63 | frudp_submsg_acknack_t *acknack, 64 | frudp_guid_prefix_t *guid_prefix); 65 | 66 | frudp_pub_t *frudp_create_user_pub(const char *topic_name, 67 | const char *type_name); 68 | 69 | void frudp_add_writer(const frudp_writer_t *writer); 70 | 71 | void frudp_send_sedp_hb(frudp_part_t *part, bool with_msgs); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /include/freertps/qos.h: -------------------------------------------------------------------------------- 1 | #ifndef FRUDP_QOS_H 2 | #define FRUDP_QOS_H 3 | 4 | #include "freertps/udp.h" 5 | 6 | /////////////////////////////////////////////////////////////// 7 | #define FRUDP_QOS_RELIABILITY_KIND_BEST_EFFORT 1 8 | #define FRUDP_QOS_RELIABILITY_KIND_RELIABLE 2 9 | 10 | #ifdef __GNUC__ 11 | 12 | typedef struct 13 | { 14 | uint32_t kind; 15 | frudp_duration_t max_blocking_time; 16 | } __attribute__((packed)) frudp_qos_reliability_t; 17 | 18 | /////////////////////////////////////////////////////////////// 19 | #define FRUDP_QOS_HISTORY_KIND_KEEP_LAST 0 20 | #define FRUDP_QOS_HISTORY_KIND_KEEP_ALL 1 21 | 22 | typedef struct 23 | { 24 | uint32_t kind; 25 | uint32_t depth; 26 | } __attribute__((packed)) frudp_qos_history_t; 27 | 28 | /////////////////////////////////////////////////////////////// 29 | #define FRUDP_QOS_PRESENTATION_SCOPE_TOPIC 1 30 | 31 | typedef struct 32 | { 33 | uint32_t scope; 34 | uint16_t coherent_access; 35 | uint16_t ordered_access; 36 | } __attribute__((packed)) frudp_qos_presentation_t; 37 | 38 | #elif __RX == 1 39 | #pragma pack 40 | 41 | typedef struct 42 | { 43 | uint32_t kind; 44 | frudp_duration_t max_blocking_time; 45 | } frudp_qos_reliability_t; 46 | 47 | /////////////////////////////////////////////////////////////// 48 | #define FRUDP_QOS_HISTORY_KIND_KEEP_LAST 0 49 | #define FRUDP_QOS_HISTORY_KIND_KEEP_ALL 1 50 | 51 | typedef struct 52 | { 53 | uint32_t kind; 54 | uint32_t depth; 55 | } frudp_qos_history_t; 56 | 57 | /////////////////////////////////////////////////////////////// 58 | #define FRUDP_QOS_PRESENTATION_SCOPE_TOPIC 1 59 | 60 | typedef struct 61 | { 62 | uint32_t scope; 63 | uint16_t coherent_access; 64 | uint16_t ordered_access; 65 | } frudp_qos_presentation_t; 66 | 67 | #pragma unpack 68 | 69 | #endif /* __RX == 1 */ 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/freertps/sedp.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_SEDP_H 2 | #define FREERTPS_SEDP_H 3 | 4 | #include "freertps/pub.h" 5 | #include "freertps/sub.h" 6 | #include "freertps/part.h" 7 | 8 | void frudp_sedp_init(void); 9 | void frudp_sedp_start(void); 10 | void frudp_sedp_tick(void); 11 | void frudp_sedp_fini(void); 12 | 13 | extern frudp_pub_t *g_sedp_sub_pub; 14 | void sedp_publish_sub(frudp_sub_t *sub); 15 | void sedp_publish_pub(frudp_pub_t *pub); 16 | 17 | void sedp_add_builtin_endpoints(frudp_part_t *part); 18 | 19 | extern frudp_pub_t *g_sedp_sub_pub; 20 | extern frudp_pub_t *g_sedp_pub_pub; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/freertps/spdp.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_SPDP_H 2 | #define FREERTPS_SPDP_H 3 | 4 | #include "freertps/id.h" 5 | extern const frudp_eid_t g_spdp_writer_id, g_spdp_reader_id; 6 | 7 | void frudp_spdp_init(void); 8 | void frudp_spdp_start(void); 9 | void frudp_spdp_tick(void); 10 | void frudp_spdp_fini(void); 11 | 12 | void frudp_spdp_bcast(void); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/freertps/sub.h: -------------------------------------------------------------------------------- 1 | #ifndef SUBSCRIPTION_H 2 | #define SUBSCRIPTION_H 3 | 4 | #include "freertps/id.h" 5 | #include "freertps/udp.h" 6 | #include "freertps/freertps.h" 7 | #include "freertps/config.h" 8 | 9 | // create userland UDP subscriptions. people should call the 10 | // freertps_create_subscription() from userland code though, to be agnostic 11 | // to the physical layer 12 | 13 | // could be dangerous to hold onto string pointers... they need to be 14 | // stored in the caller's constant memory. maybe revisit this at some point, 15 | // with a #define switch somewhere to have it use more memory for string 16 | // buffers, etc. 17 | 18 | void frudp_add_user_sub(const char *topic_name, 19 | const char *type_name, 20 | freertps_msg_cb_t msg_cb); 21 | 22 | // this is the private subscribe function used internally... should be hidden 23 | // eventually. 24 | /* 25 | bool frudp_subscribe(const frudp_entity_id_t reader_id, 26 | const frudp_entity_id_t writer_id, 27 | const frudp_rx_data_cb_t data_cb, 28 | const freertps_msg_cb_t msg_cb); 29 | */ 30 | 31 | typedef struct 32 | { 33 | const char *topic_name; 34 | const char *type_name; 35 | frudp_eid_t reader_eid; 36 | frudp_rx_data_cb_t data_cb; 37 | freertps_msg_cb_t msg_cb; 38 | bool reliable; 39 | } frudp_sub_t; 40 | 41 | void frudp_add_sub(const frudp_sub_t *s); 42 | 43 | extern frudp_sub_t g_frudp_subs[FRUDP_MAX_SUBS]; 44 | extern uint32_t g_frudp_num_subs; 45 | 46 | typedef struct 47 | { 48 | bool reliable; 49 | frudp_guid_t writer_guid; 50 | frudp_eid_t reader_eid; 51 | frudp_sn_t max_rx_sn; 52 | frudp_rx_data_cb_t data_cb; 53 | freertps_msg_cb_t msg_cb; 54 | } frudp_reader_t; 55 | 56 | // not great to have these freely available. someday hide these. 57 | extern frudp_reader_t g_frudp_readers[FRUDP_MAX_READERS]; 58 | extern uint32_t g_frudp_num_readers; 59 | 60 | void frudp_add_reader(const frudp_reader_t *reader); 61 | 62 | void frudp_print_readers(void); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/freertps/system.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_POSIX_SYSTEM_H 2 | #define FREERTPS_POSIX_SYSTEM_H 3 | 4 | #include 5 | 6 | void freertps_system_init(void); 7 | bool freertps_system_ok(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/freertps/time.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_TIME_H 2 | #define FREERTPS_TIME_H 3 | 4 | #include 5 | 6 | typedef struct 7 | { 8 | int32_t seconds; 9 | uint32_t fraction; 10 | } fr_time_t; 11 | 12 | typedef fr_time_t fr_duration_t; 13 | 14 | fr_time_t fr_time_now(void); 15 | fr_duration_t fr_time_diff(const fr_time_t *end, const fr_time_t *start); 16 | double fr_time_double(const fr_time_t *t); 17 | double fr_time_now_double(void); // convenience function 18 | double fr_duration_double(const fr_duration_t *t); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/freertps/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_TIMER_H 2 | #define FREERTPS_TIMER_H 3 | 4 | #include 5 | 6 | typedef void (*freertps_timer_cb_t)(void); 7 | void freertps_timer_set_freq(uint32_t freq, freertps_timer_cb_t cb); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/freertps/type.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_TYPE_H 2 | #define FREERTPS_TYPE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef uint32_t (*freertps_serialize_fptr_t)( 10 | void *msg, uint8_t *buf, uint32_t buf_size); 11 | 12 | typedef struct freertps_type 13 | { 14 | const char *rtps_typename; 15 | const freertps_serialize_fptr_t serialize; 16 | } freertps_type_t; 17 | 18 | #define FREERTPS_ARRAY(STRUCT_NAME, TYPE_NAME) \ 19 | typedef struct freertps__ ## STRUCT_NAME ## __array \ 20 | { \ 21 | TYPE_NAME * data; \ 22 | uint32_t size; \ 23 | uint32_t capacity; \ 24 | } freertps__ ## STRUCT_NAME ## __array_t; 25 | 26 | FREERTPS_ARRAY(bool, bool); 27 | FREERTPS_ARRAY(byte, uint8_t); 28 | FREERTPS_ARRAY(char, int8_t); 29 | FREERTPS_ARRAY(uint8, uint8_t); 30 | FREERTPS_ARRAY(int8, int8_t); 31 | FREERTPS_ARRAY(uint16, uint16_t); 32 | FREERTPS_ARRAY(int16, int16_t); 33 | FREERTPS_ARRAY(uint32, uint32_t); 34 | FREERTPS_ARRAY(int32, int32_t); 35 | FREERTPS_ARRAY(uint64, uint64_t); 36 | FREERTPS_ARRAY(int64, int64_t); 37 | FREERTPS_ARRAY(float32, float); 38 | FREERTPS_ARRAY(float64, double); 39 | FREERTPS_ARRAY(string, char *); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | freertps 4 | 0.0.0 5 | a minimalist RTPS implementation 6 | Morgan Quigley 7 | Apache License 2.0 8 | 9 | ament_cmake 10 | 11 | ament_cmake_gtest 12 | ament_lint_auto 13 | ament_lint_common 14 | 15 | 16 | ament_cmake 17 | 18 | 19 | -------------------------------------------------------------------------------- /part.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertps/udp.h" 4 | #include "freertps/disco.h" 5 | #include "freertps/part.h" 6 | #include "freertps/config.h" 7 | #include "freertps/freertps.h" 8 | 9 | //static frudp_part_t g_frudp_participant; 10 | static bool g_frudp_participant_init_complete = false; 11 | 12 | frudp_part_t *frudp_part_find(const frudp_guid_prefix_t *guid_prefix) 13 | { 14 | for (int i = 0; i < g_frudp_disco_num_parts; i++) 15 | { 16 | frudp_part_t *p = &g_frudp_disco_parts[i]; // shorter 17 | bool match = true; 18 | for (int j = 0; match && j < FRUDP_GUID_PREFIX_LEN; j++) 19 | { 20 | if (guid_prefix->prefix[j] != p->guid_prefix.prefix[j]) 21 | match = false; 22 | } 23 | if (match) 24 | return p; 25 | } 26 | return NULL; // couldn't find it. sorry. 27 | } 28 | 29 | bool frudp_part_create(void) 30 | { 31 | if (g_frudp_participant_init_complete) 32 | { 33 | printf("woah there partner. " 34 | "freertps currently only allows one participant.\r\n"); 35 | return false; 36 | } 37 | FREERTPS_INFO("frudp_part_create() on domain_id %d\r\n", 38 | (int)g_frudp_config.domain_id); 39 | //g_frudp_config.domain_id = domain_id; 40 | if (!frudp_init_participant_id()) 41 | { 42 | printf("unable to initialize participant ID\r\n"); 43 | return false; 44 | } 45 | //frudp_generic_init(); 46 | //frudp_disco_init(); 47 | g_frudp_participant_init_complete = true; 48 | printf("prefix: "); 49 | frudp_print_guid_prefix(&g_frudp_config.guid_prefix); 50 | printf("\n"); 51 | return true; 52 | } 53 | -------------------------------------------------------------------------------- /psm/ser.c: -------------------------------------------------------------------------------- 1 | #include "freertps/psm/ser.h" 2 | #include 3 | 4 | void rtps_ser_disco(void) 5 | { 6 | printf("rtps serial disco\n"); 7 | } 8 | -------------------------------------------------------------------------------- /ros2_demos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(freertps_ros2_demos) 4 | 5 | if(NOT WIN32) 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") 7 | endif() 8 | 9 | find_package(ament_cmake REQUIRED) 10 | find_package(rclcpp REQUIRED) 11 | find_package(rmw_implementation REQUIRED) 12 | find_package(sensor_msgs REQUIRED) 13 | find_package(std_msgs REQUIRED) 14 | 15 | #find_package(OpenCV REQUIRED) 16 | 17 | include_directories(include) 18 | 19 | add_executable_for_each_rmw_implementations(led_blink 20 | led_blink.cpp 21 | TARGET_DEPENDENCIES 22 | "rclcpp" 23 | "sensor_msgs" 24 | "std_msgs" 25 | #"OpenCV" 26 | INSTALL 27 | ) 28 | ament_package() 29 | -------------------------------------------------------------------------------- /ros2_demos/led_blink.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | int main(int argc, char * argv[]) 20 | { 21 | rclcpp::init(argc, argv); 22 | auto node = rclcpp::node::Node::make_shared("led_blink"); 23 | rmw_qos_profile_t qos; 24 | qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; 25 | qos.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST; 26 | qos.depth = 1; 27 | auto pub = node->create_publisher("led", qos); 28 | auto msg = std::make_shared(); 29 | rclcpp::WallRate loop_rate(4); 30 | while (rclcpp::ok()) 31 | { 32 | msg->data = !msg->data; 33 | pub->publish(msg); 34 | rclcpp::spin_some(node); 35 | loop_rate.sleep(); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /ros2_demos/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | freertps_ros2_demos 4 | 0.0.0 5 | Small demos to communicate with the freertps sample programs 6 | Morgan Quigley 7 | Apache License 2.0 8 | 9 | ament_cmake 10 | 11 | libopencv-dev 12 | rclcpp 13 | rmw_implementation 14 | sensor_msgs 15 | std_msgs 16 | 17 | libopencv-dev 18 | rclcpp 19 | rmw_implementation 20 | sensor_msgs 21 | std_msgs 22 | 23 | ament_lint_auto 24 | ament_lint_common 25 | 26 | 27 | ament_cmake 28 | 29 | 30 | -------------------------------------------------------------------------------- /rosmsg_apps/rosmsg_talker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | freertps_add_executable(rosmsg_talker rosmsg_talker.c) 2 | -------------------------------------------------------------------------------- /rosmsg_apps/rosmsg_talker/rosmsg_talker.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/freertps.h" 3 | #include 4 | //#include "std_msgs/string.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | printf("hello, world!\r\n"); 9 | freertps_system_init(); 10 | //struct std_msgs_string msg; 11 | /* could do this with macros, but I like an explicit function for debugging 12 | 13 | frudp_pub_t *pub = freertps_create_rosmsg_pub(std_msgs_string_typesupport, 14 | "chatter") 15 | 16 | maybe nicer to make auto-generated functions instead: 17 | 18 | frudp_pub_t *pub = freertps_create_std_msgs_string_pub("chatter") 19 | or 20 | frudp_pub_t *pub = freertps_create_pub_std_msgs_string("chatter") 21 | or 22 | frudp_pub_t *pub = freertps_std_msgs_string_create_pub("chatter"); 23 | */ 24 | frudp_pub_t *pub = freertps_create_pub 25 | ("chatter", 26 | "std_msgs::msg::dds_::String_"); 27 | int pub_count = 0; 28 | frudp_disco_start(); 29 | while (freertps_system_ok()) 30 | { 31 | frudp_listen(500000); 32 | frudp_disco_tick(); 33 | char msg[256] = {0}; 34 | snprintf(&msg[4], sizeof(msg) - 4, "Hello World: %d", pub_count++); 35 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 36 | *((uint32_t *)msg) = rtps_string_len; 37 | freertps_publish(pub, (uint8_t *)msg, rtps_string_len + 4); 38 | printf("sending: [%s]\n", &msg[4]); 39 | } 40 | frudp_fini(); 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /scripts/task_runner: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys, string, subprocess 3 | if len(sys.argv) != 3: 4 | print "usage: task_runner VERB SYSTEM-APP" 5 | print " common verbs: { program, gdb, gdb_server, dump_flash, ... }" 6 | sys.exit(1) 7 | verb = sys.argv[1] 8 | sys_tokens = string.split(sys.argv[2], '-') 9 | program = sys_tokens[0] 10 | system = string.join(sys_tokens[1:], ('-')) 11 | print "application: [%s] system: [%s]" % (program, system) 12 | openocd = "/usr/local/bin/openocd -f systems/%s/openocd.cfg" % system 13 | elf = "build/%s/apps/%s/%s.elf" % ( system, program, program ) 14 | # switched to programming using ELF now, but maybe BINs will be useful sometime 15 | #image = "build/%s/apps/%s/%s.bin" % ( system, program, program ) 16 | 17 | if verb == 'program': 18 | cmd = "%s -c \"init; sleep 100; reset halt; sleep 100; flash write_image erase %s; halt; verify_image %s; sleep 100; reset run; sleep 100; shutdown\"" % (openocd, elf, elf) 19 | elif verb == 'reset': 20 | cmd = "%s -c \"init; sleep 100; halt; sleep 100; reset run; sleep 100; shutdown\"" % openocd 21 | elif verb == 'gdb_server': 22 | cmd = "%s -c \"init; halt\"" % openocd 23 | elif verb == 'gdb': 24 | cmd = "arm-none-eabi-gdb %s -x systems/stm32_common/openocd/gdb_init_commands" % elf 25 | else: 26 | print "unknown verb: [%s]" % verb 27 | sys.exit(1) 28 | 29 | print "about to execute: [%s]" % cmd 30 | process = subprocess.Popen(cmd, shell=True, 31 | stdout=subprocess.PIPE, 32 | stderr=subprocess.STDOUT) 33 | while True: 34 | line = process.stdout.readline() 35 | if line == '' and process.poll() != None: 36 | break # all done 37 | sys.stdout.write(line) 38 | sys.stdout.flush() 39 | output = process.communicate()[0] 40 | -------------------------------------------------------------------------------- /systems/metal_common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PROJECT_SOURCE_DIR}/systems/metal_common) 2 | add_library(metal_common stack.c system.c stubs.c bswap.c enet.c udp.c arm_trap.c usb.c delay.c) 3 | -------------------------------------------------------------------------------- /systems/metal_common/arm_trap.c: -------------------------------------------------------------------------------- 1 | #include "metal/arm_trap.h" 2 | #include 3 | 4 | void arm_trap_unhandled_vector(void) 5 | { 6 | volatile int isr_number = (int)(__get_IPSR() & 0x1ff); 7 | printf("IT'S A TRAP!\r\n"); 8 | if (isr_number < 16) 9 | printf("unhandled ARM vector %d !\r\n", isr_number); 10 | else 11 | printf("unhandled STM32 vector position %d (ARM ISR %d)!\r\n", 12 | isr_number - 16, isr_number); 13 | while (1) { } // spin here to allow jtag trap 14 | } 15 | 16 | -------------------------------------------------------------------------------- /systems/metal_common/bswap.c: -------------------------------------------------------------------------------- 1 | #include "freertps/bswap.h" 2 | 3 | uint32_t freertps_htonl(uint32_t u) { return __builtin_bswap32(u); } 4 | uint32_t freertps_ntohl(uint32_t u) { return __builtin_bswap32(u); } 5 | 6 | uint16_t freertps_htons(uint16_t u) { return __builtin_bswap16(u); } 7 | uint16_t freertps_ntohs(uint16_t u) { return __builtin_bswap16(u); } 8 | -------------------------------------------------------------------------------- /systems/metal_common/delay.c: -------------------------------------------------------------------------------- 1 | #include "metal/systime.h" 2 | #include "metal/delay.h" 3 | #include 4 | 5 | // these functions assume that systime is running at microsecond resolution 6 | 7 | void delay_ns(uint32_t ns) 8 | { 9 | // TODO: actually tune this better on an oscilloscope 10 | for (volatile uint32_t i = 0; i < ns/10; i++) { } 11 | } 12 | 13 | void delay_us(uint32_t us) 14 | { 15 | // todo: care about wraparound 16 | volatile uint32_t t_start = systime_usecs(); 17 | while (t_start + us > systime_usecs()) { } 18 | } 19 | 20 | void delay_ms(uint32_t ms) 21 | { 22 | // todo: care about wraparound 23 | volatile uint32_t t_start = systime_usecs(); 24 | while (t_start + 1000 * ms > systime_usecs()) { } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /systems/metal_common/metal/arm_trap.h: -------------------------------------------------------------------------------- 1 | #ifndef ARM_TRAP_H 2 | #define ARM_TRAP_H 3 | 4 | void arm_trap_unhandled_vector(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /systems/metal_common/metal/console.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLE_H 2 | #define CONSOLE_H 3 | 4 | #include 5 | 6 | void console_init(void); 7 | void console_send_block(const uint8_t *buf, uint32_t len); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /systems/metal_common/metal/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef DELAY_H 2 | #define DELAY_H 3 | 4 | #include 5 | void delay_ns(uint32_t ns); 6 | void delay_us(uint32_t us); 7 | void delay_ms(uint32_t ms); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /systems/metal_common/metal/enet.h: -------------------------------------------------------------------------------- 1 | #ifndef METAL_ENET_H 2 | #define METAL_ENET_H 3 | 4 | #include 5 | #include 6 | #include "metal/enet_headers.h" 7 | 8 | void enet_init(void); 9 | 10 | extern const uint8_t g_enet_mac[6]; 11 | typedef enum { ENET_LINK_DOWN, ENET_LINK_UP } enet_link_status_t; 12 | enet_link_status_t enet_get_link_status(void); 13 | 14 | void enet_send_udp_ucast(const uint8_t *dest_mac, 15 | const uint32_t dest_ip, const uint16_t dest_port, 16 | const uint32_t source_ip, const uint16_t source_port, 17 | const uint8_t *payload, const uint16_t payload_len); 18 | 19 | void enet_send_udp_mcast(const uint32_t mcast_ip, const uint16_t mcast_port, 20 | const uint8_t *payload, const uint16_t payload_len); 21 | 22 | void enet_write_phy_reg(const uint8_t reg_idx, const uint16_t reg_val); 23 | uint16_t enet_read_phy_reg(const uint8_t reg_idx); 24 | 25 | void enet_rx_raw(const uint8_t *pkt, const uint16_t pkt_len); // enqueue it 26 | uint_fast8_t enet_process_rx_ring(void); // process the rx queue 27 | 28 | // for freertps, we only need 4 ports 29 | #ifndef ENET_MAX_ALLOWED_UDP_PORTS 30 | #define ENET_MAX_ALLOWED_UDP_PORTS 4 31 | #endif 32 | bool enet_allow_udp_port(const uint16_t port); 33 | 34 | ///////////////////////////////////////////////////////////////////////// 35 | // these functions must be provided by a chip-specific library 36 | void enet_mac_init(void); 37 | void enet_mac_tx_raw(const uint8_t *pkt, uint16_t pkt_len); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /systems/metal_common/metal/enet_config.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_CONFIG_H 2 | #define NET_CONFIG_H 3 | 4 | // hard-coded ip for now... 192.168.1.99. TODO: something smarter 5 | #define FRUDP_IP4_ADDR 0xc0a80163 6 | #define ENET_MAC { 0xa4, 0xf3, 0xc1, 0x0, 0x2, 0x0 }; 7 | 8 | /* 9 | #ifndef ETH_IP_ADDR 10 | #define ETH_IP_ADDR 0x0a42b159 11 | #endif 12 | uint32_t g_host_ip_addr = 0x0a42b164; // TODO: overwrite this intelligently 13 | */ 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /systems/metal_common/metal/enet_headers.h: -------------------------------------------------------------------------------- 1 | #ifndef ENET_HEADERS_H 2 | #define ENET_HEADERS_H 3 | 4 | #define ENET_MAC_LEN 6 5 | typedef struct enet_eth_header 6 | { 7 | uint8_t dest_addr[ENET_MAC_LEN]; 8 | uint8_t source_addr[ENET_MAC_LEN]; 9 | uint16_t ethertype; 10 | } __attribute__((packed)) enet_eth_header_t; 11 | 12 | #define ENET_ETHERTYPE_IP 0x0800 13 | #define ENET_ETHERTYPE_ARP 0x0806 14 | 15 | typedef struct enet_ip_header 16 | { 17 | struct enet_eth_header eth; 18 | uint8_t header_len : 4; 19 | uint8_t version : 4; 20 | uint8_t ecn : 2; 21 | uint8_t diff_serv : 6; 22 | uint16_t len : 16; 23 | uint16_t id : 16; 24 | uint16_t flag_frag : 16; 25 | uint8_t ttl : 8; 26 | uint8_t proto : 8; 27 | uint16_t checksum : 16; 28 | uint32_t source_addr : 32; 29 | uint32_t dest_addr : 32; 30 | } __attribute__((packed)) enet_ip_header_t; 31 | 32 | #define ENET_IP_HEADER_LEN 5 33 | #define ENET_IP_VERSION 4 34 | #define ENET_IP_DONT_FRAGMENT 0x4000 35 | 36 | #define ENET_IP_PROTO_ICMP 0x01 37 | #define ENET_IP_PROTO_UDP 0x11 38 | typedef struct enet_udp_header 39 | { 40 | struct enet_ip_header ip; 41 | uint16_t source_port; 42 | uint16_t dest_port; 43 | uint16_t len; 44 | uint16_t checksum; 45 | } __attribute__((packed)) enet_udp_header_t; 46 | 47 | typedef struct enet_arp_pkt 48 | { 49 | struct enet_eth_header eth; 50 | uint16_t hw_type; 51 | uint16_t proto_type; 52 | uint8_t hw_addr_len; 53 | uint8_t proto_addr_len; 54 | uint16_t operation; 55 | uint8_t sender_hw_addr[6]; 56 | uint32_t sender_proto_addr; 57 | uint8_t target_hw_addr[6]; 58 | uint32_t target_proto_addr; 59 | } __attribute__((packed)) enet_arp_pkt_t; 60 | #define ENET_ARP_HW_ETHERNET 1 61 | #define ENET_ARP_PROTO_IPV4 0x0800 62 | #define ENET_ARP_OP_REQUEST 1 63 | #define ENET_ARP_OP_RESPONSE 2 64 | 65 | #define ENET_ICMP_MAX_DATA 200 66 | typedef struct enet_icmp_header 67 | { 68 | struct enet_ip_header ip; 69 | uint8_t type; 70 | uint8_t code; 71 | uint16_t checksum; 72 | uint16_t id; 73 | uint16_t sequence; 74 | } __attribute__((packed)) enet_icmp_header_t; 75 | #define ENET_ICMP_ECHO_REPLY 0x00 76 | #define ENET_ICMP_ECHO_REQUEST 0x08 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /systems/metal_common/metal/metal.h: -------------------------------------------------------------------------------- 1 | #ifndef FREERTPS_METAL_H 2 | #define FREERTPS_METAL_H 3 | 4 | // definitions of metal: 5 | // 1) a most excellent style of music 6 | // 2) running without an operating system. BUCKLE YOUR SEAT BELTS KIDS 7 | 8 | static inline void freertps_metal_enable_irq(void) 9 | { 10 | __asm volatile ("cpsie i" : : : "memory"); 11 | } 12 | 13 | static inline void freertps_metal_disable_irq(void) 14 | { 15 | __asm volatile ("cpsid i" : : : "memory"); 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /systems/metal_common/metal/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef STACK_H 2 | #define STACK_H 3 | 4 | #include 5 | 6 | #ifndef STACK_SIZE 7 | # define STACK_SIZE 0x4000 8 | #endif 9 | 10 | extern volatile uint8_t g_stack[STACK_SIZE]; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /systems/metal_common/metal/systime.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTIME_H 2 | #define SYSTIME_H 3 | 4 | #include 5 | 6 | void systime_init(void); 7 | 8 | // can this be inlined somehow and defined in a chip-specific library? 9 | // i kind of doubt it, but i dunno. 10 | uint32_t systime_usecs(void); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /systems/metal_common/metal/usb.h: -------------------------------------------------------------------------------- 1 | #ifndef SAMV_USB_H 2 | #define SAMV_USB_H 3 | 4 | #include 5 | 6 | typedef struct usb_ep_desc 7 | { 8 | uint8_t len; 9 | uint8_t desc_type; 10 | uint8_t ep_addr; 11 | uint8_t attr; 12 | uint16_t max_pkt_size; 13 | uint8_t interval; 14 | } __attribute__((packed)) usb_ep_desc_t; 15 | 16 | typedef struct usb_iface_desc 17 | { 18 | uint8_t len; 19 | uint8_t desc_type; 20 | uint8_t iface_num; 21 | uint8_t alt_setting; 22 | uint8_t num_ep; 23 | uint8_t iface_class; 24 | uint8_t iface_subclass; 25 | uint8_t iface_proto; 26 | uint8_t iface_str_idx; 27 | struct usb_ep_desc eps[2]; 28 | } __attribute__((packed)) usb_iface_desc_t; 29 | 30 | typedef struct usb_config_desc 31 | { 32 | uint8_t len; 33 | uint8_t desc_type; 34 | uint16_t total_len; 35 | uint8_t num_ifaces; 36 | uint8_t config_val; 37 | uint8_t config_str_idx; 38 | uint8_t attributes; 39 | uint8_t max_power; 40 | struct usb_iface_desc ifaces[1]; 41 | } __attribute__((packed)) usb_config_desc_t; 42 | 43 | #define METAL_USB_DESC_TYPE_DEVICE 0x1 44 | #define METAL_USB_DESC_TYPE_CONFIG 0x2 45 | #define METAL_USB_DESC_TYPE_STRING 0x3 46 | #define METAL_USB_DESC_TYPE_IFACE 0x4 47 | #define METAL_USB_DESC_TYPE_ENDPOINT 0x5 48 | 49 | #define METAL_USB_EP_TYPE_BULK 0x2 50 | 51 | #define METAL_USB_PROTO 0x0200 52 | #define METAL_USB_DEV_CLASS_CUSTOM 0xff 53 | #define METAL_USB_DEV_SUBCLASS_CUSTOM 0xff 54 | #define METAL_USB_DEV_PROTO_CUSTOM 0xff 55 | #define METAL_USB_MAX_EP0_PKT_SIZE 64 56 | #define METAL_USB_VID 0xf055 57 | #define METAL_USB_BCD_DEV 0 58 | #define METAL_USB_NO_MFGR_STR 0 59 | #define METAL_USB_NO_PROD_STR 0 60 | #define METAL_USB_NO_SERIAL_STR 0 61 | 62 | typedef struct usb_device_desc 63 | { 64 | uint8_t len; 65 | uint8_t desc_type; 66 | uint16_t usb_ver; 67 | uint8_t dev_class; 68 | uint8_t dev_subclass; 69 | uint8_t dev_protocol; 70 | uint8_t max_ep0_pkt_size; 71 | uint16_t vid; 72 | uint16_t pid; 73 | uint16_t bcdDevice; // wtf 74 | uint8_t man_str_idx; 75 | uint8_t prod_str_idx; 76 | uint8_t ser_num_str_idx; 77 | uint8_t num_config; 78 | } __attribute__((packed)) usb_device_desc_t; 79 | 80 | typedef struct usb_lang_list_desc 81 | { 82 | uint8_t len; 83 | uint8_t desc_type; 84 | uint16_t langs[1]; // todo... allow more languages... someday 85 | } __attribute__((packed)) usb_lang_list_desc_t; 86 | 87 | #define METAL_USB_LANG_ID_ENGLISH_USA 0x0409 88 | 89 | typedef struct usb_string_desc 90 | { 91 | uint8_t len; 92 | uint8_t desc_type; 93 | char *str; 94 | } __attribute__((packed)) usb_string_desc_t; 95 | 96 | #define METAL_USB_VENDOR_STRING 1 97 | #define METAL_USB_PRODUCT_STRING 2 98 | 99 | ///////////////////////// 100 | 101 | // these functions are not portable and need to be implemented by chip libs 102 | void usb_init(void); 103 | void usb_tx(const unsigned ep, const void *buf, const unsigned len); 104 | void usb_set_addr(const uint8_t addr); 105 | 106 | // these functions are portable 107 | void usb_rx_setup(const uint8_t *buf, const unsigned len); 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /systems/metal_common/stack.c: -------------------------------------------------------------------------------- 1 | #include "metal/stack.h" 2 | 3 | volatile __attribute__((used,aligned(8),section(".stack"))) uint8_t g_stack[STACK_SIZE]; 4 | -------------------------------------------------------------------------------- /systems/metal_common/stubs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "metal/console.h" 5 | 6 | extern int _end; 7 | 8 | //#define PRINT_SBRK_CALLS 9 | 10 | #ifdef PRINT_SBRK_CALLS 11 | void write_integer_inefficiently(int x) 12 | { 13 | int remainder = x; 14 | for (int order = 1000000000; order; order /= 10) 15 | { 16 | uint8_t digit = '0' + remainder / order; 17 | remainder -= (digit - '0') * order; 18 | console_send_block(&digit, 1); 19 | } 20 | } 21 | #endif 22 | 23 | caddr_t _sbrk(int incr) 24 | { 25 | #ifdef PRINT_SBRK_CALLS 26 | console_send_block("sbrk ", 5); 27 | write_integer_inefficiently(incr); 28 | console_send_block("\r\n", 2); 29 | #endif 30 | static unsigned char *heap = NULL ; 31 | unsigned char *prev_heap ; 32 | if ( heap == NULL ) 33 | heap = (unsigned char *)&_end; 34 | prev_heap = heap; 35 | heap += incr ; 36 | return (caddr_t) prev_heap ; 37 | } 38 | 39 | int _kill(__attribute__((unused)) int pid, 40 | __attribute__((unused)) int sig) { return -1; } 41 | void _exit(__attribute__((unused)) int status) { while (1) {} } // spin... 42 | int _getpid(void) { return 1; } 43 | 44 | int _write(__attribute__((unused)) int fd, const void *buf, size_t count) 45 | { 46 | console_send_block((uint8_t *)buf, count); 47 | return count; 48 | } 49 | int _close(__attribute__((unused)) int fd) { return -1; } 50 | int _fstat(__attribute__((unused)) int fd, 51 | __attribute__((unused)) struct stat *st) 52 | { 53 | st->st_mode = S_IFCHR; 54 | return 0; 55 | } 56 | int _isatty(__attribute__((unused)) int fd) { return 1; } 57 | off_t _lseek(__attribute__((unused)) int fd, 58 | __attribute__((unused)) off_t offset, 59 | __attribute__((unused)) int whence) { return 0; } 60 | ssize_t _read(__attribute__((unused)) int fd, 61 | __attribute__((unused)) void *buf, 62 | __attribute__((unused)) size_t count) { return 0; } 63 | 64 | struct __FILE { int handle; }; 65 | FILE __stdout; 66 | FILE __stderr; 67 | int fputc(__attribute__((unused)) int ch, __attribute__((unused)) FILE *f) 68 | { 69 | return 0; 70 | } 71 | void _ttywrch(__attribute__((unused)) int ch) 72 | { 73 | } 74 | 75 | //int _open(const char *pathname, int flags) { return -1; } 76 | int _open(const char *pathname, int flags, mode_t mode) { return -1; } 77 | -------------------------------------------------------------------------------- /systems/metal_common/system.c: -------------------------------------------------------------------------------- 1 | #include "freertps/system.h" 2 | #include "freertps/udp.h" 3 | #include "freertps/freertps.h" 4 | #include "metal/metal.h" 5 | 6 | void freertps_system_init(void) 7 | { 8 | frudp_init(); 9 | freertps_metal_enable_irq(); 10 | } 11 | 12 | bool freertps_system_ok(void) 13 | { 14 | return true; 15 | } 16 | 17 | bool frudp_init_participant_id(void) 18 | { 19 | FREERTPS_INFO("frudp_init_participant_id()\r\n"); 20 | g_frudp_config.participant_id = 0; 21 | return true; 22 | } 23 | -------------------------------------------------------------------------------- /systems/metal_common/udp.c: -------------------------------------------------------------------------------- 1 | #include "freertps/freertps.h" 2 | #include "freertps/udp.h" 3 | #include "freertps/disco.h" 4 | #include "freertps/bswap.h" 5 | #include 6 | #include 7 | #include 8 | #include "metal/enet_config.h" 9 | #include "metal/enet.h" 10 | #include "metal/systime.h" 11 | 12 | bool frudp_init(void) 13 | { 14 | enet_init(); 15 | FREERTPS_INFO("metal udp init()\r\n"); 16 | FREERTPS_INFO("using address %d.%d.%d.%d for unicast\r\n", 17 | (FRUDP_IP4_ADDR >> 24) & 0xff, 18 | (FRUDP_IP4_ADDR >> 16) & 0xff, 19 | (FRUDP_IP4_ADDR >> 8) & 0xff, 20 | (FRUDP_IP4_ADDR ) & 0xff); 21 | g_frudp_config.unicast_addr = freertps_htonl(FRUDP_IP4_ADDR); 22 | g_frudp_config.guid_prefix.prefix[0] = FREERTPS_VENDOR_ID >> 8; 23 | g_frudp_config.guid_prefix.prefix[1] = FREERTPS_VENDOR_ID & 0xff; 24 | memcpy(&g_frudp_config.guid_prefix.prefix[2], g_enet_mac, 6); 25 | frudp_generic_init(); 26 | // not sure about endianness here. 27 | // 4 bytes left. let's use the system time in microseconds since power-up 28 | // todo: init ethernet PHY. after PHY link is up, 29 | // store system time in the guid_prefix. 30 | //memcpy(&g_frudp_config.guid_prefix.prefix[8], &pid, 4); 31 | //frudp_disco_init(); 32 | return true; 33 | } 34 | 35 | void frudp_fini(void) 36 | { 37 | frudp_disco_fini(); 38 | FREERTPS_INFO("metal udp fini\r\n"); 39 | } 40 | 41 | bool frudp_listen(const uint32_t max_usec) 42 | { 43 | // just busy-wait here for the requested amount of time 44 | volatile uint32_t t_start = systime_usecs(); 45 | while (1) 46 | { 47 | enet_process_rx_ring(); 48 | volatile uint32_t t = systime_usecs(); 49 | if (t - t_start >= max_usec) 50 | break; 51 | } 52 | return true; 53 | } 54 | 55 | bool frudp_tx(const uint32_t dst_addr, 56 | const uint16_t dst_port, 57 | const uint8_t *tx_data, 58 | const uint16_t tx_len) 59 | { 60 | if ((dst_addr & 0xe0000000) == 0xe0000000) 61 | { 62 | // ipv4 multicast 63 | enet_send_udp_mcast(dst_addr, dst_port, tx_data, tx_len); 64 | } 65 | else 66 | { 67 | uint8_t dst_mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; // todo: not this 68 | enet_send_udp_ucast(dst_mac, 69 | dst_addr, dst_port, 70 | FRUDP_IP4_ADDR, dst_port, 71 | tx_data, tx_len); 72 | } 73 | return true; 74 | } 75 | 76 | bool frudp_add_mcast_rx(uint32_t group, uint16_t port) 77 | { 78 | // todo: multicast group filtering 79 | return enet_allow_udp_port(port); 80 | } 81 | 82 | bool frudp_add_ucast_rx(const uint16_t port) 83 | { 84 | return enet_allow_udp_port(port); 85 | } 86 | -------------------------------------------------------------------------------- /systems/native-posix/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(freertps_system_native-posix time.c 2 | udp.c 3 | bswap.c 4 | system.c 5 | fake_imu.c 6 | fake_led.c 7 | ser.c) 8 | target_link_libraries(freertps_system_${SYSTEM} freertps) 9 | set(SYSTEM_EXTRA_LIBS "" CACHE STRING "") 10 | set(SYSTEM_BONUS_LIBS "m" CACHE STRING "") # not the best variable name 11 | set(SYSTEM_APPS "led talker listener imu" CACHE STRING "") 12 | set(SYSTEM_NO_ROSIDL_APPS "talker_no_rosidl listener_no_rosidl standalone_listen_for_n standalone_talk_n" CACHE STRING "") 13 | install( 14 | TARGETS freertps_system_${SYSTEM} 15 | ARCHIVE DESTINATION lib 16 | LIBRARY DESTINATION lib 17 | RUNTIME DESTINATION bin 18 | ) 19 | -------------------------------------------------------------------------------- /systems/native-posix/bswap.c: -------------------------------------------------------------------------------- 1 | #include "freertps/bswap.h" 2 | #include 3 | 4 | uint32_t freertps_htonl(uint32_t u) { return htonl(u); } 5 | uint16_t freertps_htons(uint16_t u) { return htons(u); } 6 | uint32_t freertps_ntohl(uint32_t u) { return ntohl(u); } 7 | uint16_t freertps_ntohs(uint16_t u) { return ntohs(u); } 8 | -------------------------------------------------------------------------------- /systems/native-posix/fake_imu.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/imu.h" 2 | #include 3 | 4 | void imu_init(void) 5 | { 6 | printf("native-posix fake imu init\r\n"); 7 | } 8 | 9 | bool imu_poll_accels(float *xyz) 10 | { 11 | xyz[0] = 1; 12 | xyz[1] = 2; 13 | xyz[2] = 3; 14 | return true; 15 | } 16 | -------------------------------------------------------------------------------- /systems/native-posix/fake_led.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/led.h" 2 | #include 3 | 4 | void led_init(void) 5 | { 6 | } 7 | 8 | void led_on(void) 9 | { 10 | printf("led on\n"); 11 | } 12 | 13 | void led_off(void) 14 | { 15 | printf("led off\n"); 16 | } 17 | 18 | void led_toggle(void) 19 | { 20 | printf("led toggle\n"); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /systems/native-posix/net.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_H 2 | #define NET_H 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /systems/native-posix/ser.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertps/psm/ser.h" 3 | 4 | void rtps_ser_init(void) 5 | { 6 | printf("rtps_ser_init()\n"); 7 | } 8 | -------------------------------------------------------------------------------- /systems/native-posix/system.c: -------------------------------------------------------------------------------- 1 | #include "freertps/freertps.h" 2 | #include "freertps/system.h" 3 | #include 4 | #if defined(__linux__) 5 | #include 6 | #endif 7 | #include 8 | #include "freertps/psm.h" 9 | 10 | struct rtps_psm g_rtps_psm; 11 | 12 | /* 13 | #include 14 | static bool g_done = false; 15 | static void sigint_handler(int signum) 16 | { 17 | g_done = true; 18 | } 19 | */ 20 | 21 | //#define MALLOC_DEBUG 22 | 23 | #ifdef MALLOC_DEBUG 24 | // save the glibc hook; we'll use it later 25 | static void *(*g_freertps_prev_malloc_hook)(size_t, const void *); 26 | 27 | static void *freertps_malloc(size_t size, const void *caller) 28 | { 29 | //puts("malloc\n"); 30 | //backtrace_buffer[0] = caller; 31 | static const int MAX_DEPTH = 10; 32 | void *backtrace_buffer[MAX_DEPTH]; 33 | void *frames[MAX_DEPTH]; 34 | __malloc_hook = g_freertps_prev_malloc_hook; 35 | int stack_depth = backtrace_symbols(backtrace_buffer, MAX_DEPTH); 36 | char **function_names = backtrace_symbols(backtrace_buffer, MAX_DEPTH); 37 | printf("malloc(%u) called from %s [%p]\n", 38 | (unsigned)size, function_names[0], backtrace_buffer[0]); 39 | free(function_names); 40 | void *mem = malloc(size); 41 | __malloc_hook = freertps_malloc; 42 | return mem; 43 | } 44 | 45 | void freertps_init_malloc_hook(void) 46 | { 47 | g_freertps_prev_malloc_hook = __malloc_hook; 48 | __malloc_hook = freertps_malloc; 49 | } 50 | void (*volatile __malloc_initialize_hook)(void) = freertps_init_malloc_hook; 51 | #endif 52 | 53 | void freertps_system_init(void) 54 | { 55 | //__malloc_hook = freertps_malloc; 56 | /* 57 | if (getenv("FREERTPS_SERIAL_GROUP")) 58 | { 59 | // udpv4 multicast group of the "simulated serial comms" group 60 | const char *serial_group = getenv("FREERTPS_SERIAL_GROUP"); 61 | rtps_ser_init(serial_group); 62 | } 63 | else 64 | */ 65 | g_rtps_psm = g_rtps_psm_udp; 66 | 67 | g_rtps_psm.init(); 68 | 69 | //signal(SIGINT, sigint_handler); // let ROS2 handle this now 70 | g_freertps_init_complete = true; 71 | } 72 | 73 | bool freertps_system_ok(void) 74 | { 75 | return true; //!g_done; 76 | } 77 | -------------------------------------------------------------------------------- /systems/native-posix/time.c: -------------------------------------------------------------------------------- 1 | #include "freertps/time.h" 2 | 3 | #if defined(__linux__) 4 | #include 5 | #else 6 | #include 7 | #include 8 | #include 9 | #endif 10 | 11 | static uint64_t frac_sec(uint64_t nsec) 12 | { 13 | // convert nanoseconds to the RTPS fractional seconds 14 | // FUTURE: provide faster macros for this which lose precision 15 | const uint64_t frac_sec_lcm = nsec * 8388608; 16 | return frac_sec_lcm / 1953125; 17 | } 18 | 19 | fr_time_t fr_time_now(void) 20 | { 21 | fr_time_t now; 22 | 23 | #if (defined __linux__) 24 | struct timespec ts; 25 | clock_gettime(CLOCK_REALTIME, &ts); 26 | now.seconds = ts.tv_sec; 27 | now.fraction = frac_sec(ts.tv_nsec); 28 | #else 29 | clock_serv_t cclock; 30 | mach_timespec_t mts; 31 | 32 | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); 33 | clock_get_time(cclock, &mts); 34 | mach_port_deallocate(mach_task_self(), cclock); 35 | 36 | now.seconds = mts.tv_sec; 37 | now.fraction = frac_sec(mts.tv_nsec); 38 | #endif 39 | 40 | return now; 41 | } 42 | -------------------------------------------------------------------------------- /systems/native-posix/toolchain.cmake: -------------------------------------------------------------------------------- 1 | # nothing to do here. 2 | -------------------------------------------------------------------------------- /systems/rx63n_gr_sakura/bswap.c: -------------------------------------------------------------------------------- 1 | #include "freertps/bswap.h" 2 | 3 | static uint32_t _bswap32(uint32_t u) 4 | { 5 | return (((((unsigned long)(u) & 0x000000FF)) << 24) | 6 | ((((unsigned long)(u) & 0x0000FF00)) << 8) | 7 | ((((unsigned long)(u) & 0x00FF0000)) >> 8) | 8 | ((((unsigned long)(u) & 0xFF000000)) >> 24)); 9 | } 10 | 11 | static uint16_t _bswap16(uint16_t u) 12 | { 13 | return (((((unsigned short)(u) & 0x00FF)) << 8) | 14 | (((unsigned short)(u) & 0xFF00) >> 8)); 15 | } 16 | 17 | uint32_t freertps_htonl(uint32_t u) 18 | { 19 | return _bswap32(u); 20 | } 21 | 22 | uint16_t freertps_htons(uint16_t u) 23 | { 24 | return _bswap16(u); 25 | } 26 | 27 | uint32_t freertps_ntohl(uint32_t u) 28 | { 29 | return _bswap32(u); 30 | } 31 | 32 | uint16_t freertps_ntohs(uint16_t u) 33 | { 34 | return _bswap16(u); 35 | } 36 | -------------------------------------------------------------------------------- /systems/rx63n_gr_sakura/system.c: -------------------------------------------------------------------------------- 1 | #include "r_sys_time_rx_if.h" 2 | #include "freertps/freertps.h" 3 | #include "freertps/system.h" 4 | #include "freertps/psm.h" 5 | 6 | struct rtps_psm g_rtps_psm; 7 | 8 | void freertps_system_init(void) 9 | { 10 | sys_time_err_t systime_ercd; 11 | 12 | /* Start system timer module */ 13 | systime_ercd = R_SYS_TIME_Open(); 14 | if (systime_ercd != SYS_TIME_SUCCESS) 15 | { 16 | while ((bool)1); 17 | } 18 | 19 | /* Initialize PSM part */ 20 | g_rtps_psm = g_rtps_psm_udp; 21 | g_rtps_psm.init(); 22 | g_freertps_init_complete = true; 23 | } 24 | 25 | bool freertps_system_ok(void) 26 | { 27 | return true; 28 | } 29 | -------------------------------------------------------------------------------- /systems/rx63n_gr_sakura/system_time.c: -------------------------------------------------------------------------------- 1 | #include "r_sys_time_rx_if.h" 2 | #include "freertps/time.h" 3 | 4 | fr_time_t fr_time_now(void) 5 | { 6 | SYS_TIME sys_time; 7 | fr_time_t now; 8 | 9 | /* FIXME For now, the resolution is limited to 1 second. */ 10 | R_SYS_TIME_GetCurrentTime(&sys_time); 11 | now.seconds = sys_time.unix_time; 12 | now.fraction = 0; 13 | 14 | return now; 15 | } 16 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/99-atmel-edbg.rules: -------------------------------------------------------------------------------- 1 | ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2111", MODE="0666",GROUP="plugdev" 2 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(freertps_system_samv71_xplained_ultra-metal 2 | vectors.c 3 | startup.c 4 | console.c 5 | led.c 6 | enet_mac.c 7 | systime.c 8 | time.c 9 | pin.c 10 | cam.c 11 | i2c.c 12 | usb_mac.c) 13 | #udp.c 14 | # flash.c 15 | # dcmi.c 16 | # i2c.c 17 | # camera_init_pins.c 18 | # lcd.c 19 | # lcd_init_pins.c 20 | set(SYSTEM_EXTRA_LIBS "metal_common" CACHE STRING "extra system libs") 21 | set(SYSTEM_APPS "usb_test cam" CACHE STRING "applications") 22 | set(SYSTEM_NO_ROSIDL_APPS "blink talker_no_rosidl listener_no_rosidl" CACHE STRING "") 23 | #set(SYSTEM_APPS "usb_test talker listener enet_test cam" CACHE STRING "applications") 24 | #set(SYSTEM_APPS "blink hello_world talker listener systime_test enet_test" CACHE STRING "applications") 25 | #set(SYSTEM_APPS "listener talker talker_stm32_timer cam_dm_130" CACHE STRING "applications for this system") 26 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/README: -------------------------------------------------------------------------------- 1 | when we have more than one board with this chip family, we'll need to 2 | factor this library into a SOMETHING_common library and a board-specific 3 | library, like is done for, e.g., {stm32_common, stm32f4_disco-metal} 4 | 5 | NOTE: if you are starting with a fresh chip, you'll need to set the boot 6 | vector bit: 7 | 8 | openocd -f openocd.cfg -c init -c "reset halt" -c "atsamv gpnvm set 1" -c shutdown 9 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/console.c: -------------------------------------------------------------------------------- 1 | #include "samv71q21.h" 2 | #include 3 | #include 4 | #include "metal/console.h" 5 | #include "freertps/periph/led.h" 6 | 7 | // hardware connections wired to EDBG: 8 | // PB04 = USART1 TXD on peripheral D 9 | // PA21 = USART1 RXD on peripheral A 10 | 11 | #define CONSOLE_BAUD 1000000 12 | static bool g_console_init_complete = false; 13 | 14 | #define TX_PIN PIO_PB4D_TXD1 15 | #define CONSOLE_USART USART1 16 | 17 | void console_init(void) 18 | { 19 | PMC->PMC_PCER0 = (1 << ID_USART1) | (1 << ID_PIOB); // enable clock gates 20 | PIOB->PIO_OER = TX_PIN; // output enable 21 | PIOB->PIO_PDR = TX_PIN; // disable pin gpio, enable peripheral on pin 22 | PIOB->PIO_ABCDSR[0] |= TX_PIN; // peripheral D 23 | PIOB->PIO_ABCDSR[1] |= TX_PIN; // peripheral D 24 | MATRIX->MATRIX_WPMR = MATRIX_WPMR_WPKEY_PASSWD; // unlock the matrix, neo! 25 | MATRIX->CCFG_SYSIO |= CCFG_SYSIO_SYSIO4; // use PB4 as i/o, not jtag 26 | 27 | CONSOLE_USART->US_CR = US_CR_RSTTX | US_CR_RSTRX | 28 | US_CR_TXDIS | US_CR_RXDIS | 29 | US_CR_RSTSTA; 30 | CONSOLE_USART->US_MR = US_MR_USART_MODE_NORMAL | 31 | US_MR_CHRL_8_BIT | 32 | US_MR_PAR_NO | 33 | US_MR_USCLKS_MCK | // use MCLK = 144 MHz 34 | US_MR_OVER; 35 | CONSOLE_USART->US_IDR = 0xffffffff; // no interrupts for now. 36 | //CONSOLE_USART->US_BRGR = 18; // 144 MHz / 1 megabit / 8 = 18 37 | CONSOLE_USART->US_BRGR = 156; // 144 MHz / 115200 / 8 = 156.25 38 | CONSOLE_USART->US_CR = US_CR_TXEN; 39 | g_console_init_complete = true; 40 | } 41 | 42 | void console_send_block(const uint8_t *block, const uint32_t len) 43 | { 44 | // if it ever matters, make this interrupt-driven or (bonus) dma driven 45 | if (!g_console_init_complete) 46 | console_init(); 47 | while ((CONSOLE_USART->US_CSR & US_CSR_TXRDY) == 0) { } 48 | for (uint32_t i = 0; i < len; i++) 49 | { 50 | CONSOLE_USART->US_THR = block[i]; 51 | while ((CONSOLE_USART->US_CSR & US_CSR_TXRDY) == 0) { } 52 | } 53 | while (!(CONSOLE_USART->US_CSR & US_CSR_TXEMPTY)) { } // busy-wait until done 54 | } 55 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/i2c.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/i2c.h" 2 | #include "pin.h" 3 | #include 4 | 5 | bool i2c_init(void *i2c) 6 | { 7 | Twihs *twi = (Twihs *)i2c; 8 | if (twi != TWIHS0) 9 | { 10 | printf("ahh unknown TWI peripheral\r\n"); 11 | return false; 12 | } 13 | PMC->PMC_PCER0 |= (1 << ID_TWIHS0); 14 | pin_set_mux(PIOA, 3, PERIPH_A); // sdc0 15 | pin_set_mux(PIOA, 4, PERIPH_A); // sda0 16 | // set up 400 kHz i2c timing on our 144 MHz system clock 17 | //twi->TWIHS_CWGR = TWIHS_CWGR_CHDIV(86) | TWIHS_CWGR_CLDIV(187) | TWIHS_CWGR_CKDIV(2); 18 | // hmm...this board doesn't have any i2c pullups, so let's do 100 kHz i2c 19 | twi->TWIHS_CWGR = 20 | TWIHS_CWGR_CHDIV(170) | 21 | TWIHS_CWGR_CLDIV(170) | 22 | TWIHS_CWGR_HOLD(0x1f) | // todo: need to solder on physical pullups 23 | TWIHS_CWGR_CKDIV(2); 24 | twi->TWIHS_CR = TWIHS_CR_SVDIS; // disable slave mode. ONCE I WAS THE LEARNER 25 | twi->TWIHS_CR = TWIHS_CR_MSEN; // enable master mode. NOW I AM THE MASTER 26 | printf("twi init complete\r\n"); 27 | 28 | return true; 29 | } 30 | 31 | bool i2c_read(void *i2c, uint8_t device_addr, 32 | uint8_t reg_addr, uint8_t len, uint8_t *buffer) 33 | { 34 | Twihs *twi = (Twihs *)i2c; 35 | if (twi != TWIHS0) // sanity-check... todo: other instances 36 | return false; 37 | /* 38 | printf("starting %d-byte i2c read from device 0x%02x register 0x%02x\r\n", 39 | (int)len, (unsigned)device_addr, (unsigned)reg_addr); 40 | */ 41 | twi->TWIHS_MMR = 42 | TWIHS_MMR_IADRSZ(1) | 43 | TWIHS_MMR_MREAD | 44 | TWIHS_MMR_DADR(device_addr); 45 | twi->TWIHS_IADR = reg_addr; 46 | twi->TWIHS_CR = TWIHS_CR_START; 47 | for (int i = 0; i < len; i++) 48 | { 49 | //printf("waiting for byte %d to arrive...\r\n", i); 50 | while (!(twi->TWIHS_SR & TWIHS_SR_RXRDY)); 51 | buffer[i] = twi->TWIHS_RHR; 52 | //printf("done! got byte %d\r\n", i); 53 | if (i == len - 2) 54 | twi->TWIHS_CR = TWIHS_CR_STOP; 55 | } 56 | while (!(twi->TWIHS_SR & TWIHS_SR_TXCOMP)); 57 | //printf("done with twi read\r\n"); 58 | return true; 59 | } 60 | 61 | bool i2c_write(void *i2c, uint8_t device_addr, 62 | uint8_t reg_addr, uint8_t len, uint8_t *buffer) 63 | { 64 | Twihs *twi = (Twihs *)i2c; 65 | if (twi != TWIHS0) // sanity-check... todo: other instances 66 | return false; 67 | twi->TWIHS_MMR = 68 | TWIHS_MMR_IADRSZ(1) | 69 | TWIHS_MMR_DADR(device_addr); 70 | twi->TWIHS_IADR = reg_addr; 71 | //twi->TWIHS_CR = TWIHS_CR_START; 72 | for (int i = 0; i < len; i++) 73 | { 74 | twi->TWIHS_THR = buffer[i]; 75 | while (!(twi->TWIHS_SR & TWIHS_SR_TXRDY)); 76 | } 77 | twi->TWIHS_CR = TWIHS_CR_STOP; 78 | while (!(twi->TWIHS_SR & TWIHS_SR_TXCOMP)); 79 | return true; 80 | } 81 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/led.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/led.h" 2 | #include "samv71q21.h" 3 | 4 | #define PORTA_LED PIO_PA23 5 | 6 | void led_init(void) 7 | { 8 | PMC->PMC_PCER0 |= (1 << ID_PIOA); 9 | PIOA->PIO_PER = PIOA->PIO_OER = PIOA->PIO_CODR = PORTA_LED; 10 | } 11 | 12 | void led_on(void) 13 | { 14 | PIOA->PIO_SODR = PORTA_LED; 15 | } 16 | 17 | void led_off(void) 18 | { 19 | PIOA->PIO_CODR = PORTA_LED; 20 | } 21 | 22 | void led_toggle(void) 23 | { 24 | if (PIOA->PIO_PDSR & PORTA_LED) 25 | led_off(); 26 | else 27 | led_on(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/openocd.cfg: -------------------------------------------------------------------------------- 1 | # this connects fine with the EDBG on the dev kit 2 | source [find interface/cmsis-dap.cfg] 3 | 4 | set CHIPNAME at91samv71q21 5 | 6 | source [find target/atsamv.cfg] 7 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/pin.h: -------------------------------------------------------------------------------- 1 | #ifndef PIN_H 2 | #define PIN_H 3 | 4 | #include 5 | #include 6 | #include "component/component_pio.h" 7 | 8 | // ported from the STM32 stuff... not yet all implemented 9 | 10 | void pin_set_mux(Pio *pio, const unsigned pin_idx, 11 | const unsigned function_idx); 12 | 13 | void pin_enable_pullup(Pio *pio, const unsigned pin_idx, 14 | const bool enable_pullup); 15 | 16 | void pin_set_output(Pio *pio, const unsigned pin_idx, 17 | const bool output_state); 18 | 19 | void pin_set_output_state(Pio *pio, const unsigned pin_idx, 20 | const bool output_state); 21 | 22 | 23 | #define PERIPH_A 0 24 | #define PERIPH_B 1 25 | #define PERIPH_C 2 26 | #define PERIPH_D 3 27 | 28 | #if 0 29 | #define PIN_OUTPUT_TYPE_PUSH_PULL 0 30 | #define PIN_OUTPUT_TYPE_OPEN_DRAIN 1 31 | 32 | void pin_set_output_type(GPIO_TypeDef *gpio, 33 | const uint8_t pin_idx, 34 | const uint8_t output_type); 35 | 36 | void pin_set_analog(GPIO_TypeDef *gpio, const uint8_t pin_idx); 37 | 38 | void pin_set_output(GPIO_TypeDef *gpio, 39 | const uint8_t pin_idx, 40 | const uint8_t initial_state); 41 | void pin_set_output_speed(GPIO_TypeDef *gpio, 42 | const uint_fast8_t pin_idx, 43 | const uint_fast8_t speed); 44 | 45 | void pin_set_output_state(GPIO_TypeDef *gpio, 46 | const uint8_t pin_idx, 47 | const uint8_t state); 48 | 49 | void pin_toggle_state(GPIO_TypeDef *gpio, const uint8_t pin_idx); 50 | 51 | void pin_set_input(GPIO_TypeDef *gpio, const uint8_t pin_idx, 52 | const bool enable_pullup); 53 | 54 | static inline void pin_set_output_high(GPIO_TypeDef *gpio, 55 | const uint8_t pin_idx) 56 | { 57 | gpio->BSRR = 1 << pin_idx; 58 | } 59 | 60 | static inline void pin_set_output_low(GPIO_TypeDef *gpio, 61 | const uint8_t pin_idx) 62 | { 63 | gpio->BSRR = (1 << pin_idx) << 16; 64 | } 65 | 66 | static inline bool pin_get_state(GPIO_TypeDef *gpio, const uint_fast8_t pin_idx) 67 | { 68 | return (gpio->IDR & (1 << pin_idx)) ? true : false; 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_chipid.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_CHIPID_INSTANCE_ 31 | #define _SAMV71_CHIPID_INSTANCE_ 32 | 33 | /* ========== Register definition for CHIPID peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_CHIPID_CIDR (0x400E0940U) /**< \brief (CHIPID) Chip ID Register */ 36 | #define REG_CHIPID_EXID (0x400E0944U) /**< \brief (CHIPID) Chip ID Extension Register */ 37 | #else 38 | #define REG_CHIPID_CIDR (*(__I uint32_t*)0x400E0940U) /**< \brief (CHIPID) Chip ID Register */ 39 | #define REG_CHIPID_EXID (*(__I uint32_t*)0x400E0944U) /**< \brief (CHIPID) Chip ID Extension Register */ 40 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 41 | 42 | #endif /* _SAMV71_CHIPID_INSTANCE_ */ 43 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_gpbr.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_GPBR_INSTANCE_ 31 | #define _SAMV71_GPBR_INSTANCE_ 32 | 33 | /* ========== Register definition for GPBR peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_GPBR_GPBR (0x400E1890U) /**< \brief (GPBR) General Purpose Backup Register */ 36 | #else 37 | #define REG_GPBR_GPBR (*(__IO uint32_t*)0x400E1890U) /**< \brief (GPBR) General Purpose Backup Register */ 38 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 39 | 40 | #endif /* _SAMV71_GPBR_INSTANCE_ */ 41 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_rstc.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_RSTC_INSTANCE_ 31 | #define _SAMV71_RSTC_INSTANCE_ 32 | 33 | /* ========== Register definition for RSTC peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_RSTC_CR (0x400E1800U) /**< \brief (RSTC) Control Register */ 36 | #define REG_RSTC_SR (0x400E1804U) /**< \brief (RSTC) Status Register */ 37 | #define REG_RSTC_MR (0x400E1808U) /**< \brief (RSTC) Mode Register */ 38 | #else 39 | #define REG_RSTC_CR (*(__O uint32_t*)0x400E1800U) /**< \brief (RSTC) Control Register */ 40 | #define REG_RSTC_SR (*(__I uint32_t*)0x400E1804U) /**< \brief (RSTC) Status Register */ 41 | #define REG_RSTC_MR (*(__IO uint32_t*)0x400E1808U) /**< \brief (RSTC) Mode Register */ 42 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 43 | 44 | #endif /* _SAMV71_RSTC_INSTANCE_ */ 45 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_rswdt.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_RSWDT_INSTANCE_ 31 | #define _SAMV71_RSWDT_INSTANCE_ 32 | 33 | /* ========== Register definition for RSWDT peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_RSWDT_CR (0x400E1900U) /**< \brief (RSWDT) Control Register */ 36 | #define REG_RSWDT_MR (0x400E1904U) /**< \brief (RSWDT) Mode Register */ 37 | #define REG_RSWDT_SR (0x400E1908U) /**< \brief (RSWDT) Status Register */ 38 | #else 39 | #define REG_RSWDT_CR (*(__O uint32_t*)0x400E1900U) /**< \brief (RSWDT) Control Register */ 40 | #define REG_RSWDT_MR (*(__IO uint32_t*)0x400E1904U) /**< \brief (RSWDT) Mode Register */ 41 | #define REG_RSWDT_SR (*(__I uint32_t*)0x400E1908U) /**< \brief (RSWDT) Status Register */ 42 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 43 | 44 | #endif /* _SAMV71_RSWDT_INSTANCE_ */ 45 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_utmi.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_UTMI_INSTANCE_ 31 | #define _SAMV71_UTMI_INSTANCE_ 32 | 33 | /* ========== Register definition for UTMI peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_UTMI_OHCIICR (0x400E0410U) /**< \brief (UTMI) OHCI Interrupt Configuration Register */ 36 | #define REG_UTMI_CKTRIM (0x400E0430U) /**< \brief (UTMI) UTMI Clock Trimming Register */ 37 | #else 38 | #define REG_UTMI_OHCIICR (*(__IO uint32_t*)0x400E0410U) /**< \brief (UTMI) OHCI Interrupt Configuration Register */ 39 | #define REG_UTMI_CKTRIM (*(__IO uint32_t*)0x400E0430U) /**< \brief (UTMI) UTMI Clock Trimming Register */ 40 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 41 | 42 | #endif /* _SAMV71_UTMI_INSTANCE_ */ 43 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/instance/instance_wdt.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_WDT_INSTANCE_ 31 | #define _SAMV71_WDT_INSTANCE_ 32 | 33 | /* ========== Register definition for WDT peripheral ========== */ 34 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 35 | #define REG_WDT_CR (0x400E1850U) /**< \brief (WDT) Control Register */ 36 | #define REG_WDT_MR (0x400E1854U) /**< \brief (WDT) Mode Register */ 37 | #define REG_WDT_SR (0x400E1858U) /**< \brief (WDT) Status Register */ 38 | #else 39 | #define REG_WDT_CR (*(__O uint32_t*)0x400E1850U) /**< \brief (WDT) Control Register */ 40 | #define REG_WDT_MR (*(__IO uint32_t*)0x400E1854U) /**< \brief (WDT) Mode Register */ 41 | #define REG_WDT_SR (*(__I uint32_t*)0x400E1858U) /**< \brief (WDT) Status Register */ 42 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 43 | 44 | #endif /* _SAMV71_WDT_INSTANCE_ */ 45 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/samv71.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef _SAMV71_ 31 | #define _SAMV71_ 32 | 33 | #if defined __SAMV71J19__ 34 | #include "samv71j19.h" 35 | #elif defined __SAMV71J20__ 36 | #include "samv71j20.h" 37 | #elif defined __SAMV71J21__ 38 | #include "samv71j21.h" 39 | #elif defined __SAMV71N19__ 40 | #include "samv71n19.h" 41 | #elif defined __SAMV71N20__ 42 | #include "samv71n20.h" 43 | #elif defined __SAMV71N21__ 44 | #include "samv71n21.h" 45 | #elif defined __SAMV71Q19__ 46 | #include "samv71q19.h" 47 | #elif defined __SAMV71Q20__ 48 | #include "samv71q20.h" 49 | #elif defined __SAMV71Q21__ 50 | #include "samv71q21.h" 51 | #else 52 | #error Library does not support the specified device. 53 | #endif 54 | 55 | #endif /* _SAMV71_ */ 56 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv7/system_samv71.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- */ 2 | /* Atmel Microcontroller Software Support */ 3 | /* SAM Software Package License */ 4 | /* ---------------------------------------------------------------------------- */ 5 | /* Copyright (c) 2014, Atmel Corporation */ 6 | /* */ 7 | /* All rights reserved. */ 8 | /* */ 9 | /* Redistribution and use in source and binary forms, with or without */ 10 | /* modification, are permitted provided that the following condition is met: */ 11 | /* */ 12 | /* - Redistributions of source code must retain the above copyright notice, */ 13 | /* this list of conditions and the disclaimer below. */ 14 | /* */ 15 | /* Atmel's name may not be used to endorse or promote products derived from */ 16 | /* this software without specific prior written permission. */ 17 | /* */ 18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 | /* ---------------------------------------------------------------------------- */ 29 | 30 | #ifndef SYSTEM_SAMV71_H_INCLUDED 31 | #define SYSTEM_SAMV71_H_INCLUDED 32 | 33 | /* @cond 0 */ 34 | /**INDENT-OFF**/ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /**INDENT-ON**/ 39 | /* @endcond */ 40 | 41 | #include 42 | 43 | extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */ 44 | 45 | /** 46 | * @brief Setup the microcontroller system. 47 | * Initialize the System and update the SystemCoreClock variable. 48 | */ 49 | void SystemInit(void); 50 | 51 | /** 52 | * @brief Updates the SystemCoreClock with current core Clock 53 | * retrieved from cpu registers. 54 | */ 55 | void SystemCoreClockUpdate(void); 56 | 57 | /** 58 | * Initialize flash. 59 | */ 60 | void system_init_flash(uint32_t dw_clk); 61 | 62 | void sysclk_enable_usb(void); 63 | void sysclk_disable_usb(void); 64 | 65 | /* @cond 0 */ 66 | /**INDENT-OFF**/ 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | /**INDENT-ON**/ 71 | /* @endcond */ 72 | 73 | #endif /* SYSTEM_SAMV71_H_INCLUDED */ 74 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/samv71q21.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | flash (rx) : ORIGIN = 0x00400000, LENGTH = 2048K 4 | /* for now, let's ignore the memory complexity and use normal SRAM */ 5 | sram (rwx) : ORIGIN = 0x20400000, LENGTH = 384K 6 | } 7 | 8 | ENTRY(placeholder_reset_vector) 9 | 10 | SECTIONS 11 | { 12 | .text 0x400000 : 13 | { 14 | _sfixed = .; 15 | KEEP(*(.vectors .vectors.*)) 16 | . = 0x400; /* make it obvious when the vector table is missing */ 17 | *(.text .text.* .gnu.linkonce.t*) 18 | *(.glue_7) 19 | *(.glue_7t) 20 | *(.rodata .rodata* .gnu.linkonce.r*) 21 | . = ALIGN(4); 22 | KEEP(*(.init)) 23 | . = ALIGN(4); 24 | __preinit_array_start = .; 25 | KEEP(*(.preinit_array)) 26 | __preinit_array_end = .; 27 | . = ALIGN(4); 28 | __init_array_start = .; 29 | KEEP(*(SORT(.init_array.*))) 30 | KEEP(*(.init_array)) 31 | __init_array_end = .; 32 | . = ALIGN(4); 33 | KEEP(*(.fini)) 34 | . = ALIGN(4); 35 | __fini_array_start = .; 36 | KEEP(*(SORT(.fini_array.*))) 37 | KEEP(*(.fini_array)) 38 | __fini_array_end = .; 39 | . = ALIGN(0x4); 40 | KEEP (*crtbegin.o(.ctors)) 41 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 42 | KEEP (*(SORT(.ctors.*))) 43 | KEEP (*crtend.o(.ctors)) 44 | 45 | . = ALIGN(0x4); 46 | KEEP (*crtbegin.o(.dtors)) 47 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 48 | KEEP (*(SORT(.dtors.*))) 49 | KEEP (*crtend.o(.dtors)) 50 | } > flash 51 | . = ALIGN(4); 52 | 53 | .ARM.extab : 54 | { 55 | *(.ARM.extab* .gnu.linkonce.armextab.*) 56 | } > flash 57 | 58 | .ARM.exidx : 59 | { 60 | __exidx_start = .; 61 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 62 | __exidx_end = .; 63 | } > flash 64 | 65 | _etext = .; 66 | 67 | _srelocate_flash = .; 68 | .relocate : AT(_srelocate_flash) 69 | { 70 | . = ALIGN(4); 71 | _srelocate = .; 72 | *(.ramfunc .ramfunc.*); 73 | *(.data .data.*); 74 | . = ALIGN(4); 75 | _erelocate = .; 76 | } > sram 77 | 78 | .bss (NOLOAD) : 79 | { 80 | . = ALIGN(4); 81 | _sbss = .; 82 | _szero = .; 83 | __bss_start__ = .; 84 | *(.bss .bss.*) 85 | *(COMMON) 86 | . = ALIGN(4); 87 | _ebss = .; 88 | _ezero = .; 89 | __bss_end__ = .; 90 | } > sram 91 | 92 | .stack (NOLOAD): 93 | { 94 | . = ALIGN(8); 95 | KEEP(*(.stack .stack.*)) 96 | } > sram 97 | 98 | . = ALIGN(4); 99 | _end = .; 100 | } 101 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/systime.c: -------------------------------------------------------------------------------- 1 | #include "metal/systime.h" 2 | #include 3 | 4 | void systime_init(void) 5 | { 6 | // let's use TC0 for the system timer. 7 | // we'll use the first counter to divide down to microseconds, 8 | // and chain the second 16-bit counter into the third counter 9 | // to result in a 32-bit count of microseconds since power-up. 10 | PMC->PMC_PCER0 |= (1 << ID_TC0) | (1 << ID_TC1) | (1 << ID_TC2); 11 | // we want to feed TIMER_CLOCK2 = MCK/8 into timer/counter channel 0 12 | // we're running the system at 288 MHz, so we'll get 288/2/8 = 18 MHz 13 | // need to use TCCLKS to select TIMER_CLOCK2 as TCLK0 14 | // need to select TCLK0 as input to counter 0 in TC0XC0S mux 15 | 16 | // cascade counters into each other 17 | TC0->TC_BMR = 18 | TC_BMR_TC0XC0S_TCLK0 | 19 | TC_BMR_TC1XC1S_TIOA0 | 20 | TC_BMR_TC2XC2S_TIOA1 | 21 | TC_BMR_MAXFILT(63); 22 | /* 23 | uint32_t tc0 = (uint32_t)&TC0->TC_CHANNEL[0]; 24 | uint32_t tc1 = (uint32_t)&TC0->TC_CHANNEL[1]; 25 | uint32_t tc2 = (uint32_t)&TC0->TC_CHANNEL[2]; 26 | printf("0x%08x 0x%08x 0x%08x\r\n", tc0, tc1, tc2); 27 | */ 28 | 29 | // we need WAVSEL = 10 (without trigger) to have RC reset the counter 30 | // so we can have microseconds streaming out of the first block 31 | TC0->TC_CHANNEL[0].TC_CMR = 32 | TC_CMR_TCCLKS_TIMER_CLOCK2 | // use TIMER_CLOCK2 as input 33 | TC_CMR_ACPA_SET | 34 | TC_CMR_ACPC_CLEAR | 35 | TC_CMR_WAVE | // waveform mode 36 | TC_CMR_WAVSEL_UP_RC ; // reset when the counter hits RC 37 | TC0->TC_CHANNEL[0].TC_RC = 18; // this will reset TC0 every microsecond 38 | TC0->TC_CHANNEL[0].TC_RA = 9; // set the output high halfway through 39 | TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG; 40 | // now, feed the output of block 0 into block 1 41 | TC0->TC_CHANNEL[1].TC_CMR = 42 | TC_CMR_TCCLKS_XC1 | 43 | //TC_CMR_TCCLKS_TIMER_CLOCK2 | 44 | TC_CMR_ACPA_SET | 45 | TC_CMR_ACPC_CLEAR | 46 | TC_CMR_WAVE | 47 | TC_CMR_WAVSEL_UP ; 48 | TC0->TC_CHANNEL[1].TC_RA = 32768; // set output high halfway through 49 | TC0->TC_CHANNEL[1].TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG; 50 | 51 | TC0->TC_CHANNEL[2].TC_CMR = 52 | TC_CMR_TCCLKS_XC2 | 53 | TC_CMR_CLKI | 54 | //TC_CMR_TCCLKS_TIMER_CLOCK2 | 55 | TC_CMR_WAVE | 56 | TC_CMR_WAVSEL_UP_RC ; 57 | TC0->TC_CHANNEL[2].TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG; 58 | 59 | TC0->TC_BCR = TC_BCR_SYNC; 60 | } 61 | 62 | uint32_t systime_usecs(void) 63 | { 64 | __disable_irq(); 65 | uint32_t t1 = TC0->TC_CHANNEL[1].TC_CV; 66 | uint32_t t2 = TC0->TC_CHANNEL[2].TC_CV; 67 | __enable_irq(); 68 | //printf(" %d %d\r\n", (int)t1, (int)t2); 69 | // todo: handle pathological case where t1 rolls over in between reads to 70 | // t1 and t2. that's extremely unlikely, but it will cause time to jump back 71 | // and forth 65ms when that does happen, which could lead to badness. 72 | uint32_t t = t1 | (t2 << 16); 73 | return t; 74 | /* 75 | printf("%4d %8d %8d , %08x %08x %08x\r\n", 76 | (int)t0, (int)t1, (int)t2, 77 | (unsigned)TC0->TC_CHANNEL[0].TC_SR, 78 | (unsigned)TC0->TC_CHANNEL[1].TC_SR, 79 | (unsigned)TC0->TC_CHANNEL[2].TC_SR); 80 | */ 81 | } 82 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/time.c: -------------------------------------------------------------------------------- 1 | #include "freertps/time.h" 2 | #include 3 | #include "metal/systime.h" 4 | 5 | fr_time_t fr_time_now(void) 6 | { 7 | fr_time_t now; 8 | uint32_t t = systime_usecs(); 9 | // todo: provide faster macros for this which lose precision 10 | const uint64_t frac_sec_lcm = (uint64_t)t * 1000 * 8388608; 11 | const uint64_t frac_sec = frac_sec_lcm / 1953125; 12 | now.seconds = 1442135243 + t / 1000000; // NOT SMART! fix this 13 | now.fraction = frac_sec; 14 | return now; 15 | } 16 | -------------------------------------------------------------------------------- /systems/samv71_xplained_ultra-metal/toolchain.cmake: -------------------------------------------------------------------------------- 1 | # todo: this is duplicated from stm32_common. lots of this stuff is common 2 | # to a large class of microcontrollers. figure out how to factor it nicely. 3 | set(CMAKE_SYSTEM_NAME Generic) 4 | include(CMakeForceCompiler) 5 | CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU) 6 | set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv5-d16") 7 | set(CPU "-mcpu=cortex-m7") 8 | set(ARCH "${CPU} -mthumb") 9 | #set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16") 10 | # todo: figure out how to use FPU on this chip 11 | #set(FPU_FLAGS "-mfloat-abi=softfp") 12 | #include_directories(${PROJECT_SOURCE_DIR}/systems/samv71_xplained_ultra-metal/libchip_samv7) 13 | include_directories(${PROJECT_SOURCE_DIR}/systems/samv71_xplained_ultra-metal/samv7) 14 | include_directories(${PROJECT_SOURCE_DIR}/systems/cortex_m_common/cmsis) 15 | include_directories(${PROJECT_SOURCE_DIR}/systems/metal_common) 16 | 17 | # todo: when this package is split up to have various different SAM chips, 18 | # make a separate toolchain file for those boards which sets SAM_CHIP_HEADER 19 | # similar to how the stm32 boards work 20 | set(SAM_CHIP_HEADER "samv71q21.h") 21 | 22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -ffunction-sections -fdata-sections -include ${SAM_CHIP_HEADER}") 23 | set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") 24 | set(CMAKE_EXE_LINKER_FLAGS "-lc -lgcc -mthumb -static -Wl,--print-gc-sections -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/map,--cref") 25 | #set(CMAKE_EXE_LINKER_FLAGS "-lc -lgcc -mthumb -static -Wl,--no-gc-sections -Wl,--print-gc-sections -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/map,--cref") 26 | set(CMAKE_EXECUTABLE_SUFFIX .elf) 27 | 28 | set(make_binfiles ON CACHE BOOL "build binaries from ELFs") 29 | function(make_bin exe elf bin) 30 | #message("hello i will now turn ${elf} into ${bin}") 31 | add_custom_command(OUTPUT ${bin} 32 | COMMAND arm-none-eabi-objcopy -O binary ${elf} ${bin} 33 | DEPENDS ${elf} 34 | COMMENT "creating ${bin}") 35 | add_custom_target(${exe}_bin ALL DEPENDS ${bin}) 36 | 37 | add_custom_command(OUTPUT ${elf}.objdump 38 | COMMAND arm-none-eabi-objdump -S -d ${elf} > ${elf}.objdump 39 | DEPENDS ${elf} 40 | COMMENT "disassembling ${elf}") 41 | add_custom_target(${exe}_objdump ALL DEPENDS ${elf}.objdump) 42 | endfunction() 43 | # add FPU stuff for fancy SAM7 chips 44 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FPU_FLAGS} ${ARCH}") 45 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FPU_FLAGS} ${ARCH}") 46 | # todo: dig up linker script from an old project somewhere 47 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FPU_FLAGS} ${CPU} -T ${PROJECT_SOURCE_DIR}/systems/samv71_xplained_ultra-metal/samv71q21.ld") 48 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../stm32_common) 2 | include_directories(.) 3 | add_library(freertps_system_stm3240g_eval-metal console.c 4 | led.c 5 | systime.c 6 | flash.c 7 | imu.c 8 | enet_init_pins.c 9 | usb_fs_init_pins.c 10 | ../stm32_common/stm32f4_vectors.c) 11 | set(SYSTEM_EXTRA_LIBS "stm32_common metal_common" CACHE STRING "extra system libs") 12 | set(SYSTEM_APPS "listener talker talker_stm32_timer led" CACHE STRING "applications for this system") 13 | set(SYSTEM_NO_ROSIDL_APPS "talker_no_rosidl listener_no_rosidl" CACHE STRING "") 14 | if (NOT freertps_standalone) 15 | ament_export_libraries(freertps_system_${SYSTEM}) 16 | endif() 17 | install( 18 | TARGETS freertps_system_${SYSTEM} 19 | ARCHIVE DESTINATION lib 20 | LIBRARY DESTINATION lib 21 | RUNTIME DESTINATION bin 22 | ) 23 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/console.c: -------------------------------------------------------------------------------- 1 | #include "metal/console.h" 2 | #include "pin.h" 3 | #include 4 | 5 | // finding a spare UART tx pin on the STM3240G-eval board is tricky... just 6 | // about every pin is doing several things. This configuration of UART means 7 | // that you can't use the micro-SD card. Every other configuration I could 8 | // find also has tradeoffs. At the moment I don't intend to use micro-SD 9 | // with freertps-based systems, so we'll just go with this for now. This can 10 | // be swapped for various other tradeoffs (i.e., make the camera unusable) 11 | // if desired. 12 | // 13 | // PC12 = UART5 TX on AF8 14 | 15 | #define PORTC_TX_PIN 12 16 | 17 | USART_TypeDef *g_console_usart = UART5; 18 | 19 | static volatile bool g_console_init_complete = false; 20 | 21 | void console_init(void) 22 | { 23 | RCC->APB1ENR |= RCC_APB1ENR_UART5EN; 24 | pin_set_alternate_function(GPIOC, PORTC_TX_PIN, 8); 25 | g_console_usart->CR1 &= ~USART_CR1_UE; 26 | g_console_usart->CR1 |= USART_CR1_TE; 27 | // we want 1 megabit. the UART5 bus is 168 mhz / 4 = 42 mhz. 28 | // the uart bit counter is /16, so we need to further divide by 2.625 29 | // to get 1 megabit using the fractional baud rate divider 30 | // so, we have to set mantissa=2 and fraction (sixteenths)=10 31 | g_console_usart->BRR = (((uint16_t)2) << 4) | 10; 32 | g_console_usart->CR1 |= USART_CR1_UE; 33 | g_console_init_complete = true; 34 | } 35 | 36 | void console_send_block(const uint8_t *buf, uint32_t len) 37 | { 38 | if (!g_console_init_complete) 39 | console_init(); 40 | for (uint32_t i = 0; i < len; i++) 41 | { 42 | while (!(g_console_usart->SR & USART_SR_TXE)) { } // wait for tx buffer 43 | g_console_usart->DR = buf[i]; 44 | } 45 | while (!(g_console_usart->SR & USART_SR_TC)) { } // wait for TX to finish 46 | } 47 | 48 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/enet_init_pins.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pin.h" 3 | #include "metal/delay.h" 4 | 5 | // PHY: DP83848CVV over MII 6 | 7 | #define PORTA_ETH_REFCLK 1 8 | 9 | #define PORTA_ETH_CRSDV 7 10 | #define PORTC_ETH_RXD0 4 11 | #define PORTC_ETH_RXD1 5 12 | #define PORTH_ETH_RXD2 6 13 | #define PORTH_ETH_RXD3 7 14 | 15 | #define PORTG_ETH_TXEN 11 16 | #define PORTC_ETH_TXCLK 3 17 | #define PORTG_ETH_TXD0 13 18 | #define PORTG_ETH_TXD1 14 19 | #define PORTC_ETH_TXD2 2 20 | #define PORTB_ETH_TXD3 8 21 | 22 | #define PORTC_ETH_MDC 1 23 | #define PORTA_ETH_MDIO 2 24 | 25 | #define AF_ENET 11 26 | 27 | void enet_mac_init_pins(void) 28 | { 29 | printf("enet_init_pins()\r\n"); 30 | 31 | pin_set_alternate_function(GPIOA, PORTA_ETH_REFCLK, AF_ENET); 32 | pin_set_alternate_function(GPIOA, PORTA_ETH_MDIO , AF_ENET); 33 | pin_set_alternate_function(GPIOC, PORTC_ETH_MDC , AF_ENET); 34 | 35 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXEN , AF_ENET); 36 | pin_set_alternate_function(GPIOC, PORTC_ETH_TXCLK , AF_ENET); 37 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXD0 , AF_ENET); 38 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXD1 , AF_ENET); 39 | pin_set_alternate_function(GPIOC, PORTC_ETH_TXD2 , AF_ENET); 40 | pin_set_alternate_function(GPIOB, PORTB_ETH_TXD3 , AF_ENET); 41 | 42 | pin_set_alternate_function(GPIOA, PORTA_ETH_CRSDV , AF_ENET); 43 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD0 , AF_ENET); 44 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD1 , AF_ENET); 45 | pin_set_alternate_function(GPIOH, PORTH_ETH_RXD2 , AF_ENET); 46 | pin_set_alternate_function(GPIOH, PORTH_ETH_RXD3 , AF_ENET); 47 | 48 | pin_set_output_speed(GPIOG, PORTG_ETH_TXEN , 3); // max beef 49 | pin_set_output_speed(GPIOC, PORTC_ETH_TXCLK, 3); // max beef 50 | pin_set_output_speed(GPIOG, PORTG_ETH_TXD0 , 3); // max beef 51 | pin_set_output_speed(GPIOG, PORTG_ETH_TXD1 , 3); // max beef 52 | pin_set_output_speed(GPIOC, PORTC_ETH_TXD2 , 3); // max beef 53 | pin_set_output_speed(GPIOB, PORTB_ETH_TXD3 , 3); // max beef 54 | } 55 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/flash.c: -------------------------------------------------------------------------------- 1 | #include "flash.h" 2 | 3 | void flash_init(void) 4 | { 5 | FLASH->ACR = 0; // ensure the caches are turned off, so we can reset them 6 | FLASH->ACR = FLASH_ACR_DCRST | FLASH_ACR_ICRST; // flush the cache 7 | FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | 8 | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_5WS; // re-enable the caches 9 | } 10 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/imu.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/imu.h" 2 | #include 3 | #include "pin.h" 4 | #include "metal/delay.h" 5 | 6 | // stm3240g_eval doesn't have any IMU functions. 7 | 8 | void imu_init(void) 9 | { 10 | return; 11 | } 12 | 13 | bool imu_poll_accels(float *xyz) 14 | { 15 | xyz[0] = xyz[1] = xyz[2] = 0; 16 | return true; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/led.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/led.h" 2 | #include "pin.h" 3 | 4 | #define PORTG_LED 6 5 | 6 | void led_init(void) 7 | { 8 | pin_set_output(GPIOG, PORTG_LED, 0); 9 | } 10 | 11 | void led_on(void) 12 | { 13 | pin_set_output_state(GPIOG, PORTG_LED, 1); 14 | } 15 | 16 | void led_off(void) 17 | { 18 | pin_set_output_state(GPIOG, PORTG_LED, 0); 19 | } 20 | 21 | void led_toggle(void) 22 | { 23 | GPIOG->ODR ^= 1 << PORTG_LED; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/openocd.cfg: -------------------------------------------------------------------------------- 1 | # This is an STM32F4 discovery board with a single STM32F407VGT6 chip. 2 | # http://www.st.com/internet/evalboard/product/252419.jsp 3 | 4 | source [find interface/stlink-v2.cfg] 5 | 6 | transport select hla_swd 7 | 8 | source [find target/stm32f4x.cfg] 9 | 10 | reset_config srst_only 11 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/systime.c: -------------------------------------------------------------------------------- 1 | #include "metal/systime.h" 2 | #include "metal/delay.h" 3 | 4 | void systime_init(void) 5 | { 6 | // todo; use TIM2 since it's a 32-bit counter. just have it count 7 | // microseconds since powerup or something. 8 | RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; 9 | for (volatile int i = 0; i < 10000; i++) { } 10 | TIM2->PSC = 168000000 / 2 / 1000000 - 1; // 83 11 | TIM2->ARR = 0xffffffff; // count as long as possible 12 | TIM2->EGR = TIM_EGR_UG; // load the PSC register immediately 13 | TIM2->CR1 = TIM_CR1_CEN; // start counter 14 | } 15 | 16 | uint32_t systime_usecs(void) 17 | { 18 | return TIM2->CNT; 19 | } 20 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_CHIP_HEADER "stm32f407xx.h") 2 | include_directories(${PROJECT_SOURCE_DIR}/systems/metal_common) 3 | include(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmake/stm32f4.cmake) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHSE_VALUE=25000000 -DENET_USE_MII -DENET_PHY_ADDR=1") 5 | -------------------------------------------------------------------------------- /systems/stm3240g_eval-metal/usb_fs_init_pins.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pin.h" 3 | 4 | #define PORTA_USB_FS_VBUS 9 5 | #define PORTA_USB_FS_ID 10 6 | #define PORTA_USB_FS_DM 11 7 | #define PORTA_USB_FS_DP 12 8 | 9 | #define PORTF_USB_FS_OVERCURRENT 11 10 | #define PORTH_USB_FS_PWR_SWITCH_ON 5 11 | 12 | #define AF_USB_FS 10 13 | 14 | void usb_fs_init_pins(void) 15 | { 16 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_DP, AF_USB_FS); 17 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_DM, AF_USB_FS); 18 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_ID, AF_USB_FS); 19 | 20 | pin_set_output_speed(GPIOA, PORTA_USB_FS_DM, 3); 21 | pin_set_output_speed(GPIOA, PORTA_USB_FS_DP, 3); 22 | } 23 | -------------------------------------------------------------------------------- /systems/stm32_common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(stm32_common pin.c time_stm32.c startup.c startup.c enet_mac.c timer.c) 2 | -------------------------------------------------------------------------------- /systems/stm32_common/cmake/stm32_common.cmake: -------------------------------------------------------------------------------- 1 | #set(CMAKE_SYSTEM_NAME Generic) 2 | #set(CMAKE_C_COMPILER arm-none-eabi-gcc) 3 | #set(CMAKE_RANLIB CACHE STRING arm-none-eabi-ranlib) 4 | #set(CMAKE_AR CACHE STRING arm-none-eabi-ar) 5 | set(CMAKE_SYSTEM_NAME Generic) 6 | include(CMakeForceCompiler) 7 | CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU) 8 | CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GNU) 9 | set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16") 10 | include_directories(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmsis) 11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -include ${STM32_CHIP_HEADER}") 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -include ${STM32_CHIP_HEADER}") 13 | set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") 14 | set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") 15 | set(CMAKE_EXE_LINKER_FLAGS "-lc -lgcc -mthumb -static -Wl,--print-gc-sections -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/map,--cref") 16 | #set(CMAKE_EXE_LINKER_FLAGS "-lc -lgcc -mthumb -static -Wl,--no-gc-sections -Wl,--print-gc-sections -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/map,--cref") 17 | set(CMAKE_EXECUTABLE_SUFFIX .elf) 18 | 19 | set(make_binfiles ON CACHE BOOL "build binaries from ELFs") 20 | function(make_bin exe elf bin) 21 | #message("hello i will now turn ${elf} into ${bin}") 22 | add_custom_command(OUTPUT ${bin} 23 | COMMAND arm-none-eabi-objcopy -O binary ${elf} ${bin} 24 | DEPENDS ${elf} 25 | COMMENT "creating ${bin}") 26 | add_custom_target(${exe}_bin ALL DEPENDS ${bin}) 27 | 28 | add_custom_command(OUTPUT ${elf}.objdump 29 | COMMAND arm-none-eabi-objdump -S -d ${elf} > ${elf}.objdump 30 | DEPENDS ${elf} 31 | COMMENT "disassembling ${elf}") 32 | add_custom_target(${exe}_objdump ALL DEPENDS ${elf}.objdump) 33 | endfunction() 34 | -------------------------------------------------------------------------------- /systems/stm32_common/cmake/stm32f4.cmake: -------------------------------------------------------------------------------- 1 | include(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmake/stm32_common.cmake) 2 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FPU_FLAGS} -mcpu=cortex-m4 -mthumb") 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FPU_FLAGS} -mcpu=cortex-m4 -mthumb") 4 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FPU_FLAGS} -mcpu=cortex-m4 -T ${PROJECT_SOURCE_DIR}/systems/stm32_common/ld/stm32f4xx.ld") 5 | -------------------------------------------------------------------------------- /systems/stm32_common/cmake/stm32f7.cmake: -------------------------------------------------------------------------------- 1 | # todo: not sure why, but if cortex-m7 is specified, it seems to result 2 | # link errors due to VFP instructions 3 | include(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmake/stm32_common.cmake) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FPU_FLAGS} -mcpu=cortex-m4 -mthumb") 5 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FPU_FLAGS} -mcpu=cortex-m4 -mthumb -T ${PROJECT_SOURCE_DIR}/systems/stm32_common/ld/stm32f746.ld") 6 | -------------------------------------------------------------------------------- /systems/stm32_common/cmsis/stm32f407xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/systems/stm32_common/cmsis/stm32f407xx.h -------------------------------------------------------------------------------- /systems/stm32_common/cmsis/stm32f427xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/systems/stm32_common/cmsis/stm32f427xx.h -------------------------------------------------------------------------------- /systems/stm32_common/cmsis/stm32f746xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godzilla-max/freertps/168e86133556d92b72875fa6d1b8f1d463f9a30b/systems/stm32_common/cmsis/stm32f746xx.h -------------------------------------------------------------------------------- /systems/stm32_common/enet_mac.h: -------------------------------------------------------------------------------- 1 | #ifndef ENET_MAC_H 2 | #define ENET_MAC_H 3 | 4 | #include 5 | 6 | void enet_mac_init_pins(void); // must be provided in a board-specific file 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /systems/stm32_common/flash.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_H 2 | #define FLASH_H 3 | 4 | void flash_init(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /systems/stm32_common/ld/stm32f4xx.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | flash (rx) : ORIGIN = 0x08000000, LENGTH = 1024K 4 | sram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K 5 | } 6 | 7 | ENTRY(dummy_reset_vector) 8 | 9 | SECTIONS 10 | { 11 | .text : 12 | { 13 | KEEP(*(.vectors .vectors.*)) 14 | . = 0x400; /* make it obvious when the vector table is missing */ 15 | *(.text .text.* .gnu.linkonce.t*) 16 | *(.glue_7) 17 | *(.glue_7t) 18 | *(.rodata .rodata* .gnu.linkonce.r*) 19 | . = ALIGN(4); 20 | KEEP(*(.init)) 21 | . = ALIGN(4); 22 | __preinit_array_start = .; 23 | KEEP(*(.preinit_array*)) 24 | __preinit_array_end = .; 25 | . = ALIGN(4); 26 | __init_array_start = .; 27 | KEEP(*(SORT(.init_array.*))) 28 | KEEP(*(.init_array*)) 29 | __init_array_end = .; 30 | . = ALIGN(4); 31 | KEEP(*(.fini)) 32 | . = ALIGN(4); 33 | __fini_array_start = .; 34 | KEEP(*(SORT(.fini_array.*))) 35 | KEEP(*(.fini_array)) 36 | __fini_array_end = .; 37 | . = ALIGN(0x4); 38 | KEEP (*crtbegin.o(.ctors)) 39 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 40 | KEEP (*(SORT(.ctors.*))) 41 | KEEP (*crtend.o(.ctors)) 42 | 43 | . = ALIGN(0x4); 44 | KEEP (*crtbegin.o(.dtors)) 45 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 46 | KEEP (*(SORT(.dtors.*))) 47 | KEEP (*crtend.o(.dtors)) 48 | } > flash 49 | . = ALIGN(4); 50 | 51 | .ARM.extab : 52 | { 53 | *(.ARM.extab* .gnu.linkonce.armextab.*) 54 | } > flash 55 | 56 | .ARM.exidx : 57 | { 58 | __exidx_start = .; 59 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 60 | __exidx_end = .; 61 | } > flash 62 | 63 | 64 | _srelocate_flash = .; 65 | .relocate : AT(_srelocate_flash) 66 | { 67 | . = ALIGN(4); 68 | _srelocate = .; 69 | *(.ramfunc .ramfunc.*); 70 | *(.data .data.*); 71 | . = ALIGN(4); 72 | _erelocate = .; 73 | } > sram 74 | 75 | .bss (NOLOAD) : 76 | { 77 | . = ALIGN(4); 78 | _sbss = .; 79 | __bss_start__ = .; 80 | *(.bss .bss.*) 81 | *(COMMON) 82 | . = ALIGN(4); 83 | _ebss = .; 84 | __bss_end__ = .; 85 | } > sram 86 | 87 | .stack (NOLOAD): 88 | { 89 | . = ALIGN(8); 90 | KEEP(*(.stack .stack.*)) 91 | } > sram 92 | 93 | . = ALIGN(4); 94 | _end = .; 95 | } 96 | -------------------------------------------------------------------------------- /systems/stm32_common/ld/stm32f746.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | flash (rx) : ORIGIN = 0x08000000, LENGTH = 1024K 4 | /* for now, let's ignore the memory complexity and just use SRAM1 */ 5 | sram (rwx) : ORIGIN = 0x20010000, LENGTH = 240K 6 | } 7 | 8 | ENTRY(dummy_reset_vector) 9 | 10 | SECTIONS 11 | { 12 | .text : 13 | { 14 | KEEP(*(.vectors .vectors.*)) 15 | . = 0x400; /* make it obvious when the vector table is missing */ 16 | *(.text .text.* .gnu.linkonce.t*) 17 | *(.glue_7) 18 | *(.glue_7t) 19 | *(.rodata .rodata* .gnu.linkonce.r*) 20 | . = ALIGN(4); 21 | KEEP(*(.init)) 22 | . = ALIGN(4); 23 | __preinit_array_start = .; 24 | KEEP(*(.preinit_array)) 25 | __preinit_array_end = .; 26 | . = ALIGN(4); 27 | __init_array_start = .; 28 | KEEP(*(SORT(.init_array.*))) 29 | KEEP(*(.init_array)) 30 | __init_array_end = .; 31 | . = ALIGN(4); 32 | KEEP(*(.fini)) 33 | . = ALIGN(4); 34 | __fini_array_start = .; 35 | KEEP(*(SORT(.fini_array.*))) 36 | KEEP(*(.fini_array)) 37 | __fini_array_end = .; 38 | . = ALIGN(0x4); 39 | KEEP (*crtbegin.o(.ctors)) 40 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 41 | KEEP (*(SORT(.ctors.*))) 42 | KEEP (*crtend.o(.ctors)) 43 | 44 | . = ALIGN(0x4); 45 | KEEP (*crtbegin.o(.dtors)) 46 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 47 | KEEP (*(SORT(.dtors.*))) 48 | KEEP (*crtend.o(.dtors)) 49 | } > flash 50 | . = ALIGN(4); 51 | 52 | .ARM.extab : 53 | { 54 | *(.ARM.extab* .gnu.linkonce.armextab.*) 55 | } > flash 56 | 57 | .ARM.exidx : 58 | { 59 | __exidx_start = .; 60 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 61 | __exidx_end = .; 62 | } > flash 63 | 64 | 65 | _srelocate_flash = .; 66 | .relocate : AT(_srelocate_flash) 67 | { 68 | . = ALIGN(4); 69 | _srelocate = .; 70 | *(.ramfunc .ramfunc.*); 71 | *(.data .data.*); 72 | . = ALIGN(4); 73 | _erelocate = .; 74 | } > sram 75 | 76 | .bss (NOLOAD) : 77 | { 78 | . = ALIGN(4); 79 | _sbss = .; 80 | __bss_start__ = .; 81 | *(.bss .bss.*) 82 | *(COMMON) 83 | . = ALIGN(4); 84 | _ebss = .; 85 | __bss_end__ = .; 86 | } > sram 87 | 88 | .stack (NOLOAD): 89 | { 90 | . = ALIGN(8); 91 | KEEP(*(.stack .stack.*)) 92 | } > sram 93 | 94 | . = ALIGN(4); 95 | _end = .; 96 | } 97 | -------------------------------------------------------------------------------- /systems/stm32_common/openocd/gdb_init_commands: -------------------------------------------------------------------------------- 1 | target remote localhost:3333 2 | -------------------------------------------------------------------------------- /systems/stm32_common/openocd/olimex-arm-usb-tiny-h.cfg: -------------------------------------------------------------------------------- 1 | interface ftdi 2 | ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H" 3 | ftdi_vid_pid 0x15ba 0x002a 4 | 5 | ftdi_layout_init 0x0c08 0x0f1b 6 | ftdi_layout_signal nSRST -oe 0x0200 7 | ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400 8 | ftdi_layout_signal LED -data 0x0800 9 | adapter_khz 500 10 | #reset_config none 11 | #adapter_nsrst_delay 10 12 | #adapter_nsrst_assert_width 100 13 | reset_config srst_only 14 | -------------------------------------------------------------------------------- /systems/stm32_common/openocd/stlink-v2-1.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # STMicroelectronics ST-LINK/V2-1 in-circuit debugger/programmer 3 | # 4 | 5 | interface hla 6 | hla_layout stlink 7 | hla_device_desc "ST-LINK/V2-1" 8 | hla_vid_pid 0x0483 0x374b 9 | #transport select hla_jtag 10 | transport select hla_swd 11 | 12 | # Optionally specify the serial number of ST-LINK/V2 usb device. ST-LINK/V2 13 | # devices seem to have serial numbers with unreadable characters. ST-LINK/V2 14 | # firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial 15 | # number reset issues. 16 | # eg. 17 | #hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f" 18 | 19 | -------------------------------------------------------------------------------- /systems/stm32_common/openocd/stm32f427.cfg: -------------------------------------------------------------------------------- 1 | if { [info exists CHIPNAME] } { 2 | set _CHIPNAME $CHIPNAME 3 | } else { 4 | set _CHIPNAME stm32f4x 5 | } 6 | 7 | if { [info exists ENDIAN] } { 8 | set _ENDIAN $ENDIAN 9 | } else { 10 | set _ENDIAN little 11 | } 12 | 13 | #jtag scan chain 14 | if { [info exists CPUTAPID ] } { 15 | set _CPUTAPID $CPUTAPID 16 | } else { 17 | set _CPUTAPID 0x4ba00477 18 | } 19 | 20 | jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 21 | 22 | set _TARGETNAME $_CHIPNAME.cpu 23 | 24 | if { [info exists BSTAPID] } { 25 | set _BSTAPID $BSTAPID 26 | } else { 27 | set _BSTAPID 0x06419041 28 | } 29 | 30 | jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID 31 | 32 | target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME 33 | 34 | # 16K is plenty, the smallest chip has this much 35 | $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size 16384 -work-area-backup 0 36 | 37 | $_TARGETNAME configure -event gdb-flash-erase-start { 38 | halt 39 | } 40 | 41 | 42 | set _FLASHNAME $_CHIPNAME.flash 43 | 44 | #working_area 0 0x20000000 16384 nobackup 45 | flash bank $_FLASHNAME stm32f2x 0x08000000 0x200000 0 0 $_TARGETNAME 46 | 47 | -------------------------------------------------------------------------------- /systems/stm32_common/openocd/stm32f7-disco.cfg: -------------------------------------------------------------------------------- 1 | # this is mostly a straight copy of http://sourceforge.net/p/openocd/mailman/openocd-devel/thread/20150429135144.B2F2C19809EA@mail.openocd.org/ 2 | 3 | source [find target/swj-dp.tcl] 4 | 5 | set _CHIPNAME STM32F746 6 | 7 | #jtag scan chain 8 | if { [info exists CPUTAPID ] } { 9 | set _CPUTAPID $CPUTAPID 10 | } else { 11 | if { [using_jtag] } { 12 | # See STM Document RM0385 13 | # Section 40.6.3 - corresponds to Cortex-M7 with FPU r0p0 14 | set _CPUTAPID 0x5ba00477 15 | } else { 16 | set _CPUTAPID 0x5ba02477 17 | } 18 | } 19 | 20 | swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 21 | #swd newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 22 | 23 | if { [info exists BSTAPID] } { 24 | set _BSTAPID $BSTAPID 25 | } else { 26 | # See STM Document RM0385, section 40.6.1, STM32F75xxG 27 | set _BSTAPID1 0x06449071 28 | } 29 | 30 | #if {[using_jtag]} { 31 | # swj_newdap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 32 | #} 33 | 34 | set _TARGETNAME $_CHIPNAME.cpu 35 | 36 | target create $_TARGETNAME cortex_m -endian little -chain-position $_TARGETNAME 37 | 38 | # work area of 256k 39 | $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size 0x40000 -work-area-backup 0 40 | 41 | set _FLASHNAME $_CHIPNAME.flash 42 | flash bank $_FLASHNAME stm32f7x 0 0 0 0 $_TARGETNAME 43 | 44 | adapter_khz 2000 45 | 46 | adapter_nsrst_delay 100 47 | if {[using_jtag]} { 48 | jtag_ntrst_delay 100 49 | } 50 | 51 | reset_config srst_only srst_nogate 52 | 53 | if {![using_hla]} { 54 | cortex_m reset_config sysresetreq 55 | } 56 | -------------------------------------------------------------------------------- /systems/stm32_common/pin.h: -------------------------------------------------------------------------------- 1 | #ifndef PIN_H 2 | #define PIN_H 3 | 4 | #include 5 | 6 | #define PIN_OUTPUT_TYPE_PUSH_PULL 0 7 | #define PIN_OUTPUT_TYPE_OPEN_DRAIN 1 8 | 9 | void pin_set_output_type(GPIO_TypeDef *gpio, 10 | const uint8_t pin_idx, 11 | const uint8_t output_type); 12 | void pin_set_alternate_function(GPIO_TypeDef *gpio, 13 | const uint8_t pin_idx, 14 | const uint8_t function_idx); 15 | void pin_set_analog(GPIO_TypeDef *gpio, const uint8_t pin_idx); 16 | void pin_set_output(GPIO_TypeDef *gpio, 17 | const uint8_t pin_idx, 18 | const uint8_t initial_state); 19 | void pin_set_output_speed(GPIO_TypeDef *gpio, 20 | const uint_fast8_t pin_idx, 21 | const uint_fast8_t speed); 22 | 23 | void pin_set_output_state(GPIO_TypeDef *gpio, 24 | const uint8_t pin_idx, 25 | const uint8_t state); 26 | 27 | void pin_toggle_state(GPIO_TypeDef *gpio, const uint8_t pin_idx); 28 | 29 | void pin_set_input(GPIO_TypeDef *gpio, const uint8_t pin_idx, 30 | const bool enable_pullup); 31 | 32 | static inline void pin_set_output_high(GPIO_TypeDef *gpio, 33 | const uint8_t pin_idx) 34 | { 35 | gpio->BSRR = 1 << pin_idx; 36 | } 37 | 38 | static inline void pin_set_output_low(GPIO_TypeDef *gpio, 39 | const uint8_t pin_idx) 40 | { 41 | gpio->BSRR = (1 << pin_idx) << 16; 42 | } 43 | 44 | static inline bool pin_get_state(GPIO_TypeDef *gpio, const uint_fast8_t pin_idx) 45 | { 46 | return (gpio->IDR & (1 << pin_idx)) ? true : false; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /systems/stm32_common/startup.h: -------------------------------------------------------------------------------- 1 | #ifndef STARTUP_H 2 | #define STARTUP_H 3 | 4 | void reset_vector(void); 5 | void disable_overdrive(void); 6 | void enable_overdrive(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /systems/stm32_common/time_stm32.c: -------------------------------------------------------------------------------- 1 | #include "freertps/time.h" 2 | #include 3 | #include "metal/systime.h" 4 | 5 | fr_time_t fr_time_now(void) 6 | { 7 | fr_time_t now; 8 | uint32_t t = systime_usecs(); 9 | // todo: provide faster macros for this which lose precision 10 | const uint64_t frac_sec_lcm = (uint64_t)t * 1000 * 8388608; 11 | const uint64_t frac_sec = frac_sec_lcm / 1953125; 12 | now.seconds = 1436564555 + t / 1000000; // NOT SMART! fix this 13 | now.fraction = frac_sec; 14 | return now; 15 | } 16 | -------------------------------------------------------------------------------- /systems/stm32_common/timer.c: -------------------------------------------------------------------------------- 1 | #include "freertps/timer.h" 2 | #include 3 | 4 | static freertps_timer_cb_t g_freertps_timer_cb = NULL; 5 | 6 | void freertps_timer_set_freq(uint32_t freq, freertps_timer_cb_t cb) 7 | { 8 | // set up TIM5 as the timer. generalize this someday if needed 9 | RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; 10 | TIM5->PSC = 168000000 / 2 / 1000000 - 1; // microsecond resolution 11 | if (freq == 0 || freq >= 500000) 12 | while (1) { } // extreme badness 13 | TIM5->ARR = 1000000 / freq - 1; // auto-reload @ 1000 Hz 14 | TIM5->EGR = TIM_EGR_UG; // load PSC immediately 15 | TIM5->CR1 = TIM_CR1_CEN; // start it counting 16 | TIM5->DIER = TIM_DIER_UIE; // enable update interrupt 17 | NVIC_SetPriority(TIM5_IRQn, 2); 18 | NVIC_EnableIRQ(TIM5_IRQn); 19 | g_freertps_timer_cb = cb; 20 | } 21 | 22 | void tim5_vector(void) 23 | { 24 | TIM5->SR &= ~TIM_SR_UIF; // clear the update flag 25 | if (g_freertps_timer_cb) 26 | g_freertps_timer_cb(); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../stm32_common) 2 | include_directories(.) 3 | add_library(freertps_system_stm32f4_disco-metal console.c 4 | led.c 5 | systime.c 6 | flash.c 7 | imu.c 8 | enet_init_pins.c 9 | usb_fs_init_pins.c 10 | ../stm32_common/stm32f4_vectors.c) 11 | set(SYSTEM_EXTRA_LIBS "stm32_common metal_common" CACHE STRING "extra system libs") 12 | set(SYSTEM_APPS "listener talker talker_stm32_timer imu led blink hello_world cpp_test" CACHE STRING "applications for this system") 13 | set(SYSTEM_NO_ROSIDL_APPS "talker_no_rosidl listener_no_rosidl" CACHE STRING "") 14 | if (NOT freertps_standalone) 15 | ament_export_libraries(freertps_system_${SYSTEM}) 16 | endif() 17 | install( 18 | TARGETS freertps_system_${SYSTEM} 19 | ARCHIVE DESTINATION lib 20 | LIBRARY DESTINATION lib 21 | RUNTIME DESTINATION bin 22 | ) 23 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/console.c: -------------------------------------------------------------------------------- 1 | #include "metal/console.h" 2 | #include "pin.h" 3 | #include 4 | 5 | // pin connections for stm32f7-discovery board 6 | // PC6 = UART6 TX on AF8 7 | // PC7 = UART6 RX on AF8 8 | 9 | #define PORTC_TX_PIN 6 10 | #define PORTC_RX_PIN 7 11 | 12 | USART_TypeDef *g_console_usart = USART6; 13 | 14 | static volatile bool g_console_init_complete = false; 15 | 16 | void console_init(void) 17 | { 18 | RCC->APB2ENR |= RCC_APB2ENR_USART6EN; 19 | pin_set_alternate_function(GPIOC, PORTC_RX_PIN, 8); 20 | pin_set_alternate_function(GPIOC, PORTC_TX_PIN, 8); 21 | g_console_usart->CR1 &= ~USART_CR1_UE; 22 | g_console_usart->CR1 |= USART_CR1_TE | USART_CR1_RE; 23 | // we want 1 megabit. do this with mantissa=5 and fraction (sixteenths)=4 24 | g_console_usart->BRR = (((uint16_t)5) << 4) | 4; 25 | g_console_usart->CR1 |= USART_CR1_UE; 26 | g_console_init_complete = true; 27 | } 28 | 29 | void console_send_block(const uint8_t *buf, uint32_t len) 30 | { 31 | if (!g_console_init_complete) 32 | console_init(); 33 | for (uint32_t i = 0; i < len; i++) 34 | { 35 | while (!(g_console_usart->SR & USART_SR_TXE)) { } // wait for tx buffer 36 | g_console_usart->DR = buf[i]; 37 | } 38 | while (!(g_console_usart->SR & USART_SR_TC)) { } // wait for TX to finish 39 | } 40 | 41 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/enet_init_pins.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pin.h" 3 | #include "metal/delay.h" 4 | 5 | #define PORTA_ETH_REFCLK 1 6 | #define PORTE_PHY_RESET 2 7 | 8 | #define PORTA_ETH_CRSDV 7 9 | #define PORTC_ETH_RXD0 4 10 | #define PORTC_ETH_RXD1 5 11 | 12 | #define PORTB_ETH_TXEN 11 13 | #define PORTB_ETH_TXD0 12 14 | #define PORTB_ETH_TXD1 13 15 | 16 | #define PORTC_ETH_MDC 1 17 | #define PORTA_ETH_MDIO 2 18 | 19 | #define AF_ENET 11 20 | 21 | // PHY: LAN8720 22 | 23 | void enet_mac_init_pins(void) 24 | { 25 | printf("enet_mac_init_pins()\r\n"); 26 | 27 | pin_set_alternate_function(GPIOA, PORTA_ETH_REFCLK, AF_ENET); 28 | pin_set_alternate_function(GPIOA, PORTA_ETH_MDIO , AF_ENET); 29 | pin_set_alternate_function(GPIOC, PORTC_ETH_MDC , AF_ENET); 30 | 31 | pin_set_alternate_function(GPIOB, PORTB_ETH_TXEN , AF_ENET); 32 | pin_set_alternate_function(GPIOB, PORTB_ETH_TXD0 , AF_ENET); 33 | pin_set_alternate_function(GPIOB, PORTB_ETH_TXD1 , AF_ENET); 34 | 35 | pin_set_alternate_function(GPIOA, PORTA_ETH_CRSDV , AF_ENET); 36 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD0 , AF_ENET); 37 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD1 , AF_ENET); 38 | 39 | pin_set_output_speed(GPIOB, PORTB_ETH_TXEN, 3); // max beef 40 | pin_set_output_speed(GPIOB, PORTB_ETH_TXD0, 3); // max beef 41 | pin_set_output_speed(GPIOB, PORTB_ETH_TXD1, 3); // max beef 42 | 43 | pin_set_output(GPIOE, PORTE_PHY_RESET, 1); 44 | delay_ms(100); 45 | pin_set_output_state(GPIOE, PORTE_PHY_RESET, 0); 46 | delay_ms(100); 47 | pin_set_output_state(GPIOE, PORTE_PHY_RESET, 1); 48 | delay_ms(100); 49 | } 50 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/flash.c: -------------------------------------------------------------------------------- 1 | #include "flash.h" 2 | 3 | void flash_init(void) 4 | { 5 | FLASH->ACR = 0; // ensure the caches are turned off, so we can reset them 6 | FLASH->ACR = FLASH_ACR_DCRST | FLASH_ACR_ICRST; // flush the cache 7 | FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | 8 | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_5WS; // re-enable the caches 9 | } 10 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/led.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/led.h" 2 | #include "pin.h" 3 | 4 | // let's use LED4, since it's green, and green means that everything is OK 5 | #define LED_PIN 12 6 | #define LED_GPIO GPIOD 7 | 8 | // this board has lots of LEDs though. maybe we should refactor this library 9 | // so that it can take the index of LED to turn on. 10 | 11 | void led_init(void) 12 | { 13 | pin_set_output(LED_GPIO, LED_PIN, 0); 14 | } 15 | 16 | void led_on(void) 17 | { 18 | pin_set_output_state(LED_GPIO, LED_PIN, 1); 19 | } 20 | 21 | void led_off(void) 22 | { 23 | pin_set_output_state(LED_GPIO, LED_PIN, 0); 24 | } 25 | 26 | void led_toggle(void) 27 | { 28 | LED_GPIO->ODR ^= 1 << LED_PIN; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/openocd.cfg: -------------------------------------------------------------------------------- 1 | # This is an STM32F4 discovery board with a single STM32F407VGT6 chip. 2 | # http://www.st.com/internet/evalboard/product/252419.jsp 3 | 4 | source [find interface/stlink-v2.cfg] 5 | 6 | transport select hla_swd 7 | 8 | source [find target/stm32f4x.cfg] 9 | 10 | reset_config srst_only 11 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/systime.c: -------------------------------------------------------------------------------- 1 | #include "metal/systime.h" 2 | #include "metal/delay.h" 3 | 4 | void systime_init(void) 5 | { 6 | // todo; use TIM2 since it's a 32-bit counter. just have it count 7 | // microseconds since powerup or something. 8 | RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; 9 | for (volatile int i = 0; i < 10000; i++) { } 10 | TIM2->PSC = 168000000 / 2 / 1000000 - 1; // 83 11 | TIM2->ARR = 0xffffffff; // count as long as possible 12 | TIM2->EGR = TIM_EGR_UG; // load the PSC register immediately 13 | TIM2->CR1 = TIM_CR1_CEN; // start counter 14 | } 15 | 16 | uint32_t systime_usecs(void) 17 | { 18 | return TIM2->CNT; 19 | } 20 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_CHIP_HEADER "stm32f407xx.h") 2 | include_directories(${PROJECT_SOURCE_DIR}/systems/metal_common) 3 | include(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmake/stm32f4.cmake) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHSE_VALUE=8000000") 5 | -------------------------------------------------------------------------------- /systems/stm32f4_disco-metal/usb_fs_init_pins.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pin.h" 3 | 4 | #define PORTD_USB_FS_OVERCURRENT 5 5 | #define PORTC_USB_FS_PWR_SWITCH_ON 0 6 | #define PORTA_USB_FS_ID 10 7 | #define PORTA_USB_FS_DM 11 8 | #define PORTA_USB_FS_DP 12 9 | #define PORTA_USB_FS_VBUS 9 10 | 11 | #define AF_USB_FS 10 12 | 13 | void usb_fs_init_pins(void){ 14 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_DP, AF_USB_FS); 15 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_DM, AF_USB_FS); 16 | pin_set_alternate_function(GPIOA, PORTA_USB_FS_ID, AF_USB_FS); 17 | 18 | // Output type ? Push Pull ok? 19 | // pin_set_output_type(GPIOD, PORTD_USB_FS_OVERCURRENT, PIN_OUTPUT_TYPE_OPEN_DRAIN); 20 | // pin_set_output_type(GPIOC, PORTC_USB_FS_PWR_SWITCH_ON, PIN_OUTPUT_TYPE_OPEN_DRAIN); 21 | // pin_set_output_type(GPIOA, PORTA_USB_FS_VBUS, PIN_OUTPUT_TYPE_OPEN_DRAIN); 22 | 23 | pin_set_output_speed(GPIOA, PORTA_USB_FS_DM, 3); 24 | pin_set_output_speed(GPIOA, PORTA_USB_FS_DP, 3); 25 | } 26 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../stm32_common) 2 | add_library(freertps_system_stm32f7_disco-metal console.c 3 | led.c 4 | systime.c 5 | flash.c 6 | enet_init_pins.c 7 | i2c.c 8 | ../stm32_common/stm32f7_vectors.c) 9 | set(SYSTEM_EXTRA_LIBS "stm32_common metal_common" CACHE STRING "extra system libs") 10 | set(SYSTEM_APPS "led listener talker talker_stm32_timer" CACHE STRING "applications for this system") 11 | set(SYSTEM_NO_ROSIDL_APPS "talker_no_rosidl listener_no_rosidl" CACHE STRING "") 12 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/console.c: -------------------------------------------------------------------------------- 1 | #include "metal/console.h" 2 | #include "pin.h" 3 | #include 4 | 5 | // pin connections for stm32f7-discovery board 6 | // PC6 = UART6 TX on AF8 7 | // PC7 = UART6 RX on AF8 8 | 9 | #define PORTC_TX_PIN 6 10 | #define PORTC_RX_PIN 7 11 | 12 | USART_TypeDef *g_console_usart = USART6; 13 | 14 | static volatile bool g_console_init_complete = false; 15 | 16 | void console_init(void) 17 | { 18 | RCC->APB2ENR |= RCC_APB2ENR_USART6EN; 19 | pin_set_alternate_function(GPIOC, PORTC_RX_PIN, 8); 20 | pin_set_alternate_function(GPIOC, PORTC_TX_PIN, 8); 21 | g_console_usart->CR1 &= ~USART_CR1_UE; 22 | g_console_usart->CR1 |= USART_CR1_TE | USART_CR1_RE; 23 | // we want 1 megabit. do this with mantissa=5 and fraction (sixteenths)=4 24 | g_console_usart->BRR = (((uint16_t)5) << 4) | 4; 25 | g_console_usart->CR1 |= USART_CR1_UE; 26 | g_console_init_complete = true; 27 | } 28 | 29 | void console_send_block(const uint8_t *buf, uint32_t len) 30 | { 31 | if (!g_console_init_complete) 32 | console_init(); 33 | for (uint32_t i = 0; i < len; i++) 34 | { 35 | while (!(g_console_usart->ISR & USART_ISR_TXE)) { } // wait for tx buffer 36 | g_console_usart->TDR = buf[i]; 37 | } 38 | while (!(g_console_usart->ISR & USART_ISR_TC)) { } // wait for TX to finish 39 | } 40 | 41 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/enet_init_pins.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pin.h" 3 | 4 | #define PORTA_ETH_REFCLK 1 5 | #define PORTA_ETH_CRSDV 7 6 | #define PORTC_ETH_RXD0 4 7 | #define PORTC_ETH_RXD1 5 8 | #define PORTG_ETH_RXER 2 9 | 10 | #define PORTG_ETH_TXEN 11 11 | #define PORTG_ETH_TXD0 13 12 | #define PORTG_ETH_TXD1 14 13 | 14 | #define PORTC_ETH_MDC 1 15 | #define PORTA_ETH_MDIO 2 16 | 17 | 18 | #define AF_ENET 11 19 | 20 | // PHY: LAN8742A-CZ 21 | 22 | void enet_mac_init_pins(void) 23 | { 24 | printf("enet_mac_init_pins()\r\n"); 25 | 26 | pin_set_alternate_function(GPIOA, PORTA_ETH_REFCLK, AF_ENET); 27 | pin_set_alternate_function(GPIOA, PORTA_ETH_MDIO , AF_ENET); 28 | pin_set_alternate_function(GPIOA, PORTA_ETH_CRSDV , AF_ENET); 29 | 30 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXEN , AF_ENET); 31 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXD0 , AF_ENET); 32 | pin_set_alternate_function(GPIOG, PORTG_ETH_TXD1 , AF_ENET); 33 | 34 | pin_set_alternate_function(GPIOC, PORTC_ETH_MDC , AF_ENET); 35 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD0 , AF_ENET); 36 | pin_set_alternate_function(GPIOC, PORTC_ETH_RXD1 , AF_ENET); 37 | 38 | pin_set_output_speed(GPIOG, PORTG_ETH_TXEN, 3); // max beef 39 | pin_set_output_speed(GPIOG, PORTG_ETH_TXD0, 3); // max beef 40 | pin_set_output_speed(GPIOG, PORTG_ETH_TXD1, 3); // max beef 41 | 42 | // some boards need a reset pulse... if so, generate one now 43 | /* 44 | pin_set_output_state(GPIOA, PORTA_PHY_RESET, 1); 45 | delay_ms(100); 46 | pin_set_output_state(GPIOA, PORTA_PHY_RESET, 0); 47 | delay_ms(200); 48 | pin_set_output_state(GPIOA, PORTA_PHY_RESET, 1); 49 | delay_ms(500); 50 | */ 51 | } 52 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/flash.c: -------------------------------------------------------------------------------- 1 | #include "flash.h" 2 | 3 | void flash_init(void) 4 | { 5 | FLASH->ACR = 0; // ensure the caches are turned off, so we can reset them 6 | FLASH->ACR = FLASH_ACR_PRFTEN | // enable flash prefetch 7 | FLASH_ACR_ARTEN | // enable ART (flash accelerator) 8 | FLASH_ACR_LATENCY_5WS; // set 5-wait-state 9 | } 10 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef I2C_H 2 | #define I2C_H 3 | 4 | void i2c_init(I2C_TypeDef *i2c); 5 | //uint8_t i2c_read_byte(I2C_TypeDef *i2c, uint16_t DeviceAddr, uint16_t RegAddr, uint8_t RegSizeByte); 6 | void i2c_read(I2C_TypeDef *i2c, uint16_t DeviceAddr, uint16_t RegAddr, uint8_t RegSizeByte, uint8_t* buffer); 7 | void i2c_write(I2C_TypeDef *i2c, uint16_t DeviceAddr, uint16_t RegAddr, uint8_t RegSizeByte, uint8_t* data); 8 | //void i2c_master_send(void); //TODO define prototype and implement 9 | //void i2c_master_receive(void); 10 | //void i2c_slave_send(void); // no slave for now 11 | //void i2c_slave_receive(void); 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/led.c: -------------------------------------------------------------------------------- 1 | #include "freertps/periph/led.h" 2 | #include "pin.h" 3 | 4 | #define PORTI_LED 1 5 | 6 | void led_init(void) 7 | { 8 | pin_set_output(GPIOI, PORTI_LED, 0); 9 | } 10 | 11 | void led_on(void) 12 | { 13 | pin_set_output_state(GPIOI, PORTI_LED, 1); 14 | } 15 | 16 | void led_off(void) 17 | { 18 | pin_set_output_state(GPIOI, PORTI_LED, 0); 19 | } 20 | 21 | void led_toggle(void) 22 | { 23 | GPIOI->ODR ^= 1 << PORTI_LED; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/openocd.cfg: -------------------------------------------------------------------------------- 1 | # this is mostly a straight copy of http://sourceforge.net/p/openocd/mailman/openocd-devel/thread/20150429135144.B2F2C19809EA@mail.openocd.org/ 2 | 3 | interface hla 4 | hla_layout stlink 5 | hla_device_desc "ST-LINK/V2-1" 6 | hla_vid_pid 0x0483 0x374b 7 | #transport select hla_jtag 8 | transport select hla_swd 9 | 10 | source [find target/swj-dp.tcl] 11 | 12 | set _CHIPNAME STM32F746 13 | 14 | #jtag scan chain 15 | if { [info exists CPUTAPID ] } { 16 | set _CPUTAPID $CPUTAPID 17 | } else { 18 | if { [using_jtag] } { 19 | # See STM Document RM0385 20 | # Section 40.6.3 - corresponds to Cortex-M7 with FPU r0p0 21 | set _CPUTAPID 0x5ba00477 22 | } else { 23 | set _CPUTAPID 0x5ba02477 24 | } 25 | } 26 | 27 | swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 28 | #swd newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 29 | 30 | if { [info exists BSTAPID] } { 31 | set _BSTAPID $BSTAPID 32 | } else { 33 | # See STM Document RM0385, section 40.6.1, STM32F75xxG 34 | set _BSTAPID1 0x06449071 35 | } 36 | 37 | #if {[using_jtag]} { 38 | # swj_newdap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 39 | #} 40 | 41 | set _TARGETNAME $_CHIPNAME.cpu 42 | 43 | target create $_TARGETNAME cortex_m -endian little -chain-position $_TARGETNAME 44 | 45 | # work area of 256k 46 | $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size 0x40000 -work-area-backup 0 47 | 48 | set _FLASHNAME $_CHIPNAME.flash 49 | flash bank $_FLASHNAME stm32f7x 0 0 0 0 $_TARGETNAME 50 | 51 | adapter_khz 2000 52 | 53 | adapter_nsrst_delay 100 54 | if {[using_jtag]} { 55 | jtag_ntrst_delay 100 56 | } 57 | 58 | reset_config srst_only srst_nogate 59 | 60 | if {![using_hla]} { 61 | cortex_m reset_config sysresetreq 62 | } 63 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/systime.c: -------------------------------------------------------------------------------- 1 | #include "metal/systime.h" 2 | #include "metal/delay.h" 3 | 4 | void systime_init(void) 5 | { 6 | // todo; use TIM2 since it's a 32-bit counter. just have it count 7 | // microseconds since powerup or something. 8 | RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; 9 | for (volatile int i = 0; i < 10000; i++) { } 10 | TIM2->PSC = 168000000 / 2 / 1000000 - 1; // 83 11 | TIM2->ARR = 0xffffffff; // count as long as possible 12 | TIM2->EGR = TIM_EGR_UG; // load the PSC register immediately 13 | TIM2->CR1 = TIM_CR1_CEN; // start counter 14 | } 15 | 16 | uint32_t systime_usecs(void) 17 | { 18 | return TIM2->CNT; 19 | } 20 | -------------------------------------------------------------------------------- /systems/stm32f7_disco-metal/toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_CHIP_HEADER "stm32f746xx.h") 2 | include_directories(${PROJECT_SOURCE_DIR}/systems/metal_common) 3 | include(${PROJECT_SOURCE_DIR}/systems/stm32_common/cmake/stm32f7.cmake) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHSE_VALUE=25000000") 5 | -------------------------------------------------------------------------------- /tests/fake_imu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(fake_imu) 4 | 5 | if(NOT WIN32) 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") 7 | endif() 8 | 9 | find_package(ament_cmake REQUIRED) 10 | find_package(sensor_interfaces REQUIRED) 11 | find_package(rclcpp REQUIRED) 12 | find_package(rmw REQUIRED) 13 | find_package(rmw_implementation REQUIRED) 14 | find_package(std_interfaces REQUIRED) 15 | 16 | ament_package() 17 | 18 | # This file provides the add_executable_for_each_rmw_impl function. 19 | include(cmake/add_executable_for_each_rmw_impl.cmake) 20 | 21 | add_executable_for_each_rmw_impl(fake_imu fake_imu.cpp) 22 | add_executable_for_each_rmw_impl(imu_listener imu_listener.cpp) 23 | 24 | -------------------------------------------------------------------------------- /tests/fake_imu/cmake/add_executable_for_each_rmw_impl.cmake: -------------------------------------------------------------------------------- 1 | # This file provides the add_executable_for_each_rmw_impl function. 2 | # The function takes similar arguments as add_executable, but several executables. 3 | # It creates one executable of the name you provide, which uses the default rmw implementation. 4 | # It also creates a version of your executable for each rmw implementation specifically. 5 | # These executables will be the name you gave plus a suffix like '__'. 6 | # This makes it easier to test the examples across different middleware implementations. 7 | 8 | # Get the rmw implementations which are available. 9 | get_available_rmw_implementations(middleware_implementations) 10 | foreach(middleware_impl ${middleware_implementations}) 11 | # Find package each of them. 12 | find_package("${middleware_impl}" REQUIRED) 13 | endforeach() 14 | 15 | function(add_executable_for_each_rmw_impl executable) 16 | # Build the executable for the default rmw implementation. 17 | add_executable(${executable} ${ARGN}) 18 | target_link_libraries(${executable} pthread) 19 | ament_target_dependencies(${executable} 20 | "rclcpp" 21 | "rmw_implementation" 22 | "std_interfaces" 23 | "example_interfaces" 24 | "sensor_interfaces" 25 | ) 26 | target_link_libraries(${executable} pthread) 27 | 28 | install(TARGETS ${executable} DESTINATION bin) 29 | 30 | # Build an executable for each rmw implementation. 31 | foreach(middleware_impl_tmp ${middleware_implementations}) 32 | add_executable(${executable}__${middleware_impl_tmp} ${ARGN}) 33 | ament_target_dependencies(${executable}__${middleware_impl_tmp} 34 | "rclcpp" 35 | "${middleware_impl_tmp}" 36 | "std_interfaces" 37 | "example_interfaces" 38 | "sensor_interfaces" 39 | ) 40 | target_link_libraries(${executable}__${middleware_impl_tmp} pthread) 41 | 42 | install(TARGETS ${executable}__${middleware_impl_tmp} DESTINATION bin) 43 | endforeach() 44 | 45 | endfunction() 46 | -------------------------------------------------------------------------------- /tests/fake_imu/fake_imu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | rclcpp::init(argc, argv); 8 | auto node = rclcpp::Node::make_shared("fake_imu"); 9 | auto pub = node->create_publisher("imu", 1); 10 | rclcpp::WallRate loop_rate(2); 11 | auto msg = std::make_shared(); 12 | printf("greetings, i will now start publishing fake IMU data\n"); 13 | msg->header.stamp.sec = 1234; 14 | msg->header.stamp.nanosec = 5678; 15 | msg->header.frame_id = "imu_frame"; 16 | int pub_count = 0; 17 | while (rclcpp::ok()) 18 | { 19 | pub_count++; 20 | msg->orientation.x = 1 + pub_count; 21 | msg->orientation.y = 2; 22 | msg->orientation.z = 3; 23 | msg->orientation.w = 4; 24 | msg->angular_velocity.x = 5; 25 | msg->angular_velocity.y = 6; 26 | msg->angular_velocity.z = 7; 27 | msg->linear_acceleration.x = 8; 28 | msg->linear_acceleration.y = 9; 29 | msg->linear_acceleration.z = 10; 30 | for (int i = 0; i < 9; i++) 31 | { 32 | msg->orientation_covariance[i] = i + 11; 33 | msg->angular_velocity_covariance[i] = i + 20; 34 | msg->linear_acceleration_covariance[i] = i + 29; 35 | } 36 | printf("pub\n"); 37 | pub->publish(msg); 38 | rclcpp::spin_some(node); 39 | loop_rate.sleep(); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /tests/fake_imu/imu_listener.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void imu_cb(const sensor_interfaces::msg::Imu::ConstSharedPtr &msg) 6 | { 7 | printf(" accel: [%+6.3f %+6.3f %+6.3f]\n", 8 | msg->linear_acceleration.x, 9 | msg->linear_acceleration.y, 10 | msg->linear_acceleration.z); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | rclcpp::init(argc, argv); 16 | auto node = rclcpp::Node::make_shared("imu_listener"); 17 | auto sub = node->create_subscription 18 | ("imu", 1, imu_cb); 19 | rclcpp::spin(node); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tests/fake_imu/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | fake_imu 4 | 0.0.0 5 | fake imu 6 | Morgan Quigley 7 | Apache License 2.0 8 | 9 | ament_cmake 10 | 11 | rosidl_default_generators 12 | 13 | sensor_interfaces 14 | rclcpp 15 | rmw_implementation 16 | std_interfaces 17 | 18 | sensor_interfaces 19 | rclcpp 20 | rmw_implementation 21 | rosidl_default_runtime 22 | std_interfaces 23 | 24 | 25 | ament_cmake 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/standalone_talker_listener_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | TALKER=build/native-posix/apps/standalone_talk_n/standalone_talk_n 3 | LISTENER=build/native-posix/apps/standalone_listen_for_n/standalone_listen_for_n 4 | # wait for 10 messages or a 30-second timeout 5 | $LISTENER 10 2 & 6 | LISTENER_PID=$! 7 | # send 10 messages at 0.5-second intervals 8 | $TALKER 10 0.1 & 9 | wait -n $LISTENER_PID 10 | RC=$? 11 | # wait for terminal debris to stop 12 | sleep 0.5 13 | # print success or failure 14 | echo "====================================================" 15 | if [ $RC -eq 0 ]; then 16 | echo "HOORAY! IT WORKS! HOORAY! CONFETTI! KAZOOS!" 17 | else 18 | echo "bogus........ it didn't work." 19 | fi 20 | -------------------------------------------------------------------------------- /tests/talker_listener_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "gtest/gtest.h" 7 | 8 | #include 9 | 10 | // necessary due to limitations of the API 11 | static uint32_t n_msg_recv = 0; // cue the raptors plz 12 | 13 | void chatter_cb(const void *msg) 14 | { 15 | uint32_t str_len = *((uint32_t *)msg); 16 | char buf[128] = {0}; 17 | for (uint32_t i = 0; i < str_len && i < sizeof(buf)-1; i++) 18 | buf[i] = ((uint8_t *)msg)[4+i]; 19 | printf("I heard: [%s]\n", buf); 20 | n_msg_recv++; 21 | } 22 | 23 | TEST(talker_listener_test, talk_n_times) 24 | { 25 | const int n_msg = 15; 26 | const double max_seconds = 30; 27 | const double target_dt = 0.1; 28 | 29 | fr_time_t t_start = fr_time_now(); 30 | pid_t pid = fork(); 31 | 32 | if (pid == 0) 33 | { 34 | // child process talks 35 | 36 | printf("HELLO WORLD I WILL TALK AS REQUESTED BECAUSE I AM A ROBOT\r\n"); 37 | printf("sending %d messages at %.3f-second intervals\n", n_msg, target_dt); 38 | freertps_system_init(); 39 | frudp_pub_t *pub = freertps_create_pub( 40 | "chatter", "std_msgs::msg::dds_::String_"); 41 | frudp_disco_start(); 42 | char msg[64] = {0}; 43 | for (uint32_t pub_count = 0; 44 | pub_count < n_msg && freertps_system_ok(); 45 | pub_count++) 46 | { 47 | frudp_listen(target_dt * 1000000); 48 | frudp_disco_tick(); 49 | snprintf(&msg[4], sizeof(msg) - 4, "Hello World: %d", pub_count); 50 | uint32_t rtps_string_len = strlen(&msg[4]) + 1; 51 | uint32_t *str_len_ptr = (uint32_t *)msg; 52 | *str_len_ptr = rtps_string_len; 53 | freertps_publish(pub, (uint8_t *)msg, rtps_string_len + 4); 54 | printf("sending: [%s]\r\n", &msg[4]); 55 | } 56 | frudp_fini(); 57 | return; 58 | } 59 | 60 | freertps_system_init(); 61 | // parent process listens 62 | freertps_create_sub("chatter", 63 | "std_msgs::msg::dds_::String_", 64 | chatter_cb); 65 | frudp_disco_start(); // we're alive now; announce ourselves to the world 66 | while (freertps_system_ok()) 67 | { 68 | frudp_listen(target_dt * 1000000); 69 | frudp_disco_tick(); // stayin' alive FLOOR-TOM FLOOR-TOM CYMBAL-CRASH 70 | fr_time_t t = fr_time_now(); 71 | fr_duration_t dt = fr_time_diff(&t, &t_start); 72 | double dt_secs = fr_duration_double(&dt); 73 | if (n_msg_recv >= n_msg || 74 | dt_secs > max_seconds) 75 | break; 76 | } 77 | frudp_fini(); 78 | ASSERT_GE(n_msg_recv, n_msg); 79 | printf("HOORAY, I received all the messages.\n"); 80 | } 81 | -------------------------------------------------------------------------------- /tests/test_time.c: -------------------------------------------------------------------------------- 1 | #include "freertps/time.h" 2 | #include 3 | #include 4 | 5 | void run_test(const int32_t t1_secs, const uint32_t t1_frac, 6 | const int32_t t2_secs, const uint32_t t2_frac) 7 | { 8 | const fr_time_t t1 = { .seconds = t1_secs, .fraction = t1_frac }; 9 | const fr_time_t t2 = { .seconds = t2_secs, .fraction = t2_frac }; 10 | const fr_duration_t d = fr_time_diff(&t1, &t2); 11 | const double d_d = fr_duration_double(&d); 12 | 13 | const double t1_d = fr_time_double(&t1); 14 | const double t2_d = fr_time_double(&t2); 15 | const double diff_d = t1_d - t2_d; 16 | 17 | if (fabs(d_d - diff_d) > 1e-9) 18 | printf("FAILED! %.9f != %.9f\n", d_d, diff_d); 19 | printf("(%d, %u) - (%d, %u) = %.3f - %.3f = %.3f (%d, %u)\n", 20 | t1.seconds, t1.fraction, 21 | t2.seconds, t2.fraction, 22 | t1_d, t2_d, d_d, 23 | d.seconds, d.fraction); 24 | } 25 | 26 | int main(int argc, char **argv) 27 | { 28 | run_test(7, 100000000, 5, 50000000); 29 | run_test(7, 100000000, 5, 150000000); 30 | run_test(5, 100000000, 7, 50000000); 31 | run_test(5, 100000000, 7, 150000000); 32 | run_test(5, 0, 7, 0); 33 | run_test(7, 0, 5, 0); 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /time.c: -------------------------------------------------------------------------------- 1 | #include "freertps/time.h" 2 | #include "freertps/freertps.h" 3 | #include 4 | 5 | fr_duration_t fr_time_diff(const fr_time_t *end, const fr_time_t *start) 6 | { 7 | // FUTURE: this can probably be simplified. 8 | fr_duration_t d; 9 | if (end->seconds >= start->seconds) 10 | { 11 | d.fraction = end->fraction - start->fraction; 12 | if (end->fraction >= start->fraction) 13 | d.seconds = end->seconds - start->seconds; 14 | else 15 | d.seconds = end->seconds - start->seconds - 1; 16 | } 17 | else 18 | { 19 | d.fraction = start->fraction - end->fraction; 20 | if (end->fraction > start->fraction) 21 | d.seconds = end->seconds - start->seconds + 1; 22 | else 23 | d.seconds = end->seconds - start->seconds; 24 | } 25 | return d; 26 | } 27 | 28 | double fr_time_double(const fr_time_t *t) 29 | { 30 | if (t->seconds >= 0) 31 | return t->seconds + t->fraction / (double)UINT_MAX; 32 | else 33 | { 34 | FREERTPS_ERROR("invalid fr_time: (%d, %u)\n", 35 | (int)t->seconds, (unsigned)t->fraction); 36 | return 0; 37 | } 38 | return t->seconds - t->fraction / (double)UINT_MAX; 39 | } 40 | 41 | double fr_duration_double(const fr_duration_t *t) 42 | { 43 | if (t->seconds >= 0) 44 | return t->seconds + t->fraction / (double)UINT_MAX; 45 | else 46 | return t->seconds - t->fraction / (double)UINT_MAX; 47 | } 48 | 49 | double fr_time_now_double(void) 50 | { 51 | fr_time_t t = fr_time_now(); 52 | return fr_duration_double(&t); 53 | } 54 | -------------------------------------------------------------------------------- /tiny/notes: -------------------------------------------------------------------------------- 1 | freertps low-bandwidth frame format 2 | 0: preamble = 0x42 3 | 1: frame format. various formats defined for best-effort vs. realiable, self-contained vs. fragmented, etc. 4 | 2: length. in format 0x1 (the most basic best-effort, self-contained frame format) this is just 1 byte 5 | 3: destination address (8-bit) 6 | 4: source address (8-bit) 7 | 5: destination endpoint (8-bit) 8 | 6: source endpoint (8-bit) 9 | 7-N: data payload 10 | N+1: checksum low byte 11 | N+2: checksum high byte 12 | ==== 13 | address 0xff is the broadcast address, and has a pre-defined endpoints for node discovery and address allocation 14 | ==== 15 | what should this be called? 16 | TRTPS: tiny RTPS 17 | LBRTPS: low-bandwidth RTPS 18 | SRTPS: small RTPS 19 | CRTPS: compact RTPS 20 | c "namespace" (prefix) = frc = freertps "small" 21 | then rename "normal" rtps to "fru" for "freertps UDP" but that conflicts with "freertps usb" 22 | 23 | how about "fr" for "freertps" and then a 3-digit code for the transport: 24 | 25 | rtps_ is the prefix for all user-facing calls 26 | 27 | internal library prefixes: 28 | 29 | rtps_udp = udp transport library prefix, implements nominal RTPS spec 30 | rtps_usb = usb transport library prefix 31 | rtps_ser = unframed-serial transport library prefix 32 | rtps_compact = commonly-used stuff by rtps_usb and rtps_ser 33 | -------------------------------------------------------------------------------- /utils/Makefile: -------------------------------------------------------------------------------- 1 | BIN=bin 2 | NAME=console 3 | OUT=$(BIN)/$(NAME) 4 | 5 | LDFLAGS=-g 6 | CFLAGS=-O2 -g 7 | 8 | SRCS=main.cpp lightweightserial.cpp 9 | OBJS=$(SRCS:%.cpp=$(BIN)/%.o) 10 | 11 | default: $(BIN) $(OUT) 12 | 13 | $(BIN): 14 | mkdir -p $(BIN) 15 | 16 | $(BIN)/%.o: %.cpp 17 | g++ $(CFLAGS) -c $< -o $@ 18 | 19 | $(OUT): $(OBJS) 20 | g++ $(OBJS) $(LDFLAGS) -o $(OUT) 21 | 22 | run: $(OUT) 23 | @echo "=================================================" 24 | @$(OUT) 25 | @echo "=================================================" 26 | -------------------------------------------------------------------------------- /utils/lightweightserial.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // The serial_port package provides small, simple static libraries to access 3 | // serial devices 4 | // 5 | // Copyright (C) 2008, Morgan Quigley 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of Stanford University nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | // POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef SERIALPORT_LIGHTWEIGHT_SERIAL_H 31 | #define SERIALPORT_LIGHTWEIGHT_SERIAL_H 32 | 33 | #include 34 | 35 | class LightweightSerial 36 | { 37 | public: 38 | LightweightSerial(const char *port, int baud); 39 | ~LightweightSerial(); 40 | 41 | bool read(uint8_t *b); 42 | int read_block(uint8_t *block, uint32_t max_read_len); 43 | 44 | bool write(const uint8_t b); 45 | bool write_block(const uint8_t *block, uint32_t write_len); 46 | bool write_cstr(const char *cstr); 47 | 48 | inline bool is_ok(void) { return happy; } 49 | 50 | // type-conversion wrappers so we can handle either signed or unsigned 51 | inline bool read(char *c) { return read((uint8_t *)c); } 52 | inline int read_block(char *block, uint32_t max_read_len) { return read_block(block, max_read_len); } 53 | inline bool write(char c) { return write((uint8_t)c); } 54 | inline bool write_block(const char *block, uint32_t write_len) { return write_block((uint8_t *)block, write_len); } 55 | 56 | private: 57 | int baud; 58 | int fd; 59 | bool happy; 60 | }; 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /utils/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lightweightserial.h" 5 | #include 6 | #include 7 | 8 | void perish_if(bool b, const char *msg) 9 | { 10 | if (b) 11 | { 12 | printf("%s\n", msg); 13 | exit(1); 14 | } 15 | } 16 | 17 | static bool g_done = false; 18 | void signal_handler(int signum) 19 | { 20 | if (signum == SIGINT) 21 | g_done = true; 22 | } 23 | 24 | void usage(void) 25 | { 26 | printf("usage: console DEVICE\n"); 27 | exit(1); 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | signal(SIGINT, signal_handler); 33 | if (argc != 2) 34 | usage(); 35 | const char *serial_device = argv[1]; 36 | LightweightSerial *port = new LightweightSerial(serial_device, 1000000); 37 | perish_if(!port, "could't open the specified serial port"); 38 | uint8_t b = 0; 39 | while (port->is_ok() && !g_done) 40 | { 41 | if (port->read(&b)) 42 | { 43 | putc(b, stdout); 44 | fflush(stdout); 45 | } 46 | else 47 | usleep(1000); 48 | } 49 | return 0; 50 | } 51 | 52 | --------------------------------------------------------------------------------