sys.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <limits.h>
  7. #include <rtdevice.h>
  8. #include "log.h"
  9. #include "sys.h"
  10. #include "lock.h"
  11. #include "paras.h"
  12. #include "cfg.h"
  13. #include "fs.h"
  14. #include "thread.h"
  15. ////////////////////////////////////////////////////////////////////
  16. int sys_reboot(void)
  17. {
  18. int r=0;
  19. r = system("reboot");
  20. if(r) {
  21. LOGE("sys_reboot failed!\n");
  22. return -1;
  23. }
  24. return r;
  25. }
  26. int sys_get_chip_id(int *id)
  27. {
  28. if(!id) {
  29. return -1;
  30. }
  31. return 0;
  32. }
  33. static void* poll_thread(void *arg)
  34. {
  35. thread_handle_t *h=(thread_handle_t*)arg;
  36. //wdog_init();
  37. //tmp_create();
  38. while(h->quit==0) {
  39. sleep(1);
  40. }
  41. pthread_exit(NULL);
  42. }
  43. static int sd_mount(void)
  44. {
  45. int r=1,n=0;
  46. while(n<10) {
  47. r = mmcsd_wait_cd_changed(500);
  48. if(r==MMCSD_HOST_PLUGED) {
  49. r = fs_mount("sd", 1);
  50. }
  51. else if(r==MMCSD_HOST_UNPLUGED) {
  52. r = fs_mount("sd", 0);
  53. }
  54. if(r<=0) break;
  55. n++;
  56. }
  57. return r;
  58. }
  59. static void mk_dir(void)
  60. {
  61. fs_mkdir("/cfg");
  62. }
  63. int sys_init(void)
  64. {
  65. sd_mount();
  66. mk_dir();
  67. paras_init();
  68. //thread_start(THREAD_ID_POLL, poll_thread, NULL);
  69. return 0;
  70. }