Esempio n. 1
0
unsigned short ADS7843_read(volatile unsigned short mode)
{
	volatile int tmp;
	GPIO_ClearValue(4,1<<12);
	SSP_SendData(LPC_SSP0,mode);
	SSP_SendData(LPC_SSP0,0);
  while(LPC_SSP0->SR & SSP_SR_BSY) ;
  mode=(SSP_ReceiveData(LPC_SSP0));
  mode=(SSP_ReceiveData(LPC_SSP0));
	
  return mode; // x = 0..127, y = 0..127
}
Esempio n. 2
0
/*********************************************************************//**
 * @brief		Send command to slave in master mode
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void ssp_MW_SendCMD(LPC_SSP_TypeDef *SSPx, uint8_t cmd)
{
	// wait for current SSP activity complete
	while (SSP_GetStatus(SSPx, SSP_STAT_BUSY) ==  SET);

	SSP_SendData(SSPx, (uint16_t) cmd);
}
Esempio n. 3
0
/*********************************************************************//**
 * @brief		Send respond to master in slave mode
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void ssp_MW_SendRSP(LPC_SSP_TypeDef *SSPx, uint16_t Rsp)
{
	// wait for current SSP activity complete
	while (SSP_GetStatus(SSPx, SSP_STAT_BUSY) ==  SET);

	SSP_SendData(SSPx, Rsp);
}
Esempio n. 4
0
void speed_write(uint8_t data)
{

	while (SSP_GetStatus(LPC_SSP0, SSP_STAT_TXFIFO_NOTFULL) ==  RESET);

	SSP_SendData(LPC_SSP0, (uint16_t) data);

}
Esempio n. 5
0
//==============================================================//
// Write 9-bit word to the LCD
// Hardware-specific function
//==============================================================//
void LcdWrite(uint8_t val, uint8_t mode)
{
	uint16_t temp = val;
	if (mode == DATA)		
		temp |= 0x0100;;	// set D/C bit (MSB of the packet)
	// Wait if TX FIFO is full
	while( SSP_GetFlagStatus(MDR_SSP2,SSP_FLAG_TNF)!= SET );
	SSP_SendData (MDR_SSP2,temp);
}
Esempio n. 6
0
/*******************************************************************************
* Function Name  : WR_CMD
* Description    : 向 ADS7843写数据
* Input          : - cmd: 传输的数据
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
static uint8_t WR_CMD (uint8_t cmd)  
{ 
	/* wait for current SSP activity complete */
	while (SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY) ==  SET);

	SSP_SendData(LPC_SSP0, (uint16_t) cmd);

	while (SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY) == RESET);
	return (SSP_ReceiveData(LPC_SSP0));
} 
Esempio n. 7
0
/*******************************************************************************
* Function Name  : LPC17xx_SPI_SendRecvByte
* Description    : Send one byte then recv one byte of response
* Input          : - byte_s: byte_s
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
uint8_t LPC17xx_SPI_SendRecvByte (uint8_t byte_s)
{
	/* wait for current SSP activity complete */
	while (SSP_GetStatus(LPC_SSP0, SSP_STAT_TXFIFO_NOTFULL) ==  RESET);

	SSP_SendData(LPC_SSP0, (uint16_t) byte_s);

	while (SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY) == RESET);
	return (SSP_ReceiveData(LPC_SSP0));
	//return 1;
}
Esempio n. 8
0
/*****************************************************************************
* Function Name  : Flash_ReadWriteByte
* Description    : send a byte to SST25VF016B
* Input          : - data: send data
* Output         : None
* Return         : return data
* Attention		 : None
*******************************************************************************/
uint8_t SPI_ReadByte(uint8_t* data)		
{
	uint16_t tmp;
	while ((SSP_GetStatus(RTC_FLASH_SSP, SSP_STAT_RXFIFO_NOTEMPTY) ==  SET ))
	{
		tmp = SSP_ReceiveData(RTC_FLASH_SSP);
	}
	SSP_SendData(RTC_FLASH_SSP, (uint16_t) 0xFFFF);
	while ((SSP_GetStatus(RTC_FLASH_SSP, SSP_STAT_RXFIFO_NOTEMPTY) ==  RESET ))
	{
	}	
	tmp = SSP_ReceiveData(RTC_FLASH_SSP); 
	return tmp;
}
Esempio n. 9
0
static int ssp_drv_pio_read(mdev_t *dev, uint8_t *data, uint32_t num)
{
	int len = 0;
	sspdev_data_t *ssp_data_p;

	ssp_data_p = (sspdev_data_t *) dev->private_data;

	if (ssp_data_p->slave == SSP_SLAVE) {
		while (num > 0) {
			if (!is_rx_buf_empty(ssp_data_p))
				*data = (uint8_t)read_rx_buf(ssp_data_p);
			else
				break;
			num--;
			len++;
			data++;
		}
	} else {
		/* In master mode, first send dummy data in TX line and read
		 * simultaneously. If nothing is on RX line then it can read
		 * 0x0 or 0xff. Application should check whether data is
		 * vaild or not.
		*/
		while (num > 0) {
			while (SSP_GetStatus(dev->port_id, SSP_STATUS_TFNF)
				!= SET)
				os_thread_relinquish();

			SSP_SendData(dev->port_id, SPI_DUMMY_BYTE);
			while (SSP_GetStatus(dev->port_id, SSP_STATUS_RFNE)
				!= SET)
				os_thread_relinquish();
			*data = (uint8_t)SSP_RecvData(dev->port_id);
			data++;
			len++;
			num--;
		}
	}
	return len;
}
Esempio n. 10
0
/*
 * This is a bit special SPI method.
 *    - Pulses Asserts SSEL (CS) and holds high for the duration of command.
 *    - Does not pulse SSEL between bytes.
 *    - Does not change SSEL after the write.
 */
void SPI_Write(const uint8_t *data, uint16_t len)
{
    if (len == 0)
        return;

    while (SSP_GetStatus(CL632_SPI, SSP_STAT_TXFIFO_EMPTY) == RESET);

    // Send reset.
    GPIO_ResetBits(CL632_SSEL_PORT, CL632_SSEL_PIN);
    delay_ns(100);
    GPIO_SetBits(CL632_SSEL_PORT, CL632_SSEL_PIN);
    delay_ns(100);

    while (len-- > 0) {
        SSP_SendData(CL632_SPI, *data++);
        while (SSP_GetStatus(CL632_SPI, SSP_STAT_TXFIFO_NOTFULL) == RESET);
    }

    while (SSP_GetStatus(CL632_SPI, SSP_STAT_TXFIFO_EMPTY) == RESET);

    delay_ns(100);
}
Esempio n. 11
0
File: main.c Progetto: Wiznet/W7500
/**
  * @brief  Main Function
  */
int main()
{

    /* Set Systme init */
    SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* < SSP_StructInit default values
       SSP_InitStructure.SSP_SerialClockRate   = 0x00;
       SSP_InitStructure.SSP_FrameFormat       = SSP_FrameFormat_MO; 
       SSP_InitStructure.SSP_CPHA              = SSP_CPHA_1Edge;   
       SSP_InitStructure.SSP_CPOL              = SSP_CPOL_Low;
       SSP_InitStructure.SSP_DataSize          = SSP_DataSize_8b;
       SSP_InitStructure.SSP_SOD               = SSP_SOD_RESET;
       SSP_InitStructure.SSP_Mode              = SSP_Mode_Master;
       SSP_InitStructure.SSP_NSS               = SSP_NSS_Hard;
       SSP_InitStructure.SSP_LBM               = SSP_LBM_RESET;
       SSP_InitStructure.SSP_SSE               = SSP_SSE_SET;
       SSP_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_2;
    */

    /* SSP0 Init -- SSP Master */ 
    SSP_StructInit(&SSP0_InitStructure);
    SSP0_InitStructure.SSP_FrameFormat  = SSP_FrameFormat_MO; // Motorora SPI mode
    SSP0_InitStructure.SSP_DataSize = SSP_DataSize_16b;
    SSP_Init(SSP0,&SSP0_InitStructure);

    /* SSP1 Init -- SSP Slave */
    SSP_StructInit(&SSP1_InitStructure);
    SSP1_InitStructure.SSP_DataSize = SSP_DataSize_16b;
    SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave
    SSP_Init(SSP1,&SSP1_InitStructure);
        
    /* GPIO LED(R) Setting */
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_8; // Connecting GPIO_Pin_8(LED(R))
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port
    GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC
	PAD_AFConfig(PAD_PC,GPIO_Pin_8, PAD_AF1); // PAD Config - LED used 2nd Function

    /* GPIO LED(G) Setting */
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_9; // Connecting GPIO_Pin_9(LED(G))
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port
    GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC
	PAD_AFConfig(PAD_PC,GPIO_Pin_9, PAD_AF1); // PAD Config - LED used 2nd Function
            
    GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off
    GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off
        
    /* Send only data to SSP1 */ 
    for (TxIdx=0; TxIdx<BufferSize; TxIdx++)
    {
        SSP_SendData(SSP0, SSP0_Buffer_Tx[TxIdx]);
        while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) );
    }
    
    /* Receive only data from SSP0 */ 
    while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE))
    {
        SSP1_Buffer_Rx[RxIdx] = (uint16_t)SSP_ReceiveData(SSP1);
        RxIdx++;
    }
    
    /* Check the received data with the send ones */
    TransferStatus = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, BufferSize);
    /* TransferStatus = PASSED, if the data transmitted and received are correct */
    /* TransferStatus = FAILED, if the data transmitted and received are different */
    
    if(TransferStatus == PASSED)
    {
        GPIO_ResetBits(GPIOC, GPIO_Pin_9); //Received are correct == LED green On
    }
    else if(TransferStatus == FAILED)
    {
        GPIO_ResetBits(GPIOC, GPIO_Pin_8); //Received are different == LED red On
    }
    
}
Esempio n. 12
0
void TIMER0_IRQHandler(void){
//	xprintf("TIMER0_IRQ");
	if (TIM_GetIntStatus(LPC_TIM0,TIM_MR0_INT)){
		TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
#if 0
		if(TOG[0])
//			FIO_SetValue(LED_LE_PORT, LED_LE_BIT);
			GPIO_SetValue(LED_4_PORT, LED_4_BIT);
		else
//			FIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
			GPIO_ClearValue(LED_4_PORT, LED_4_BIT);
		TOG[0]=!TOG[0];
//		TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
//		return;
#endif
//		xprintf(INFO "RIT N=%d B=%x NXT_T=%d TX=%x\n",SENDSEQ,SEND_BIT,DELAY_TIME,LED_PRECALC[0][SEND_BIT]);

		//Setup new timing for next Timer
		DELAY_TIME=SEQ_TIME[SENDSEQ];
		SEND_BIT=SEQ_BIT[SENDSEQ];

		//Retart sequence if required
		SENDSEQ++;
		SENDSEQ>=no_SEQ_BITS ? SENDSEQ=0 : 0;

#ifdef DMA
//		xprintf("SEND_BIT:%d\n",SEND_BIT);
//		xprintf("DELAY_TIME:%d\n",DELAY_TIME);
		GPDMACfg.DMALLI = (uint32_t) &LinkerList[0][SEND_BIT][BufferNo];
		GPDMA_Setup(&GPDMACfg);
		GPDMA_ChannelCmd(0, ENABLE);
#endif
		TIM_UpdateMatchValue(LPC_TIM0,0,DELAY_TIME);
		FIO_SetValue(LED_OE_PORT, LED_OE_BIT);
#ifdef RxDMA
		GPDMA_ChannelCmd(1, ENABLE);
		uint8_t reg;
		for(reg=6; 0<reg;reg--){
			xprintf("%d ",reg-1);
#if 0
			if(BUFFER==1)
				SSP_SendData(LED_SPI_CHN, LED_PRECALC1[reg][SEND_BIT]);
			else
				SSP_SendData(LED_SPI_CHN, LED_PRECALC2[reg][SEND_BIT]);
#endif
			//WaitForSend();//Wait if TX buffer full
			//while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
			while(SSP_GetStatus(LED_SPI_CHN, SSP_STAT_BUSY)){
			};
			SSP_SendData(LED_SPI_CHN, LED_PRECALC[reg-1][SEND_BIT]);
			xprintf("%4x ",(LED_PRECALC[reg-1][SEND_BIT]));
		}
		for(reg=12; reg>6;reg--){
			xprintf("%d ",reg-1);
#if 0
			if(BUFFER==1)
				SSP_SendData(LED_SPI_CHN, LED_PRECALC1[reg][SEND_BIT]);
			else
				SSP_SendData(LED_SPI_CHN, LED_PRECALC2[reg][SEND_BIT]);
#endif
			//WaitForSend();//Wait if TX buffer full
			while(SSP_GetStatus(LED_SPI_CHN, SSP_STAT_BUSY)){
			}
			SSP_SendData(LED_SPI_CHN, LED_PRECALC[reg-1][SEND_BIT]);
//			if (reg==7){
				xprintf("%4x ",(LED_PRECALC[reg-1][SEND_BIT]));
//			}
		}
		LatchIn();
#endif
/*		UPDATE_COUNT+=1;
		ATE_COUNT=0;
			LED_UPDATE_REQUIRED=1;
		}*/
	}
}
Esempio n. 13
0
void LED_simple_all_colors(){ //simple all colors
	TIM_Cmd(LPC_TIM0,DISABLE);	// To start timer 0
//	while(1){
	for (uint8_t i=0;i<16;i++){
//		xprintf(OK "%d",i+1);FFL_();
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		for (uint8_t j=0;j<11;j++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
//		SSP_SendData(LED_SPI_CHN, 0x0001<<i);
		SSP_SendData(LED_SPI_CHN, 0x1249);
		while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		for (uint8_t k=0;k<0;k++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
		GPIO_SetValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low
		delay_ms(150);
	};
	for (uint8_t i=0;i<16;i++){
//		xprintf(OK "%d",i+1);FFL_();
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		for (uint8_t j=0;j<11;j++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
//		SSP_SendData(LED_SPI_CHN, 0x0001<<i);
		SSP_SendData(LED_SPI_CHN, 0x2492);
		while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		for (uint8_t k=0;k<0;k++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
		GPIO_SetValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low
		delay_ms(150);
	};
	for (uint8_t i=0;i<16;i++){
	xprintf(OK "%d",i+1);FFL_();
	GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
	for (uint8_t j=0;j<11;j++){
		SSP_SendData(LED_SPI_CHN, 0x0000);
		while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
	}
//	SSP_SendData(LED_SPI_CHN, 0x0001<<i);
	SSP_SendData(LED_SPI_CHN, 0x4924);
	while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
	for (uint8_t k=0;k<0;k++){
		SSP_SendData(LED_SPI_CHN, 0x0000);
		while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
	}
	GPIO_SetValue(LED_LE_PORT, LED_LE_BIT);
	GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
	GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low
	delay_ms(150);
	};
	for (uint8_t i=0;i<16;i++){
//		xprintf(OK "%d",i+1);FFL_();
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		for (uint8_t j=0;j<11;j++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
//		SSP_SendData(LED_SPI_CHN, 0x0001<<i);
		SSP_SendData(LED_SPI_CHN, 0xffff);
		while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		for (uint8_t k=0;k<0;k++){
			SSP_SendData(LED_SPI_CHN, 0x0000);
			while(LED_SPI_CHN->SR & SSP_STAT_BUSY);
		}
		GPIO_SetValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_LE_PORT, LED_LE_BIT);
		GPIO_ClearValue(LED_OE_PORT, LED_OE_BIT);//LED's on. active low
		delay_ms(150);
	};
//	};
	TIM_Cmd(LPC_TIM0,ENABLE);	// To start timer 0
	LED_PATTERN=0;
}
Esempio n. 14
0
/*****************************************************************************
* Function Name  : Flash_ReadWriteByte
* Description    : send a byte to SST25VF016B
* Input          : - data: send data
* Output         : None
* Return         : return data
* Attention		 : None
*******************************************************************************/
void SPI_WriteByte(uint8_t data)		
{
	while ((SSP_GetStatus(RTC_FLASH_SSP, SSP_STAT_TXFIFO_NOTFULL) ==  RESET ));
	SSP_SendData(RTC_FLASH_SSP, (uint16_t) data);
}
Esempio n. 15
0
static int ssp_drv_pio_write(mdev_t *dev, const uint8_t *data, uint8_t *din,
		uint32_t num, bool flag)
{
	uint32_t len = 0;

	sspdev_data_t *ssp_data_p;
	ssp_data_p = (sspdev_data_t *) dev->private_data;

	while (num > 0) {
		/* Wait if fifo is full */
		while (SSP_GetStatus(dev->port_id, SSP_STATUS_TFNF) != SET)
			os_thread_relinquish();

		SSP_SendData(dev->port_id, *data);
		/* Enable read RXFIFO during write operation if flag is set */
		if (flag) {

			/* read data while write operation is on to enable
			 * full duplex support in SPI protocol*/
			/*
			 * Read rxfifo and store data, provided valid din
			 * buffer is provided by user else discard it.
			 */

			if (ssp_data_p->slave == SSP_MASTER) {

				/* SSP_STATUS_BIT == SET when SSPx port is
				 * currently transmitting or receiving framed
				 * data.
				 * */
				while (SSP_GetStatus(dev->port_id,
						     SSP_STATUS_BUSY) == SET)
					os_thread_relinquish();

				/*  SSP_STATUS_RFNE == SET when RXFIFO is
				 *  non-empty
				 */
				while (SSP_GetStatus(dev->port_id,
						     SSP_STATUS_RFNE) != SET)
					os_thread_relinquish();

				if (din)
					*din++ = (uint8_t)
						SSP_RecvData(dev->port_id);
				else
					SSP_RecvData(dev->port_id);

			} else {
				/* if slave mode is enabled read from software
				 * fifo*/
				while (is_rx_buf_empty(ssp_data_p) == true)
					os_thread_relinquish();
				if (!is_rx_buf_empty(ssp_data_p) && din)
					*din++ = (uint8_t)
						read_rx_buf(ssp_data_p);
			}
		}
		data++;
		num--;
		len++;
	}
	return len;
}
Esempio n. 16
0
void WriteSPDR (uint16_t data)
{
  SSP_SendData (SSP, data);
}
Esempio n. 17
0
/*********************************************************************//**
 * @brief 		SSP Read write data function
 * @param[in]	SSPx 	Pointer to SSP peripheral, should be
 * 						- LPC_SSP0: SSP0 peripheral
 * 						- LPC_SSP1: SSP1 peripheral
 * @param[in]	dataCfg	Pointer to a SSP_DATA_SETUP_Type structure that
 * 						contains specified information about transmit
 * 						data configuration.
 * @param[in]	xfType	Transfer type, should be:
 * 						- SSP_TRANSFER_POLLING: Polling mode
 * 						- SSP_TRANSFER_INTERRUPT: Interrupt mode
 * @return 		Actual Data length has been transferred in polling mode.
 * 				In interrupt mode, always return (0)
 * 				Return (-1) if error.
 * Note: This function can be used in both master and slave mode.
 ***********************************************************************/
int32_t SSP_ReadWrite (LPC_SSP_TypeDef *SSPx, SSP_DATA_SETUP_Type *dataCfg, \
						SSP_TRANSFER_Type xfType)
{
	uint8_t *rdata8 = 0;
    uint8_t *wdata8 = 0;
	uint16_t *rdata16 = 0;
    uint16_t *wdata16 = 0;
    uint32_t stat;
    uint32_t tmp;
    int32_t dataword;

    dataCfg->rx_cnt = 0;
    dataCfg->tx_cnt = 0;
    dataCfg->status = 0;


	/* Clear all remaining data in RX FIFO */
	while (SSPx->SR & SSP_SR_RNE){
		tmp = (uint32_t) SSP_ReceiveData(SSPx);
	}

	// Clear status
	SSPx->ICR = SSP_ICR_BITMASK;
	if(SSP_GetDataSize(SSPx)>8)
		dataword = 1;
	else dataword = 0;

	// Polling mode ----------------------------------------------------------------------
	if (xfType == SSP_TRANSFER_POLLING){
		if (dataword == 0){
			rdata8 = (uint8_t *)dataCfg->rx_data;
			wdata8 = (uint8_t *)dataCfg->tx_data;
		} else {
			rdata16 = (uint16_t *)dataCfg->rx_data;
			wdata16 = (uint16_t *)dataCfg->tx_data;
		}
		while ((dataCfg->tx_cnt != dataCfg->length) || (dataCfg->rx_cnt != dataCfg->length)){
			if ((SSPx->SR & SSP_SR_TNF) && (dataCfg->tx_cnt != dataCfg->length)){
				// Write data to buffer
				if(dataCfg->tx_data == NULL){
					if (dataword == 0){
						SSP_SendData(SSPx, 0xFF);
						dataCfg->tx_cnt++;
					} else {
						SSP_SendData(SSPx, 0xFFFF);
						dataCfg->tx_cnt += 2;
					}
				} else {
					if (dataword == 0){
						SSP_SendData(SSPx, *wdata8);
						wdata8++;
						dataCfg->tx_cnt++;
					} else {
						SSP_SendData(SSPx, *wdata16);
						wdata16++;
						dataCfg->tx_cnt += 2;
					}
				}
			}

			// Check overrun error
			if ((stat = SSPx->RIS) & SSP_RIS_ROR){
				// save status and return
				dataCfg->status = stat | SSP_STAT_ERROR;
				return (-1);
			}

			// Check for any data available in RX FIFO
			while ((SSPx->SR & SSP_SR_RNE) && (dataCfg->rx_cnt != dataCfg->length)){
				// Read data from SSP data
				tmp = SSP_ReceiveData(SSPx);

				// Store data to destination
				if (dataCfg->rx_data != NULL)
				{
					if (dataword == 0){
						*(rdata8) = (uint8_t) tmp;
						rdata8++;
					} else {
						*(rdata16) = (uint16_t) tmp;
						rdata16++;
					}
				}
				// Increase counter
				if (dataword == 0){
					dataCfg->rx_cnt++;
				} else {
					dataCfg->rx_cnt += 2;
				}
			}
		}

		// save status
		dataCfg->status = SSP_STAT_DONE;

		if (dataCfg->tx_data != NULL){
			return dataCfg->tx_cnt;
		} else if (dataCfg->rx_data != NULL){
			return dataCfg->rx_cnt;
		} else {
			return (0);
		}
	}

	// Interrupt mode ----------------------------------------------------------------------
	else if (xfType == SSP_TRANSFER_INTERRUPT){

		while ((SSPx->SR & SSP_SR_TNF) && (dataCfg->tx_cnt != dataCfg->length)){
			// Write data to buffer
			if(dataCfg->tx_data == NULL){
				if (dataword == 0){
					SSP_SendData(SSPx, 0xFF);
					dataCfg->tx_cnt++;
				} else {
					SSP_SendData(SSPx, 0xFFFF);
					dataCfg->tx_cnt += 2;
				}
			} else {
				if (dataword == 0){
					SSP_SendData(SSPx, (*(uint8_t *)((uint32_t)dataCfg->tx_data + dataCfg->tx_cnt)));
					dataCfg->tx_cnt++;
				} else {
					SSP_SendData(SSPx, (*(uint16_t *)((uint32_t)dataCfg->tx_data + dataCfg->tx_cnt)));
					dataCfg->tx_cnt += 2;
				}
			}

			// Check error
			if ((stat = SSPx->RIS) & SSP_RIS_ROR){
				// save status and return
				dataCfg->status = stat | SSP_STAT_ERROR;
				return (-1);
			}

			// Check for any data available in RX FIFO
			while ((SSPx->SR & SSP_SR_RNE) && (dataCfg->rx_cnt != dataCfg->length)){
				// Read data from SSP data
				tmp = SSP_ReceiveData(SSPx);

				// Store data to destination
				if (dataCfg->rx_data != NULL)
				{
					if (dataword == 0){
						*(uint8_t *)((uint32_t)dataCfg->rx_data + dataCfg->rx_cnt) = (uint8_t) tmp;
					} else {
						*(uint16_t *)((uint32_t)dataCfg->rx_data + dataCfg->rx_cnt) = (uint16_t) tmp;
					}
				}
				// Increase counter
				if (dataword == 0){
					dataCfg->rx_cnt++;
				} else {
					dataCfg->rx_cnt += 2;
				}
			}
		}

		// If there more data to sent or receive
		if ((dataCfg->rx_cnt != dataCfg->length) || (dataCfg->tx_cnt != dataCfg->length)){
			// Enable all interrupt
			SSPx->IMSC = SSP_IMSC_BITMASK;
		} else {
			// Save status
			dataCfg->status = SSP_STAT_DONE;
		}
		return (0);
	}

	return (-1);
}
Esempio n. 18
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main()
{

#ifdef DEBUG
    debug();
#endif
 
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);    /*Use OSC as the default clock source*/
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/
 
  /* SCU configuration */
  SCU_Configuration();

  /* GPIO pins configuration */
  GPIO_Configuration();

  /* SSP0 configuration */
  SSP_DeInit(SSP0);
  SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
  SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
  SSP_InitStructure.SSP_CPOL = SSP_CPOL_High;
  SSP_InitStructure.SSP_CPHA = SSP_CPHA_2Edge;
  SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b;
  SSP_InitStructure.SSP_ClockRate = 5;
  SSP_InitStructure.SSP_ClockPrescaler = 2;
  SSP_Init(SSP0, &SSP_InitStructure);

  /* SSP1 configuration */
  SSP_DeInit(SSP1);
  SSP_InitStructure.SSP_Mode = SSP_Mode_Slave;
  SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable;
  SSP_Init(SSP1, &SSP_InitStructure);

  /* SSP0 enable */
  SSP_Cmd(SSP0, ENABLE);

  /* SSP1 enable */
  SSP_Cmd(SSP1, ENABLE);

  /* Master to slave transfer procedure */
  while(Tx_Idx<32)
  {
    SSP_SendData(SSP0, SSP0_Buffer_Tx[Tx_Idx++]);
    while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty)==RESET);
    SSP1_Buffer_Rx[Rx_Idx++] = SSP_ReceiveData(SSP1);
  }

  /* Check the received data with the send ones */
  TransferStatus1 = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, 32);
  /* TransferStatus = PASSED, if the data transmitted from SSP0 and
     received by SSP1 are the same */
  /* TransferStatus = FAILED, if the data transmitted from SSP0 and
     received by SSP1 are different */

  /* Clear SSP0 receive Fifo */
  for(k=0; k<8; k++) SSP0_Buffer_Rx[k] = SSP_ReceiveData(SSP0);

  /* Reset counters */
  Tx_Idx=Rx_Idx=0;

  /* Slave to master transfer procedure */
  while(Tx_Idx<32)
  {
    SSP_SendData(SSP1, SSP1_Buffer_Tx[Tx_Idx]);

    /* send a dummy bit to generate the clock */
    SSP_SendData(SSP0, SSP0_Buffer_Tx[Tx_Idx++]);

    while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty)==RESET);
    SSP0_Buffer_Rx[Rx_Idx++] = SSP_ReceiveData(SSP0);
  }

  /* Check the received data with the send ones */
  TransferStatus2 = Buffercmp(SSP1_Buffer_Tx, SSP0_Buffer_Rx, 32);
  /* TransferStatus = PASSED, if the data transmitted from SSP1 and
     received by SSP0 are the same */
  /* TransferStatus = FAILED, if the data transmitted from SSP1 and
     received by SSP0 are different */

  while(1);
}
Esempio n. 19
0
/*********************************************************************//**
 * @brief 		SSP Slave Interrupt sub-routine used for reading
 * 				and writing handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void ssp_Slave_IntHandler(void)
{
	uint16_t tmp;

	/* Clear all interrupt */
	SSP_ClearIntPending(SSPDEV_S, SSP_INTCLR_ROR);
	SSP_ClearIntPending(SSPDEV_S, SSP_INTCLR_RT);

	/* check if RX FIFO contains data */
	while (SSP_GetStatus(SSPDEV_S, SSP_STAT_RXFIFO_NOTEMPTY) == SET)
	{
		tmp = SSP_ReceiveData(SSPDEV_S);
		if ((pRdBuf_S!= NULL) && (RdIdx_S < DatLen_S))
		{
			*(pRdBuf_S + RdIdx_S) = (uint8_t) tmp;
		}
		RdIdx_S++;
	}

	/* Check if TX FIFO is not full */
	while ((SSP_GetStatus(SSPDEV_S, SSP_STAT_TXFIFO_NOTFULL) == SET)
			&& (WrIdx_S < DatLen_S))
	{
		/* check if RX FIFO contains data */
		while (SSP_GetStatus(SSPDEV_S, SSP_STAT_RXFIFO_NOTEMPTY) == SET)
		{
			tmp = SSP_ReceiveData(SSPDEV_S);
			if ((pRdBuf_S!= NULL) && (RdIdx_S < DatLen_S))
			{
				*(pRdBuf_S + RdIdx_S) = (uint8_t) tmp;
			}
			RdIdx_S++;
		}

		if (pWrBuf_S != NULL)
		{
			SSP_SendData(SSPDEV_S, (uint16_t)(*(pWrBuf_S + WrIdx_S)));
		}
		else
		{
			SSP_SendData(SSPDEV_S, IDLE_CHAR);
		}
		WrIdx_S++;
	}

	/* There're more data to send */
	if (WrIdx_S < DatLen_S)
	{
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_TX, ENABLE);
	}
	/* Otherwise */
	else
	{
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_TX, DISABLE);
	}

	/* There're more data to receive */
	if (RdIdx_S < DatLen_S)
	{
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_ROR, ENABLE);
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_RT, ENABLE);
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_RX, ENABLE);
	}
	/* Otherwise */
	else
	{
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_ROR, DISABLE);
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_RT, DISABLE);
		SSP_IntConfig(SSPDEV_S, SSP_INTCFG_RX, DISABLE);
	}

	/* Set Flag if both Read and Write completed */
	if ((WrIdx_S == DatLen_S) && (RdIdx_S == DatLen_S))
	{
		complete_S = TRUE;
	}
}
Esempio n. 20
0
File: main.c Progetto: Wiznet/W7500P
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03}; 
    uint8_t src_addr[4] = {192, 168,  0,  9};
    uint8_t gw_addr[4]  = {192, 168,  0,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};		
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    uint8_t tmp[8];
		
		int32_t ret;
		uint16_t port=5000, size = 0, sentsize=0;
		uint8_t destip[4];
		uint16_t destport;

		*(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
		
		/* External Clock */
    //CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set Systme init */
    SystemInit();
		
		SSP0_Initialize();
		SSP1_Initialize();
		GPIO_Initialize();	

		GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off
		GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off
		GPIO_ResetBits(GPIOC, GPIO_Pin_6); // Test off

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART1,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        


#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif	
    printf("PHY is linked. \r\n"); 
#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    //mdio_error_check(GPIOB, MDC, MDIO); //need verify...
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif

    /* Network Configuration */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);
    printf(" MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); 
    getSIPR(tmp);
    printf("IP ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);
    printf("GW ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp);
    printf("SN MASK: %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
   
    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);

    printf(" TEST- START \r\n");  
		
    while(1)
    {
        switch(getSn_SR(SOCK_NUM))
				{
					case SOCK_ESTABLISHED:
					if(getSn_IR(SOCK_NUM) & Sn_IR_CON)
					{
						getSn_DIPR(SOCK_NUM, destip);
						destport = getSn_DPORT(SOCK_NUM);
						printf("%d:Connected - %d.%d.%d.%d : %d\r\n",SOCK_NUM, destip[0], destip[1], destip[2], destip[3], destport);
						setSn_IR(SOCK_NUM,Sn_IR_CON);
					}
					if((size = getSn_RX_RSR(SOCK_NUM)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
					{
						if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
						ret = recv(SOCK_NUM, test_buf, size);

						if(ret <= 0) return ret;      // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
						
						 /* Send only data to SSP1 */ 
						for (TxIdx=0; TxIdx<size; TxIdx++)
						{
							SSP_SendData(SSP0, test_buf[TxIdx]);
							while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) );
						}
						
						/* Receive only data from SSP0 */
						while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE))
						{
							SSP1_Buffer_Rx[RxIdx] = SSP_ReceiveData(SSP1);
							RxIdx++;
						} 
						RxIdx=0;
						
						sentsize = 0;

						while(size != sentsize)
						{
							ret = send(SOCK_NUM, SSP1_Buffer_Rx+sentsize, size-sentsize);
							if(ret < 0)
							{
								close(SOCK_NUM);
								return ret;
							}
							sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
						}
					}
						break;
					case SOCK_CLOSE_WAIT:
						printf("%d:CloseWait\r\n",SOCK_NUM);
						if((ret = disconnect(SOCK_NUM)) != SOCK_OK) return ret;
						printf("%d:Socket Closed\r\n", SOCK_NUM);

						break;
					case SOCK_INIT:
						printf("%d:Listen, TCP server loopback, port [%d]\r\n", SOCK_NUM, port);
						if( (ret = listen(SOCK_NUM)) != SOCK_OK) return ret;
						break;
					
					case SOCK_CLOSED:
						
						printf("%d:TCP server loopback start\r\n",SOCK_NUM);
						if((ret = socket(SOCK_NUM, Sn_MR_TCP, port, 0x00)) != SOCK_NUM) return ret;
						printf("%d:Socket opened\r\n",SOCK_NUM);
					
						break;
					
					default:
						break;
					
				}
    }

}
/*********************************************************************//**
 * @brief 		SSP0 Interrupt used for reading and writing handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void SSP0_IRQHandler(void)
{
	SSP_DATA_SETUP_Type *xf_setup;
	uint16_t tmp;
	uint8_t dataword;

	// Disable all SSP interrupts
	SSP_IntConfig(LPC_SSP0, SSP_INTCFG_ROR|SSP_INTCFG_RT|SSP_INTCFG_RX|SSP_INTCFG_TX, DISABLE);

	if(SSP_GetDataSize(LPC_SSP0)>8)
		dataword = 1;
	else
		dataword = 0;
	xf_setup = &xferConfig;
	// save status
	tmp = SSP_GetRawIntStatusReg(LPC_SSP0);
	xf_setup->status = tmp;

	// Check overrun error
	if (tmp & SSP_RIS_ROR){
		// Clear interrupt
		SSP_ClearIntPending(LPC_SSP0, SSP_INTCLR_ROR);
		// update status
		xf_setup->status |= SSP_STAT_ERROR;
		// Set Complete Flag
		complete = SET;
		return;
	}

	if ((xf_setup->tx_cnt != xf_setup->length) || (xf_setup->rx_cnt != xf_setup->length)){
		/* check if RX FIFO contains data */
		while ((SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY)) && (xf_setup->rx_cnt != xf_setup->length)){
			// Read data from SSP data
			tmp = SSP_ReceiveData(LPC_SSP0);

			// Store data to destination
			if (xf_setup->rx_data != NULL)
			{
				if (dataword == 0){
					*(uint8_t *)((uint32_t)xf_setup->rx_data + xf_setup->rx_cnt) = (uint8_t) tmp;
				} else {
					*(uint16_t *)((uint32_t)xf_setup->rx_data + xf_setup->rx_cnt) = (uint16_t) tmp;
				}
			}
			// Increase counter
			if (dataword == 0){
				xf_setup->rx_cnt++;
			} else {
				xf_setup->rx_cnt += 2;
			}
		}

		while ((SSP_GetStatus(LPC_SSP0, SSP_STAT_TXFIFO_NOTFULL)) && (xf_setup->tx_cnt != xf_setup->length)){
			// Write data to buffer
			if(xf_setup->tx_data == NULL){
				if (dataword == 0){
					SSP_SendData(LPC_SSP0, 0xFF);
					xf_setup->tx_cnt++;
				} else {
					SSP_SendData(LPC_SSP0, 0xFFFF);
					xf_setup->tx_cnt += 2;
				}
			} else {
				if (dataword == 0){
					SSP_SendData(LPC_SSP0, (*(uint8_t *)((uint32_t)xf_setup->tx_data + xf_setup->tx_cnt)));
					xf_setup->tx_cnt++;
				} else {
					SSP_SendData(LPC_SSP0, (*(uint16_t *)((uint32_t)xf_setup->tx_data + xf_setup->tx_cnt)));
					xf_setup->tx_cnt += 2;
				}
			}

			// Check overrun error
			if (SSP_GetRawIntStatus(LPC_SSP0, SSP_INTSTAT_RAW_ROR)){
				// update status
				xf_setup->status |= SSP_STAT_ERROR;
				// Set Complete Flag
				complete = SET;
				return;
			}

			// Check for any data available in RX FIFO
			while ((SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY)) && (xf_setup->rx_cnt != xf_setup->length)){
				// Read data from SSP data
				tmp = SSP_ReceiveData(LPC_SSP0);

				// Store data to destination
				if (xf_setup->rx_data != NULL)
				{
					if (dataword == 0){
						*(uint8_t *)((uint32_t)xf_setup->rx_data + xf_setup->rx_cnt) = (uint8_t) tmp;
					} else {
						*(uint16_t *)((uint32_t)xf_setup->rx_data + xf_setup->rx_cnt) = (uint16_t) tmp;
					}
				}
				// Increase counter
				if (dataword == 0){
					xf_setup->rx_cnt++;
				} else {
					xf_setup->rx_cnt += 2;
				}
			}
		}
	}

	// If there more data to sent or receive
	if ((xf_setup->rx_cnt != xf_setup->length) || (xf_setup->tx_cnt != xf_setup->length)){
		// Enable all interrupt
		SSP_IntConfig(LPC_SSP0, SSP_INTCFG_ROR|SSP_INTCFG_RT|SSP_INTCFG_RX|SSP_INTCFG_TX, ENABLE);
	} else {
		// Save status
		xf_setup->status = SSP_STAT_DONE;
		// Set Complete Flag
		complete = SET;
	}
}