mac_low_level.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**************************************************************************************************
  2. Filename: mac_low_level.c
  3. Revised: $Date: 2007-09-11 10:58:41 -0700 (Tue, 11 Sep 2007) $
  4. Revision: $Revision: 15371 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2009 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. /* ------------------------------------------------------------------------------------------------
  34. * Includes
  35. * ------------------------------------------------------------------------------------------------
  36. */
  37. /* hal */
  38. #include "hal_types.h"
  39. #include "hal_mcu.h"
  40. /* exported low-level */
  41. #include "mac_low_level.h"
  42. /* low-level specific */
  43. #include "mac_radio.h"
  44. #include "mac_rx.h"
  45. #include "mac_tx.h"
  46. #include "mac_rx_onoff.h"
  47. #include "mac_backoff_timer.h"
  48. #include "mac_sleep.h"
  49. /* target specific */
  50. #include "mac_radio_defs.h"
  51. /* debug */
  52. #include "mac_assert.h"
  53. #if !defined ( HAL_CLOCK_CRYSTAL )
  54. /* DCO has a frequency error of 2% */
  55. const uint16 CODE macBeaconMarginDCO[] =
  56. {
  57. 3,
  58. 3,
  59. 4,
  60. 8,
  61. 16,
  62. 31,
  63. 62,
  64. 123,
  65. 246,
  66. 492,
  67. 983,
  68. 1967,
  69. 3933,
  70. 7865,
  71. 15729,
  72. 0
  73. };
  74. #endif
  75. /**************************************************************************************************
  76. * @fn macLowLevelInit
  77. *
  78. * @brief Initialize low-level MAC. Called only once on system power-up.
  79. *
  80. * @param none
  81. *
  82. * @return none
  83. **************************************************************************************************
  84. */
  85. MAC_INTERNAL_API void macLowLevelInit(void)
  86. {
  87. /* initialize mcu before anything else */
  88. MAC_RADIO_MCU_INIT();
  89. /* initialize (override) beacon margin timing table */
  90. #if !defined ( HAL_CLOCK_CRYSTAL )
  91. {
  92. uint8 i;
  93. for (i = 0; i < sizeof(macBeaconMarginDCO)/sizeof(macBeaconMarginDCO[0]); i++)
  94. {
  95. macBeaconMargin[i] = macBeaconMarginDCO[i];
  96. }
  97. }
  98. #endif
  99. /* software initialziation */
  100. macRadioInit();
  101. macRxOnOffInit();
  102. macRxInit();
  103. macTxInit();
  104. macBackoffTimerInit();
  105. }
  106. /**************************************************************************************************
  107. * @fn macLowLevelReset
  108. *
  109. * @brief Reset low-level MAC.
  110. *
  111. * @param none
  112. *
  113. * @return none
  114. **************************************************************************************************
  115. */
  116. MAC_INTERNAL_API void macLowLevelReset(void)
  117. {
  118. MAC_ASSERT(!HAL_INTERRUPTS_ARE_ENABLED()); /* interrupts must be disabled */
  119. /* reset radio modules; if not awake, skip this */
  120. if (macSleepState == MAC_SLEEP_STATE_AWAKE)
  121. {
  122. macRxTxReset();
  123. macRadioReset();
  124. }
  125. /* reset timer */
  126. macBackoffTimerReset();
  127. /* power up the radio */
  128. macSleepWakeUp();
  129. }
  130. /**************************************************************************************************
  131. */