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