Landzo_K60Z_WebServer/src/main.c

123 lines
2.6 KiB
C

#include <stdio.h>
#include <time.h>
/* SDK drivers */
#include "fsl_sdhc.h"
/* HW Related */
#include "board.h"
#include "clock_config.h"
#include "peripherals.h"
#include "pin_mux.h"
/* Console */
#include "fsl_debug_console.h"
/* MISC */
#include "ip_stack_helpers.h"
#include "system_utilities.h"
/*FreeRTOS*/
#include "FreeRTOS.h"
#include "task.h"
/* FatFS */
#include "fs_helpers.h"
/* LVGL */
#include "lvgl_helpers.h"
/* UI */
#include "ui_helpers.h"
/* MbedTLS */
#include "mbedtls/aes.h"
#include "mbedtls/gcm.h"
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
static void vTaskHello(void *pvParameters);
static void mtls_selftests(int verbose);
int main(void) {
BOARD_InitBootPins();
BOARD_BootClockRUN();
BOARD_InitBootPeripherals();
BOARD_DisableSYSMPU();
BOARD_EnableRTC();
BOARD_EnableLCD();
BOARD_EnableEDMA();
BOARD_InitDebugConsole();
print_hardware();
sram_test();
// mtls_selftests(1);
xTaskCreate(vTaskHello, "HELLO", 512, NULL, 32, NULL);
vTaskStartScheduler();
for (;;) {
__WFI();
}
}
static void vTaskHello(void *pvParameters) {
while (fs_mount() < 0) {
vTaskDelay(pdMS_TO_TICKS(5000));
}
if (lvgl_setup() < 0) {
vTaskSuspend(NULL);
}
if (ui_setup() < 0) {
vTaskSuspend(NULL);
}
ip_stack_setup();
mtls_selftests(1);
time_t t;
struct tm *cur_tm;
for (;;) {
vTaskDelay(pdMS_TO_TICKS(1000));
t = time(NULL);
cur_tm = localtime(&t);
cur_tm->tm_hour += 8U;
cur_tm->tm_isdst = 0;
mktime(cur_tm);
char *time_str = pvPortMalloc(7);
ui_standby_queue_t cmd = {
.cmd = UI_STANDBY_CMD_UPDATE_TIME,
.payload = time_str,
};
strftime(time_str, 7, "%H:%M", cur_tm);
xQueueSend(g_ui_standby_queue, &cmd, portMAX_DELAY);
printf("Current time: %04d-%02d-%02d %02d:%02d:%02d\r\n", cur_tm->tm_year + 1900, cur_tm->tm_mon + 1,
cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, cur_tm->tm_sec);
}
}
static void mtls_selftests(int verbose) {
uint8_t failed_cases = 0;
if (mbedtls_aes_self_test(verbose) != 0) failed_cases++;
if (mbedtls_gcm_self_test(verbose) != 0) failed_cases++;
if (mbedtls_sha1_self_test(verbose) != 0) failed_cases++;
if (mbedtls_sha256_self_test(verbose) != 0) failed_cases++;
if (mbedtls_sha512_self_test(verbose) != 0) failed_cases++;
printf("MbedTLS selftests completed, %d case(s) failed.\r\n", failed_cases);
}