ksync.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <linux/version.h>
  2. #include <linux/init.h>
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/syscalls.h>
  6. #include <linux/mutex.h>
  7. #include <linux/errno.h>
  8. #include "defines.h"
  9. #include "ksync.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. static DEFINE_MUTEX(g_mtxSync);
  12. static DEFINE_MUTEX(g_mtxSPI);
  13. /////////////////////////////////////////////////////////////////////////////
  14. void ksync_lock(void)
  15. {
  16. mutex_lock(&g_mtxSync);
  17. }
  18. /////////////////////////////////////////////////////////////////////////////
  19. void ksync_unlock(void)
  20. {
  21. mutex_unlock(&g_mtxSync);
  22. }
  23. /////////////////////////////////////////////////////////////////////////////
  24. int ksync_sleep_jiffies(long jiffies)
  25. {
  26. if(jiffies <= 0)
  27. return 0;
  28. set_current_state(TASK_INTERRUPTIBLE); // may return early if a signal is delivered to the current task
  29. return schedule_timeout(jiffies);
  30. }
  31. /////////////////////////////////////////////////////////////////////////////
  32. int ksync_sleep_ms(long ms)
  33. {
  34. return ksync_sleep_jiffies(msecs_to_jiffies(ms));
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. void kfile_lock(void)
  38. {
  39. mutex_lock(&g_mtxSPI);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. void kfile_unlock(void)
  43. {
  44. mutex_unlock(&g_mtxSPI);
  45. }