spi_slave.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. // File name : spi_slave.h
  3. // Description : SPI1 Slave DMA LLI Ping-Pong transport layer for GMSP
  4. // national crypto co-processor firmware.
  5. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. #ifndef GMSP_SPI_SLAVE_H_
  7. #define GMSP_SPI_SLAVE_H_
  8. #include "type.h"
  9. #include "../src/drv/inc/spi_drv.h"
  10. /* Buffer size per Ping-Pong node (bytes) */
  11. #define GMSP_BUF_SIZE 256
  12. /* DMA channel used for SPI1 slave RX */
  13. #define GMSP_SPI_RX_DMA_CH DMACCH1
  14. /* SPI1 data register address (base + 0x12 offset) */
  15. #define GMSP_SPI1_DR_ADDR (SPI1_BASE_ADDR + 0x12)
  16. /*******************************************************************************
  17. * Function Name : gmsp_transport_init
  18. * Description : Initialize SPI1 as slave (CPOL=0, CPHA=0, 8-bit, MSB first)
  19. * and start DMA LLI Ping-Pong dual-buffer receive.
  20. * Input : None
  21. * Output : None
  22. * Return : None
  23. ******************************************************************************/
  24. void gmsp_transport_init(void);
  25. /*******************************************************************************
  26. * Function Name : gmsp_recv_ready
  27. * Description : Check if a new DMA receive block has completed (non-blocking).
  28. * Input : None
  29. * Output : None
  30. * Return : 1 if data ready, 0 otherwise
  31. ******************************************************************************/
  32. UINT8 gmsp_recv_ready(void);
  33. /*******************************************************************************
  34. * Function Name : gmsp_get_rx_buf
  35. * Description : Get pointer to the most recently completed receive buffer
  36. * and its length.
  37. * Input : out_len - pointer to receive the data length (may be NULL)
  38. * Output : *out_len = GMSP_BUF_SIZE
  39. * Return : Pointer to the completed buffer (buf_A or buf_B)
  40. ******************************************************************************/
  41. UINT8 *gmsp_get_rx_buf(UINT16 *out_len);
  42. /*******************************************************************************
  43. * Function Name : gmsp_send_response
  44. * Description : Send response data back to host via SPI1.
  45. * Short responses (<=8 bytes) use SPI register write loop.
  46. * Long responses use blocking DMA transfer.
  47. * Input : resp - pointer to response data
  48. * len - response length in bytes
  49. * Output : None
  50. * Return : None
  51. ******************************************************************************/
  52. void gmsp_send_response(const UINT8 *resp, UINT16 len);
  53. /*******************************************************************************
  54. * Function Name : gmsp_transport_rearm
  55. * Description : Reset DMA receive for next frame after processing.
  56. * Stops TX DMA, restarts LLI Ping-Pong receive, clears flag.
  57. * Input : None
  58. * Output : None
  59. * Return : None
  60. ******************************************************************************/
  61. void gmsp_transport_rearm(void);
  62. #endif /* GMSP_SPI_SLAVE_H_ */