diff --git a/src/drivers/payload_uart.c b/src/drivers/payload_uart.c index 1288e2f..a1753fe 100644 --- a/src/drivers/payload_uart.c +++ b/src/drivers/payload_uart.c @@ -6,11 +6,11 @@ */ #include "hardware/irq.h" #include "hardware/uart.h" -#include "pico/printf.h" #include "pico/stdlib.h" #include "pico/util/queue.h" #include "drivers/payload_uart.h" +#include "macros.h" #include "pins.h" #include "slate.h" @@ -29,10 +29,6 @@ #define SYN_BYTE '$' #define SYN_COUNT 3 -static int chars_rxed = 0; - -uint8_t packet_buf[MAX_PACKET_LEN]; - static slate_t *slate_for_irq; // Need to save to be accessible to IRQ typedef struct @@ -204,6 +200,8 @@ bool payload_uart_init(slate_t *slate) // Now enable the UART to send interrupts - RX only uart_set_irq_enables(PAYLOAD_UART_ID, true, false); + + return true; } /** @@ -220,7 +218,7 @@ bool payload_uart_write_packet(slate_t *slate, const uint8_t *packet, // Check packet length if (len > MAX_PACKET_LEN) { - printf("Packet is too long!\n"); + LOG_DEBUG("Packet is too long!\n"); return false; } @@ -244,7 +242,7 @@ bool payload_uart_write_packet(slate_t *slate, const uint8_t *packet, if (!syn_acknowledged) { - printf("Payload did not respond to sync!\n"); + LOG_DEBUG("Payload did not respond to sync!\n"); return false; } @@ -257,7 +255,7 @@ bool payload_uart_write_packet(slate_t *slate, const uint8_t *packet, if (!receive_ack(slate)) { - printf("Header was not acknowledged!\n"); + LOG_DEBUG("Header was not acknowledged!\n"); return false; } @@ -281,7 +279,7 @@ uint16_t payload_uart_read_packet(slate_t *slate, uint8_t *packet) // Wait for sync if (!receive_syn(slate)) { - printf("Syn was not received!\n"); + LOG_DEBUG("Syn was not received!\n"); return 0; } send_ack(); @@ -293,7 +291,7 @@ uint16_t payload_uart_read_packet(slate_t *slate, uint8_t *packet) if (bytes_received < sizeof(packet_header_t)) { - printf("Header was not received!\n"); + LOG_DEBUG("Header was not received!\n"); return 0; } send_ack(); @@ -301,7 +299,7 @@ uint16_t payload_uart_read_packet(slate_t *slate, uint8_t *packet) // Check header if (header.length > MAX_PACKET_LEN) { - printf("Packet is too long!\n"); + LOG_DEBUG("Packet is too long!\n"); return 0; } @@ -310,14 +308,14 @@ uint16_t payload_uart_read_packet(slate_t *slate, uint8_t *packet) if (bytes_received < header.length) { - printf("Packet was not fully received!\n"); + LOG_DEBUG("Packet was not fully received!\n"); return 0; } // Verify checksum if (crc32(packet, header.length) != header.checksum) { - printf("Invalid checksum!\n"); + LOG_DEBUG("Invalid checksum!\n"); return 0; } send_ack(); diff --git a/src/init.c b/src/init.c index e0ddfc7..0535c96 100644 --- a/src/init.c +++ b/src/init.c @@ -12,6 +12,8 @@ #include "pico/stdlib.h" #include "scheduler/scheduler.h" +#include "drivers/payload_uart.h" + /** * Initialize all gpio pins to their default states. * @@ -38,6 +40,11 @@ bool init(slate_t *slate) */ ASSERT(init_gpio_pins()); + /* + * Initialize uart + */ + ASSERT(payload_uart_init(slate)); + /* * Initialize the state machine */ diff --git a/src/pins.h b/src/pins.h index 6a17ea2..619d739 100644 --- a/src/pins.h +++ b/src/pins.h @@ -14,5 +14,10 @@ #define RFM9X_CS (20) #define RFM9X_D0 (28) -#define SAMWISE_RPI_UART_TX (30) -#define SAMWISE_RPI_UART_RX (31) \ No newline at end of file +// TODO: Replace with these for pycubed +// #define SAMWISE_RPI_UART_TX (30) +// #define SAMWISE_RPI_UART_RX (31) + +// For pico +#define SAMWISE_RPI_UART_TX (0) +#define SAMWISE_RPI_UART_RX (1) \ No newline at end of file diff --git a/src/state_machine/states/running.c b/src/state_machine/states/running.c index 846c6bd..46b5f4f 100644 --- a/src/state_machine/states/running.c +++ b/src/state_machine/states/running.c @@ -4,8 +4,8 @@ sched_state_t running_state = { .name = "running", - .num_tasks = 3, - .task_list = {&print_task, &blink_task, &radio_task}, + .num_tasks = 2, + .task_list = {&print_task, &blink_task, /*&radio_task*/}, .get_next_state = &running_get_next_state}; sched_state_t *running_get_next_state(slate_t *slate)