Skip to content

Commit

Permalink
identified where the second socket hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
Known4225 committed Aug 16, 2024
1 parent 60baefd commit 6c912d2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
4 changes: 2 additions & 2 deletions sdk/freertos_app_cpu0/src/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
#define configUSE_IDLE_HOOK 0 // TODO: For low-power, set 1 and implement vApplicationIdleHook()
#define configUSE_TICK_HOOK 0 // TODO: Set as 1 if we want to run function every tick
#define configMAX_PRIORITIES (7)
#define configTOTAL_HEAP_SIZE (125 * 1024)
#define configMAX_TASK_NAME_LEN (10)
#define configTOTAL_HEAP_SIZE (250 * 1024)
#define configMAX_TASK_NAME_LEN (32)
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
Expand Down
4 changes: 4 additions & 0 deletions sdk/freertos_app_cpu0/src/ip/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void start_tcp(uint16_t usStackSize, UBaseType_t uxPriority) {
configASSERT(xConnectedSocket != FREERTOS_INVALID_SOCKET);

/* Spawn a task to handle the connection. */
xil_printf("create task\n");
xTaskCreateStatic(prvServerConnectionInstance, "ip", configMINIMAL_STACK_SIZE, (void *) xConnectedSocket, tskIDLE_PRIORITY, echoServerTaskStack, &echoServerTaskBuffer);
}
}
Expand Down Expand Up @@ -236,8 +237,11 @@ void start_tcp(uint16_t usStackSize, UBaseType_t uxPriority) {
socket_manager_remove(xConnectedSocket);
break; // abort socket
}
xil_printf("before memset\n");
memset(rxBuffer, 0x00, ipconfigTCP_MSS);
xil_printf("after memset\n");
recvBytes = FreeRTOS_recv(xConnectedSocket, rxBuffer, ipconfigTCP_MSS, 0);
xil_printf("recv_data\n");
if (recvBytes <= 0) {
break;
}
Expand Down
25 changes: 3 additions & 22 deletions sdk/freertos_app_cpu0/src/ip/socket_manager.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "socket_manager.h"
#include "ringbuf.h"
#include "xil_io.h"
#include "xil_printf.h"
#include "xstatus.h"
Expand All @@ -8,27 +7,7 @@
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"

// Communications
#define MAX_NUM_SOCKETS (8)
#define MAX_RX_RING_BUFFER_DATA (1024 * 1024)

typedef enum {
SOCKET_TYPE_UNUSED = 0,
SOCKET_TYPE_IDLE,
SOCKET_TYPE_ASCII_CMD,
SOCKET_TYPE_LOG_VAR,
} socket_type_e;

typedef struct socket {
Socket_t raw_socket; // this is a freertos+tcp Socket_t type
socket_type_e type;

// Rx stuff
struct ringbuf_t rx_ring_buffer;
uint8_t rx_ring_buffer_data[MAX_RX_RING_BUFFER_DATA];
} socket_t; // could change the name

static socket_t socket_list[MAX_NUM_SOCKETS];
socket_t socket_list[MAX_NUM_SOCKETS];

static void reset_socket(socket_t *socket_ptr)
{
Expand Down Expand Up @@ -181,8 +160,10 @@ int socket_recv(char *buffer, uint32_t length, Socket_t *rawSocketRet) {

if (d[0] == 12 && d[1] == 34) {
socket->type = SOCKET_TYPE_ASCII_CMD;
xil_printf("ascii socket\n");
} else if (d[0] == 56 && d[1] == 78) {
socket->type = SOCKET_TYPE_LOG_VAR;
xil_printf("log socket\n");
} else {
// User specified bogus type.
// Keep as IDLE and wait for user to try again
Expand Down
21 changes: 21 additions & 0 deletions sdk/freertos_app_cpu0/src/ip/socket_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "ringbuf.h"

// Communications
#define MAX_NUM_SOCKETS (8)
#define MAX_RX_RING_BUFFER_DATA (1024 * 1024)

typedef enum {
SOCKET_TYPE_UNUSED = 0,
SOCKET_TYPE_IDLE,
SOCKET_TYPE_ASCII_CMD,
SOCKET_TYPE_LOG_VAR,
} socket_type_e;

typedef struct socket {
Socket_t raw_socket; // this is a freertos+tcp Socket_t type
socket_type_e type;

// Rx stuff
struct ringbuf_t rx_ring_buffer;
uint8_t rx_ring_buffer_data[MAX_RX_RING_BUFFER_DATA];
} socket_t; // could change the name

void socket_manager_init(void);

Expand Down
23 changes: 20 additions & 3 deletions sdk/shared/sys/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "sys/crc32.h"
#include "sys/debug.h"
#include "sys/defines.h"
#include "sys/icc_tx.h"
#include "sys/log.h"
#include "sys/serial.h"
#include "sys/util.h"
#include "ip/socket_manager.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -147,6 +147,8 @@ static void _do_log_to_buffer(uint32_t elapsed_usec)
}
}

extern socket_t *socket_list;

static void _do_log_to_stream(uint32_t elapsed_usec)
{
for (uint8_t i = 0; i < LOG_MAX_NUM_VARIABLES; i++) {
Expand All @@ -161,6 +163,7 @@ static void _do_log_to_stream(uint32_t elapsed_usec)
// Variable not streaming
continue;
}
xil_printf("log stream\n");

uint32_t usec_since_last_streamed = elapsed_usec - v->last_streamed_usec;

Expand All @@ -183,8 +186,22 @@ static void _do_log_to_stream(uint32_t elapsed_usec)
*f = (float) value;
}

// Pass to streaming utility
icc_tx_log_stream(v->socket_id, i, stream_obj_ts, stream_obj_data);
// Pass through socket
static const int packet_len = 20;
uint8_t bytes_to_send[20] = {0};

uint32_t *ptr_header = (uint32_t *) &bytes_to_send[0];
uint32_t *ptr_var_slot = (uint32_t *) &bytes_to_send[4];
uint32_t *ptr_ts = (uint32_t *) &bytes_to_send[8];
uint32_t *ptr_data = (uint32_t *) &bytes_to_send[12];
uint32_t *ptr_footer = (uint32_t *) &bytes_to_send[16];

*ptr_header = 0x11111111;
*ptr_var_slot = i;
*ptr_ts = stream_obj_ts;
*ptr_data = stream_obj_data;
*ptr_footer = 0x22222222;
FreeRTOS_send(socket_list[v->socket_id].raw_socket, bytes_to_send, packet_len, 0);
}
}
}
Expand Down

0 comments on commit 6c912d2

Please sign in to comment.