Skip to content

Commit f0b568a

Browse files
committed
Update submodule commits and enhance startup file handlers
1 parent 28154e2 commit f0b568a

8 files changed

Lines changed: 132 additions & 101 deletions

File tree

lib/dmheap

lib/dmvfs

Submodule dmvfs updated 1 file

src/arch/armv7/cortex-m4/startup.s

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ vectors:
3737
.word 0 /* 8: Reserved */
3838
.word 0 /* 9: Reserved */
3939
.word 0 /* 10: Reserved */
40-
.word SVC_Handler /* 11: SVCall Handler */
40+
.word dmosi_syscall_handler /* 11: SVCall Handler */
4141
.word DebugMon_Handler /* 12: Debug Monitor Handler */
4242
.word 0 /* 13: Reserved */
43-
.word PendSV_Handler /* 14: PendSV Handler */
44-
.word SysTick_Handler /* 15: SysTick Handler */
43+
.word dmosi_context_switch_handler /* 14: PendSV Handler */
44+
.word dmosi_tick_handler /* 15: SysTick Handler */
4545

4646
/*==============================================================================
4747
ARMv7-M (Cortex-M4) startup code
@@ -200,21 +200,21 @@ assign undefined exception handlers to __default_handler
200200
.global UsageFault_Handler
201201
.set UsageFault_Handler, __default_handler
202202

203-
.weak SVC_Handler
204-
.global SVC_Handler
205-
.set SVC_Handler, __default_handler
203+
.weak dmosi_syscall_handler
204+
.global dmosi_syscall_handler
205+
.set dmosi_syscall_handler, __default_handler
206206

207207
.weak DebugMon_Handler
208208
.global DebugMon_Handler
209209
.set DebugMon_Handler, __default_handler
210210

211-
.weak PendSV_Handler
212-
.global PendSV_Handler
213-
.set PendSV_Handler, __default_handler
211+
.weak dmosi_context_switch_handler
212+
.global dmosi_context_switch_handler
213+
.set dmosi_context_switch_handler, __default_handler
214214

215-
.weak SysTick_Handler
216-
.global SysTick_Handler
217-
.set SysTick_Handler, __default_handler
215+
.weak dmosi_tick_handler
216+
.global dmosi_tick_handler
217+
.set dmosi_tick_handler, __default_handler
218218

219219
/*******************************************************************************
220220
END OF FILE

src/arch/armv7/cortex-m7/startup.s

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ vectors:
3737
.word 0 /* 8: Reserved */
3838
.word 0 /* 9: Reserved */
3939
.word 0 /* 10: Reserved */
40-
.word SVC_Handler /* 11: SVCall Handler */
40+
.word dmosi_syscall_handler /* 11: SVCall Handler */
4141
.word DebugMon_Handler /* 12: Debug Monitor Handler */
4242
.word 0 /* 13: Reserved */
43-
.word PendSV_Handler /* 14: PendSV Handler */
44-
.word SysTick_Handler /* 15: SysTick Handler */
43+
.word dmosi_context_switch_handler /* 14: PendSV Handler */
44+
.word dmosi_tick_handler /* 15: SysTick Handler */
4545

4646
/*==============================================================================
4747
ARMv7-M (Cortex-M7) startup code
@@ -200,21 +200,21 @@ assign undefined exception handlers to __default_handler
200200
.global UsageFault_Handler
201201
.set UsageFault_Handler, __default_handler
202202

203-
.weak SVC_Handler
204-
.global SVC_Handler
205-
.set SVC_Handler, __default_handler
203+
.weak dmosi_syscall_handler
204+
.global dmosi_syscall_handler
205+
.set dmosi_syscall_handler, __default_handler
206206

207207
.weak DebugMon_Handler
208208
.global DebugMon_Handler
209209
.set DebugMon_Handler, __default_handler
210210

211-
.weak PendSV_Handler
212-
.global PendSV_Handler
213-
.set PendSV_Handler, __default_handler
211+
.weak dmosi_context_switch_handler
212+
.global dmosi_context_switch_handler
213+
.set dmosi_context_switch_handler, __default_handler
214214

215-
.weak SysTick_Handler
216-
.global SysTick_Handler
217-
.set SysTick_Handler, __default_handler
215+
.weak dmosi_tick_handler
216+
.global dmosi_tick_handler
217+
.set dmosi_tick_handler, __default_handler
218218

219219
/*******************************************************************************
220220
END OF FILE

src/arch/armv7/dmod_critical.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@
4242

4343
static uint32_t critical_nesting = 0;
4444

45+
/**
46+
* @brief Assertion handler for critical section functions
47+
*
48+
* This function is called when an assertion fails in the critical section code.
49+
* It logs the error message and halts the system to prevent further damage.
50+
*
51+
* @param Condition The condition that failed (should be false)
52+
* @param Message A message describing the assertion failure
53+
* @param File The source file where the assertion failed
54+
* @param Line The line number in the source file where the assertion failed
55+
* @param Function The function name where the assertion failed
56+
*/
57+
void Dmod_Assert( int Condition, const char* Message, const char* File, int Line, const char* Function )
58+
{
59+
if( !Condition )
60+
{
61+
DMOD_LOG_ERROR("Assertion failed: %s, at %s:%d in function %s\n", Message, File, Line, Function);
62+
__asm volatile ("BKPT #0"); // Trigger a breakpoint for debugging
63+
while(1); // Halt the system
64+
}
65+
}
66+
4567
/**
4668
* @brief Enter critical section
4769
*

src/main.c

Lines changed: 82 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void delay(int cycles)
3535
void HardFault_Handler(void)
3636
{
3737
DMOD_LOG_ERROR("HardFault_Handler invoked!\n");
38-
while(1);
38+
DMOD_ASSERT_MSG(false, "A hard fault occurred. System halted.");
3939
}
4040

4141
static void load_embedded_startup_dmp(void)
@@ -212,9 +212,9 @@ static void start_main_module(Dmod_Context_t* main_ctx)
212212
char argv0[] = "main_module";
213213
char* argv[] = { argv0 };
214214
int argc = 1;
215-
if( Dmod_Run(main_ctx, argc, argv) != 0 )
215+
if( Dmod_RunDetached(main_ctx, argc, argv) == 0 )
216216
{
217-
DMOD_LOG_ERROR("Failed to run main application module\n");
217+
DMOD_ASSERT_MSG(false, "Failed to run main application module. System halted.");
218218
}
219219
}
220220
else
@@ -305,77 +305,8 @@ static void mount_embedded_filesystems(void)
305305
dmvfs_mount_fs("dmdevfs", "/dev", "/configs");
306306
}
307307

308-
int main(int argc, char** argv)
308+
static void boot_shell(dmlog_ctx_t ctx)
309309
{
310-
Dmod_SetLogLevel(Dmod_LogLevel_Info);
311-
void* logs_start = &__logs_start__;
312-
void* logs_end = &__logs_end__;
313-
dmlog_index_t logs_size = (dmlog_index_t)((uintptr_t)logs_end - (uintptr_t)logs_start);
314-
315-
memset(logs_start, 0, logs_size);
316-
317-
dmlog_ctx_t ctx = dmlog_create(logs_start, logs_size);
318-
dmlog_set_as_default(ctx);
319-
320-
void* heap_start = &__heap_start__;
321-
void* heap_end = &__heap_end__;
322-
size_t heap_size = (size_t)((uintptr_t)heap_end - (uintptr_t)heap_start);
323-
324-
if(!dmheap_init(heap_start, heap_size, sizeof(void*)))
325-
{
326-
DMOD_LOG_ERROR("Heap initialization failed!\n");
327-
while(1);
328-
}
329-
DMOD_LOG_INFO("Heap initialized: Start=0x%X, Size=%u bytes\n", (uintptr_t)heap_start, (unsigned int)heap_size);
330-
331-
dmenv_ctx_t dmenv_ctx = dmenv_create(NULL);
332-
if(dmenv_ctx == NULL)
333-
{
334-
DMOD_LOG_ERROR("DMEnv initialization failed!\n");
335-
while(1);
336-
}
337-
dmenv_set_root_context(dmenv_ctx);
338-
339-
if(!Dmod_Initialize())
340-
{
341-
DMOD_LOG_ERROR("DMOD initialization failed!\n");
342-
while(1);
343-
}
344-
345-
if(!dmvfs_init(DMBOOT_MAX_MOUNT_POINTS, DMBOOT_MAX_OPEN_FILES))
346-
{
347-
DMOD_LOG_ERROR("VFS initialization failed!\n");
348-
while(1);
349-
}
350-
351-
dmenv_set(dmenv_ctx, "HOSTNAME", DMBOOT_MCU_NAME_STRING);
352-
dmenv_set(dmenv_ctx, "DMOD_VERSION", DMOD_VERSION_STRING);
353-
dmenv_set(dmenv_ctx, "DMBOOT_MCU_NAME", DMBOOT_MCU_NAME_STRING);
354-
dmenv_set(dmenv_ctx, "DMBOOT_MCU_SERIES", DMBOOT_MCU_SERIES_STRING);
355-
dmenv_seti(dmenv_ctx, "DMBOOT_MAX_MOUNT_POINTS", DMBOOT_MAX_MOUNT_POINTS);
356-
dmenv_set(dmenv_ctx, "DMOD_REPO_DIR", DMOD_REPO_DIR);
357-
dmenv_set(dmenv_ctx, "DMOD_REPO_PATHS", DMOD_REPO_PATHS);
358-
dmenv_seti(dmenv_ctx, "DMBOOT_EMULATION", DMBOOT_EMULATION_ENABLED);
359-
dmenv_set(dmenv_ctx, "PWD", "/");
360-
361-
// Set user_data environment variables if embedded in ROM
362-
setup_embedded_user_data(dmenv_ctx);
363-
364-
// Load modules.dmp if embedded in ROM
365-
Dmod_Context_t* mainModule = load_embedded_modules_dmp();
366-
367-
// Mount embedded filesystems
368-
mount_embedded_filesystems();
369-
370-
// Load startup.dmp if embedded in ROM
371-
load_embedded_startup_dmp();
372-
373-
// Mark that the boot process is done
374-
dmlog_puts(ctx, "DMOD-Boot started\n");
375-
376-
// Start main module if loaded
377-
start_main_module(mainModule);
378-
379310
Dmod_Printf("Entering interactive shell. Type 'help' for commands.\n");
380311

381312
while(1)
@@ -493,6 +424,84 @@ int main(int argc, char** argv)
493424
}
494425
}
495426
}
427+
}
428+
429+
int main(int argc, char** argv)
430+
{
431+
Dmod_SetLogLevel(Dmod_LogLevel_Info);
432+
void* logs_start = &__logs_start__;
433+
void* logs_end = &__logs_end__;
434+
dmlog_index_t logs_size = (dmlog_index_t)((uintptr_t)logs_end - (uintptr_t)logs_start);
435+
436+
memset(logs_start, 0, logs_size);
437+
438+
dmlog_ctx_t ctx = dmlog_create(logs_start, logs_size);
439+
dmlog_set_as_default(ctx);
440+
441+
void* heap_start = &__heap_start__;
442+
void* heap_end = &__heap_end__;
443+
size_t heap_size = (size_t)((uintptr_t)heap_end - (uintptr_t)heap_start);
444+
445+
if(!dmheap_init(heap_start, heap_size, sizeof(void*)))
446+
{
447+
DMOD_LOG_ERROR("Heap initialization failed!\n");
448+
while(1);
449+
}
450+
DMOD_LOG_INFO("Heap initialized: Start=0x%X, Size=%u bytes\n", (uintptr_t)heap_start, (unsigned int)heap_size);
451+
452+
dmenv_ctx_t dmenv_ctx = dmenv_create(NULL);
453+
if(dmenv_ctx == NULL)
454+
{
455+
DMOD_LOG_ERROR("DMEnv initialization failed!\n");
456+
while(1);
457+
}
458+
dmenv_set_root_context(dmenv_ctx);
459+
460+
if(!Dmod_Initialize())
461+
{
462+
DMOD_LOG_ERROR("DMOD initialization failed!\n");
463+
while(1);
464+
}
465+
466+
if(!dmvfs_init(DMBOOT_MAX_MOUNT_POINTS, DMBOOT_MAX_OPEN_FILES))
467+
{
468+
DMOD_LOG_ERROR("VFS initialization failed!\n");
469+
while(1);
470+
}
471+
472+
dmenv_set(dmenv_ctx, "HOSTNAME", DMBOOT_MCU_NAME_STRING);
473+
dmenv_set(dmenv_ctx, "DMOD_VERSION", DMOD_VERSION_STRING);
474+
dmenv_set(dmenv_ctx, "DMBOOT_MCU_NAME", DMBOOT_MCU_NAME_STRING);
475+
dmenv_set(dmenv_ctx, "DMBOOT_MCU_SERIES", DMBOOT_MCU_SERIES_STRING);
476+
dmenv_seti(dmenv_ctx, "DMBOOT_MAX_MOUNT_POINTS", DMBOOT_MAX_MOUNT_POINTS);
477+
dmenv_set(dmenv_ctx, "DMOD_REPO_DIR", DMOD_REPO_DIR);
478+
dmenv_set(dmenv_ctx, "DMOD_REPO_PATHS", DMOD_REPO_PATHS);
479+
dmenv_seti(dmenv_ctx, "DMBOOT_EMULATION", DMBOOT_EMULATION_ENABLED);
480+
dmenv_set(dmenv_ctx, "PWD", "/");
481+
482+
// Set user_data environment variables if embedded in ROM
483+
setup_embedded_user_data(dmenv_ctx);
484+
485+
// Load modules.dmp if embedded in ROM
486+
Dmod_Context_t* mainModule = load_embedded_modules_dmp();
487+
488+
// Mount embedded filesystems
489+
mount_embedded_filesystems();
490+
491+
// Load startup.dmp if embedded in ROM
492+
load_embedded_startup_dmp();
493+
494+
// Mark that the boot process is done
495+
dmlog_puts(ctx, "DMOD-Boot started\n");
496+
497+
// Start main module if loaded
498+
start_main_module(mainModule);
499+
500+
// Initialize RTOS and start scheduler (if applicable)
501+
dmosi_init();
502+
503+
// fallback to interactive shell
504+
boot_shell(ctx);
496505

497506
return 0;
498507
}

0 commit comments

Comments
 (0)