Skip to content

Commit 1be99c3

Browse files
committed
Merge pull request #2365 from cmaglie/ide-1.0.x-spi-transaction
[IDE 1.0.x (backport from 1.5.x)] SPI Transactions
2 parents 060c1e7 + ae402c2 commit 1be99c3

File tree

45 files changed

+1071
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1071
-456
lines changed

build/shared/revisions.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
ARDUINO 1.0.7
33

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

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

1216
ARDUINO 1.0.6 - 2014.09.16
1317

hardware/arduino/cores/arduino/Arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
extern "C"{
3535
#endif
3636

37+
void yield(void);
38+
3739
#define HIGH 0x1
3840
#define LOW 0x0
3941

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright (c) 2012 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**
20+
* Empty yield() hook.
21+
*
22+
* This function is intended to be used by library writers to build
23+
* libraries or sketches that supports cooperative threads.
24+
*
25+
* Its defined as a weak symbol and it can be redefined to implement a
26+
* real cooperative scheduler.
27+
*/
28+
static void __empty() {
29+
// Empty
30+
}
31+
void yield(void) __attribute__ ((weak, alias("__empty")));

hardware/arduino/cores/arduino/wiring.c

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ void delay(unsigned long ms)
111111
uint16_t start = (uint16_t)micros();
112112

113113
while (ms > 0) {
114+
yield();
114115
if (((uint16_t)micros() - start) >= 1000) {
115116
ms--;
116117
start += 1000;

libraries/Ethernet/Dhcp.cpp

100755100644
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// DHCP Library v0.3 - April 25, 2009
22
// Author: Jordan Terrell - blog.jordanterrell.com
33

4-
#include "w5100.h"
4+
#include "utility/w5100.h"
55

66
#include <string.h>
77
#include <stdlib.h>
88
#include "Dhcp.h"
99
#include "Arduino.h"
10-
#include "util.h"
10+
#include "utility/util.h"
1111

1212
int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
1313
{

libraries/Ethernet/Dhcp.h

100755100644
File mode changed.

libraries/Ethernet/Dns.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// (c) Copyright 2009-2010 MCQN Ltd.
33
// Released under Apache License, version 2.0
44

5-
#include "w5100.h"
5+
#include "utility/w5100.h"
66
#include "EthernetUdp.h"
7-
#include "util.h"
7+
#include "utility/util.h"
88

99
#include "Dns.h"
1010
#include <string.h>

libraries/Ethernet/Ethernet.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "w5100.h"
1+
#include "utility/w5100.h"
22
#include "Ethernet.h"
33
#include "Dhcp.h"
44

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

1717
// Initialise the basic info
1818
W5100.init();
19+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
1920
W5100.setMACAddress(mac_address);
2021
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
22+
SPI.endTransaction();
2123

2224
// Now try to get our config info from a DHCP server
2325
int ret = _dhcp->beginWithDHCP(mac_address);
2426
if(ret == 1)
2527
{
2628
// We've successfully found a DHCP server and got our configuration info, so set things
2729
// accordingly
30+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
2831
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
2932
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
3033
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
34+
SPI.endTransaction();
3135
_dnsServerAddress = _dhcp->getDnsServerIp();
3236
}
3337

@@ -61,10 +65,12 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
6165
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
6266
{
6367
W5100.init();
68+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
6469
W5100.setMACAddress(mac);
65-
W5100.setIPAddress(local_ip._address);
66-
W5100.setGatewayIp(gateway._address);
67-
W5100.setSubnetMask(subnet._address);
70+
W5100.setIPAddress(local_ip.raw_address());
71+
W5100.setGatewayIp(gateway.raw_address());
72+
W5100.setSubnetMask(subnet.raw_address());
73+
SPI.endTransaction();
6874
_dnsServerAddress = dns_server;
6975
}
7076

@@ -80,9 +86,11 @@ int EthernetClass::maintain(){
8086
case DHCP_CHECK_RENEW_OK:
8187
case DHCP_CHECK_REBIND_OK:
8288
//we might have got a new IP.
89+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
8390
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
8491
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
8592
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
93+
SPI.endTransaction();
8694
_dnsServerAddress = _dhcp->getDnsServerIp();
8795
break;
8896
default:
@@ -96,21 +104,27 @@ int EthernetClass::maintain(){
96104
IPAddress EthernetClass::localIP()
97105
{
98106
IPAddress ret;
107+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
99108
W5100.getIPAddress(ret.raw_address());
109+
SPI.endTransaction();
100110
return ret;
101111
}
102112

103113
IPAddress EthernetClass::subnetMask()
104114
{
105115
IPAddress ret;
116+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
106117
W5100.getSubnetMask(ret.raw_address());
118+
SPI.endTransaction();
107119
return ret;
108120
}
109121

110122
IPAddress EthernetClass::gatewayIP()
111123
{
112124
IPAddress ret;
125+
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
113126
W5100.getGatewayIp(ret.raw_address());
127+
SPI.endTransaction();
114128
return ret;
115129
}
116130

libraries/Ethernet/EthernetClient.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "w5100.h"
2-
#include "socket.h"
1+
#include "utility/w5100.h"
2+
#include "utility/socket.h"
33

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

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

8989
int EthernetClient::available() {
9090
if (_sock != MAX_SOCK_NUM)
91-
return W5100.getRXReceivedSize(_sock);
91+
return recvAvailable(_sock);
9292
return 0;
9393
}
9494

@@ -120,8 +120,7 @@ int EthernetClient::peek() {
120120
}
121121

122122
void EthernetClient::flush() {
123-
while (available())
124-
read();
123+
::flush(_sock);
125124
}
126125

127126
void EthernetClient::stop() {
@@ -154,7 +153,7 @@ uint8_t EthernetClient::connected() {
154153

155154
uint8_t EthernetClient::status() {
156155
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
157-
return W5100.readSnSR(_sock);
156+
return socketStatus(_sock);
158157
}
159158

160159
// the next function allows us to use the client returned by

libraries/Ethernet/EthernetServer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "w5100.h"
2-
#include "socket.h"
1+
#include "utility/w5100.h"
2+
#include "utility/socket.h"
33
extern "C" {
44
#include "string.h"
55
}

libraries/Ethernet/EthernetUdp.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* [email protected] 12/30/2008
2727
*/
2828

29-
#include "w5100.h"
30-
#include "socket.h"
29+
#include "utility/w5100.h"
30+
#include "utility/socket.h"
3131
#include "Ethernet.h"
3232
#include "Udp.h"
3333
#include "Dns.h"
@@ -41,7 +41,7 @@ uint8_t EthernetUDP::begin(uint16_t port) {
4141
return 0;
4242

4343
for (int i = 0; i < MAX_SOCK_NUM; i++) {
44-
uint8_t s = W5100.readSnSR(i);
44+
uint8_t s = socketStatus(i);
4545
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
4646
_sock = i;
4747
break;
@@ -120,7 +120,7 @@ int EthernetUDP::parsePacket()
120120
// discard any remaining bytes in the last packet
121121
flush();
122122

123-
if (W5100.getRXReceivedSize(_sock) > 0)
123+
if (recvAvailable(_sock) > 0)
124124
{
125125
//HACK - hand-parse the UDP packet using TCP recv method
126126
uint8_t tmpBuf[8];

0 commit comments

Comments
 (0)