add different version of iolib
							parent
							
								
									7d207209b5
								
							
						
					
					
						commit
						e2a9d85b76
					
				
											
												Binary file not shown.
											
										
									
								| @ -0,0 +1,386 @@ | |||||||
|  | //*****************************************************************************
 | ||||||
|  | //
 | ||||||
|  | //! \file w5100.c
 | ||||||
|  | //! \brief W5100 HAL Interface.
 | ||||||
|  | //! \version 1.0.0
 | ||||||
|  | //! \date 2013/10/21
 | ||||||
|  | //! \par  Revision history
 | ||||||
|  | //!       <2013/10/21> 1st Release
 | ||||||
|  | //! \author MidnightCow
 | ||||||
|  | //! 
 | ||||||
|  | //! Copyright (c)  2013, WIZnet Co., LTD.
 | ||||||
|  | //! All rights reserved.
 | ||||||
|  | //! 
 | ||||||
|  | //! Redistribution and use in source and binary forms, with or without 
 | ||||||
|  | //! modification, are permitted provided that the following conditions 
 | ||||||
|  | //! are met: 
 | ||||||
|  | //! 
 | ||||||
|  | //!     * Redistributions of source code must retain the above copyright 
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer. 
 | ||||||
|  | //!     * Redistributions in binary form must reproduce the above copyright
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer in the
 | ||||||
|  | //! documentation and/or other materials provided with the distribution. 
 | ||||||
|  | //!     * Neither the name of the <ORGANIZATION> nor the names of its 
 | ||||||
|  | //! contributors may be used to endorse or promote products derived 
 | ||||||
|  | //! from this software without specific prior written permission. 
 | ||||||
|  | //! 
 | ||||||
|  | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | ||||||
|  | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | ||||||
|  | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | ||||||
|  | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 | ||||||
|  | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 | ||||||
|  | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 | ||||||
|  | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | ||||||
|  | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 | ||||||
|  | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 | ||||||
|  | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 | ||||||
|  | //! THE POSSIBILITY OF SUCH DAMAGE.
 | ||||||
|  | //
 | ||||||
|  | //*****************************************************************************
 | ||||||
|  | 
 | ||||||
|  | #include "w5100.h" | ||||||
|  | 
 | ||||||
|  | #if   (_WIZCHIP_ == 5100) | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes the data into W5100 registers. | ||||||
|  | */ | ||||||
|  | void     WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ) | ||||||
|  | { | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(wb);    // Data write (write 1byte data)
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(AddrSel,wb);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(AddrSel,wb); | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus 
 | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_DR,wb);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_DR,wb); | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads the value from W5100 registers. | ||||||
|  | */ | ||||||
|  | uint8_t  WIZCHIP_READ(uint32_t AddrSel) | ||||||
|  | { | ||||||
|  |    uint8_t ret; | ||||||
|  | 
 | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  |    ret = WIZCHIP.IF.SPI._read_byte();  | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //ret = WIZCHIP.IF.BUS._read_byte(AddrSel);
 | ||||||
|  |    ret = WIZCHIP.IF.BUS._read_data(AddrSel);    | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus
 | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	
 | ||||||
|  |    //ret = WIZCHIP.IF.BUS._read_byte(IDM_DR);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    ret = WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  | 
 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!"    | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  |    return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes into W5100 memory(Buffer) | ||||||
|  | */  | ||||||
|  | void     WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  | 
 | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select();   //M20150601 : Moved here.
 | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |   for(i = 0; i < len; i++) | ||||||
|  |   { | ||||||
|  |      //M20160715 : Depricated "M20150601 : Remove _select() to top-side"
 | ||||||
|  |      //            CS should be controlled every SPI frames
 | ||||||
|  |      WIZCHIP.CS._select(); | ||||||
|  |      WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  |      WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0xFF00) >>  8); | ||||||
|  |      WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0x00FF) >>  0); | ||||||
|  |      WIZCHIP.IF.SPI._write_byte(pBuf[i]);    // Data write (write 1byte data)
 | ||||||
|  |      //M20160715 : Depricated "M20150601 : Remove _select() to top-side"
 | ||||||
|  | 	  WIZCHIP.CS._deselect(); | ||||||
|  |   } | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    //  WIZCHIP.IF.BUS._write_byte(AddrSel+i,pBuf[i]);  
 | ||||||
|  |        WIZCHIP.IF.BUS._write_data(AddrSel+i,pBuf[i]);   | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR,WIZCHIP_READ(MR) | MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_byte(IDM_DR,pBuf[i]); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);    | ||||||
|  |    */ | ||||||
|  |    setMR(getMR()|MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_DR,pBuf[i]); | ||||||
|  |    setMR(getMR() & ~MR_AI);    | ||||||
|  | 
 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!!" | ||||||
|  | #endif | ||||||
|  |     | ||||||
|  |    WIZCHIP.CS._deselect();  //M20150601 : Moved here.
 | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads into W5100 memory(Buffer) | ||||||
|  | */  | ||||||
|  | 
 | ||||||
|  | void     WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select();   //M20150601 : Moved here.
 | ||||||
|  |     | ||||||
|  |    #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    { | ||||||
|  |      //M20160715 : Depricated "M20150601 : Remove _select() to top-side"
 | ||||||
|  |      //            CS should be controlled every SPI frames
 | ||||||
|  |      WIZCHIP.CS._select(); | ||||||
|  |       WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  |       WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0xFF00) >>  8); | ||||||
|  |       WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0x00FF) >>  0); | ||||||
|  |       pBuf[i] = WIZCHIP.IF.SPI._read_byte();  | ||||||
|  |      //M20160715 : Depricated "M20150601 : Remove _select() to top-side"
 | ||||||
|  | 	  WIZCHIP.CS._deselect(); | ||||||
|  |    } | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    // pBuf[i]	= WIZCHIP.IF.BUS._read_byte(AddrSel+i);
 | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_data(AddrSel+i); | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) | MR_AI);     | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_byte(IDM_DR); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);  | ||||||
|  |    */ | ||||||
|  |    setMR(getMR() | MR_AI); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  |    setMR(getMR() & ~MR_AI);  | ||||||
|  |     | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect();    //M20150601 : Moved Here.
 | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | // Socket N regsiter IO function //
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_TX_FSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_RX_RSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | // Sn_TXBUF & Sn_RXBUF IO function //
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | uint32_t getSn_RxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  | #if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) | ||||||
|  |    uint32_t rxbase = _W5100_IO_BASE_ + _WIZCHIP_IO_RXBUF_; | ||||||
|  | #else    | ||||||
|  |    uint32_t rxbase = _WIZCHIP_IO_RXBUF_; | ||||||
|  | #endif    | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       rxbase += getSn_RxMAX(i); | ||||||
|  | 
 | ||||||
|  |    return rxbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint32_t getSn_TxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  | #if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) | ||||||
|  |    uint32_t txbase = _W5100_IO_BASE_ + _WIZCHIP_IO_TXBUF_; | ||||||
|  | #else    | ||||||
|  |    uint32_t txbase = _WIZCHIP_IO_TXBUF_; | ||||||
|  | #endif    | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       txbase += getSn_TxMAX(i); | ||||||
|  |    return txbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by send() and sendto() function also. for copy the data form application buffer to Transmite buffer of the chip. | ||||||
|  | 
 | ||||||
|  | This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer | ||||||
|  | register. User should read upper byte first and lower byte later to get proper value. | ||||||
|  | And this function is being used for copy the data form application buffer to Transmite | ||||||
|  | buffer of the chip. It calculate the actual physical address where one has to write | ||||||
|  | the data in transmite buffer. Here also take care of the condition while it exceed | ||||||
|  | the Tx memory uper-bound of socket. | ||||||
|  | 
 | ||||||
|  | */ | ||||||
|  | void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t dst_mask; | ||||||
|  |   uint16_t dst_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_TX_WR(sn); | ||||||
|  | 
 | ||||||
|  |   dst_mask = ptr & getSn_TxMASK(sn); | ||||||
|  |   dst_ptr = getSn_TxBASE(sn) + dst_mask; | ||||||
|  |    | ||||||
|  |   if (dst_mask + len > getSn_TxMAX(sn))  | ||||||
|  |   { | ||||||
|  |     size = getSn_TxMAX(sn) - dst_mask; | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  |     dst_ptr = getSn_TxBASE(sn); | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, len); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ptr += len; | ||||||
|  | 
 | ||||||
|  |   setSn_TX_WR(sn, ptr);   | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by recv() also. This function is being used for copy the data form Receive buffer of the chip to application buffer. | ||||||
|  | 
 | ||||||
|  | This function read the Rx read pointer register | ||||||
|  | and after copy the data from receive buffer update the Rx write pointer register. | ||||||
|  | User should read upper byte first and lower byte later to get proper value. | ||||||
|  | It calculate the actual physical address where one has to read | ||||||
|  | the data from Receive buffer. Here also take care of the condition while it exceed | ||||||
|  | the Rx memory uper-bound of socket. | ||||||
|  | */ | ||||||
|  | void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t src_mask; | ||||||
|  |   uint16_t src_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   src_mask = (uint32_t)ptr & getSn_RxMASK(sn); | ||||||
|  |   src_ptr = (getSn_RxBASE(sn) + src_mask); | ||||||
|  | 
 | ||||||
|  |    | ||||||
|  |   if( (src_mask + len) > getSn_RxMAX(sn) )  | ||||||
|  |   { | ||||||
|  |     size = getSn_RxMAX(sn) - src_mask; | ||||||
|  |     WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  | 	src_ptr = getSn_RxBASE(sn); | ||||||
|  |     WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, len); | ||||||
|  |   } | ||||||
|  |      | ||||||
|  |   ptr += len; | ||||||
|  |    | ||||||
|  |   setSn_RX_RD(sn, ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_recv_ignore(uint8_t sn, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   ptr += len; | ||||||
|  |   setSn_RX_RD(sn,ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -0,0 +1,425 @@ | |||||||
|  | //*****************************************************************************
 | ||||||
|  | //
 | ||||||
|  | //! \file w5100S.c
 | ||||||
|  | //! \brief W5100S HAL Interface.
 | ||||||
|  | //! \version 1.0.0
 | ||||||
|  | //! \date 2018/03/29
 | ||||||
|  | //! \par  Revision history
 | ||||||
|  | //!       <2018/03/29> 1st Release
 | ||||||
|  | //! \author Peter
 | ||||||
|  | //! 
 | ||||||
|  | //! Copyright (c)  2013, WIZnet Co., LTD.
 | ||||||
|  | //! All rights reserved.
 | ||||||
|  | //! 
 | ||||||
|  | //! Redistribution and use in source and binary forms, with or without 
 | ||||||
|  | //! modification, are permitted provided that the following conditions 
 | ||||||
|  | //! are met: 
 | ||||||
|  | //! 
 | ||||||
|  | //!     * Redistributions of source code must retain the above copyright 
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer. 
 | ||||||
|  | //!     * Redistributions in binary form must reproduce the above copyright
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer in the
 | ||||||
|  | //! documentation and/or other materials provided with the distribution. 
 | ||||||
|  | //!     * Neither the name of the <ORGANIZATION> nor the names of its 
 | ||||||
|  | //! contributors may be used to endorse or promote products derived 
 | ||||||
|  | //! from this software without specific prior written permission. 
 | ||||||
|  | //! 
 | ||||||
|  | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | ||||||
|  | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | ||||||
|  | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | ||||||
|  | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 | ||||||
|  | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 | ||||||
|  | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 | ||||||
|  | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | ||||||
|  | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 | ||||||
|  | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 | ||||||
|  | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 | ||||||
|  | //! THE POSSIBILITY OF SUCH DAMAGE.
 | ||||||
|  | //
 | ||||||
|  | //*****************************************************************************
 | ||||||
|  | 
 | ||||||
|  | #include "w5100s.h" | ||||||
|  | 
 | ||||||
|  | #if   (_WIZCHIP_ == W5100S) | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes the data into W5100S registers. | ||||||
|  | */ | ||||||
|  | void     WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ) | ||||||
|  | { | ||||||
|  | 	int i; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(wb);    // Data write (write 1byte data)
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte(wb);    // Data write (write 1byte data)
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus 
 | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_DR,wb);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_DR,wb); | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100. !!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads the value from W5100S registers. | ||||||
|  | */ | ||||||
|  | uint8_t  WIZCHIP_READ(uint32_t AddrSel) | ||||||
|  | { | ||||||
|  |    uint8_t ret; | ||||||
|  |    int i; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ ==  _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  |    ret = WIZCHIP.IF.SPI._read_byte();  | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((AddrSel & 0xFF00) >>  8); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF) >>  0); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  | 	ret = WIZCHIP.IF.SPI._read_byte(); | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus
 | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	
 | ||||||
|  |    //ret = WIZCHIP.IF.BUS._read_byte(IDM_DR);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF)); | ||||||
|  |    ret = WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  | 
 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!"    | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  |    return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes into W5100S memory(Buffer) | ||||||
|  | */  | ||||||
|  | void     WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  |    int j,k,l; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select();   //M20150601 : Moved here.
 | ||||||
|  | 
 | ||||||
|  | #if((_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0x00FF) >>  0); | ||||||
|  | 
 | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    { | ||||||
|  | 	   WIZCHIP.IF.SPI._write_byte(pBuf[i]);    // Data write (write 1byte data)
 | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) | ||||||
|  | 
 | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0xFF00) >>  8); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte((((uint16_t)(AddrSel+i)) & 0x00FF) >>  0); | ||||||
|  | 	WIZCHIP.IF.SPI._write_byte(0xF0); | ||||||
|  | 
 | ||||||
|  | 	for(i = 0; i < len; i++) | ||||||
|  | 	{ | ||||||
|  | 		WIZCHIP.IF.SPI._write_byte(pBuf[i]);    // Data write (write 1byte data)
 | ||||||
|  | 	} | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR,WIZCHIP_READ(MR) | MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_byte(IDM_DR,pBuf[i]); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);    | ||||||
|  |    */ | ||||||
|  |    setMR(getMR()|MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_DR,pBuf[i]); | ||||||
|  |    setMR(getMR() & ~MR_AI);    | ||||||
|  | 
 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!!" | ||||||
|  | #endif | ||||||
|  |     | ||||||
|  |    WIZCHIP.CS._deselect();  //M20150601 : Moved here.
 | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads into W5100S memory(Buffer) | ||||||
|  | */  | ||||||
|  | 
 | ||||||
|  | void     WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select();   //M20150601 : Moved here.
 | ||||||
|  |     | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_) ) | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0x00FF) >>  0); | ||||||
|  | 
 | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    { | ||||||
|  |       pBuf[i] = WIZCHIP.IF.SPI._read_byte();  | ||||||
|  |    } | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_5500_) ) | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((uint16_t)((AddrSel+i) & 0x00FF) >>  0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x0F); | ||||||
|  | 
 | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    { | ||||||
|  |       pBuf[i] = WIZCHIP.IF.SPI._read_byte(); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with ioLibrary  
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) | MR_AI);     | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_byte(IDM_DR); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);  | ||||||
|  |    */ | ||||||
|  |    setMR(getMR() | MR_AI); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0xFF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x00FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  |    setMR(getMR() & ~MR_AI);  | ||||||
|  |     | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5100S. !!!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect();    //M20150601 : Moved Here.
 | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | // Socket N regsiter IO function //
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_TX_FSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_RX_RSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | // Sn_TXBUF & Sn_RXBUF IO function //
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | uint32_t getSn_RxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  | #if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) | ||||||
|  |    uint32_t rxbase = _W5100S_IO_BASE_ + _WIZCHIP_IO_RXBUF_; | ||||||
|  | #else    | ||||||
|  |    uint32_t rxbase = _WIZCHIP_IO_RXBUF_; | ||||||
|  | #endif    | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       rxbase += getSn_RxMAX(i); | ||||||
|  | 
 | ||||||
|  |    return rxbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint32_t getSn_TxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  | #if ( _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) | ||||||
|  |    uint32_t txbase = _W5100S_IO_BASE_ + _WIZCHIP_IO_TXBUF_; | ||||||
|  | #else    | ||||||
|  |    uint32_t txbase = _WIZCHIP_IO_TXBUF_; | ||||||
|  | #endif    | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       txbase += getSn_TxMAX(i); | ||||||
|  |    return txbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by send() and sendto() function also. for copy the data form application buffer to Transmite buffer of the chip. | ||||||
|  | 
 | ||||||
|  | This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer | ||||||
|  | register. User should read upper byte first and lower byte later to get proper value. | ||||||
|  | And this function is being used for copy the data form application buffer to Transmite | ||||||
|  | buffer of the chip. It calculate the actual physical address where one has to write | ||||||
|  | the data in transmite buffer. Here also take care of the condition while it exceed | ||||||
|  | the Tx memory uper-bound of socket. | ||||||
|  | 
 | ||||||
|  | */ | ||||||
|  | void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t dst_mask; | ||||||
|  |   uint16_t dst_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_TX_WR(sn); | ||||||
|  | 
 | ||||||
|  |   dst_mask = ptr & getSn_TxMASK(sn); | ||||||
|  |   dst_ptr = getSn_TxBASE(sn) + dst_mask; | ||||||
|  |    | ||||||
|  |   if (dst_mask + len > getSn_TxMAX(sn))  | ||||||
|  |   { | ||||||
|  |     size = getSn_TxMAX(sn) - dst_mask; | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  |     dst_ptr = getSn_TxBASE(sn); | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_WRITE_BUF(dst_ptr, wizdata, len); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ptr += len; | ||||||
|  | 
 | ||||||
|  |   setSn_TX_WR(sn, ptr);   | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by recv() also. This function is being used for copy the data form Receive buffer of the chip to application buffer. | ||||||
|  | 
 | ||||||
|  | This function read the Rx read pointer register | ||||||
|  | and after copy the data from receive buffer update the Rx write pointer register. | ||||||
|  | User should read upper byte first and lower byte later to get proper value. | ||||||
|  | It calculate the actual physical address where one has to read | ||||||
|  | the data from Receive buffer. Here also take care of the condition while it exceed | ||||||
|  | the Rx memory uper-bound of socket. | ||||||
|  | */ | ||||||
|  | void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t src_mask; | ||||||
|  |   uint16_t src_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   src_mask = (uint32_t)ptr & getSn_RxMASK(sn); | ||||||
|  |   src_ptr = (getSn_RxBASE(sn) + src_mask); | ||||||
|  | 
 | ||||||
|  |    | ||||||
|  |   if( (src_mask + len) > getSn_RxMAX(sn) )  | ||||||
|  |   { | ||||||
|  |     size = getSn_RxMAX(sn) - src_mask; | ||||||
|  |     WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  | 	src_ptr = getSn_RxBASE(sn); | ||||||
|  |     WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_READ_BUF(src_ptr, (uint8_t*)wizdata, len); | ||||||
|  |   } | ||||||
|  |      | ||||||
|  |   ptr += len; | ||||||
|  |    | ||||||
|  |   setSn_RX_RD(sn, ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_recv_ignore(uint8_t sn, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   ptr += len; | ||||||
|  |   setSn_RX_RD(sn,ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_mdio_write(uint8_t PHYMDIO_regadr, uint16_t var) | ||||||
|  | { | ||||||
|  |     WIZCHIP_WRITE(PHYRAR,PHYMDIO_regadr); | ||||||
|  |     WIZCHIP_WRITE(PHYDIR, (uint8_t)(var >> 8)); | ||||||
|  |     WIZCHIP_WRITE(PHYDIR+1, (uint8_t)(var)); | ||||||
|  |     WIZCHIP_WRITE(PHYACR, PHYACR_WRITE); | ||||||
|  |     while(WIZCHIP_READ(PHYACR));  //wait for command complete
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint16_t wiz_mdio_read(uint8_t PHYMDIO_regadr) | ||||||
|  | { | ||||||
|  |     WIZCHIP_WRITE(PHYRAR,PHYMDIO_regadr); | ||||||
|  |     WIZCHIP_WRITE(PHYACR, PHYACR_READ); | ||||||
|  |     while(WIZCHIP_READ(PHYACR));  //wait for command complete
 | ||||||
|  |     return ((uint16_t)WIZCHIP_READ(PHYDOR) << 8) | WIZCHIP_READ(PHYDOR+1); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_delay_ms(uint32_t milliseconds) | ||||||
|  | { | ||||||
|  | 	uint32_t i; | ||||||
|  | 	for(i = 0 ; i < milliseconds ; i++) | ||||||
|  | 	{ | ||||||
|  | 		//Write any values to clear the TCNTCLKR register
 | ||||||
|  | 		setTCNTCLKR(0xff); | ||||||
|  | 
 | ||||||
|  | 		// Wait until counter register value reaches 10.(10 = 1ms : TCNTR is 100us tick counter register)
 | ||||||
|  | 		while(getTCNTR() < 0x0a){} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -0,0 +1,353 @@ | |||||||
|  | //*****************************************************************************
 | ||||||
|  | //
 | ||||||
|  | //! \file w5200.c
 | ||||||
|  | //! \brief W5200 HAL Interface.
 | ||||||
|  | //! \version 1.0.0
 | ||||||
|  | //! \date 2013/10/21
 | ||||||
|  | //! \par  Revision history
 | ||||||
|  | //!       <2013/10/21> 1st Release
 | ||||||
|  | //! \author MidnightCow
 | ||||||
|  | //! 
 | ||||||
|  | //! Copyright (c)  2013, WIZnet Co., LTD.
 | ||||||
|  | //! All rights reserved.
 | ||||||
|  | //! 
 | ||||||
|  | //! Redistribution and use in source and binary forms, with or without 
 | ||||||
|  | //! modification, are permitted provided that the following conditions 
 | ||||||
|  | //! are met: 
 | ||||||
|  | //! 
 | ||||||
|  | //!     * Redistributions of source code must retain the above copyright 
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer. 
 | ||||||
|  | //!     * Redistributions in binary form must reproduce the above copyright
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer in the
 | ||||||
|  | //! documentation and/or other materials provided with the distribution. 
 | ||||||
|  | //!     * Neither the name of the <ORGANIZATION> nor the names of its 
 | ||||||
|  | //! contributors may be used to endorse or promote products derived 
 | ||||||
|  | //! from this software without specific prior written permission. 
 | ||||||
|  | //! 
 | ||||||
|  | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | ||||||
|  | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | ||||||
|  | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | ||||||
|  | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 | ||||||
|  | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 | ||||||
|  | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 | ||||||
|  | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | ||||||
|  | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 | ||||||
|  | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 | ||||||
|  | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 | ||||||
|  | //! THE POSSIBILITY OF SUCH DAMAGE.
 | ||||||
|  | //
 | ||||||
|  | //*****************************************************************************
 | ||||||
|  | 
 | ||||||
|  | #include "w5200.h" | ||||||
|  | 
 | ||||||
|  | #if   (_WIZCHIP_ == 5200) | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes the data into W5200 registers. | ||||||
|  | */ | ||||||
|  | void     WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb ) | ||||||
|  | { | ||||||
|  | 	WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >>  0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(_W5200_SPI_WRITE_);  // Data write command and Write data length upper
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x01);  // Write data length lower
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(wb);    // Data write (write 1byte data)
 | ||||||
|  | 
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus 
 | ||||||
|  |    //M20150601 : Rename the function for integrating with W5300
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF));	
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_DR,wb);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF));	 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_DR,wb); | ||||||
|  | 
 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads the value from W5200 registers. | ||||||
|  | */ | ||||||
|  | uint8_t  WIZCHIP_READ(uint32_t AddrSel) | ||||||
|  | { | ||||||
|  |    uint8_t ret; | ||||||
|  | 
 | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >>  0); | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(_W5200_SPI_READ_);                             // Read data length upper    
 | ||||||
|  |    WIZCHIP.IF.SPI._write_byte(0x01);                             // Data length lower  
 | ||||||
|  |    ret = WIZCHIP.IF.SPI._read_byte();  | ||||||
|  | 
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) | ||||||
|  | 
 | ||||||
|  |    //add indirect bus
 | ||||||
|  |    //M20150601 : Rename the function for integrating with W5300
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >>  8);
 | ||||||
|  |    //WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF));	
 | ||||||
|  |    //ret = WIZCHIP.IF.BUS._read_byte(IDM_DR);
 | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF));	 | ||||||
|  |    ret = WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  |    	 | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!"    | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  |    return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function writes into W5200 memory(Buffer) | ||||||
|  | */  | ||||||
|  | void     WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >>  8); | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >>  0); | ||||||
|  |   WIZCHIP.IF.SPI._write_byte(_W5200_SPI_WRITE_ | ((len & 0x7F00) >> 8));         // Write data op code and length upper    
 | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((len & 0x00FF) >> 0);         // length lower
 | ||||||
|  |   for(i = 0; i < len; i++) | ||||||
|  |      WIZCHIP.IF.SPI._write_byte(pBuf[i]); | ||||||
|  | 
 | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with W5300
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR,WIZCHIP_READ(MR) | MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_byte(IDM_DR,pBuf[i]); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);    | ||||||
|  |    */ | ||||||
|  |    setMR(getMR() | MR_AI);      | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF)); | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_DR,pBuf[i]); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);    | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function reads into W5200 memory(Buffer) | ||||||
|  | */  | ||||||
|  | void     WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len) | ||||||
|  | { | ||||||
|  |    uint16_t i = 0; | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)) | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >>  8); | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >>  0); | ||||||
|  |   WIZCHIP.IF.SPI._write_byte( _W5200_SPI_READ_ | ((len & 0x7F00) >> 8));         // Write data op code and length upper    
 | ||||||
|  |   WIZCHIP.IF.SPI._write_byte((len & 0x00FF) >> 0);         // length lower
 | ||||||
|  |   for(i = 0; i < len; i++) | ||||||
|  |     pBuf[i] = WIZCHIP.IF.SPI._read_byte(); | ||||||
|  |   | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_) ) | ||||||
|  |    //M20150601 : Rename the function for integrating with W5300
 | ||||||
|  |    /*
 | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) | MR_AI);     | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_byte(IDM_AR1,(AddrSel & 0x000000FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_byte(IDM_DR); | ||||||
|  |    WIZCHIP_WRITE(MR, WIZCHIP_READ(MR) & ~MR_AI);  | ||||||
|  |    */ | ||||||
|  |    setMR(getMR() | MR_AI);     | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR0,(AddrSel & 0x0000FF00) >>  8); | ||||||
|  |    WIZCHIP.IF.BUS._write_data(IDM_AR1,(AddrSel & 0x000000FF));	 | ||||||
|  |    for(i = 0 ; i < len; i++) | ||||||
|  |       pBuf[i]	= WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  |    setMR(getMR() & ~MR_AI);  | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5200. !!!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | // Socket N regsiter IO function //
 | ||||||
|  | ///////////////////////////////////
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_TX_FSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_TX_FSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_RX_RSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint16_t val=0,val1=0; | ||||||
|  |    do | ||||||
|  |    { | ||||||
|  |       val1 = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |       val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       if (val1 != 0) | ||||||
|  |       { | ||||||
|  |         val = WIZCHIP_READ(Sn_RX_RSR(sn)); | ||||||
|  |         val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1)); | ||||||
|  |       } | ||||||
|  |    }while (val != val1); | ||||||
|  |    return val; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | // Sn_TXBUF & Sn_RXBUF IO function //
 | ||||||
|  | /////////////////////////////////////
 | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_RxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  |    uint16_t rxbase = _WIZCHIP_IO_RXBUF_; | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       rxbase += getSn_RxMAX(i); | ||||||
|  |    return rxbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint16_t getSn_TxBASE(uint8_t sn) | ||||||
|  | { | ||||||
|  |    int8_t  i; | ||||||
|  |    uint16_t txbase = _WIZCHIP_IO_TXBUF_; | ||||||
|  |    for(i = 0; i < sn; i++) | ||||||
|  |       txbase += getSn_TxMAX(i); | ||||||
|  |    return txbase; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by send() and sendto() function also. for copy the data form application buffer to Transmite buffer of the chip. | ||||||
|  | 
 | ||||||
|  | This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer | ||||||
|  | register. User should read upper byte first and lower byte later to get proper value. | ||||||
|  | And this function is being used for copy the data form application buffer to Transmite | ||||||
|  | buffer of the chip. It calculate the actual physical address where one has to write | ||||||
|  | the data in transmite buffer. Here also take care of the condition while it exceed | ||||||
|  | the Tx memory uper-bound of socket. | ||||||
|  | 
 | ||||||
|  | */ | ||||||
|  |                                          | ||||||
|  | void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |    | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t dst_mask; | ||||||
|  |   uint8_t * dst_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_TX_WR(sn); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   dst_mask = (uint32_t)ptr & getSn_TxMASK(sn); | ||||||
|  |   dst_ptr = (uint8_t*)((uint32_t)getSn_TxBASE(sn) + dst_mask); | ||||||
|  |    | ||||||
|  |   if (dst_mask + len > getSn_TxMAX(sn))  | ||||||
|  |   { | ||||||
|  |     size = getSn_TxMAX(sn) - dst_mask; | ||||||
|  |     WIZCHIP_WRITE_BUF((uint32_t)dst_ptr, wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  |     dst_ptr = (uint8_t*)((uint32_t)getSn_TxBASE(sn)); | ||||||
|  |     WIZCHIP_WRITE_BUF((uint32_t)dst_ptr, wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_WRITE_BUF((uint32_t)dst_ptr, wizdata, len); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ptr += len; | ||||||
|  | 
 | ||||||
|  |   setSn_TX_WR(sn, ptr);   | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | @brief  This function is being called by recv() also. This function is being used for copy the data form Receive buffer of the chip to application buffer. | ||||||
|  | 
 | ||||||
|  | This function read the Rx read pointer register | ||||||
|  | and after copy the data from receive buffer update the Rx write pointer register. | ||||||
|  | User should read upper byte first and lower byte later to get proper value. | ||||||
|  | It calculate the actual physical address where one has to read | ||||||
|  | the data from Receive buffer. Here also take care of the condition while it exceed | ||||||
|  | the Rx memory uper-bound of socket. | ||||||
|  | */ | ||||||
|  | void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  |   uint16_t size; | ||||||
|  |   uint16_t src_mask; | ||||||
|  |   uint8_t * src_ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   src_mask = (uint32_t)ptr & getSn_RxMASK(sn); | ||||||
|  |   src_ptr = (uint8_t *)((uint32_t)getSn_RxBASE(sn) + src_mask); | ||||||
|  |    | ||||||
|  |   if( (src_mask + len) > getSn_RxMAX(sn) )  | ||||||
|  |   { | ||||||
|  |     size = getSn_RxMAX(sn) - src_mask; | ||||||
|  |     WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |     wizdata += size; | ||||||
|  |     size = len - size; | ||||||
|  |     src_ptr = (uint8_t*)((uint32_t)getSn_RxBASE(sn)); | ||||||
|  |     WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, size); | ||||||
|  |   }  | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     WIZCHIP_READ_BUF((uint32_t)src_ptr, (uint8_t*)wizdata, len); | ||||||
|  |   } | ||||||
|  |      | ||||||
|  |   ptr += len; | ||||||
|  |    | ||||||
|  |   setSn_RX_RD(sn, ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_recv_ignore(uint8_t sn, uint16_t len) | ||||||
|  | { | ||||||
|  |   uint16_t ptr; | ||||||
|  | 
 | ||||||
|  |   ptr = getSn_RX_RD(sn); | ||||||
|  |    | ||||||
|  |   ptr += len; | ||||||
|  |   setSn_RX_RD(sn,ptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -0,0 +1,225 @@ | |||||||
|  | //*****************************************************************************
 | ||||||
|  | //
 | ||||||
|  | //! \file w5300.h
 | ||||||
|  | //! \brief W5300 HAL implement File.
 | ||||||
|  | //! \version 1.0.0
 | ||||||
|  | //! \date 2015/05/01
 | ||||||
|  | //! \par  Revision history
 | ||||||
|  | //!       <2015/05/01> 1st Released for integrating with ioLibrary 
 | ||||||
|  | //!        Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary.
 | ||||||
|  | //!        >> https://github.com/Wiznet/ioLibrary_Driver
 | ||||||
|  | //! \author MidnightCow
 | ||||||
|  | //! \copyright
 | ||||||
|  | //!
 | ||||||
|  | //! Copyright (c)  2015, WIZnet Co., LTD.
 | ||||||
|  | //! All rights reserved.
 | ||||||
|  | //! 
 | ||||||
|  | //! Redistribution and use in source and binary forms, with or without 
 | ||||||
|  | //! modification, are permitted provided that the following conditions 
 | ||||||
|  | //! are met: 
 | ||||||
|  | //! 
 | ||||||
|  | //!     * Redistributions of source code must retain the above copyright 
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer. 
 | ||||||
|  | //!     * Redistributions in binary form must reproduce the above copyright
 | ||||||
|  | //! notice, this list of conditions and the following disclaimer in the
 | ||||||
|  | //! documentation and/or other materials provided with the distribution. 
 | ||||||
|  | //!     * Neither the name of the <ORGANIZATION> nor the names of its 
 | ||||||
|  | //! contributors may be used to endorse or promote products derived 
 | ||||||
|  | //! from this software without specific prior written permission. 
 | ||||||
|  | //! 
 | ||||||
|  | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | ||||||
|  | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | ||||||
|  | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | ||||||
|  | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 | ||||||
|  | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 | ||||||
|  | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 | ||||||
|  | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | ||||||
|  | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 | ||||||
|  | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 | ||||||
|  | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 | ||||||
|  | //! THE POSSIBILITY OF SUCH DAMAGE.
 | ||||||
|  | //
 | ||||||
|  | //*****************************************************************************
 | ||||||
|  | 
 | ||||||
|  | #include <stdint.h> | ||||||
|  | #include "wizchip_conf.h" | ||||||
|  | 
 | ||||||
|  | #if _WIZCHIP_ == 5300 | ||||||
|  | 
 | ||||||
|  |    extern uint8_t sock_remained_byte[_WIZCHIP_SOCK_NUM_]; | ||||||
|  |    extern uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_]; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /***********************
 | ||||||
|  |  * Basic I/O  Function * | ||||||
|  |  ***********************/ | ||||||
|  |   | ||||||
|  | void     WIZCHIP_WRITE(uint32_t AddrSel, uint16_t wb ) | ||||||
|  | { | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(AddrSel,  (uint8_t)(wb>>8)); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(AddrSel,1),(uint8_t)wb); | ||||||
|  |    #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(AddrSel,  wb);    | ||||||
|  |    #else | ||||||
|  |       #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" | ||||||
|  |    #endif | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_AR,                      (uint8_t)(AddrSel >> 8)); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_AR,1),(uint8_t)AddrSel); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_DR,(uint8_t)(wb>>8)); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_DR,1),(uint8_t)wb);          | ||||||
|  |    #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_AR, (uint16_t)AddrSel); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_DR, wb); | ||||||
|  |    #else | ||||||
|  |       #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" | ||||||
|  |    #endif | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5300. !!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint16_t WIZCHIP_READ(uint32_t AddrSel) | ||||||
|  | { | ||||||
|  |    uint16_t ret; | ||||||
|  | 
 | ||||||
|  |    WIZCHIP_CRITICAL_ENTER(); | ||||||
|  |    WIZCHIP.CS._select(); | ||||||
|  | 
 | ||||||
|  | #if ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_DIR_) ) | ||||||
|  |    #if (_WIZCHIP_IO_BUS_WIDTH_ == 8) | ||||||
|  |       ret = (((uint16_t)WIZCHIP.IF.BUS._read_data(AddrSel)) << 8) |  | ||||||
|  |             (((uint16_t)WIZCHIP.IF.BUS._read_data(WIZCHIP_OFFSET_INC(AddrSel,1))) & 0x00FF) ;    | ||||||
|  |    #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) | ||||||
|  |       ret = WIZCHIP.IF.BUS._read_data(AddrSel); | ||||||
|  |    #else | ||||||
|  |       #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" | ||||||
|  |    #endif          | ||||||
|  | #elif ( (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_) ) | ||||||
|  |    #if(_WIZCHIP_IO_BUS_WIDTH_ == 8) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_AR,                      (uint8_t)(AddrSel >> 8)); | ||||||
|  |       WIZCHIP.IF.BUS._write_data(WIZCHIP_OFFSET_INC(IDM_AR,1),(uint8_t)AddrSel); | ||||||
|  |       ret = (((uint16_t)WIZCHIP.IF.BUS._read_data(IDM_DR)) << 8) |  | ||||||
|  |             (((uint16_t)WIZCHIP.IF.BUS._read_data(WIZCHIP_OFFSET_INC(IDM_DR,1))) & 0x00FF); | ||||||
|  |    #elif(_WIZCHIP_IO_BUS_WIDTH_ == 16) | ||||||
|  |       WIZCHIP.IF.BUS._write_data(IDM_AR, (uint16_t)AddrSel); | ||||||
|  |       ret = WIZCHIP.IF.BUS._read_data(IDM_DR); | ||||||
|  |    #else | ||||||
|  |       #error "Abnoraml _WIZCHIP_IO_BUS_WIDTH_. Should be 8 or 16" | ||||||
|  |    #endif | ||||||
|  | #else | ||||||
|  |    #error "Unknown _WIZCHIP_IO_MODE_ in W5300. !!!" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |    WIZCHIP.CS._deselect(); | ||||||
|  |    WIZCHIP_CRITICAL_EXIT(); | ||||||
|  |    return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void setTMSR(uint8_t sn,uint8_t tmsr) | ||||||
|  | { | ||||||
|  |    uint16_t tmem; | ||||||
|  |    tmem = WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))); | ||||||
|  |    if(sn & 0x01)  tmem = (tmem & 0xFF00) | (((uint16_t)tmsr ) & 0x00FF) ; | ||||||
|  |    else tmem =  (tmem & 0x00FF) | (((uint16_t)tmsr) << 8) ; | ||||||
|  |    WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE)),tmem); | ||||||
|  | } | ||||||
|  |     | ||||||
|  | uint8_t getTMSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    if(sn & 0x01) | ||||||
|  |       return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))) & 0x00FF); | ||||||
|  |    return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(TMS01R, (sn & 0xFE))) >> 8); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void setRMSR(uint8_t sn,uint8_t rmsr) | ||||||
|  | { | ||||||
|  |    uint16_t rmem; | ||||||
|  |    rmem = WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))); | ||||||
|  |    if(sn & 0x01)  rmem = (rmem & 0xFF00) | (((uint16_t)rmsr ) & 0x00FF) ; | ||||||
|  |    else rmem =  (rmem & 0x00FF) | (((uint16_t)rmsr) << 8) ; | ||||||
|  |    WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE)),rmem); | ||||||
|  | } | ||||||
|  |     | ||||||
|  | uint8_t getRMSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    if(sn & 0x01) | ||||||
|  |       return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))) & 0x00FF); | ||||||
|  |    return (uint8_t)(WIZCHIP_READ(WIZCHIP_OFFSET_INC(RMS01R, (sn & 0xFE))) >> 8); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint32_t getSn_TX_FSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint32_t free_tx_size=0; | ||||||
|  |    uint32_t free_tx_size1=1; | ||||||
|  |    while(1) | ||||||
|  |    { | ||||||
|  |       free_tx_size = (((uint32_t)WIZCHIP_READ(Sn_TX_FSR(sn))) << 16) |  | ||||||
|  |                      (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),2))) & 0x0000FFFF);                           // read
 | ||||||
|  |       if(free_tx_size == free_tx_size1) break;  // if first == sencond, Sn_TX_FSR value is valid.                                                          
 | ||||||
|  |       free_tx_size1 = free_tx_size;             // save second value into first                                                   
 | ||||||
|  |    }                                                                        | ||||||
|  |    return free_tx_size;                                                     | ||||||
|  | }                                                                           | ||||||
|  | 
 | ||||||
|  | uint32_t getSn_RX_RSR(uint8_t sn) | ||||||
|  | { | ||||||
|  |    uint32_t received_rx_size=0; | ||||||
|  |    uint32_t received_rx_size1=1; | ||||||
|  |    while(1) | ||||||
|  |    { | ||||||
|  |       received_rx_size = (((uint32_t)WIZCHIP_READ(Sn_RX_RSR(sn))) << 16) |  | ||||||
|  |                          (((uint32_t)WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),2))) & 0x0000FFFF); | ||||||
|  |       if(received_rx_size == received_rx_size1) break;                                                                          | ||||||
|  |       received_rx_size1 = received_rx_size;                                      // if first == sencond, Sn_RX_RSR value is valid.
 | ||||||
|  |    }                                                                             // save second value into first                
 | ||||||
|  |    return received_rx_size + (uint32_t)((sock_pack_info[sn] & 0x02) ? 1 : 0);    | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint32_t len) | ||||||
|  | { | ||||||
|  |    uint32_t i = 0; | ||||||
|  |    if(len == 0)  return; | ||||||
|  |     | ||||||
|  |    for(i = 0; i < len ; i += 2) | ||||||
|  |       setSn_TX_FIFOR(sn, (((uint16_t)wizdata[i]) << 8) | (((uint16_t)wizdata[i+1]) & 0x00FF)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint32_t len) | ||||||
|  | { | ||||||
|  |    uint16_t rd = 0; | ||||||
|  |    uint32_t i = 0; | ||||||
|  |     | ||||||
|  |    if(len == 0) return; | ||||||
|  |        | ||||||
|  |    for(i = 0; i < len; i++) | ||||||
|  |    { | ||||||
|  |       if((i & 0x01)==0) | ||||||
|  |       { | ||||||
|  |          rd = getSn_RX_FIFOR(sn); | ||||||
|  |          wizdata[i]   = (uint8_t)(rd >> 8); | ||||||
|  |       } | ||||||
|  |       else  wizdata[i] = (uint8_t)rd;  // For checking the memory access violation
 | ||||||
|  |    } | ||||||
|  |    sock_remained_byte[sn] = (uint8_t)rd; // back up the remaind fifo byte.
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void wiz_recv_ignore(uint8_t sn, uint32_t len) | ||||||
|  | { | ||||||
|  |    uint32_t i = 0; | ||||||
|  |    for(i = 0; i < len ; i += 2) getSn_RX_FIFOR(sn); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								
		Reference in New Issue