📄 lh7a404_ssp_driver.c
字号:
}
return status;
}
/***********************************************************************
*
* Function: ssp_read_polled
*
* Purpose: SSP polled read function
*
* Processing:
* If the init flag for the SSP structure is FALSE, return 0 to
* the caller. Otherwise, loop until max_bytes equals 0 or until
* the receive FIFO is empty, whichever comes first. Read the data
* from the SSP FIFO and place it user buffer. Increment the
* address of the user buffer. Increment bytes, and decrement
* max_bytes. Exit the loop based on the loop conditions and
* return the number of bytes read to the caller.
*
* Parameters:
* devid: Pointer to SSP config structure
* buffer: Pointer to data buffer to copy to
* max_bytes: Number of bytes to read
*
* Outputs: None
*
* Returns: Number of bytes actually read
*
* Notes: None
*
**********************************************************************/
INT_32 ssp_read_polled(INT_32 devid,
void *buffer,
INT_32 max_bytes)
{
SSP_REGS_T *sspregs;
SSP_CFG_T *sspcfgptr = (SSP_CFG_T *) devid;
UNS_16 *data = (UNS_16 *) buffer;
INT_32 bytes = 0;
if (sspcfgptr->init == TRUE)
{
sspregs = sspcfgptr->regptr;
/* Loop until receive FIFO is empty or until max_bytes
expires */
while ((max_bytes > 0) &&
((sspregs->sr & SSP_SR_RNE) != 0))
{
/* Read data from FIFO into buffer */
*data = (UNS_16) sspregs->dr;
data++;
/* Increment data count and decrement buffer size count */
bytes++;
max_bytes--;
}
}
return bytes;
}
/***********************************************************************
*
* Function: ssp_write_polled
*
* Purpose: SSP polled write function
*
* Processing:
* If the init flag for the SSP structure is FALSE, return 0 to
* the caller. Otherwise, loop until n_bytes equals 0. Loop until
* the transmit FIFO is full insisde the n_bytes loop. Read the data
* from the user buffer and place it in the SSP FIFO. Increment
* the address of the user buffer. Increment bytes, and decrement
* n_bytes. Exit the loop based on the loop conditions and
* return the number of actually bytes written to the caller.
*
* Parameters:
* devid: Pointer to SSP config structure
* buffer: Pointer to data buffer to copy from
* n_bytes: Number of bytes to write
*
* Outputs: None
*
* Returns: Number of bytes actually written
*
* Notes: None
*
**********************************************************************/
INT_32 ssp_write_polled(INT_32 devid,
void *buffer,
INT_32 n_bytes)
{
SSP_REGS_T *sspregs;
SSP_CFG_T *sspcfgptr = (SSP_CFG_T *) devid;
UNS_16 *data = (UNS_16 *) buffer;
INT_32 bytes = 0;
if (sspcfgptr->init == TRUE)
{
sspregs = sspcfgptr->regptr;
/* Loop until n_bytes expires to 0 */
while (n_bytes > 0)
{
if ((sspregs->sr & SSP_SR_TNF) != 0)
{
/* Write data from buffer into FIFO */
sspregs->dr = (UNS_32) *data;
data++;
/* Increment data count and decrement buffer size
count */
bytes++;
n_bytes--;
}
}
}
return bytes;
}
/***********************************************************************
*
* Function: ssp_read_ring
*
* Purpose: SSP ring buffer (interrupt) read function
*
* Processing:
* If the init flag for the SSP structure is FALSE, return 0 to
* the caller. Otherwise, save the state of the receive interrupt
* and disable the receive interrupt. Loop until max_bytes equals
* 0 or until the receive ring buffer is empty, whichever comes
* first. Read the data from the ring buffer indexed by the tail
* pointer and place it into the user buffer. Increment the tail
* pointer and user buffer pointer. If the tail pointer exceeds the
* buffer size, set the tail pointer to 0. Increment bytes, and
* decrement max_bytes. Exit the loop based on the loop conditions,
* re-enable the receive interrupts, and return the number of bytes
* read to the caller.
*
* Parameters:
* devid: Pointer to SSP config structure
* buffer: Pointer to data buffer to copy to
* max_bytes: Number of bytes to read
*
* Outputs: None
*
* Returns: Number of bytes actually read
*
* Notes: None
*
**********************************************************************/
INT_32 ssp_read_ring(INT_32 devid,
void *buffer,
INT_32 max_bytes)
{
SSP_REGS_T *sspregs;
UNS_32 tmp1;
SSP_CFG_T *sspcfgptr = (SSP_CFG_T *) devid;
UNS_16 *data = (UNS_16 *) buffer;
INT_32 bytes = 0;
if (sspcfgptr->init == TRUE)
{
sspregs = sspcfgptr->regptr;
/* Temporarily lock out SSP receive interrupts during this
read so the SSP receive interrupt won't cause problems
with the index values */
tmp1 = sspregs->cr1 & SSP_CR1_RIE;
sspregs->cr1 &= ~SSP_CR1_RIE;
/* Loop until receive ring buffer is empty or until max_bytes
expires */
while ((max_bytes > 0) &&
(sspcfgptr->rx_tail != sspcfgptr->rx_head))
{
/* Read data from ring buffer into user buffer */
*data = sspcfgptr->rx[sspcfgptr->rx_tail];
data++;
/* Update tail pointer */
sspcfgptr->rx_tail++;
/* Make sure tail didn't overflow */
if (sspcfgptr->rx_tail >= SSP_R_SIZE)
{
sspcfgptr->rx_tail = 0;
}
/* Increment data count and decrement buffer size count */
bytes++;
max_bytes--;
}
/* Re-enable SSP interrupts */
sspregs->cr1 |= tmp1;
}
return bytes;
}
/***********************************************************************
*
* Function: ssp_write_ring
*
* Purpose: SSP ring buffer (interrupt) write function
*
* Processing:
* If the init flag for the SSP structure is FALSE, return 0 to
* the caller. Otherwise, disable the transmit interrupts. Loop
* until n_bytes equals 0 or until the transmit ring buffer is full,
* whichever comes first. Write the data from the user buffer to
* the transmit ring buffer indexed by the head pointer. Increment
* the user buffer pointer and head pointer. If the head pointer
* exceeds the buffer size, set the head pointer to 0. Increment
* bytes, and decrement n_bytes. Exit the loop based on the loop
* conditions. If the number bytes written to the ring buffer was
* greater then 0, call the ssp_standard_transmit() fucntion.
* Return the number of bytes read to the caller.
*
* Parameters:
* devid: Pointer to SSP config structure
* buffer: Pointer to data buffer to copy from
* n_bytes: Number of bytes to write
*
* Outputs: None
*
* Returns: Number of bytes actually written
*
* Notes: None
*
**********************************************************************/
INT_32 ssp_write_ring(INT_32 devid,
void *buffer,
INT_32 n_bytes)
{
SSP_REGS_T *sspregs;
SSP_CFG_T *sspcfgptr = (SSP_CFG_T *) devid;
UNS_16 *data = (UNS_16 *) buffer;
INT_32 bytes = 0;
if (sspcfgptr->init == TRUE)
{
sspregs = sspcfgptr->regptr;
/* Temporarily lock out SSP transmit interrupts during this
read so the SSP transmit interrupt won't cause problems
with the index values */
sspregs->cr1 &= ~SSP_CR1_TIE;
/* Loop until transmit ring buffer is full or until n_bytes
expires */
while ((n_bytes > 0) &&
(ssp_get_free_tx_count(sspcfgptr) > 0))
{
/* Write data from buffer into ring buffer */
sspcfgptr->tx[sspcfgptr->tx_head] = *data;
data++;
/* Increment head pointer */
sspcfgptr->tx_head++;
if (sspcfgptr->tx_head >= SSP_R_SIZE)
{
sspcfgptr->tx_head = 0;
}
/* Increment data count and decrement buffer size count */
bytes++;
n_bytes--;
}
/* Now start sending the data - this will also re-enable the
transmit interrupt */
if (bytes > 0)
{
ssp_standard_transmit(sspcfgptr);
}
}
return bytes;
}
/***********************************************************************
*
* Function: ssp_isr
*
* Purpose: Default SSP interrupt
*
* Processing:
* Call the standard SSP interrupt function
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void ssp_isr(void)
{
ssp_standard_interrupt(&sspcfg);
}
//
// /**********************************************************************
// *
// * Function: record
// * Parameters: None
// * Outputs: None
// * Returns:
// * Notes: None
// **********************************************************************/
// void record()
// {
// unsigned short sdata [500]={0};
// status_control_port=Reg(0x48000000);
// status_control_port&=0xd7ff; // bit 11,13 set 00
// status_control_port|=0x1600; // set bit 9,10 ,12
// Reg(0x44000000) =status_control_port;
//
// DevIntEnable(VIC_SSPRX);
// ssp_enable();
// while(1)
// {
// ssp_send_frame(sdata,500);
// if(ssp_rtail>=40960) //SSPBUFLEN
// break;
// }
// // ssp_disable();
// DevIntDisable(VIC_SSPRX);
// }
//
//
// /**********************************************************************
// *
// * Function: playTone
// * Parameters: None
// * Outputs: None
// * Returns:
// * Notes: None
// **********************************************************************/
// void playTone()
// {
// status_control_port=Reg(0x48000000);
// status_control_port|=0x1600; // set bit 9,10 ,12
// status_control_port&=0xd7ff; // bit 11,13 set 00
// Reg(0x44000000) =status_control_port;
// //ssp_enable();
// if(ssp_rtail!=0)
// while(1)
// {
// ssp_send_frame(ssp_rdata,ssp_rtail);
// }
// return;
//
// }
#define SSP_ADDR 0x80000b00
void c_entry(void)
{
ssp_open((void*)SSP_ADDR,0);
char buffer[128];
int i;
for (i=0;i<64;i++)
buffer[i]=i;
///record();
///playTone();
ssp_write_ring(SSP_ADDR,buffer,64);
ssp_close(SSP_ADDR);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -