#include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "timers.h" #include "murax.h" #include #include #include "lib/cJSON.h" #define mainTIMER_PERIOD_MS (1 / portTICK_PERIOD_MS) // Ustawienie okresu timera na 1 sekundę #define QUEUE_LENGTH 5 #define QUEUE_ITEM_SIZE sizeof(uint32_t) extern "C" { void vApplicationMallocFailedHook(void); void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName); extern char _heap_start []; // Początek sterty extern char _heap_end []; // Koniec sterty extern int errno; static char *current_heap_end = (char *) _heap_start; #define ENOMEM 12 void *_sbrk(intptr_t increment) { char *prev_heap_end; if ((current_heap_end + increment) > (char *)_heap_end) { // Brak wystarczającej pamięci errno = ENOMEM; return (void *)-1; } prev_heap_end = current_heap_end; current_heap_end += increment; return (void *)prev_heap_end; } } void print(const char*str){ while(*str){ uart_write(UART,*str); str++; } } void println(const char*str){ print(str); uart_write(UART,'\n'); } /*-----------------------------------------------------------*/ // Deklaracja funkcji dla zadania i callbacku timera static void hungryTask(void *pvParameters); static void timerCallback(TimerHandle_t xTimer); // Globalna kolejka static QueueHandle_t xQueue; /*-----------------------------------------------------------*/ #include class MyTask : public FreeRTOS::Task { public: MyTask(const UBaseType_t priority, const char* name) : FreeRTOS::Task(priority, configMINIMAL_STACK_SIZE, name) {} void taskFunction() final; }; // Task to be created. void MyTask::taskFunction() { cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "sensor", "gps"); cJSON_AddNumberToObject(root, "time", 1351824120); cJSON *data = cJSON_CreateObject(); cJSON_AddItemToObject(root, "data", data); cJSON_AddNumberToObject(data, "lat", 48.756080); cJSON_AddNumberToObject(data, "lon", 2.302038); char *jsonString = cJSON_Print(root); println (jsonString); std::string result(jsonString); cJSON_Delete(root); free(jsonString); for (;;) { println("Delay 10ms"); vTaskDelay(pdMS_TO_TICKS(10)); // Task code goes here. } } #include "include/Timer.hpp" const Timer_Reg* TimeR::ptr = reinterpret_cast(0xF0020040); #include "X.hpp" #include "SimpleOStream.hpp" int main(void) { // Definicja globalnego obiektu strumienia wyjściowego SimpleOStream simpleCout; X var {7}; println("hello world arty a7 v1"); xQueue = xQueueCreate(QUEUE_LENGTH, QUEUE_ITEM_SIZE); // Tworzenie kolejki if (xQueue == NULL) { return -1; // Błąd podczas tworzenia kolejki } TimerHandle_t xCheckTimer = NULL; /* // Inicjalizacja timera xCheckTimer = xTimerCreate("CheckTimer", mainTIMER_PERIOD_MS, pdTRUE, (void *)0, timerCallback); */ // Start timera if (xCheckTimer != NULL) { xTimerStart(xCheckTimer, 0); } // Tworzenie zadania hungryTask xTaskCreate(hungryTask, "Hungry Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL); // Create the task. MyTask task((tskIDLE_PRIORITY + 1), "NAME"); /* // Check that the task was created successfully. if (task.isValid()) { FreeRTOS::Kernel::startScheduler(); } */ // Uruchomienie planisty vTaskStartScheduler(); // Teoretycznie nigdy nie powinniśmy tu dotrzeć for (;;); return 0; } /*-----------------------------------------------------------*/ // Definicja funkcji callback timera static void timerCallback(TimerHandle_t xTimer) { uint32_t ulValueToSend = 1; // Przykładowa wartość do wysłania xQueueSendFromISR(xQueue, &ulValueToSend, NULL); } // Definicja zadania static void hungryTask(void *pvParameters) { uint32_t ulReceivedValue; for (;;) { println("Delay 10ms"); vTaskDelay(pdMS_TO_TICKS(10)); // if (xQueueReceive(xQueue, &ulReceivedValue, portMAX_DELAY) == pdPASS) { //printf("hungry\n"); // Drukowanie, gdy odbierzemy wartość z kolejki // } } } /*-----------------------------------------------------------*/ void vApplicationMallocFailedHook(void) { for (;;); } void vApplicationIdleHook(void) { // Można tu umieścić kod wykonywany w stanie bezczynności } void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { for (;;); }