F2837xD_can.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //###########################################################################
  2. //
  3. // FILE: F2837xD_can.c
  4. //
  5. // TITLE: F2837xD CAN Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. //
  43. // Included Files
  44. //
  45. #include "F2837xD_device.h"
  46. #include "F2837xD_Examples.h"
  47. //
  48. // InitCAN - Initializes the CAN-A controller after reset.
  49. //
  50. void InitCAN(void)
  51. {
  52. int16_t iMsg;
  53. //
  54. // Place CAN controller in init state, regardless of previous state. This
  55. // will put controller in idle, and allow the message object RAM to be
  56. // programmed.
  57. //
  58. CanaRegs.CAN_CTL.bit.Init = 1;
  59. CanaRegs.CAN_CTL.bit.SWR = 1;
  60. //
  61. // Wait for busy bit to clear
  62. //
  63. while(CanaRegs.CAN_IF1CMD.bit.Busy)
  64. {
  65. }
  66. //
  67. // Clear the message value bit in the arbitration register. This indicates
  68. // the message is not valid and is a "safe" condition to leave the message
  69. // object. The same arb reg is used to program all the message objects.
  70. //
  71. CanaRegs.CAN_IF1CMD.bit.DIR = 1;
  72. CanaRegs.CAN_IF1CMD.bit.Arb = 1;
  73. CanaRegs.CAN_IF1CMD.bit.Control = 1;
  74. CanaRegs.CAN_IF1ARB.all = 0;
  75. CanaRegs.CAN_IF1MCTL.all = 0;
  76. CanaRegs.CAN_IF2CMD.bit.DIR = 1;
  77. CanaRegs.CAN_IF2CMD.bit.Arb = 1;
  78. CanaRegs.CAN_IF2CMD.bit.Control = 1;
  79. CanaRegs.CAN_IF2ARB.all = 0;
  80. CanaRegs.CAN_IF2MCTL.all = 0;
  81. //
  82. // Loop through to program all 32 message objects
  83. //
  84. for(iMsg = 1; iMsg <= 32; iMsg+=2)
  85. {
  86. //
  87. // Wait for busy bit to clear
  88. //
  89. while(CanaRegs.CAN_IF1CMD.bit.Busy)
  90. {
  91. }
  92. //
  93. // Initiate programming the message object
  94. //
  95. CanaRegs.CAN_IF1CMD.bit.MSG_NUM = iMsg;
  96. //
  97. // Wait for busy bit to clear
  98. //
  99. while(CanaRegs.CAN_IF2CMD.bit.Busy)
  100. {
  101. }
  102. //
  103. // Initiate programming the message object
  104. //
  105. CanaRegs.CAN_IF2CMD.bit.MSG_NUM = iMsg + 1;
  106. }
  107. //
  108. // Acknowledge any pending status interrupts.
  109. //
  110. volatile uint32_t discardRead = CanaRegs.CAN_ES.all;
  111. }
  112. //
  113. // End of file
  114. //