forked from ROMEO/obsw
192 lines
5.0 KiB
C
192 lines
5.0 KiB
C
/* Standard includes. */
|
|
#include <limits.h>
|
|
#include <stdio.h>
|
|
|
|
/* Scheduler include files. */
|
|
#include "FreeRTOS.h"
|
|
#include "semphr.h"
|
|
#include "task.h"
|
|
|
|
#include "lwip/init.h"
|
|
#include "lwip/timeouts.h"
|
|
#include "lwip/udp.h"
|
|
#include <lwip/ip_addr.h>
|
|
#include <lwip/netif.h>
|
|
#include "netif/slipif.h"
|
|
|
|
void rust_main();
|
|
|
|
#include <hardware/interfaces.h>
|
|
#include <unistd.h>
|
|
|
|
void test_hardware() {
|
|
int fd0 = hw_device_open("uart0", 5);
|
|
write(fd0, "UART0\n", 6);
|
|
int fd1 = hw_device_open("uart1", 5);
|
|
write(fd1, "uart1\n", 6);
|
|
|
|
|
|
|
|
uint8_t buffer[255];
|
|
|
|
|
|
// for (int i = 0; i< sizeof(buffer); i++) {
|
|
// buffer[i] = i;
|
|
// }
|
|
|
|
// write(fd0, buffer, sizeof(buffer));
|
|
|
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
|
|
|
write(1, "got:\n", 5);
|
|
|
|
int read_bytes = read(fd0, buffer, sizeof(buffer));
|
|
write(1, buffer, read_bytes);
|
|
read_bytes = read(fd1, buffer, sizeof(buffer));
|
|
write(1, buffer, read_bytes);
|
|
}
|
|
|
|
|
|
struct netif netif;
|
|
struct slipif_priv slipif_config;
|
|
static struct udp_pcb *udpecho_raw_pcb;
|
|
|
|
u32_t sys_now(void) { return xTaskGetTickCount() * portTICK_PERIOD_MS; }
|
|
|
|
void test_lwip() {
|
|
lwip_init();
|
|
|
|
ip4_addr_t slip_addr = {PP_HTONL(LWIP_MAKEU32(10, 13, 80, 10))},
|
|
slip_mask = {PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))},
|
|
slip_gw = {PP_HTONL(LWIP_MAKEU32(10, 13, 80, 1))};
|
|
|
|
slipif_config.fd = hw_device_open("uart1", 5);
|
|
|
|
netif_add(&netif, &slip_addr, &slip_mask, &slip_gw, &slipif_config, slipif_init,
|
|
netif_input);
|
|
|
|
netif_set_default(&netif);
|
|
// should be done by driver, which does not do it, so we do it here
|
|
netif_set_link_up(&netif);
|
|
netif_set_up(&netif);
|
|
|
|
udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
|
if (udpecho_raw_pcb != NULL) {
|
|
err_t err;
|
|
|
|
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, 7);
|
|
if (err != ERR_OK) {
|
|
return;
|
|
}
|
|
|
|
ip_addr_t addr = IPADDR4_INIT_BYTES(10,13,80,1);
|
|
|
|
uint8_t data[] = {'1','2','3','4'};
|
|
|
|
struct pbuf* tx = pbuf_alloc_reference(data, sizeof(data), PBUF_REF);
|
|
|
|
udp_sendto(udpecho_raw_pcb,tx,&addr,1234);
|
|
}
|
|
}
|
|
|
|
// called to stop execution (either a panic or program ended)
|
|
// to be implemented by bsp (do not return from it!)
|
|
void done();
|
|
|
|
|
|
|
|
void init_task(void * _) {
|
|
(void )_;
|
|
// printf("Starting Mission\n");
|
|
|
|
//test_hardware();
|
|
|
|
test_lwip();
|
|
|
|
rust_main();
|
|
|
|
// printf("Started Tasks, deleting init task\n");
|
|
|
|
done();
|
|
|
|
vTaskDelete(NULL);
|
|
}
|
|
|
|
|
|
|
|
void mission(void) {
|
|
|
|
int taskParameters = 0;
|
|
|
|
// static const size_t stackSizeWords = 102400;
|
|
// StaticTask_t xTaskBuffer;
|
|
// StackType_t xStack[stackSizeWords];
|
|
|
|
xTaskCreate(init_task, /* The function that implements the task. */
|
|
"init", /* The text name assigned to the task - for debug only as
|
|
it is not used by the kernel. */
|
|
10240, /* The size of the stack to allocate to the task. */
|
|
&taskParameters, /* The parameter passed to the task - not used in
|
|
this simple case. */
|
|
4, /* The priority assigned to the task. */
|
|
NULL);
|
|
|
|
vTaskStartScheduler();
|
|
|
|
/* If all is well, the scheduler will now be running, and the following
|
|
line will never be reached. If the following line does execute, then
|
|
there was either insufficient FreeRTOS heap memory available for the idle
|
|
and/or timer tasks to be created, or vTaskStartScheduler() was called from
|
|
User mode. See the memory management section on the FreeRTOS web site for
|
|
more details on the FreeRTOS heap http://www.freertos.org/a00111.html. The
|
|
mode from which main() is called is set in the C start up code and must be
|
|
a privileged mode (not user mode). */
|
|
|
|
done();
|
|
|
|
for (;;)
|
|
;
|
|
/* Don't expect to reach here. */
|
|
return;
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) {
|
|
(void)pcTaskName;
|
|
(void)pxTask;
|
|
|
|
/* Run time stack overflow checking is performed if
|
|
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
|
|
function is called if a stack overflow is detected. */
|
|
taskDISABLE_INTERRUPTS();
|
|
// TODO panic
|
|
for (;;)
|
|
;
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
void rust_alloc_failed();
|
|
|
|
void vApplicationMallocFailedHook(void) {
|
|
/* Called if a call to pvPortMalloc() fails because there is insufficient
|
|
free memory available in the FreeRTOS heap. pvPortMalloc() is called
|
|
internally by FreeRTOS API functions that create tasks, queues, software
|
|
timers, and semaphores. The size of the FreeRTOS heap is set by the
|
|
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
|
|
taskDISABLE_INTERRUPTS();
|
|
rust_alloc_failed();
|
|
for (;;)
|
|
;
|
|
}
|
|
|
|
void rust_assert_called(const char *pcFile, unsigned long ulLine);
|
|
|
|
void vAssertCalled(const char *pcFile, unsigned long ulLine) {
|
|
taskDISABLE_INTERRUPTS();
|
|
rust_assert_called(pcFile, ulLine);
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|