obsw/mission/mission.c
2024-10-10 16:04:18 +02:00

138 lines
3.7 KiB
C

/* Standard includes. */
#include <limits.h>
#include <stdio.h>
/* Scheduler include files. */
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.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);
}
// 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();
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);
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/