ssp_001.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * @brief SSP Registers and control functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #include "ssp_001.h"
  32. /*****************************************************************************
  33. * Private types/enumerations/variables
  34. ****************************************************************************/
  35. /*****************************************************************************
  36. * Public types/enumerations/variables
  37. ****************************************************************************/
  38. /*****************************************************************************
  39. * Private functions
  40. ****************************************************************************/
  41. /*****************************************************************************
  42. * Public functions
  43. ****************************************************************************/
  44. /*Set up output clocks per bit for SSP bus*/
  45. void IP_SSP_Set_ClockRate(IP_SSP_001_Type *pSSP, uint32_t clk_rate, uint32_t prescale)
  46. {
  47. pSSP->CR0 &= ~(SSP_CR0_SCR(0xFF));
  48. pSSP->CR0 |= SSP_CR0_SCR(clk_rate);
  49. pSSP->CPSR = prescale;
  50. }
  51. /* Set up the SSP frame format */
  52. void IP_SSP_Set_Format(IP_SSP_001_Type *pSSP, uint32_t bits, uint32_t frameFormat, uint32_t clockFormat)
  53. {
  54. pSSP->CR0 = (pSSP->CR0 & ~0xFF) | bits | frameFormat | clockFormat;
  55. }
  56. /* Set the SSP working as master or slave mode */
  57. void IP_SSP_Set_Mode(IP_SSP_001_Type *pSSP, uint32_t mode)
  58. {
  59. pSSP->CR1 = (pSSP->CR1 & ~(1 << 2)) | mode;
  60. }
  61. /* Disable SSP operation */
  62. void IP_SSP_DeInit(IP_SSP_001_Type *pSSP)
  63. {
  64. pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
  65. }
  66. /* Enable/Disable SSP operation */
  67. void IP_SSP_Cmd(IP_SSP_001_Type *pSSP, FunctionalState NewState)
  68. {
  69. if (NewState == ENABLE) {
  70. pSSP->CR1 |= SSP_CR1_SSP_EN;
  71. }
  72. else {
  73. pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
  74. }
  75. }
  76. /* Send SSP 16-bit data */
  77. void IP_SSP_SendFrame(IP_SSP_001_Type *pSSP, uint16_t tx_data)
  78. {
  79. pSSP->DR = SSP_DR_BITMASK(tx_data);
  80. }
  81. /* Get received SSP data */
  82. uint16_t IP_SSP_ReceiveFrame(IP_SSP_001_Type *pSSP)
  83. {
  84. return (uint16_t) (SSP_DR_BITMASK(pSSP->DR));
  85. }
  86. /* Enable/Disable loopback mode */
  87. void IP_SSP_LoopBackCmd(IP_SSP_001_Type *pSSP, FunctionalState NewState)
  88. {
  89. if (NewState == ENABLE) {
  90. pSSP->CR1 |= SSP_CR1_LBM_EN;
  91. }
  92. else {
  93. pSSP->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK;
  94. }
  95. }
  96. /* Get the raw interrupt status */
  97. IntStatus IP_SSP_GetRawIntStatus(IP_SSP_001_Type *pSSP, SSP_Raw_Int_Status_Type RawInt)
  98. {
  99. return (pSSP->RIS & RawInt) ? SET : RESET;
  100. }
  101. /* Get the masked interrupt status */
  102. uint32_t IP_SSP_GetIntStatus(IP_SSP_001_Type *pSSP)
  103. {
  104. return pSSP->MIS;
  105. }
  106. /* Clear the corresponding interrupt condition(s) in the SSP controller */
  107. void IP_SSP_ClearIntPending(IP_SSP_001_Type *pSSP, SSP_Int_Clear_Type IntClear)
  108. {
  109. pSSP->ICR = IntClear;
  110. }
  111. /* Get the current status of SSP controller */
  112. FlagStatus IP_SSP_GetStatus(IP_SSP_001_Type *pSSP, SSP_Status_Type Stat)
  113. {
  114. return (pSSP->SR & Stat) ? SET : RESET;
  115. }
  116. /* Get the number of bits transferred in each frame */
  117. uint8_t IP_SSP_GetDataSize(IP_SSP_001_Type *pSSP)
  118. {
  119. return SSP_CR0_DSS(pSSP->CR0);
  120. }
  121. /* Enable/Disable interrupt for the SSP */
  122. void IP_SSP_Int_Enable(IP_SSP_001_Type *pSSP, SSP_Int_Mask_Type IntType, FunctionalState NewState)
  123. {
  124. if (NewState == ENABLE) {
  125. pSSP->IMSC |= IntType;
  126. }
  127. else {
  128. pSSP->IMSC &= (~IntType);
  129. }
  130. }
  131. /* Enable/Disable DMA for SSP */
  132. void IP_SSP_DMA_Cmd(IP_SSP_001_Type *pSSP, SSP_DMA_Type ssp_dma_t, FunctionalState NewState)
  133. {
  134. #if !defined(CHIP_LPC111X_CXX) && !defined(CHIP_LPC11UXX)
  135. if (NewState == ENABLE) {
  136. pSSP->DMACR |= ssp_dma_t;
  137. }
  138. else {
  139. pSSP->DMACR &= (~ssp_dma_t);
  140. }
  141. #endif
  142. }