| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 #include <stdlib.h> | |
| 6 | |
| 7 #include <cmsis_os.h> | |
| 8 extern "C" { | |
| 9 #include <lcd_log.h> | |
| 10 } | |
| 11 #include <stm32746g_discovery.h> | |
| 12 #include <stm32746g_discovery_lcd.h> | |
| 13 | |
| 14 #include "include/fletch_api.h" | |
| 15 #include "include/static_ffi.h" | |
| 16 | |
| 17 #include "platforms/stm/disco_fletch/src/fletch_entry.h" | |
| 18 #include "platforms/stm/disco_fletch/src/page_allocator.h" | |
| 19 #include "platforms/stm/disco_fletch/src/uart.h" | |
| 20 #include "src/shared/platform.h" | |
| 21 #include "src/shared/utils.h" | |
| 22 | |
| 23 extern unsigned char _binary_event_handler_test_snapshot_start; | |
| 24 extern unsigned char _binary_event_handler_test_snapshot_end; | |
| 25 extern unsigned char _binary_event_handler_test_snapshot_size; | |
| 26 | |
| 27 extern PageAllocator* page_allocator; | |
| 28 | |
| 29 // `MessageQueueProducer` will send a message every `kMessageFrequency` | |
| 30 // millisecond. | |
| 31 const int kMessageFrequency = 400; | |
| 32 | |
| 33 // Sends a message on a port_id with a fixed interval. | |
| 34 static void MessageQueueProducer(const void *argument) { | |
| 35 uint16_t counter = 0; | |
| 36 for (;;) { | |
| 37 counter++; | |
| 38 int port_id = 1; | |
| 39 int status = fletch::SendMessageCmsis(port_id, counter); | |
| 40 if (status != osOK) { | |
| 41 fletch::Print::Error("Error Sending %d\n", status); | |
| 42 } | |
| 43 osDelay(kMessageFrequency); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 // Implementation of write used from syscalls.c to redirect all printf | |
| 48 // calls to the print interceptors. | |
| 49 extern "C" int Write(int file, char *ptr, int len) { | |
| 50 for (int i = 0; i < len; i++) { | |
| 51 if (file == 2) { | |
| 52 fletch::Print::Error("%c", *ptr++); | |
| 53 } else { | |
| 54 fletch::Print::Out("%c", *ptr++); | |
| 55 } | |
| 56 } | |
| 57 return len; | |
| 58 } | |
| 59 | |
| 60 FLETCH_EXPORT_TABLE_BEGIN | |
| 61 FLETCH_EXPORT_TABLE_ENTRY("BSP_LED_On", BSP_LED_On) | |
| 62 FLETCH_EXPORT_TABLE_ENTRY("BSP_LED_Off", BSP_LED_Off) | |
| 63 FLETCH_EXPORT_TABLE_END | |
| 64 | |
| 65 // Run fletch on the linked in snapshot. | |
| 66 void StartFletch(void const * argument) { | |
| 67 fletch::Print::Out("Setup fletch\n"); | |
| 68 FletchSetup(); | |
| 69 fletch::Print::Out("Read fletch snapshot\n"); | |
| 70 unsigned char *snapshot = &_binary_event_handler_test_snapshot_start; | |
| 71 int snapshot_size = | |
| 72 reinterpret_cast<int>(&_binary_event_handler_test_snapshot_size); | |
| 73 FletchProgram program = FletchLoadSnapshot(snapshot, snapshot_size); | |
| 74 fletch::Print::Out("Run fletch program\n"); | |
| 75 FletchRunMain(program); | |
| 76 fletch::Print::Out("Fletch program exited\n"); | |
| 77 } | |
| 78 | |
| 79 // LCDLogPutchar is defined by the STM LCD log utility | |
| 80 // (Utilities/Log/lcd_log.c) by means of the macro definitions of | |
| 81 // LCD_LOG_PUTCHAR in lcd_log_conf.h. | |
| 82 extern "C" int LCDLogPutchar(int ch); | |
| 83 void LCDPrintIntercepter(const char* message, int out, void* data) { | |
| 84 int len = strlen(message); | |
| 85 if (out == 3) { | |
| 86 LCD_LineColor = LCD_COLOR_RED; | |
| 87 } else { | |
| 88 LCD_LineColor = LCD_COLOR_BLACK; | |
| 89 } | |
| 90 for (int i = 0; i < len; i++) { | |
| 91 LCDLogPutchar(message[i]); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 // Main entry point from FreeRTOS. Running in the default task. | |
| 96 void FletchEntry(void const * argument) { | |
| 97 // Add an arena of the 8Mb of external memory. | |
| 98 uint32_t ext_mem_arena = | |
| 99 page_allocator->AddArena("ExtMem", 0xc0000000, 0x800000); | |
| 100 BSP_LED_Init(LED1); | |
| 101 | |
| 102 // Initialize the LCD. | |
| 103 size_t fb_bytes = (RK043FN48H_WIDTH * RK043FN48H_HEIGHT * 2); | |
| 104 size_t fb_pages = page_allocator->PagesForBytes(fb_bytes); | |
| 105 void* fb = page_allocator->AllocatePages(fb_pages, ext_mem_arena); | |
| 106 BSP_LCD_Init(); | |
| 107 BSP_LCD_LayerDefaultInit(1, reinterpret_cast<uint32_t>(fb)); | |
| 108 BSP_LCD_SelectLayer(1); | |
| 109 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); | |
| 110 | |
| 111 fletch::Platform::Setup(); | |
| 112 | |
| 113 // Initialize LCD Log module. | |
| 114 LCD_LOG_Init(); | |
| 115 LCD_LOG_SetHeader(reinterpret_cast<uint8_t*>(const_cast<char*>("Fletch"))); | |
| 116 LCD_LOG_SetFooter(reinterpret_cast<uint8_t*>(const_cast<char*>( | |
| 117 "STM32746G-Discovery"))); | |
| 118 FletchRegisterPrintInterceptor(LCDPrintIntercepter, NULL); | |
| 119 fletch::Print::DisableStandardOutput(); | |
| 120 | |
| 121 osThreadDef(START_FLETCH, StartFletch, osPriorityNormal, 0, | |
| 122 3 * 1024 /* stack size */); | |
| 123 osThreadCreate(osThread(START_FLETCH), NULL); | |
| 124 | |
| 125 osThreadDef(PRODUCER, MessageQueueProducer, osPriorityNormal, 0, 2 * 1024); | |
| 126 osThreadCreate(osThread(PRODUCER), NULL); | |
| 127 | |
| 128 // No more to do right now. | |
| 129 for (;;) { | |
| 130 osDelay(1); | |
| 131 } | |
| 132 } | |
| OLD | NEW |