diff --git a/frtos/CMakeLists.txt b/frtos/CMakeLists.txt index d972636..3a6c4f4 100644 --- a/frtos/CMakeLists.txt +++ b/frtos/CMakeLists.txt @@ -1,4 +1,29 @@ include(FreeRTOS_Kernel_import.cmake) -add_subdirectory(car) +add_subdirectory(wheel) add_subdirectory(line_sensor) + +add_executable(rtos_car rtos_car.c) + +target_compile_definitions(rtos_car PRIVATE + WIFI_SSID=\"${WIFI_SSID}\" + WIFI_PASSWORD=\"${WIFI_PASSWORD}\" + NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h) + LWIP_SOCKET=1 # we need the socket API (generally this would be in your lwipopts.h) + PING_USE_SOCKETS=1 +) +target_include_directories(rtos_car PRIVATE + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/wheel + ${CMAKE_CURRENT_LIST_DIR}/line_sensor +) +target_link_libraries(rtos_car + pico_cyw43_arch_lwip_sys_freertos + pico_stdlib + pico_lwip_iperf + FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap + hardware_adc + hardware_pwm +) +pico_enable_stdio_usb(rtos_car 1) +pico_add_extra_outputs(rtos_car) diff --git a/frtos/car/FreeRTOSConfig.h b/frtos/FreeRTOSConfig.h similarity index 100% rename from frtos/car/FreeRTOSConfig.h rename to frtos/FreeRTOSConfig.h diff --git a/frtos/car/CMakeLists.txt b/frtos/car/CMakeLists.txt deleted file mode 100644 index ca9cfb1..0000000 --- a/frtos/car/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -add_executable(rtos_car - rtos_car.c -) -target_compile_definitions(rtos_car PRIVATE - WIFI_SSID=\"${WIFI_SSID}\" - WIFI_PASSWORD=\"${WIFI_PASSWORD}\" - NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h) - LWIP_SOCKET=1 # we need the socket API (generally this would be in your lwipopts.h) - PING_USE_SOCKETS=1 -) -target_include_directories(rtos_car PRIVATE - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/../.. # for our common lwipopts -) -target_link_libraries(rtos_car - pico_cyw43_arch_lwip_sys_freertos - pico_stdlib - pico_lwip_iperf - FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap - hardware_adc - hardware_pwm -) -pico_enable_stdio_usb(rtos_car 1) -pico_add_extra_outputs(rtos_car) diff --git a/frtos/line_sensor/line_sensor.c b/frtos/line_sensor/line_sensor.c index 53dbcfd..7c054d0 100644 --- a/frtos/line_sensor/line_sensor.c +++ b/frtos/line_sensor/line_sensor.c @@ -68,9 +68,9 @@ line_sensor_setup() { } /** - * @brief Initialize the car's initial state + * @brief Initialize the wheel's initial state * - * @return The initialized car state + * @return The initialized wheel state */ car_state_t initialize_car_state() { @@ -86,9 +86,9 @@ initialize_car_state() { } /** - * @brief Update the map based on the car's state + * @brief Update the map based on the wheel's state * - * @param car_state The current car state + * @param car_state The current wheel state */ static inline void update_map(car_state_t car_state) { @@ -99,14 +99,14 @@ update_map(car_state_t car_state) { } /** - * @brief Handle forward movement of the car + * @brief Handle forward movement of the wheel * - * @param car_state The current car state + * @param car_state The current wheel state */ static void handle_forward_movement(car_state_t *car_state) { printf("FORWARD, "); - // TODO: Check car's actual forward movement + // TODO: Check wheel's actual forward movement switch (car_state->orientation) { case NORTH: printf("NORTH\n"); @@ -128,11 +128,11 @@ handle_forward_movement(car_state_t *car_state) { } /** - * @brief Handle a right turn of the car + * @brief Handle a right turn of the wheel * * Note: Bitwise AND with 0x03 to ensure that the orientation * is always between 0 and 3 - * @param car_state The current car state + * @param car_state The current wheel state */ static inline void handle_right_turn(car_state_t *car_state) { @@ -140,9 +140,9 @@ handle_right_turn(car_state_t *car_state) { } /** - * @brief Handle a left turn of the car + * @brief Handle a left turn of the wheel * - * @param car_state The current car state + * @param car_state The current wheel state */ static inline void handle_left_turn(car_state_t *car_state) { diff --git a/frtos/car/lwipopts.h b/frtos/lwipopts.h similarity index 93% rename from frtos/car/lwipopts.h rename to frtos/lwipopts.h index 09cb7af..051c08a 100644 --- a/frtos/car/lwipopts.h +++ b/frtos/lwipopts.h @@ -5,7 +5,7 @@ // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) // // This example uses a common include to avoid repetition -#include "../lwipopts_examples_common.h" +#include "lwipopts_examples_common.h" #if !NO_SYS #define TCPIP_THREAD_STACKSIZE 1024 diff --git a/frtos/car/rtos_car.c b/frtos/rtos_car.c similarity index 98% rename from frtos/car/rtos_car.c rename to frtos/rtos_car.c index b3d4474..d41ffc4 100644 --- a/frtos/car/rtos_car.c +++ b/frtos/rtos_car.c @@ -18,6 +18,7 @@ #include "semphr.h" #include "wheel.h" +#include "line_sensor.h" #define READ_LEFT_WHEEL_SPEED_PRIO (tskIDLE_PRIORITY + 1UL) #define READ_RIGHT_WHEEL_SPEED_PRIO (tskIDLE_PRIORITY + 1UL) @@ -25,6 +26,9 @@ void launch() { + + + // isr to detect right wheel slot gpio_set_irq_enabled(SPEED_PIN_RIGHT, GPIO_IRQ_EDGE_FALL, true); gpio_add_raw_irq_handler(SPEED_PIN_RIGHT, diff --git a/frtos/wheel/CMakeLists.txt b/frtos/wheel/CMakeLists.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/frtos/wheel/CMakeLists.txt @@ -0,0 +1 @@ + diff --git a/frtos/car/wheel.h b/frtos/wheel/wheel.h similarity index 100% rename from frtos/car/wheel.h rename to frtos/wheel/wheel.h