Skip to content

Commit

Permalink
Switches the USB-CAN application to use select()-based implementation.
Browse files Browse the repository at this point in the history
This dramatically reduces the RAM requirements.

Removes five tasks:
- CAN-bus read/write threads
- Serial port read/write tasks
- merges the main thread and the main executor thread
  • Loading branch information
balazsracz committed Nov 14, 2023
1 parent ff08d4f commit f138eca
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions applications/usb_can/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
#include "utils/GridConnectHub.hxx"
#include "utils/Hub.hxx"
#include "utils/HubDevice.hxx"
#include "utils/HubDeviceSelect.hxx"
#include "utils/blinker.h"

Executor<1> g_executor("g_executor", 0, 1024);
Executor<1> g_executor(NO_THREAD{});
Service g_service(&g_executor);
CanHubFlow can_hub0(&g_service);

Expand All @@ -62,7 +63,8 @@ OVERRIDE_CONST(main_thread_stack_size, 2500);
OVERRIDE_CONST(main_thread_stack_size, 900);
#endif

OVERRIDE_CONST(gridconnect_bridge_max_incoming_packets, 10);
OVERRIDE_CONST(gridconnect_bridge_max_incoming_packets, 5);
OVERRIDE_CONST(gridconnect_port_max_incoming_packets, 2);

/** Entry point to application.
* @param argc number of command line arguments
Expand All @@ -73,19 +75,17 @@ int appl_main(int argc, char* argv[])
{
int serial_fd = ::open("/dev/serUSB0", O_RDWR); // or /dev/ser0
HASSERT(serial_fd >= 0);
create_gc_port_for_can_hub(&can_hub0, serial_fd);
::fcntl(serial_fd, F_SETFL, O_NONBLOCK);

create_gc_port_for_can_hub(&can_hub0, serial_fd, nullptr, true);

int can_fd = ::open("/dev/can0", O_RDWR);
HASSERT(can_fd >= 0);
::fcntl(can_fd, F_SETFL, O_NONBLOCK);

FdHubPort<CanHubFlow> can_hub_port(
HubDeviceSelect<CanHubFlow> can_hub_port(
&can_hub0, can_fd, EmptyNotifiable::DefaultInstance());

while(1) {
sleep(1);
resetblink(1);
sleep(1);
resetblink(0);
}
g_executor.thread_body();
return 0;
}

0 comments on commit f138eca

Please sign in to comment.