init_em.c 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <stdint.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include <rtthread.h>
  16. #include <msh.h>
  17. int em_init(void)
  18. {
  19. int count = 5;
  20. char *em_cmd = "/services/em.elf &";
  21. while (count --)
  22. {
  23. int fd;
  24. fd = open("/services/em.elf", O_RDONLY);
  25. if (fd >= 0)
  26. {
  27. close(fd);
  28. msh_exec(em_cmd, rt_strlen(em_cmd) + 1);
  29. return 0;
  30. }
  31. else
  32. {
  33. rt_thread_mdelay(500);
  34. }
  35. }
  36. if (count <= 0)
  37. {
  38. printf("open em failed!\n");
  39. }
  40. return -1;
  41. }
  42. INIT_APP_EXPORT(em_init);