sys.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. int sys_init(void)
  60. {
  61. sd_mount();
  62. paras_init();
  63. //thread_start(THREAD_ID_POLL, poll_thread, NULL);
  64. return 0;
  65. }