1 /*
2  * Copyright 2023 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 #include <zephyr/linker/section_tags.h>
9 #include "memc_nxp_flexram.h"
10 #include <zephyr/kernel.h>
11 #include <zephyr/console/console.h>
12 #include <zephyr/cache.h>
13 
14 K_SEM_DEFINE(dtcm_magic, 0, 1);
15 
16 __dtcm_bss_section uint8_t var;
17 int cnt;
18 
flexram_magic_addr_isr_cb(enum memc_flexram_interrupt_cause cause,void * data)19 void flexram_magic_addr_isr_cb(enum memc_flexram_interrupt_cause cause,
20 						void *data)
21 {
22 	ARG_UNUSED(data);
23 
24 	if (cause == flexram_dtcm_magic_addr) {
25 		printf("Magic DTCM address accessed %d times\n", ++cnt);
26 		k_sem_give(&dtcm_magic);
27 	}
28 }
29 
main(void)30 int main(void)
31 {
32 	memc_flexram_register_callback(flexram_magic_addr_isr_cb, NULL);
33 
34 	console_init();
35 
36 	printf("%s is opening spellbook...\n", CONFIG_BOARD);
37 	printf("Cast some characters:\n");
38 
39 	uint32_t dtcm_addr = (uint32_t)&var;
40 
41 	memc_flexram_set_dtcm_magic_addr(dtcm_addr);
42 
43 	uint8_t tmp;
44 
45 	while (1) {
46 		printf("\n");
47 		tmp = console_getchar();
48 		printf("Writing %c to magic addr...\n", tmp);
49 		var = tmp;
50 		k_sem_take(&dtcm_magic, K_FOREVER);
51 		printf("Reading from magic addr...\n");
52 		printf("Magic variable got: %c\n", var);
53 		k_sem_take(&dtcm_magic, K_FOREVER);
54 	}
55 
56 	return 0;
57 }
58