// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // File name : spi_slave.h // Description : SPI1 Slave DMA LLI Ping-Pong transport layer for GMSP // national crypto co-processor firmware. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #ifndef GMSP_SPI_SLAVE_H_ #define GMSP_SPI_SLAVE_H_ #include "type.h" #include "../src/drv/inc/spi_drv.h" /* Buffer size per Ping-Pong node (bytes) */ #define GMSP_BUF_SIZE 256 /* DMA channel used for SPI1 slave RX */ #define GMSP_SPI_RX_DMA_CH DMACCH1 /* SPI1 data register address (base + 0x12 offset) */ #define GMSP_SPI1_DR_ADDR (SPI1_BASE_ADDR + 0x12) /******************************************************************************* * Function Name : gmsp_transport_init * Description : Initialize SPI1 as slave (CPOL=0, CPHA=0, 8-bit, MSB first) * and start DMA LLI Ping-Pong dual-buffer receive. * Input : None * Output : None * Return : None ******************************************************************************/ void gmsp_transport_init(void); /******************************************************************************* * Function Name : gmsp_recv_ready * Description : Check if a new DMA receive block has completed (non-blocking). * Input : None * Output : None * Return : 1 if data ready, 0 otherwise ******************************************************************************/ UINT8 gmsp_recv_ready(void); /******************************************************************************* * Function Name : gmsp_get_rx_buf * Description : Get pointer to the most recently completed receive buffer * and its length. * Input : out_len - pointer to receive the data length (may be NULL) * Output : *out_len = GMSP_BUF_SIZE * Return : Pointer to the completed buffer (buf_A or buf_B) ******************************************************************************/ UINT8 *gmsp_get_rx_buf(UINT16 *out_len); /******************************************************************************* * Function Name : gmsp_send_response * Description : Send response data back to host via SPI1. * Short responses (<=8 bytes) use SPI register write loop. * Long responses use blocking DMA transfer. * Input : resp - pointer to response data * len - response length in bytes * Output : None * Return : None ******************************************************************************/ void gmsp_send_response(const UINT8 *resp, UINT16 len); /******************************************************************************* * Function Name : gmsp_transport_rearm * Description : Reset DMA receive for next frame after processing. * Stops TX DMA, restarts LLI Ping-Pong receive, clears flag. * Input : None * Output : None * Return : None ******************************************************************************/ void gmsp_transport_rearm(void); #endif /* GMSP_SPI_SLAVE_H_ */