ti_msp_dl_config.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2023, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * ============ ti_msp_dl_config.c =============
  34. * Configured MSPM0 DriverLib module definitions
  35. *
  36. * DO NOT EDIT - This file is generated for the MSPM0L130X
  37. * by the SysConfig tool.
  38. */
  39. #include "ti_msp_dl_config.h"
  40. /*
  41. * ======== SYSCFG_DL_init ========
  42. * Perform any initialization needed before using any board APIs
  43. */
  44. SYSCONFIG_WEAK void SYSCFG_DL_init(void)
  45. {
  46. SYSCFG_DL_initPower();
  47. SYSCFG_DL_GPIO_init();
  48. /* Module-Specific Initializations*/
  49. SYSCFG_DL_SYSCTL_init();
  50. SYSCFG_DL_PWM_0_init();
  51. SYSCFG_DL_I2C_controller_init();
  52. SYSCFG_DL_I2C_target_init();
  53. }
  54. SYSCONFIG_WEAK void SYSCFG_DL_initPower(void)
  55. {
  56. DL_GPIO_reset(GPIOA);
  57. DL_TimerG_reset(PWM_0_INST);
  58. DL_I2C_reset(I2C_controller_INST);
  59. DL_I2C_reset(I2C_target_INST);
  60. DL_GPIO_enablePower(GPIOA);
  61. DL_TimerG_enablePower(PWM_0_INST);
  62. DL_I2C_enablePower(I2C_controller_INST);
  63. DL_I2C_enablePower(I2C_target_INST);
  64. delay_cycles(POWER_STARTUP_DELAY);
  65. }
  66. SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void)
  67. {
  68. DL_GPIO_initPeripheralOutputFunction(GPIO_PWM_0_C0_IOMUX,GPIO_PWM_0_C0_IOMUX_FUNC);
  69. DL_GPIO_enableOutput(GPIO_PWM_0_C0_PORT, GPIO_PWM_0_C0_PIN);
  70. DL_GPIO_initPeripheralInputFunctionFeatures(
  71. GPIO_I2C_controller_IOMUX_SDA, GPIO_I2C_controller_IOMUX_SDA_FUNC,
  72. DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
  73. DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
  74. DL_GPIO_initPeripheralInputFunctionFeatures(
  75. GPIO_I2C_controller_IOMUX_SCL, GPIO_I2C_controller_IOMUX_SCL_FUNC,
  76. DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_UP,
  77. DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
  78. DL_GPIO_enableHiZ(GPIO_I2C_controller_IOMUX_SDA);
  79. DL_GPIO_enableHiZ(GPIO_I2C_controller_IOMUX_SCL);
  80. DL_GPIO_initPeripheralInputFunctionFeatures(
  81. GPIO_I2C_target_IOMUX_SDA, GPIO_I2C_target_IOMUX_SDA_FUNC,
  82. DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_NONE,
  83. DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
  84. DL_GPIO_initPeripheralInputFunctionFeatures(
  85. GPIO_I2C_target_IOMUX_SCL, GPIO_I2C_target_IOMUX_SCL_FUNC,
  86. DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_NONE,
  87. DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
  88. DL_GPIO_enableHiZ(GPIO_I2C_target_IOMUX_SDA);
  89. DL_GPIO_enableHiZ(GPIO_I2C_target_IOMUX_SCL);
  90. }
  91. SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void)
  92. {
  93. //Low Power Mode is configured to be SLEEP0
  94. DL_SYSCTL_setBORThreshold(DL_SYSCTL_BOR_THRESHOLD_LEVEL_0);
  95. DL_SYSCTL_disableNRSTPin();
  96. DL_SYSCTL_setSYSOSCFreq(DL_SYSCTL_SYSOSC_FREQ_BASE);
  97. DL_SYSCTL_setMCLKDivider(DL_SYSCTL_MCLK_DIVIDER_DISABLE);
  98. }
  99. /*
  100. * Timer clock configuration to be sourced by / 1 (32000000 Hz)
  101. * timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
  102. * 32000000 Hz = 32000000 Hz / (1 * (0 + 1))
  103. */
  104. static const DL_TimerG_ClockConfig gPWM_0ClockConfig = {
  105. .clockSel = DL_TIMER_CLOCK_BUSCLK,
  106. .divideRatio = DL_TIMER_CLOCK_DIVIDE_1,
  107. .prescale = 0U
  108. };
  109. static const DL_TimerG_PWMConfig gPWM_0Config = {
  110. .pwmMode = DL_TIMER_PWM_MODE_EDGE_ALIGN,
  111. .period = 400,
  112. .isTimerWithFourCC = false,
  113. .startTimer = DL_TIMER_STOP,
  114. };
  115. SYSCONFIG_WEAK void SYSCFG_DL_PWM_0_init(void) {
  116. DL_TimerG_setClockConfig(
  117. PWM_0_INST, (DL_TimerG_ClockConfig *) &gPWM_0ClockConfig);
  118. DL_TimerG_initPWMMode(
  119. PWM_0_INST, (DL_TimerG_PWMConfig *) &gPWM_0Config);
  120. // Set Counter control to the smallest CC index being used
  121. DL_TimerG_setCounterControl(PWM_0_INST,DL_TIMER_CZC_CCCTL0_ZCOND,DL_TIMER_CAC_CCCTL0_ACOND,DL_TIMER_CLC_CCCTL0_LCOND);
  122. DL_TimerG_setCaptureCompareOutCtl(PWM_0_INST, DL_TIMER_CC_OCTL_INIT_VAL_LOW,
  123. DL_TIMER_CC_OCTL_INV_OUT_DISABLED, DL_TIMER_CC_OCTL_SRC_FUNCVAL,
  124. DL_TIMERG_CAPTURE_COMPARE_0_INDEX);
  125. DL_TimerG_setCaptCompUpdateMethod(PWM_0_INST, DL_TIMER_CC_UPDATE_METHOD_IMMEDIATE, DL_TIMERG_CAPTURE_COMPARE_0_INDEX);
  126. DL_TimerG_setCaptureCompareValue(PWM_0_INST, 360, DL_TIMER_CC_0_INDEX);
  127. DL_TimerG_enableClock(PWM_0_INST);
  128. DL_TimerG_setCCPDirection(PWM_0_INST , DL_TIMER_CC0_OUTPUT );
  129. }
  130. static const DL_I2C_ClockConfig gI2C_controllerClockConfig = {
  131. .clockSel = DL_I2C_CLOCK_BUSCLK,
  132. .divideRatio = DL_I2C_CLOCK_DIVIDE_1,
  133. };
  134. SYSCONFIG_WEAK void SYSCFG_DL_I2C_controller_init(void) {
  135. DL_I2C_setClockConfig(I2C_controller_INST,
  136. (DL_I2C_ClockConfig *) &gI2C_controllerClockConfig);
  137. DL_I2C_setAnalogGlitchFilterPulseWidth(I2C_controller_INST,
  138. DL_I2C_ANALOG_GLITCH_FILTER_WIDTH_50NS);
  139. DL_I2C_enableAnalogGlitchFilter(I2C_controller_INST);
  140. /* Configure Controller Mode */
  141. DL_I2C_resetControllerTransfer(I2C_controller_INST);
  142. /* Set frequency to 100000 Hz*/
  143. DL_I2C_setTimerPeriod(I2C_controller_INST, 31);
  144. DL_I2C_setControllerTXFIFOThreshold(I2C_controller_INST, DL_I2C_TX_FIFO_LEVEL_EMPTY);
  145. DL_I2C_setControllerRXFIFOThreshold(I2C_controller_INST, DL_I2C_RX_FIFO_LEVEL_BYTES_1);
  146. DL_I2C_enableControllerClockStretching(I2C_controller_INST);
  147. /* Configure Interrupts */
  148. DL_I2C_enableInterrupt(I2C_controller_INST,
  149. DL_I2C_INTERRUPT_CONTROLLER_ARBITRATION_LOST |
  150. DL_I2C_INTERRUPT_CONTROLLER_NACK |
  151. DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER |
  152. DL_I2C_INTERRUPT_CONTROLLER_RX_DONE |
  153. DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER |
  154. DL_I2C_INTERRUPT_CONTROLLER_TX_DONE);
  155. /* Enable module */
  156. DL_I2C_enableController(I2C_controller_INST);
  157. }
  158. static const DL_I2C_ClockConfig gI2C_targetClockConfig = {
  159. .clockSel = DL_I2C_CLOCK_BUSCLK,
  160. .divideRatio = DL_I2C_CLOCK_DIVIDE_1,
  161. };
  162. SYSCONFIG_WEAK void SYSCFG_DL_I2C_target_init(void) {
  163. DL_I2C_setClockConfig(I2C_target_INST,
  164. (DL_I2C_ClockConfig *) &gI2C_targetClockConfig);
  165. DL_I2C_setAnalogGlitchFilterPulseWidth(I2C_target_INST,
  166. DL_I2C_ANALOG_GLITCH_FILTER_WIDTH_50NS);
  167. DL_I2C_enableAnalogGlitchFilter(I2C_target_INST);
  168. /* Configure Target Mode */
  169. DL_I2C_setTargetOwnAddress(I2C_target_INST, I2C_target_TARGET_OWN_ADDR);
  170. DL_I2C_setTargetTXFIFOThreshold(I2C_target_INST, DL_I2C_TX_FIFO_LEVEL_EMPTY);
  171. DL_I2C_setTargetRXFIFOThreshold(I2C_target_INST, DL_I2C_RX_FIFO_LEVEL_BYTES_1);
  172. DL_I2C_enableTargetClockStretching(I2C_target_INST);
  173. /* Workaround for errata I2C_ERR_04 */
  174. DL_I2C_disableTargetWakeup(I2C_target_INST);
  175. /* Configure Interrupts */
  176. DL_I2C_enableInterrupt(I2C_target_INST,
  177. DL_I2C_INTERRUPT_TARGET_RXFIFO_TRIGGER |
  178. DL_I2C_INTERRUPT_TARGET_START |
  179. DL_I2C_INTERRUPT_TARGET_STOP |
  180. DL_I2C_INTERRUPT_TARGET_TXFIFO_TRIGGER);
  181. /* Enable module */
  182. DL_I2C_enableTarget(I2C_target_INST);
  183. }