adjust root folder
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
|
||||
* SPI Master library for arduino.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of either the GNU General Public License version 2
|
||||
* or the GNU Lesser General Public License version 2.1, both as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "pins_arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
SPIClass SPI;
|
||||
|
||||
void SPIClass::begin() {
|
||||
|
||||
// Set SS to high so a connected chip will be "deselected" by default
|
||||
digitalWrite(SS, HIGH);
|
||||
|
||||
// When the SS pin is set as OUTPUT, it can be used as
|
||||
// a general purpose output port (it doesn't influence
|
||||
// SPI operations).
|
||||
pinMode(SS, OUTPUT);
|
||||
|
||||
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||
// automatically switches to Slave, so the data direction of
|
||||
// the SS pin MUST be kept as OUTPUT.
|
||||
SPCR |= _BV(MSTR);
|
||||
SPCR |= _BV(SPE);
|
||||
|
||||
// Set direction register for SCK and MOSI pin.
|
||||
// MISO pin automatically overrides to INPUT.
|
||||
// By doing this AFTER enabling SPI, we avoid accidentally
|
||||
// clocking in a single bit since the lines go directly
|
||||
// from "input" to SPI control.
|
||||
// http://code.google.com/p/arduino/issues/detail?id=888
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void SPIClass::end() {
|
||||
SPCR &= ~_BV(SPE);
|
||||
}
|
||||
|
||||
void SPIClass::setBitOrder(uint8_t bitOrder)
|
||||
{
|
||||
if(bitOrder == LSBFIRST) {
|
||||
SPCR |= _BV(DORD);
|
||||
} else {
|
||||
SPCR &= ~(_BV(DORD));
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t mode)
|
||||
{
|
||||
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t rate)
|
||||
{
|
||||
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
|
||||
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
#include "w5100.h"
|
||||
#include "socket.h"
|
||||
|
||||
static uint16_t local_port;
|
||||
|
||||
/**
|
||||
* @brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it.
|
||||
* @return 1 for success else 0.
|
||||
*/
|
||||
uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
|
||||
{
|
||||
if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE))
|
||||
{
|
||||
close(s);
|
||||
W5100.writeSnMR(s, protocol | flag);
|
||||
if (port != 0) {
|
||||
W5100.writeSnPORT(s, port);
|
||||
}
|
||||
else {
|
||||
local_port++; // if don't set the source port, set local_port number.
|
||||
W5100.writeSnPORT(s, local_port);
|
||||
}
|
||||
|
||||
W5100.execCmdSn(s, Sock_OPEN);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function close the socket and parameter is "s" which represent the socket number
|
||||
*/
|
||||
void close(SOCKET s)
|
||||
{
|
||||
W5100.execCmdSn(s, Sock_CLOSE);
|
||||
W5100.writeSnIR(s, 0xFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer.
|
||||
* @return 1 for success else 0.
|
||||
*/
|
||||
uint8_t listen(SOCKET s)
|
||||
{
|
||||
if (W5100.readSnSR(s) != SnSR::INIT)
|
||||
return 0;
|
||||
W5100.execCmdSn(s, Sock_LISTEN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function established the connection for the channel in Active (client) mode.
|
||||
* This function waits for the untill the connection is established.
|
||||
*
|
||||
* @return 1 for success else 0.
|
||||
*/
|
||||
uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port)
|
||||
{
|
||||
if
|
||||
(
|
||||
((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
|
||||
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
|
||||
(port == 0x00)
|
||||
)
|
||||
return 0;
|
||||
|
||||
// set destination IP
|
||||
W5100.writeSnDIPR(s, addr);
|
||||
W5100.writeSnDPORT(s, port);
|
||||
W5100.execCmdSn(s, Sock_CONNECT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function used for disconnect the socket and parameter is "s" which represent the socket number
|
||||
* @return 1 for success else 0.
|
||||
*/
|
||||
void disconnect(SOCKET s)
|
||||
{
|
||||
W5100.execCmdSn(s, Sock_DISCON);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function used to send the data in TCP mode
|
||||
* @return 1 for success else 0.
|
||||
*/
|
||||
uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
|
||||
{
|
||||
uint8_t status=0;
|
||||
uint16_t ret=0;
|
||||
uint16_t freesize=0;
|
||||
|
||||
if (len > W5100.SSIZE)
|
||||
ret = W5100.SSIZE; // check size not to exceed MAX size.
|
||||
else
|
||||
ret = len;
|
||||
|
||||
// if freebuf is available, start.
|
||||
do
|
||||
{
|
||||
freesize = W5100.getTXFreeSize(s);
|
||||
status = W5100.readSnSR(s);
|
||||
if ((status != SnSR::ESTABLISHED) && (status != SnSR::CLOSE_WAIT))
|
||||
{
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (freesize < ret);
|
||||
|
||||
// copy data
|
||||
W5100.send_data_processing(s, (uint8_t *)buf, ret);
|
||||
W5100.execCmdSn(s, Sock_SEND);
|
||||
|
||||
/* +2008.01 bj */
|
||||
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
|
||||
{
|
||||
/* m2008.01 [bj] : reduce code */
|
||||
if ( W5100.readSnSR(s) == SnSR::CLOSED )
|
||||
{
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* +2008.01 bj */
|
||||
W5100.writeSnIR(s, SnIR::SEND_OK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is an application I/F function which is used to receive the data in TCP mode.
|
||||
* It continues to wait for data as much as the application wants to receive.
|
||||
*
|
||||
* @return received data size for success else -1.
|
||||
*/
|
||||
int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
|
||||
{
|
||||
// Check how much data is available
|
||||
int16_t ret = W5100.getRXReceivedSize(s);
|
||||
if ( ret == 0 )
|
||||
{
|
||||
// No data available.
|
||||
uint8_t status = W5100.readSnSR(s);
|
||||
if ( status == SnSR::LISTEN || status == SnSR::CLOSED || status == SnSR::CLOSE_WAIT )
|
||||
{
|
||||
// The remote end has closed its side of the connection, so this is the eof state
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The connection is still up, but there's no data waiting to be read
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
else if (ret > len)
|
||||
{
|
||||
ret = len;
|
||||
}
|
||||
|
||||
if ( ret > 0 )
|
||||
{
|
||||
W5100.recv_data_processing(s, buf, ret);
|
||||
W5100.execCmdSn(s, Sock_RECV);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the first byte in the receive queue (no checking)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
uint16_t peek(SOCKET s, uint8_t *buf)
|
||||
{
|
||||
W5100.recv_data_processing(s, buf, 1, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 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.
|
||||
*
|
||||
* @return This function return send data size for success else -1.
|
||||
*/
|
||||
uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
|
||||
{
|
||||
uint16_t ret=0;
|
||||
|
||||
if (len > W5100.SSIZE) ret = W5100.SSIZE; // 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)) ||(ret == 0)
|
||||
)
|
||||
{
|
||||
/* +2008.01 [bj] : added return value */
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
W5100.writeSnDIPR(s, addr);
|
||||
W5100.writeSnDPORT(s, port);
|
||||
|
||||
// copy data
|
||||
W5100.send_data_processing(s, (uint8_t *)buf, ret);
|
||||
W5100.execCmdSn(s, Sock_SEND);
|
||||
|
||||
/* +2008.01 bj */
|
||||
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
|
||||
{
|
||||
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
|
||||
{
|
||||
/* +2008.01 [bj]: clear interrupt */
|
||||
W5100.writeSnIR(s, (SnIR::SEND_OK | SnIR::TIMEOUT)); /* clear SEND_OK & TIMEOUT */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* +2008.01 bj */
|
||||
W5100.writeSnIR(s, SnIR::SEND_OK);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is an application I/F function which is used to receive the data in other then
|
||||
* TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well.
|
||||
*
|
||||
* @return This function return received data size for success else -1.
|
||||
*/
|
||||
uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
|
||||
{
|
||||
uint8_t head[8];
|
||||
uint16_t data_len=0;
|
||||
uint16_t ptr=0;
|
||||
|
||||
if ( len > 0 )
|
||||
{
|
||||
ptr = W5100.readSnRX_RD(s);
|
||||
switch (W5100.readSnMR(s) & 0x07)
|
||||
{
|
||||
case SnMR::UDP :
|
||||
W5100.read_data(s, (uint8_t *)ptr, head, 0x08);
|
||||
ptr += 8;
|
||||
// read peer's IP address, port number.
|
||||
addr[0] = head[0];
|
||||
addr[1] = head[1];
|
||||
addr[2] = head[2];
|
||||
addr[3] = head[3];
|
||||
*port = head[4];
|
||||
*port = (*port << 8) + head[5];
|
||||
data_len = head[6];
|
||||
data_len = (data_len << 8) + head[7];
|
||||
|
||||
W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy.
|
||||
ptr += data_len;
|
||||
|
||||
W5100.writeSnRX_RD(s, ptr);
|
||||
break;
|
||||
|
||||
case SnMR::IPRAW :
|
||||
W5100.read_data(s, (uint8_t *)ptr, head, 0x06);
|
||||
ptr += 6;
|
||||
|
||||
addr[0] = head[0];
|
||||
addr[1] = head[1];
|
||||
addr[2] = head[2];
|
||||
addr[3] = head[3];
|
||||
data_len = head[4];
|
||||
data_len = (data_len << 8) + head[5];
|
||||
|
||||
W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy.
|
||||
ptr += data_len;
|
||||
|
||||
W5100.writeSnRX_RD(s, ptr);
|
||||
break;
|
||||
|
||||
case SnMR::MACRAW:
|
||||
W5100.read_data(s,(uint8_t*)ptr,head,2);
|
||||
ptr+=2;
|
||||
data_len = head[0];
|
||||
data_len = (data_len<<8) + head[1] - 2;
|
||||
|
||||
W5100.read_data(s,(uint8_t*) ptr,buf,data_len);
|
||||
ptr += data_len;
|
||||
W5100.writeSnRX_RD(s, ptr);
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
W5100.execCmdSn(s, Sock_RECV);
|
||||
}
|
||||
return data_len;
|
||||
}
|
||||
|
||||
|
||||
uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)
|
||||
{
|
||||
uint8_t status=0;
|
||||
uint16_t ret=0;
|
||||
|
||||
if (len > W5100.SSIZE)
|
||||
ret = W5100.SSIZE; // check size not to exceed MAX size.
|
||||
else
|
||||
ret = len;
|
||||
|
||||
if (ret == 0)
|
||||
return 0;
|
||||
|
||||
W5100.send_data_processing(s, (uint8_t *)buf, ret);
|
||||
W5100.execCmdSn(s, Sock_SEND);
|
||||
|
||||
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
|
||||
{
|
||||
status = W5100.readSnSR(s);
|
||||
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
|
||||
{
|
||||
/* in case of igmp, if send fails, then socket closed */
|
||||
/* if you want change, remove this code. */
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
W5100.writeSnIR(s, SnIR::SEND_OK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len)
|
||||
{
|
||||
uint16_t ret =0;
|
||||
if (len > W5100.getTXFreeSize(s))
|
||||
{
|
||||
ret = W5100.getTXFreeSize(s); // check size not to exceed MAX size.
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = len;
|
||||
}
|
||||
W5100.send_data_processing_offset(s, offset, buf, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int startUDP(SOCKET s, uint8_t* addr, uint16_t port)
|
||||
{
|
||||
if
|
||||
(
|
||||
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
|
||||
((port == 0x00))
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
W5100.writeSnDIPR(s, addr);
|
||||
W5100.writeSnDPORT(s, port);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int sendUDP(SOCKET s)
|
||||
{
|
||||
W5100.execCmdSn(s, Sock_SEND);
|
||||
|
||||
/* +2008.01 bj */
|
||||
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
|
||||
{
|
||||
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
|
||||
{
|
||||
/* +2008.01 [bj]: clear interrupt */
|
||||
W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* +2008.01 bj */
|
||||
W5100.writeSnIR(s, SnIR::SEND_OK);
|
||||
|
||||
/* Sent ok */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of either the GNU General Public License version 2
|
||||
* or the GNU Lesser General Public License version 2.1, both as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "w5100.h"
|
||||
|
||||
// W5100 controller instance
|
||||
W5100Class W5100;
|
||||
|
||||
#define TX_RX_MAX_BUF_SIZE 2048
|
||||
#define TX_BUF 0x1100
|
||||
#define RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)
|
||||
|
||||
#define TXBUF_BASE 0x4000
|
||||
#define RXBUF_BASE 0x6000
|
||||
|
||||
void W5100Class::init(void)
|
||||
{
|
||||
delay(300);
|
||||
|
||||
SPI.begin();
|
||||
initSS();
|
||||
|
||||
writeMR(1<<RST);
|
||||
writeTMSR(0x55);
|
||||
writeRMSR(0x55);
|
||||
|
||||
for (int i=0; i<MAX_SOCK_NUM; i++) {
|
||||
SBASE[i] = TXBUF_BASE + SSIZE * i;
|
||||
RBASE[i] = RXBUF_BASE + RSIZE * i;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t W5100Class::getTXFreeSize(SOCKET s)
|
||||
{
|
||||
uint16_t val=0, val1=0;
|
||||
do {
|
||||
val1 = readSnTX_FSR(s);
|
||||
if (val1 != 0)
|
||||
val = readSnTX_FSR(s);
|
||||
}
|
||||
while (val != val1);
|
||||
return val;
|
||||
}
|
||||
|
||||
uint16_t W5100Class::getRXReceivedSize(SOCKET s)
|
||||
{
|
||||
uint16_t val=0,val1=0;
|
||||
do {
|
||||
val1 = readSnRX_RSR(s);
|
||||
if (val1 != 0)
|
||||
val = readSnRX_RSR(s);
|
||||
}
|
||||
while (val != val1);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
void W5100Class::send_data_processing(SOCKET s, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
// This is same as having no offset in a call to send_data_processing_offset
|
||||
send_data_processing_offset(s, 0, data, len);
|
||||
}
|
||||
|
||||
void W5100Class::send_data_processing_offset(SOCKET s, uint16_t data_offset, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
uint16_t ptr = readSnTX_WR(s);
|
||||
ptr += data_offset;
|
||||
uint16_t offset = ptr & SMASK;
|
||||
uint16_t dstAddr = offset + SBASE[s];
|
||||
|
||||
if (offset + len > SSIZE)
|
||||
{
|
||||
// Wrap around circular buffer
|
||||
uint16_t size = SSIZE - offset;
|
||||
write(dstAddr, data, size);
|
||||
write(SBASE[s], data + size, len - size);
|
||||
}
|
||||
else {
|
||||
write(dstAddr, data, len);
|
||||
}
|
||||
|
||||
ptr += len;
|
||||
writeSnTX_WR(s, ptr);
|
||||
}
|
||||
|
||||
|
||||
void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
|
||||
{
|
||||
uint16_t ptr;
|
||||
ptr = readSnRX_RD(s);
|
||||
read_data(s, (uint8_t *)ptr, data, len);
|
||||
if (!peek)
|
||||
{
|
||||
ptr += len;
|
||||
writeSnRX_RD(s, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len)
|
||||
{
|
||||
uint16_t size;
|
||||
uint16_t src_mask;
|
||||
uint16_t src_ptr;
|
||||
|
||||
src_mask = (uint16_t)src & RMASK;
|
||||
src_ptr = RBASE[s] + src_mask;
|
||||
|
||||
if( (src_mask + len) > RSIZE )
|
||||
{
|
||||
size = RSIZE - src_mask;
|
||||
read(src_ptr, (uint8_t *)dst, size);
|
||||
dst += size;
|
||||
read(RBASE[s], (uint8_t *) dst, len - size);
|
||||
}
|
||||
else
|
||||
read(src_ptr, (uint8_t *) dst, len);
|
||||
}
|
||||
|
||||
|
||||
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
|
||||
{
|
||||
setSS();
|
||||
SPI.transfer(0xF0);
|
||||
SPI.transfer(_addr >> 8);
|
||||
SPI.transfer(_addr & 0xFF);
|
||||
SPI.transfer(_data);
|
||||
resetSS();
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
|
||||
{
|
||||
for (uint16_t i=0; i<_len; i++)
|
||||
{
|
||||
setSS();
|
||||
SPI.transfer(0xF0);
|
||||
SPI.transfer(_addr >> 8);
|
||||
SPI.transfer(_addr & 0xFF);
|
||||
_addr++;
|
||||
SPI.transfer(_buf[i]);
|
||||
resetSS();
|
||||
}
|
||||
return _len;
|
||||
}
|
||||
|
||||
uint8_t W5100Class::read(uint16_t _addr)
|
||||
{
|
||||
setSS();
|
||||
SPI.transfer(0x0F);
|
||||
SPI.transfer(_addr >> 8);
|
||||
SPI.transfer(_addr & 0xFF);
|
||||
uint8_t _data = SPI.transfer(0);
|
||||
resetSS();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
|
||||
{
|
||||
for (uint16_t i=0; i<_len; i++)
|
||||
{
|
||||
setSS();
|
||||
SPI.transfer(0x0F);
|
||||
SPI.transfer(_addr >> 8);
|
||||
SPI.transfer(_addr & 0xFF);
|
||||
_addr++;
|
||||
_buf[i] = SPI.transfer(0);
|
||||
resetSS();
|
||||
}
|
||||
return _len;
|
||||
}
|
||||
|
||||
void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
|
||||
// Send command to socket
|
||||
writeSnCR(s, _cmd);
|
||||
// Wait for command to complete
|
||||
while (readSnCR(s))
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* w5100Wrapper.cpp
|
||||
*
|
||||
* Created on: 26 de Mai de 2013
|
||||
* Author: mgf
|
||||
*/
|
||||
|
||||
|
||||
#include "w5100.h"
|
||||
#include "w5100Wrapper.h"
|
||||
|
||||
extern "C"{
|
||||
|
||||
CSnMR * CSnMR_new(){
|
||||
SnMR* s = new SnMR();
|
||||
return (CSnMR*)s;
|
||||
}
|
||||
void CSnMR_delete(const CSnMR* obj){
|
||||
SnMR* s = (SnMR*)obj;
|
||||
delete s;
|
||||
}
|
||||
uint8_t SnMR_CLOSE(){ return SnMR::CLOSE; }
|
||||
uint8_t SnMR_UDP(){ return SnMR::UDP; }
|
||||
uint8_t SnMR_TCP(){ return SnMR::TCP; }
|
||||
uint8_t SnMR_IPRAW(){ return SnMR::IPRAW; }
|
||||
uint8_t SnMR_MACRAW(){ return SnMR::MACRAW; }
|
||||
uint8_t SnMR_PPPOE(){ return SnMR::PPPOE; }
|
||||
uint8_t SnMR_ND(){ return SnMR::ND; }
|
||||
uint8_t SnMR_MULTI(){ return SnMR::MULTI; }
|
||||
|
||||
CSnIR * CSnIR_new(){
|
||||
SnIR* s = new SnIR();
|
||||
return (CSnIR*) s;
|
||||
}
|
||||
void CSnIR_delete(const CSnIR* obj){
|
||||
SnIR* s = (SnIR*)obj;
|
||||
delete s;
|
||||
}
|
||||
uint8_t SnIR_SEND_OK(){ return SnIR::SEND_OK; }
|
||||
uint8_t SnIR_TIMEOUT(){ return SnIR::TIMEOUT; }
|
||||
uint8_t SnIR_RECV(){ return SnIR::RECV; }
|
||||
uint8_t SnIR_DISCON(){ return SnIR::DISCON; }
|
||||
uint8_t SnIR_CON(){ return SnIR::CON; }
|
||||
|
||||
CSnSR * CSnSR_new(){
|
||||
SnSR* s = new SnSR();
|
||||
return (CSnSR*) s;
|
||||
}
|
||||
void CSnSR_delete(const CSnSR* obj){
|
||||
SnSR* s = (SnSR*)obj;
|
||||
delete s;
|
||||
}
|
||||
uint8_t SnSR_CLOSED(){ return SnSR::CLOSED; }
|
||||
uint8_t SnSR_INIT(){ return SnSR::INIT; }
|
||||
uint8_t SnSR_LISTEN(){ return SnSR::LISTEN; }
|
||||
uint8_t SnSR_SYNSENT(){ return SnSR::SYNSENT; }
|
||||
uint8_t SnSR_SYNRECV(){ return SnSR::SYNRECV; }
|
||||
uint8_t SnSR_ESTABLISHED(){ return SnSR::ESTABLISHED; }
|
||||
uint8_t SnSR_FIN_WAIT(){ return SnSR::FIN_WAIT; }
|
||||
uint8_t SnSR_CLOSING(){ return SnSR::CLOSING; }
|
||||
uint8_t SnSR_TIME_WAIT(){ return SnSR::TIME_WAIT; }
|
||||
uint8_t SnSR_CLOSE_WAIT(){ return SnSR::CLOSE_WAIT; }
|
||||
uint8_t SnSR_LAST_ACK(){ return SnSR::LAST_ACK; }
|
||||
uint8_t SnSR_UDP(){ return SnSR::UDP; }
|
||||
uint8_t SnSR_IPRAW(){ return SnSR::IPRAW; }
|
||||
uint8_t SnSR_MACRAW(){ return SnSR::MACRAW; }
|
||||
uint8_t SnSR_PPPOE(){ return SnSR::PPPOE; }
|
||||
|
||||
CIPPROTO * CIPPROTO_new(){
|
||||
IPPROTO* i = new IPPROTO();
|
||||
return (CIPPROTO*) i;
|
||||
}
|
||||
void CIPPROTO_delete(const CIPPROTO* obj){
|
||||
IPPROTO* i = (IPPROTO*) obj;
|
||||
delete i;
|
||||
}
|
||||
uint8_t IPPROTO_IP(){ return IPPROTO::IP; }
|
||||
uint8_t IPPROTO_ICMP(){ return IPPROTO::ICMP; }
|
||||
uint8_t IPPROTO_IGMP(){ return IPPROTO::IGMP; }
|
||||
uint8_t IPPROTO_GGP(){ return IPPROTO::GGP; }
|
||||
uint8_t IPPROTO_TCP(){ return IPPROTO::TCP; }
|
||||
uint8_t IPPROTO_PUP(){ return IPPROTO::PUP; }
|
||||
uint8_t IPPROTO_UDP(){ return IPPROTO::UDP; }
|
||||
uint8_t IPPROTO_IDP(){ return IPPROTO::IDP; }
|
||||
uint8_t IPPROTO_ND(){ return IPPROTO::ND; }
|
||||
uint8_t IPPROTO_RAW(){ return IPPROTO::RAW; }
|
||||
|
||||
CW5100Class * CW5100Class_new(){
|
||||
return (CW5100Class*) &W5100;
|
||||
}
|
||||
|
||||
void init_func(const CW5100Class * obj){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->init();
|
||||
}
|
||||
|
||||
void read_data_func(const CW5100Class * obj, SOCKET s, volatile uint8_t * src, volatile uint8_t * dst,
|
||||
uint16_t len){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->read_data(s, src, dst, len);
|
||||
}
|
||||
|
||||
void send_data_processing_func(const CW5100Class * obj, SOCKET s, const uint8_t *data, uint16_t len){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->send_data_processing(s, data, len);
|
||||
}
|
||||
void send_data_processing_offset_func(const CW5100Class * obj, SOCKET s, uint16_t data_offset,
|
||||
const uint8_t *data, uint16_t len){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->send_data_processing_offset(s, data_offset, data, len);
|
||||
}
|
||||
//FIXME: Removed defaul value of 0(zero) from the peek argument
|
||||
void recv_data_processing_func(const CW5100Class * obj, SOCKET s, uint8_t *data, uint16_t len,
|
||||
uint8_t peek){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->recv_data_processing(s, data, len, peek);
|
||||
}
|
||||
void setGatewayIp_func(const CW5100Class * obj, uint8_t *_addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setGatewayIp(_addr);
|
||||
}
|
||||
void getGatewayIp_func(const CW5100Class * obj, uint8_t *_addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->getGatewayIp(_addr);
|
||||
}
|
||||
|
||||
void setSubnetMask_func(const CW5100Class * obj, uint8_t *_addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setSubnetMask(_addr);
|
||||
}
|
||||
void getSubnetMask_func(const CW5100Class * obj, uint8_t *_addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->getSubnetMask(_addr);
|
||||
}
|
||||
|
||||
void setMACAddress_func(const CW5100Class * obj, uint8_t * addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setMACAddress(addr);
|
||||
}
|
||||
void getMACAddress_func(const CW5100Class * obj, uint8_t * addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->getMACAddress(addr);
|
||||
}
|
||||
void setIPAddress_func(const CW5100Class * obj, uint8_t * addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setIPAddress(addr);
|
||||
}
|
||||
void getIPAddress_func(const CW5100Class * obj, uint8_t * addr){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->getIPAddress(addr);
|
||||
}
|
||||
void setRetransmissionTime_func(const CW5100Class * obj, uint16_t timeout){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setRetransmissionTime(timeout);
|
||||
}
|
||||
void setRetransmissionCount_func(const CW5100Class * obj, uint8_t _retry){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
w->setRetransmissionCount(_retry);
|
||||
}
|
||||
|
||||
uint16_t getTXFreeSize_func(const CW5100Class * obj,SOCKET s){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
return w->getTXFreeSize(s);
|
||||
}
|
||||
uint16_t getRXReceivedSize_func(const CW5100Class * obj,SOCKET s){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
return w->getRXReceivedSize(s);
|
||||
}
|
||||
|
||||
uint8_t readSnSR_func(const CW5100Class* obj, SOCKET s){
|
||||
W5100Class* w = (W5100Class*) obj;
|
||||
return w->readSnSR(s);
|
||||
}
|
||||
|
||||
}//externC
|
||||
|
||||
Reference in New Issue
Block a user