forked from ROMEO/fsw-ws
zedboard working
This commit is contained in:
220
mission/main.cpp
220
mission/main.cpp
@@ -90,19 +90,29 @@ extern "C" {
|
||||
#include "xscugic.h"
|
||||
#include "xscutimer.h"
|
||||
#include "xuartps_hw.h"
|
||||
|
||||
// TODO why? is in bsp
|
||||
|
||||
void _exit(sint32 status);
|
||||
|
||||
// (void)status;
|
||||
// while (1) {
|
||||
// ;
|
||||
// }
|
||||
// }
|
||||
sint32 _write(sint32 fd, char8 *buf, sint32 nbytes);
|
||||
}
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/ipc/CommandMessageCleaner.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw/objectmanager/frameworkObjects.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <objects/systemObjects.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
void messagetypes::clearMissionMessage(CommandMessage* message){};
|
||||
|
||||
#include <objects/ObjectFactory.h>
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
ServiceInterfaceStream sif::debug("DEBUG", false);
|
||||
ServiceInterfaceStream sif::info("INFO", false);
|
||||
ServiceInterfaceStream sif::warning("WARNING", false);
|
||||
ServiceInterfaceStream sif::error("ERROR", false, true, true);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Configure the hardware as necessary to run this demo.
|
||||
*/
|
||||
@@ -133,145 +143,29 @@ XScuWdt xWatchDogInstance;
|
||||
other modules. */
|
||||
XScuGic xInterruptController;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
#define XPS_UART0_BASEADDR 0xE0000000U
|
||||
#define UART_BASE XPS_UART0_BASEADDR
|
||||
#define XUARTPS_SR_TNFUL 0x00004000U /**< TX FIFO Nearly Full Status */
|
||||
#define XUARTPS_SR_TACTIVE 0x00000800U /**< TX active */
|
||||
#define XUARTPS_SR_RXEMPTY 0x00000002U /**< RX FIFO empty */
|
||||
|
||||
#define POINTER_TO_REGISTER(REG) (*((volatile uint32_t *)(REG)))
|
||||
|
||||
#define UART_FIFO POINTER_TO_REGISTER(UART_BASE + XUARTPS_FIFO_OFFSET) // FIFO
|
||||
#define UART_STATUS \
|
||||
POINTER_TO_REGISTER(UART_BASE + XUARTPS_SR_OFFSET) // Channel Status
|
||||
|
||||
void uart_send(char c) {
|
||||
while (UART_STATUS & XUARTPS_SR_TNFUL)
|
||||
;
|
||||
UART_FIFO = c;
|
||||
while (UART_STATUS & XUARTPS_SR_TACTIVE)
|
||||
;
|
||||
}
|
||||
|
||||
/* Priorities at which the tasks are created. */
|
||||
#define mainQUEUE_RECEIVE_TASK_PRIORITY (tskIDLE_PRIORITY + 2)
|
||||
#define mainQUEUE_SEND_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
|
||||
|
||||
/* The rate at which data is sent to the queue. The 200ms value is converted
|
||||
to ticks using the portTICK_PERIOD_MS constant. */
|
||||
#define mainQUEUE_SEND_FREQUENCY_MS (1000 / portTICK_PERIOD_MS)
|
||||
|
||||
/* The number of items the queue can hold. This is 1 as the receive task
|
||||
will remove items as they are added, meaning the send task should always find
|
||||
the queue empty. */
|
||||
#define mainQUEUE_LENGTH (1)
|
||||
|
||||
/* The LED toggled by the Rx task. */
|
||||
#define mainTASK_LED (0)
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* The tasks as described in the comments at the top of this file.
|
||||
*/
|
||||
static void prvQueueReceiveTask(void *pvParameters);
|
||||
static void prvQueueSendTask(void *pvParameters);
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The queue used by both tasks. */
|
||||
static QueueHandle_t xQueue = NULL;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void uart_send(char c);
|
||||
|
||||
static void prvQueueSendTask(void *pvParameters) {
|
||||
TickType_t xNextWakeTime;
|
||||
const unsigned long ulValueToSend = 100UL;
|
||||
|
||||
/* Remove compiler warning about unused parameter. */
|
||||
(void)pvParameters;
|
||||
|
||||
/* Initialise xNextWakeTime - this only needs to be done once. */
|
||||
xNextWakeTime = xTaskGetTickCount();
|
||||
// vTaskDelayUntil(&xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS / 2);
|
||||
|
||||
for (;;) {
|
||||
/* Place this task in the blocked state until it is time to run again. */
|
||||
vTaskDelayUntil(&xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS);
|
||||
|
||||
uart_send('C');
|
||||
|
||||
/* Send to the queue - causing the queue receive task to unblock and
|
||||
toggle the LED. 0 is used as the block time so the sending operation
|
||||
will not block - it shouldn't need to block as the queue should always
|
||||
be empty at this point in the code. */
|
||||
xQueueSend(xQueue, &ulValueToSend, 0U);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvQueueReceiveTask(void *pvParameters) {
|
||||
unsigned long ulReceivedValue;
|
||||
const unsigned long ulExpectedValue = 100UL;
|
||||
|
||||
/* Remove compiler warning about unused parameter. */
|
||||
(void)pvParameters;
|
||||
|
||||
for (;;) {
|
||||
/* Wait until something arrives in the queue - this task will block
|
||||
indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
|
||||
FreeRTOSConfig.h. */
|
||||
xQueueReceive(xQueue, &ulReceivedValue, portMAX_DELAY);
|
||||
|
||||
uart_send('0');
|
||||
|
||||
/* To get here something must have been received from the queue, but
|
||||
is it the expected value? If it is, toggle the LED. */
|
||||
if (ulReceivedValue == ulExpectedValue) {
|
||||
// vParTestToggleLED(mainTASK_LED);
|
||||
ulReceivedValue = 0U;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
void mission(void *);
|
||||
|
||||
int main(void) {
|
||||
|
||||
/* Configure the hardware ready to run the demo. */
|
||||
prvSetupHardware();
|
||||
|
||||
|
||||
|
||||
printf("Booting Software\n");
|
||||
|
||||
|
||||
/* Create the queue. */
|
||||
xQueue = xQueueCreate(mainQUEUE_LENGTH, sizeof(uint32_t));
|
||||
int taskParameters =0;
|
||||
|
||||
if (xQueue != NULL) {
|
||||
/* Start the two tasks as described in the comments at the top of this
|
||||
file. */
|
||||
xTaskCreate(
|
||||
prvQueueReceiveTask, /* The function that implements the task. */
|
||||
"Rx", /* The text name assigned to the task - for debug only as it is
|
||||
not used by the kernel. */
|
||||
configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the
|
||||
task. */
|
||||
NULL, /* The parameter passed to the task - not used in this case. */
|
||||
mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task.
|
||||
*/
|
||||
NULL); /* The task handle is not required, so NULL is passed. */
|
||||
|
||||
xTaskCreate(prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL,
|
||||
mainQUEUE_SEND_TASK_PRIORITY, NULL);
|
||||
|
||||
/* Start the tasks and timer running. */
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
xTaskCreate(
|
||||
mission, /* 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. */
|
||||
configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */
|
||||
&taskParameters, /* The parameter passed to the task - not used in this simple case. */
|
||||
1, /* The priority assigned to the task. */
|
||||
nullptr); /* The task handle is not required, so NULL is passed. */
|
||||
|
||||
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
|
||||
@@ -285,6 +179,56 @@ int main(void) {
|
||||
/* Don't expect to reach here. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define sev() __asm__("sev")
|
||||
#define CPU1STARTADR 0xfffffff0
|
||||
|
||||
void mission(void *){
|
||||
|
||||
printf("Starting Mission\n");
|
||||
|
||||
printf("CPU0: writing startaddress for cpu1\n\r");
|
||||
Xil_Out32(CPU1STARTADR, 0x00200000);
|
||||
dmb(); //waits until write has finished
|
||||
|
||||
printf("CPU0: sending the SEV to wake up CPU1\n\r");
|
||||
sev();
|
||||
|
||||
sif::debug << "OStreams working" << std::endl;
|
||||
|
||||
ObjectManager* objManager = ObjectManager::instance();
|
||||
objManager->setObjectFactoryFunction(ObjectFactory::produce, nullptr);
|
||||
|
||||
printf("Created Objects\n");
|
||||
|
||||
objManager->initialize();
|
||||
|
||||
printf("Initialized Objects\n");
|
||||
|
||||
TaskFactory* taskFactory = TaskFactory::instance();
|
||||
if (taskFactory == nullptr) {
|
||||
printf("Ooopsie\n");
|
||||
return;
|
||||
}
|
||||
|
||||
TaskPriority currPrio;
|
||||
|
||||
TaskDeadlineMissedFunction deadlineMissedFunc = nullptr;
|
||||
|
||||
currPrio = 2;
|
||||
|
||||
PeriodicTaskIF* controllerTask = taskFactory->createPeriodicTask(
|
||||
"controller", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, nullptr);
|
||||
controllerTask->addComponent(123);
|
||||
|
||||
printf("Created Tasks\n");
|
||||
|
||||
controllerTask->startTask();
|
||||
|
||||
printf("Started Tasks, deleting init task\n");
|
||||
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSetupHardware(void) {
|
||||
|
||||
Reference in New Issue
Block a user