fft.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include <stddef.h>
  16. #include "dmac.h"
  17. #include "fft.h"
  18. #include "sysctl.h"
  19. #include "utils.h"
  20. static volatile fft_t *const fft = (volatile fft_t *)FFT_BASE_ADDR;
  21. static void fft_init(uint8_t point, uint8_t mode, uint16_t shift, uint8_t is_dma, uint8_t input_mode, uint8_t data_mode)
  22. {
  23. fft->fft_ctrl.fft_point = point;
  24. fft->fft_ctrl.fft_mode = mode;
  25. fft->fft_ctrl.fft_shift = shift;
  26. fft->fft_ctrl.dma_send = is_dma;
  27. fft->fft_ctrl.fft_enable = 1;
  28. fft->fft_ctrl.fft_input_mode = input_mode;
  29. fft->fft_ctrl.fft_data_mode = data_mode;
  30. }
  31. void fft_complex_uint16_dma(dmac_channel_number_t dma_send_channel_num, dmac_channel_number_t dma_receive_channel_num,
  32. uint16_t shift, fft_direction_t direction, const uint64_t *input, size_t point_num, uint64_t *output)
  33. {
  34. fft_point_t point = FFT_512;
  35. switch(point_num)
  36. {
  37. case 512:
  38. point = FFT_512;
  39. break;
  40. case 256:
  41. point = FFT_256;
  42. break;
  43. case 128:
  44. point = FFT_128;
  45. break;
  46. case 64:
  47. point = FFT_64;
  48. break;
  49. default:
  50. configASSERT(!"fft point error");
  51. break;
  52. }
  53. sysctl_clock_enable(SYSCTL_CLOCK_FFT);
  54. sysctl_reset(SYSCTL_RESET_FFT);
  55. fft_init(point, direction, shift, 1, 0, 0);
  56. sysctl_dma_select(dma_receive_channel_num, SYSCTL_DMA_SELECT_FFT_RX_REQ);
  57. sysctl_dma_select(dma_send_channel_num, SYSCTL_DMA_SELECT_FFT_TX_REQ);
  58. dmac_set_single_mode(dma_receive_channel_num, (void *)(&fft->fft_output_fifo), output, DMAC_ADDR_NOCHANGE, DMAC_ADDR_INCREMENT,
  59. DMAC_MSIZE_4, DMAC_TRANS_WIDTH_64, point_num >> 1);
  60. dmac_set_single_mode(dma_send_channel_num, input, (void *)(&fft->fft_input_fifo), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
  61. DMAC_MSIZE_4, DMAC_TRANS_WIDTH_64, point_num >> 1);
  62. dmac_wait_done(dma_send_channel_num);
  63. dmac_wait_done(dma_receive_channel_num);
  64. }