message_layer.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. $License:
  3. Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
  4. See included License.txt for License information.
  5. $
  6. */
  7. /**
  8. * @defgroup Message_Layer message_layer
  9. * @brief Motion Library - Message Layer
  10. * Holds Low Occurance messages
  11. *
  12. * @{
  13. * @file message_layer.c
  14. * @brief Holds Low Occurance Messages.
  15. */
  16. #include "message_layer.h"
  17. #include "log.h"
  18. struct message_holder_t {
  19. long message;
  20. };
  21. static struct message_holder_t mh;
  22. /** Sets a message.
  23. * @param[in] set The flags to set.
  24. * @param[in] clear Before setting anything this will clear these messages,
  25. * which is useful for mutually exclusive messages such
  26. * a motion or no motion message.
  27. * @param[in] level Level of the messages. It starts at 0, and may increase
  28. * in the future to allow more messages if the bit storage runs out.
  29. */
  30. void inv_set_message(long set, long clear, int level)
  31. {
  32. if (level == 0) {
  33. mh.message &= ~clear;
  34. mh.message |= set;
  35. }
  36. }
  37. /** Returns Message Flags for Level 0 Messages.
  38. * Levels are to allow expansion of more messages in the future.
  39. * @param[in] clear If set, will clear the message. Typically this will be set
  40. * for one reader, so that you don't get the same message over and over.
  41. * @return bit field to corresponding message.
  42. */
  43. long inv_get_message_level_0(int clear)
  44. {
  45. long msg;
  46. msg = mh.message;
  47. if (clear) {
  48. mh.message = 0;
  49. }
  50. return msg;
  51. }
  52. /**
  53. * @}
  54. */