Skip to content

Commit

Permalink
Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
niklas-vainio committed Jan 18, 2025
1 parent dcde676 commit b3cbb24
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
24 changes: 11 additions & 13 deletions src/drivers/payload_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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();
Expand All @@ -293,15 +291,15 @@ 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();

// Check header
if (header.length > MAX_PACKET_LEN)
{
printf("Packet is too long!\n");
LOG_DEBUG("Packet is too long!\n");
return 0;
}

Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -38,6 +40,11 @@ bool init(slate_t *slate)
*/
ASSERT(init_gpio_pins());

/*
* Initialize uart
*/
ASSERT(payload_uart_init(slate));

/*
* Initialize the state machine
*/
Expand Down
9 changes: 7 additions & 2 deletions src/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
#define RFM9X_CS (20)
#define RFM9X_D0 (28)

#define SAMWISE_RPI_UART_TX (30)
#define SAMWISE_RPI_UART_RX (31)
// 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)
4 changes: 2 additions & 2 deletions src/state_machine/states/running.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3cbb24

Please sign in to comment.