Skip to content

Commit

Permalink
Merge pull request #2365 from cmaglie/ide-1.0.x-spi-transaction
Browse files Browse the repository at this point in the history
[IDE 1.0.x (backport from 1.5.x)] SPI Transactions
  • Loading branch information
cmaglie committed Dec 2, 2014
2 parents 060c1e7 + ae402c2 commit 1be99c3
Show file tree
Hide file tree
Showing 45 changed files with 1,071 additions and 456 deletions.
10 changes: 7 additions & 3 deletions build/shared/revisions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
ARDUINO 1.0.7

[libraries]
* Backported GSM from IDE 1.5.x
* EthernetClien: use IANA recommended ephemeral port range, 49152-65535 (Jack Christensen, cifer-lee)
* Backported SPI Transaction API from IDE 1.5.x (Paul Stoffregen)
* Backported GSM from IDE 1.5.x: fix build regression
* Backported Ethernet from IDE 1.5.x
* Backported SD from IDE 1.5.x
* Backported SPI from IDE 1.5.x
* EthernetClient: use IANA recommended ephemeral port range, 49152-65535 (Jack Christensen, cifer-lee)

[core]
* Fixed missing NOT_AN_INTERRUPT constant in digitalPinToInterrupt() macro
* Fixed regression in HardwareSerial::available() introduced with https://github.com/arduino/Arduino/pull/2057
* Fixed performance regression in HardwareSerial::available() introduced with https://github.com/arduino/Arduino/pull/2057

ARDUINO 1.0.6 - 2014.09.16

Expand Down
2 changes: 2 additions & 0 deletions hardware/arduino/cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
extern "C"{
#endif

void yield(void);

#define HIGH 0x1
#define LOW 0x0

Expand Down
31 changes: 31 additions & 0 deletions hardware/arduino/cores/arduino/hooks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2012 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

/**
* Empty yield() hook.
*
* This function is intended to be used by library writers to build
* libraries or sketches that supports cooperative threads.
*
* Its defined as a weak symbol and it can be redefined to implement a
* real cooperative scheduler.
*/
static void __empty() {
// Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));
1 change: 1 addition & 0 deletions hardware/arduino/cores/arduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void delay(unsigned long ms)
uint16_t start = (uint16_t)micros();

while (ms > 0) {
yield();
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
Expand Down
4 changes: 2 additions & 2 deletions libraries/Ethernet/Dhcp.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// DHCP Library v0.3 - April 25, 2009
// Author: Jordan Terrell - blog.jordanterrell.com

#include "w5100.h"
#include "utility/w5100.h"

#include <string.h>
#include <stdlib.h>
#include "Dhcp.h"
#include "Arduino.h"
#include "util.h"
#include "utility/util.h"

int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
{
Expand Down
Empty file modified libraries/Ethernet/Dhcp.h
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions libraries/Ethernet/Dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// (c) Copyright 2009-2010 MCQN Ltd.
// Released under Apache License, version 2.0

#include "w5100.h"
#include "utility/w5100.h"
#include "EthernetUdp.h"
#include "util.h"
#include "utility/util.h"

#include "Dns.h"
#include <string.h>
Expand Down
22 changes: 18 additions & 4 deletions libraries/Ethernet/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "w5100.h"
#include "utility/w5100.h"
#include "Ethernet.h"
#include "Dhcp.h"

Expand All @@ -16,18 +16,22 @@ int EthernetClass::begin(uint8_t *mac_address)

// Initialise the basic info
W5100.init();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac_address);
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
SPI.endTransaction();

// Now try to get our config info from a DHCP server
int ret = _dhcp->beginWithDHCP(mac_address);
if(ret == 1)
{
// We've successfully found a DHCP server and got our configuration info, so set things
// accordingly
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
_dnsServerAddress = _dhcp->getDnsServerIp();
}

Expand Down Expand Up @@ -61,10 +65,12 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
W5100.init();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac);
W5100.setIPAddress(local_ip._address);
W5100.setGatewayIp(gateway._address);
W5100.setSubnetMask(subnet._address);
W5100.setIPAddress(local_ip.raw_address());
W5100.setGatewayIp(gateway.raw_address());
W5100.setSubnetMask(subnet.raw_address());
SPI.endTransaction();
_dnsServerAddress = dns_server;
}

Expand All @@ -80,9 +86,11 @@ int EthernetClass::maintain(){
case DHCP_CHECK_RENEW_OK:
case DHCP_CHECK_REBIND_OK:
//we might have got a new IP.
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
_dnsServerAddress = _dhcp->getDnsServerIp();
break;
default:
Expand All @@ -96,21 +104,27 @@ int EthernetClass::maintain(){
IPAddress EthernetClass::localIP()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getIPAddress(ret.raw_address());
SPI.endTransaction();
return ret;
}

IPAddress EthernetClass::subnetMask()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getSubnetMask(ret.raw_address());
SPI.endTransaction();
return ret;
}

IPAddress EthernetClass::gatewayIP()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getGatewayIp(ret.raw_address());
SPI.endTransaction();
return ret;
}

Expand Down
13 changes: 6 additions & 7 deletions libraries/Ethernet/EthernetClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "w5100.h"
#include "socket.h"
#include "utility/w5100.h"
#include "utility/socket.h"

extern "C" {
#include "string.h"
Expand Down Expand Up @@ -40,7 +40,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) {
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
_sock = i;
break;
Expand Down Expand Up @@ -88,7 +88,7 @@ size_t EthernetClient::write(const uint8_t *buf, size_t size) {

int EthernetClient::available() {
if (_sock != MAX_SOCK_NUM)
return W5100.getRXReceivedSize(_sock);
return recvAvailable(_sock);
return 0;
}

Expand Down Expand Up @@ -120,8 +120,7 @@ int EthernetClient::peek() {
}

void EthernetClient::flush() {
while (available())
read();
::flush(_sock);
}

void EthernetClient::stop() {
Expand Down Expand Up @@ -154,7 +153,7 @@ uint8_t EthernetClient::connected() {

uint8_t EthernetClient::status() {
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
return W5100.readSnSR(_sock);
return socketStatus(_sock);
}

// the next function allows us to use the client returned by
Expand Down
4 changes: 2 additions & 2 deletions libraries/Ethernet/EthernetServer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "w5100.h"
#include "socket.h"
#include "utility/w5100.h"
#include "utility/socket.h"
extern "C" {
#include "string.h"
}
Expand Down
8 changes: 4 additions & 4 deletions libraries/Ethernet/EthernetUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* [email protected] 12/30/2008
*/

#include "w5100.h"
#include "socket.h"
#include "utility/w5100.h"
#include "utility/socket.h"
#include "Ethernet.h"
#include "Udp.h"
#include "Dns.h"
Expand All @@ -41,7 +41,7 @@ uint8_t EthernetUDP::begin(uint16_t port) {
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
Expand Down Expand Up @@ -120,7 +120,7 @@ int EthernetUDP::parsePacket()
// discard any remaining bytes in the last packet
flush();

if (W5100.getRXReceivedSize(_sock) > 0)
if (recvAvailable(_sock) > 0)
{
//HACK - hand-parse the UDP packet using TCP recv method
uint8_t tmpBuf[8];
Expand Down
Loading

0 comments on commit 1be99c3

Please sign in to comment.