diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d5ea84..9aadebf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ set(FSFW_ADDITIONAL_INC_PATHS set(FSFW_ADD_MONITORING ON) add_subdirectory(fsfw) +add_subdirectory(common) add_subdirectory(${MISSION_PATH}) @@ -68,10 +69,11 @@ add_subdirectory(${MISSION_PATH}) # ############################################################################## # Add libraries for all sources. -target_link_libraries(${TARGET_NAME} PUBLIC freertos_kernel fsfw) +target_link_libraries(fsfw PUBLIC freertos_kernel) +target_link_libraries(${TARGET_NAME} PUBLIC fsfw) -# target_include_directories( -# ${TARGET_NAME} PUBLIC ${COMMON_DIR}/include) +target_include_directories( + ${TARGET_NAME} PUBLIC ${BSP_PATH}) target_link_options(${TARGET_NAME} PRIVATE -Wl,--start-group,-lgcc,-lc,--end-group -Wl,-Map=${TARGET_NAME}.map -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -Wl,-build-id=none -T${CMAKE_SOURCE_DIR}/${FreeRTOS_CONFIG_PATH}/lscript.ld -specs=${CMAKE_SOURCE_DIR}/${FreeRTOS_CONFIG_PATH}/Xilinx.spec) diff --git a/bsp_z7/CMakeLists.txt b/bsp_z7/CMakeLists.txt index 240bf63..68d6496 100644 --- a/bsp_z7/CMakeLists.txt +++ b/bsp_z7/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(freeRTOS) -add_subdirectory(ps7_cortexa9_0) \ No newline at end of file +add_subdirectory(ps7_cortexa9_0) +add_subdirectory(objects) \ No newline at end of file diff --git a/bsp_z7/freeRTOS/FreeRTOSConfig.h b/bsp_z7/freeRTOS/FreeRTOSConfig.h index bee124f..5510287 100644 --- a/bsp_z7/freeRTOS/FreeRTOSConfig.h +++ b/bsp_z7/freeRTOS/FreeRTOSConfig.h @@ -77,7 +77,7 @@ #define configUSE_TICK_HOOK 1 #define configMAX_PRIORITIES ( 7 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 250 ) /* Large in case configUSE_TASK_FPU_SUPPORT is 2 in which case all tasks have an FPU context. */ -#define configTOTAL_HEAP_SIZE ( 125 * 1024 ) +#define configTOTAL_HEAP_SIZE ( 20 * 1024 * 1024 ) #define configMAX_TASK_NAME_LEN ( 10 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 @@ -90,7 +90,7 @@ #define configUSE_APPLICATION_TASK_TAG 0 #define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_QUEUE_SETS 1 -#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_STATIC_ALLOCATION 0 /* Include the query-heap CLI command to query the free heap space. */ #define configINCLUDE_QUERY_HEAP_COMMAND 1 diff --git a/bsp_z7/freeRTOS/lscript.ld b/bsp_z7/freeRTOS/lscript.ld index 8608f22..602aa9e 100644 --- a/bsp_z7/freeRTOS/lscript.ld +++ b/bsp_z7/freeRTOS/lscript.ld @@ -11,7 +11,7 @@ /*******************************************************************/ _STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000; -_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x2000; +_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x01400000; _ABORT_STACK_SIZE = DEFINED(_ABORT_STACK_SIZE) ? _ABORT_STACK_SIZE : 1024; _SUPERVISOR_STACK_SIZE = DEFINED(_SUPERVISOR_STACK_SIZE) ? _SUPERVISOR_STACK_SIZE : 2048; @@ -23,7 +23,7 @@ _UNDEF_STACK_SIZE = DEFINED(_UNDEF_STACK_SIZE) ? _UNDEF_STACK_SIZE : 1024; MEMORY { - ps7_ddr_0_S_AXI_BASEADDR : ORIGIN = 0x00100000, LENGTH = 0x01000000 + ps7_ddr_0_S_AXI_BASEADDR : ORIGIN = 0x00100000, LENGTH = 0x20000000 ps7_qspi_linear_0_S_AXI_BASEADDR : ORIGIN = 0xFC000000, LENGTH = 0x1000000 ps7_ram_0_S_AXI_BASEADDR : ORIGIN = 0x0, LENGTH = 0x30000 ps7_ram_1_S_AXI_BASEADDR : ORIGIN = 0xFFFF0000, LENGTH = 0xFE00 diff --git a/bsp_z7/objects/CMakeLists.txt b/bsp_z7/objects/CMakeLists.txt index 2f01ac7..b494312 100644 --- a/bsp_z7/objects/CMakeLists.txt +++ b/bsp_z7/objects/CMakeLists.txt @@ -1,5 +1,3 @@ -add_subdirectory(communication) - target_sources( ${TARGET_NAME} PRIVATE ObjectFactory.cpp) \ No newline at end of file diff --git a/bsp_z7/objects/ObjectFactory.cpp b/bsp_z7/objects/ObjectFactory.cpp index 45b425b..739cb57 100644 --- a/bsp_z7/objects/ObjectFactory.cpp +++ b/bsp_z7/objects/ObjectFactory.cpp @@ -3,16 +3,11 @@ #include #include #include -#include -#include -#include -#include +#include #include "fsfw/events/EventManager.h" #include "fsfw/health/HealthTable.h" #include "fsfw/internalerror/InternalErrorReporter.h" -#include "objects/communication/SerialTCPCookie.h" -#include "objects/communication/ServoCommInterface.h" #include "systemObjects.h" namespace objects { @@ -29,32 +24,26 @@ enum commonObjects : object_id_t { }; } -namespace ObjectFactory { -uint16_t listeningPort = 0; -socklen_t defaultDestinationLen = 0; -const sockaddr *defaultDestination = nullptr; -const char *simString = nullptr; -} // namespace ObjectFactory -void Factory::setStaticFrameworkObjectIds() { - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// void Factory::setStaticFrameworkObjectIds() { +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; +// // MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - // PusServiceBase::PUS_DISTRIBUTOR = objects::PUS_DISTRIBUTOR; - // PusServiceBase::PACKET_DESTINATION = objects::PUS_TM_FUNNEL; +// // PusServiceBase::PUS_DISTRIBUTOR = objects::PUS_DISTRIBUTOR; +// // PusServiceBase::PACKET_DESTINATION = objects::PUS_TM_FUNNEL; - // CommandingServiceBase::defaultPacketSource = objects::PUS_DISTRIBUTOR; - // CommandingServiceBase::defaultPacketDestination = objects::PUS_TM_FUNNEL; +// // CommandingServiceBase::defaultPacketSource = objects::PUS_DISTRIBUTOR; +// // CommandingServiceBase::defaultPacketDestination = objects::PUS_TM_FUNNEL; - // VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; -} +// // VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; +// } void ObjectFactory::produce(void *args) { - Factory::setStaticFrameworkObjectIds(); + //Factory::setStaticFrameworkObjectIds(); @@ -69,4 +58,6 @@ void ObjectFactory::produce(void *args) { new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); new TmManager(objects::TM_MANAGER); + + new PrintController(123); } diff --git a/bsp_z7/objects/ObjectFactory.h b/bsp_z7/objects/ObjectFactory.h index 4eabd64..228e1bc 100644 --- a/bsp_z7/objects/ObjectFactory.h +++ b/bsp_z7/objects/ObjectFactory.h @@ -1,13 +1,8 @@ #pragma once #include -#include + namespace ObjectFactory { -extern uint16_t listeningPort; -extern socklen_t defaultDestinationLen ; -extern const sockaddr * defaultDestination ; -extern const char * simString; - void produce(void* args); } // namespace ObjectFactory \ No newline at end of file diff --git a/bsp_z7/ps7_cortexa9_0/include/xparameters.h b/bsp_z7/ps7_cortexa9_0/include/xparameters.h index 165806d..986c0c1 100644 --- a/bsp_z7/ps7_cortexa9_0/include/xparameters.h +++ b/bsp_z7/ps7_cortexa9_0/include/xparameters.h @@ -23,8 +23,8 @@ #include "xparameters_ps.h" -#define STDIN_BASEADDRESS 0xE0000000 -#define STDOUT_BASEADDRESS 0xE0000000 +#define STDIN_BASEADDRESS 0xE0001000 +#define STDOUT_BASEADDRESS 0xE0001000 /******************************************************************/ diff --git a/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/boot.S b/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/boot.S index 1beda67..3ee6914 100644 --- a/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/boot.S +++ b/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/boot.S @@ -204,6 +204,7 @@ OKToRun: /* set VBAR to the _vector_table address in linker script */ ldr r0, =vector_base mcr p15, 0, r0, c12, c0, 0 + MRC p15, 0, r1, c12, c0, 0 /*invalidate scu*/ #if USE_AMP!=1 diff --git a/mission/CMakeLists.txt b/mission/CMakeLists.txt index cf347ca..fe377c2 100644 --- a/mission/CMakeLists.txt +++ b/mission/CMakeLists.txt @@ -1 +1 @@ -target_sources(${TARGET_NAME} PRIVATE main.cpp) \ No newline at end of file +target_sources(${TARGET_NAME} PRIVATE main.cpp controller/PrintController.cpp) \ No newline at end of file diff --git a/mission/controller/PrintController.cpp b/mission/controller/PrintController.cpp index e69de29..e2818d6 100644 --- a/mission/controller/PrintController.cpp +++ b/mission/controller/PrintController.cpp @@ -0,0 +1,19 @@ +#include "PrintController.h" + +#include + +PrintController::PrintController(object_id_t setObjectId) + : SystemObject(setObjectId) {} + +ReturnValue_t PrintController::initialize() { + ReturnValue_t result = SystemObject::initialize(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; +} + +ReturnValue_t PrintController::performOperation(uint8_t operationCode) { + printf("running\n"); + return returnvalue::OK; +} diff --git a/mission/controller/PrintController.h b/mission/controller/PrintController.h index e69de29..75009a8 100644 --- a/mission/controller/PrintController.h +++ b/mission/controller/PrintController.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + + +class PrintController: public SystemObject, public ExecutableObjectIF { + public: + PrintController(object_id_t setObjectId); + virtual ~PrintController() = default; + + ReturnValue_t initialize() override; + + ReturnValue_t performOperation(uint8_t operationCode) override; +}; \ No newline at end of file diff --git a/mission/main.cpp b/mission/main.cpp index dbd3f05..b10a6a6 100644 --- a/mission/main.cpp +++ b/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 +#include +#include +#include +#include +#include +#include + +#include + +void messagetypes::clearMissionMessage(CommandMessage* message){}; + +#include + +#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) {