deca_mutex.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*! ----------------------------------------------------------------------------
  2. * @file deca_mutex.c
  3. * @brief IRQ interface / mutex implementation
  4. *
  5. * @attention
  6. *
  7. * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. */
  12. #include "deca_device_api.h"
  13. #include "port.h"
  14. // ---------------------------------------------------------------------------
  15. //
  16. // NB: The purpose of this file is to provide for microprocessor interrupt enable/disable, this is used for
  17. // controlling mutual exclusion from critical sections in the code where interrupts and background
  18. // processing may interact. The code using this is kept to a minimum and the disabling time is also
  19. // kept to a minimum, so blanket interrupt disable may be the easiest way to provide this. But at a
  20. // minimum those interrupts coming from the decawave device should be disabled/re-enabled by this activity.
  21. //
  22. // In porting this to a particular microprocessor, the implementer may choose to use #defines in the
  23. // deca_irq.h include file to map these calls transparently to the target system. Alternatively the
  24. // appropriate code may be embedded in the functions provided below.
  25. //
  26. // This mutex dependent on HW port.
  27. // If HW port uses EXT_IRQ line to receive ready/busy status from DW1000 then mutex should use this signal
  28. // If HW port not use EXT_IRQ line (i.e. SW polling) then no necessary for decamutex(on/off)
  29. //
  30. // For critical section use this mutex instead
  31. // __save_intstate()
  32. // __restore_intstate()
  33. // ---------------------------------------------------------------------------
  34. /*! ------------------------------------------------------------------------------------------------------------------
  35. * Function: decamutexon()
  36. *
  37. * Description: This function should disable interrupts. This is called at the start of a critical section
  38. * It returns the irq state before disable, this value is used to re-enable in decamutexoff call
  39. *
  40. * Note: The body of this function is defined in deca_mutex.c and is platform specific
  41. *
  42. * input parameters:
  43. *
  44. * output parameters
  45. *
  46. * returns the state of the DW1000 interrupt
  47. */
  48. decaIrqStatus_t decamutexon(void)
  49. {
  50. decaIrqStatus_t s = port_GetEXT_IRQStatus();
  51. if(s) {
  52. port_DisableEXT_IRQ(); //disable the external interrupt line
  53. }
  54. return s ; // return state before disable, value is used to re-enable in decamutexoff call
  55. }
  56. /*! ------------------------------------------------------------------------------------------------------------------
  57. * Function: decamutexoff()
  58. *
  59. * Description: This function should re-enable interrupts, or at least restore their state as returned(&saved) by decamutexon
  60. * This is called at the end of a critical section
  61. *
  62. * Note: The body of this function is defined in deca_mutex.c and is platform specific
  63. *
  64. * input parameters:
  65. * @param s - the state of the DW1000 interrupt as returned by decamutexon
  66. *
  67. * output parameters
  68. *
  69. * returns the state of the DW1000 interrupt
  70. */
  71. void decamutexoff(decaIrqStatus_t s) // put a function here that re-enables the interrupt at the end of the critical section
  72. {
  73. if(s) { //need to check the port state as we can't use level sensitive interrupt on the STM ARM
  74. port_EnableEXT_IRQ();
  75. }
  76. }