1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022/01/20     bernard      the first version
9  */
10 
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 
15 #include <unistd.h>
16 #include <fcntl.h>
17 
18 #include <rtthread.h>
19 #include <msh.h>
20 
em_init(void)21 int em_init(void)
22 {
23     int count = 5;
24     char *em_cmd = "/services/em.elf &";
25 
26     while (count --)
27     {
28         int fd;
29         fd = open("/services/em.elf", O_RDONLY);
30         if (fd >= 0)
31         {
32             close(fd);
33 
34             msh_exec(em_cmd, rt_strlen(em_cmd) + 1);
35             return 0;
36         }
37         else
38         {
39             rt_thread_mdelay(500);
40         }
41     }
42 
43     if (count <= 0)
44     {
45         printf("open em failed!\n");
46     }
47 
48     return -1;
49 }
50 INIT_APP_EXPORT(em_init);
51