DSP2803x_Lin.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_Lin.c
  4. //
  5. // TITLE: DSP2803x LIN Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  9. // $Release Date: May 8, 2015 $
  10. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  11. // http://www.ti.com/ ALL RIGHTS RESERVED $
  12. //###########################################################################
  13. #include "DSP2803x_Device.h"
  14. #include "DSP2803x_Examples.h"
  15. //---------------------------------------------------------------------------
  16. // InitLin:
  17. //---------------------------------------------------------------------------
  18. // This function initializes the LIN to a known state.
  19. //
  20. void InitLin(void)
  21. {
  22. InitLina();
  23. }
  24. void InitLina(void)
  25. {
  26. EALLOW;
  27. //Initialize LIN
  28. //Reset module and release reset.
  29. LinaRegs.SCIGCR0.bit.RESET = 0;
  30. LinaRegs.SCIGCR0.bit.RESET = 1;
  31. //LIN into software reset mode
  32. LinaRegs.SCIGCR1.bit.SWnRST = 0;
  33. //Select LIN Mode
  34. LinaRegs.SCIGCR1.bit.LINMODE = 1;
  35. //Configure LIN mode
  36. LinaRegs.SCIGCR1.bit.CLK_MASTER = 1; // 1-->Master, 0-->Slave
  37. LinaRegs.SCIGCR1.bit.ADAPT = 0; // Fixed baud rate
  38. LinaRegs.SCIGCR1.bit.COMMMODE= 0; // ID bits 4 and 5 not used for length control
  39. LinaRegs.SCIGCR1.bit.CONT = 1; // Continue on Emulation suspend
  40. LinaRegs.SCIGCR1.bit.CTYPE = 1; // LIN 2.0 Enhanced checksum used
  41. LinaRegs.SCIGCR1.bit.HGENCTRL = 1; // ID match vs LinaRegs.bit.IDSLAVETASKBYTE
  42. LinaRegs.SCIGCR1.bit.LOOPBACK = 0; // External communication mode
  43. LinaRegs.SCIGCR1.bit.MBUFMODE = 1; // Buffered mode
  44. LinaRegs.SCIGCR1.bit.PARITYENA = 1; // Check received ID for parity
  45. LinaRegs.SCIGCR1.bit.RXENA = 1; // Enable RX pin
  46. LinaRegs.SCIGCR1.bit.TXENA = 1; // Enable TX pin
  47. //More LIN configs
  48. LinaRegs.SCIGCR2.bit.CC = 1; // Validate checksum
  49. //Set all interrupts to disabled
  50. LinaRegs.SCICLEARINT.all = 0xFFFFFFFF;
  51. //Baud Rate Settings - 60MHz device
  52. LinaRegs.BRSR.bit.SCI_LIN_PSL = 96; // 19.2 kbps
  53. LinaRegs.BRSR.bit.M = 11;
  54. LinaRegs.MBRSR = 92; //20kHz (max autobaud rate)
  55. //LIN Character Size and Length
  56. LinaRegs.SCIFORMAT.bit.LENGTH = 0; // 8 bit transmission/response
  57. //SYNC Field Configuration
  58. LinaRegs.LINCOMP.bit.SBREAK = 5; // Sync break is 13 + 5 = 18 Tbits
  59. LinaRegs.LINCOMP.bit.SDEL = 3; // Sync delimiter is 1 + 3 = 4 Tbits
  60. //LIN MASK Configuartion
  61. LinaRegs.LINMASK.bit.TXIDMASK = 0xFF; // Mask ID so TX match will always happen
  62. LinaRegs.LINMASK.bit.RXIDMASK = 0xFF; // Mask ID so RX match will always happen
  63. //IODFT Configuarations
  64. LinaRegs.IODFTCTRL.bit.IODFTENA = 0x0; // IODFT testing module disabled
  65. LinaRegs.IODFTCTRL.bit.LPBENA = 0; // IODFT loopback disabled
  66. //Release SCI from software reset state - End of Config
  67. LinaRegs.SCIGCR1.bit.SWnRST = 1;
  68. EDIS;
  69. }
  70. //---------------------------------------------------------------------------
  71. // GenIdParity:
  72. //---------------------------------------------------------------------------
  73. // This function generates the ID parity bits and appends them to the ID.
  74. // Call this function on a desired ID before header generation in master
  75. // mode when LinaRegs.SCIGCR1.bit.PARITYENA is set.
  76. //
  77. Uint16 P0;
  78. Uint16 P1;
  79. Uint16 GenIdParity(Uint16 id)
  80. {
  81. P0 = ((id << 6) ^ (id << 5) ^ (id << 4) ^ (id << 2)) & BIT6;
  82. P1 = (((id << 6) ^ (id << 4) ^ (id << 3) ^ (id << 2)) & BIT7) ^ BIT7;
  83. return id | P0 | P1;
  84. }
  85. //---------------------------------------------------------------------------
  86. // Example: InitLinGpio:
  87. //---------------------------------------------------------------------------
  88. // This function initializes GPIO pins to function as LIN pins
  89. //
  90. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  91. // peripheral functional pins. By default all pins come up as GPIO
  92. // inputs after reset.
  93. //
  94. // Caution:
  95. // Only one GPIO pin should be enabled for LIN TX operation.
  96. // Only one GPIO pin shoudl be enabled for LIN RX operation.
  97. // Comment out other unwanted lines.
  98. void InitLinGpio()
  99. {
  100. InitLinaGpio();
  101. }
  102. void InitLinaGpio()
  103. {
  104. EALLOW;
  105. /* Enable internal pull-up for the selected pins */
  106. // Pull-ups can be enabled or disabled by the user.
  107. // This will enable the pullups for the specified pins.
  108. GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Enable pull-up for GPIO9 (LIN TX)
  109. // GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0; // Enable pull-up for GPIO14 (LIN TX)
  110. // GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up for GPIO18 (LIN TX)
  111. // GpioCtrlRegs.GPAPUD.bit.GPIO22 = 0; // Enable pull-up for GPIO22 (LIN TX)
  112. GpioCtrlRegs.GPAPUD.bit.GPIO11 = 0; // Enable pull-up for GPIO11 (LIN RX)
  113. // GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0; // Enable pull-up for GPIO15 (LIN RX)
  114. // GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up for GPIO19 (LIN RX)
  115. // GpioCtrlRegs.GPAPUD.bit.GPIO23 = 0; // Enable pull-up for GPIO23 (LIN RX)
  116. /* Set qualification for selected pins to asynch only */
  117. // Inputs are synchronized to SYSCLKOUT by default.
  118. // This will select asynch (no qualification) for the selected pins.
  119. GpioCtrlRegs.GPAQSEL1.bit.GPIO11 = 3; // Asynch input GPIO11 (LINRXA)
  120. // GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3; // Asynch input GPIO15 (LINRXA)
  121. // GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (LINRXA)
  122. // GpioCtrlRegs.GPAQSEL2.bit.GPIO23 = 3; // Asynch input GPIO23 (LINRXA)
  123. /* Configure LIN-A pins using GPIO regs*/
  124. // This specifies which of the possible GPIO pins will be LIN pins.
  125. // Only one set of pins should be enabled at any time for LIN operation.
  126. GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 2; // Configure GPIO9 for LIN TX operation (2-Enable,0-Disable)
  127. // GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 2; // Configure GPIO14 for LIN TX operation (2-Enable,0-Disable)
  128. // GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 2; // Configure GPIO18 for LIN TX operation (2-Enable,0-Disable)
  129. // GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 3; // Configure GPIO19 for LIN TX operation (3-Enable,0-Disable)
  130. GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 2; // Configure GPIO11 for LIN RX operation (2-Enable,0-Disable)
  131. // GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 2; // Configure GPIO15 for LIN RX operation (2-Enable,0-Disable)
  132. // GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 2; // Configure GPIO19 for LIN RX operation (2-Enable,0-Disable)
  133. // GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 3; // Configure GPIO23 for LIN RX operation (3-Enable,0-Disable)
  134. EDIS;
  135. }
  136. //===========================================================================
  137. // End of file.
  138. //===========================================================================