コード例 #1
0
        public int SendIGMP(byte[] buf, int len)
        {
            byte s      = _scoket_number;
            byte status = 0;
            //	uint8 isr=0;
            int ret = 0;

            if (len > W5100.GetTxMAX(s))
            {
                ret = W5100.GetTxMAX(s);                         // check size not to exceed MAX size.
            }
            else
            {
                ret = len;
            }

            if (ret != 0)
            {
                // copy data
                W5100.SendDataProc(s, buf, ret);
                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.CR, (byte)CR_val.Sn_CR_SEND);
                /* +2008.01 bj */
                while (W5100.IINCHIP_READ(s, W5100.SocketRegisters.CR) != 0)
                {
                    ;
                }
                /* ------- */

                while ((W5100.IINCHIP_READ(s, W5100.SocketRegisters.IR) & (byte)IR_val.Sn_IR_SEND_OK) != (byte)IR_val.Sn_IR_SEND_OK)
                {
                    status = W5100.IINCHIP_READ(s, W5100.SocketRegisters.SR);
                    if ((W5100.IINCHIP_READ(s, W5100.SocketRegisters.IR) & (byte)IR_val.Sn_IR_TIMEOUT) != 0)
                    {
                        Debug.Print("igmpsend fail.\r\n");
                        Close();

                        return(0);
                    }
                }

                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.IR, (byte)IR_val.Sn_IR_SEND_OK);
            }
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// This function is an application I/F function which is used to send the data for other then TCP mode.
        /// Unlike TCP transmission, The peer's destination address and the port is needed.
        /// </summary>
        /// <param name="buf">a pointer to the data</param>
        /// <param name="len">the data size to send</param>
        /// <param name="addr">the peer's Destination IP address </param>
        /// <param name="port">the peer's destination port number </param>
        /// <returns>This function return send data size for success else -1</returns>
        public int Sendto(
            byte [] buf,
            int len,
            byte[] addr,
            UInt16 port
            )
        {
            //	uint8 status=0;
            //	uint8 isr=0;
            byte s   = _scoket_number;
            int  ret = 0;

            if (len > W5100.GetTxMAX(s))
            {
                ret = W5100.GetTxMAX(s);                         // check size not to exceed MAX size.
            }
            else
            {
                ret = len;
            }

            if
            (
                ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
                ((port == 0x00)) || (len == 0)
            )
            {
                /* +2008.01 [bj] : added return value */

                //#ifdef __DEF_IINCHIP_DBG__
                //  printf("%d Fail[%.2x.%.2x.%.2x.%.2x, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len);
                throw new Exception("Fail[invalid ip,port]\r\n");
                //#endif
            }
            else
            {
                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.DIPR0, addr[0]);
                W5100.IINCHIP_WRITE(s, (W5100.SocketRegisters.DIPR0 + 1), addr[1]);
                W5100.IINCHIP_WRITE(s, (W5100.SocketRegisters.DIPR0 + 2), addr[2]);
                W5100.IINCHIP_WRITE(s, (W5100.SocketRegisters.DIPR0 + 3), addr[3]);
                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.DPORT0, (byte)((port & 0xff00) >> 8));
                W5100.IINCHIP_WRITE(s, (W5100.SocketRegisters.DPORT0 + 1), (byte)(port & 0x00ff));

                // copy data
                W5100.SendDataProc(s, buf, ret);
                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.CR, (byte)CR_val.Sn_CR_SEND);

                /* +20071122[chungs]:wait to process the command... */
                while (W5100.IINCHIP_READ(s, W5100.SocketRegisters.CR) != 0)
                {
                    ;
                }
                /* ------- */

                while ((W5100.IINCHIP_READ(s, W5100.SocketRegisters.IR) & (byte)IR_val.Sn_IR_SEND_OK) != (byte)IR_val.Sn_IR_SEND_OK)
                {
                    if ((W5100.IINCHIP_READ(s, W5100.SocketRegisters.IR) & (byte)IR_val.Sn_IR_TIMEOUT) != 0)
                    //#endif
                    {
                        //#ifdef __DEF_IINCHIP_DBG__
                        Debug.Print("send fail.\r\n");
                        //#endif
                        /* +2008.01 [bj]: clear interrupt */
                        //#ifdef __DEF_IINCHIP_INT__
                        //	        putISR(s, getISR(s) & ~(Sn_IR_SEND_OK | Sn_IR_TIMEOUT));  /* clear SEND_OK & TIMEOUT */
                        //#else
                        W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.IR, (byte)(IR_val.Sn_IR_SEND_OK | IR_val.Sn_IR_TIMEOUT)); /* clear SEND_OK & TIMEOUT */
                        //#endif
                        return(0);
                    }
                }

                /* +2008.01 bj */
                //#ifdef __DEF_IINCHIP_INT__
                //      putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
                //#else
                W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.IR, (byte)IR_val.Sn_IR_SEND_OK);
                //#endif
            }
            return(ret);
        }
コード例 #3
0
        /// <summary>
        ///   This function used to send the data in TCP mode
        /// </summary>
        /// <param name="buf">a pointer to data</param>
        /// <param name="len">the data size to be send</param>
        /// <returns>returns 1 if succeeded</returns>
        public int Send(
            byte [] buf,
            int len
            )
        {
            byte s        = _scoket_number;
            byte status   = 0;
            int  freesize = 0;
            int  ret;


            if (len > W5100.GetTxMAX(s))
            {
                ret = W5100.GetTxMAX(s); // check size not to exceed MAX size.
            }
            else
            {
                ret = len;
            }

            // if freebuf is available, start.
            do
            {
                freesize = W5100.Get_TX_FSR(s);
                status   = W5100.IINCHIP_READ(s, W5100.SocketRegisters.SR);
                if ((status != (byte)SR_val.SOCK_ESTABLISHED) && (status != (byte)SR_val.SOCK_CLOSE_WAIT))
                {
                    ret = 0;
                    break;
                }
                Debug.Print("socket " + s.ToString() + "  freesize(" + freesize.ToString() + " empty or error");
            } while (freesize < ret);

            // copy data
            W5100.SendDataProc(s, buf, ret);
            W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.CR, (byte)CR_val.Sn_CR_SEND);

            /* +20071122[chungs]:wait to process the command... */
            while (W5100.IINCHIP_READ(s, W5100.SocketRegisters.CR) != 0)
            {
                ;
            }
            /* ------- */

            /* +2008.01 bj */
            //#ifdef __DEF_IINCHIP_INT__
            //  while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
            //#else
            while ((W5100.IINCHIP_READ(s, W5100.SocketRegisters.IR) & (byte)IR_val.Sn_IR_SEND_OK) != (byte)IR_val.Sn_IR_SEND_OK)
            //#endif
            {
                /* m2008.01 [bj] : reduce code */
                if (W5100.IINCHIP_READ(s, W5100.SocketRegisters.SR) == (byte)SR_val.SOCK_CLOSED)
                {
                    Debug.Print("SOCK_CLOSED.\r\n");

                    Close();
                    return(0);
                }
            }
            /* +2008.01 bj */
            //#ifdef __DEF_IINCHIP_INT__
            //  putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
            //#else
            W5100.IINCHIP_WRITE(s, W5100.SocketRegisters.IR, (byte)IR_val.Sn_IR_SEND_OK);
            //#endif
            return(ret);
        }