Skip to content

Commit

Permalink
#45 Fixes to compilation issues in udp/spi systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Dec 23, 2022
1 parent 2d14d52 commit f742a5f
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 73 deletions.
28 changes: 28 additions & 0 deletions receivers/native/arm/peripherals/spi/all/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-spi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>zcode-receivers-spi-all</artifactId>
<packaging>nar</packaging>
<name>Zcode full peripheral set</name>

<dependencies>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-spi-for-wiznet</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-spi-for-wiznet-stm32</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions receivers/native/arm/peripherals/spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<packaging>pom</packaging>
<name>Zcode SPI</name>
<modules>
<module>all</module>
<module>spi-for-wiznet</module>
<module>spi-for-wiznet-stm32</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,6 @@
#ifndef USE_SPI_1
#error SPI_1 is needed for udp comunications...
#endif
#ifdef USE_SPI_1
#if !SPI_SCK(_SPI_1, SPI_1_SCK)
#error Not defined as a valid SPI 1 SCK pin: SPI_1_SCK
#endif
#if !SPI_MISO(_SPI_1, SPI_1_MISO)
#error Not defined as a valid SPI 1 MISO pin: SPI_1_MISO
#endif
#if !SPI_MOSI(_SPI_1, SPI_1_MOSI)
#error Not defined as a valid SPI 1 MOSI pin: SPI_1_MOSI
#endif
#endif

#ifdef USE_SPI_2
#if !SPI_SCK(_SPI_2, SPI_2_SCK)
#error Not defined as a valid SPI 2 SCK pin: SPI_2_SCK
#endif
#if !SPI_MISO(_SPI_2, SPI_2_MISO)
#error Not defined as a valid SPI 2 MISO pin: SPI_2_MISO
#endif
#if !SPI_MOSI(_SPI_2, SPI_2_MOSI)
#error Not defined as a valid SPI 2 MOSI pin: SPI_2_MOSI
#endif
#endif

template<class LL>
class SPIClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*/

#if defined(SPI_WIZNET_STM32)
#if defined(STM32)
#include <spi-for-wiznet-stm32/lowlevel/SPI.h>
#else
#error Please select a supported device family
Expand Down
28 changes: 28 additions & 0 deletions receivers/native/arm/peripherals/udp/all/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-udp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>zcode-receivers-udp-all</artifactId>
<packaging>nar</packaging>
<name>Zcode full peripheral set</name>

<dependencies>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-udp-core</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-wiznet-udp-ll</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions receivers/native/arm/peripherals/udp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<packaging>pom</packaging>
<name>Zcode UDP</name>
<modules>
<module>all</module>
<module>udp-core</module>
<module>wiznet-udp-ll</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <zcode/channels/ZcodeChannelInStream.hpp>
#include <zcode/channels/ZcodeCommandChannel.hpp>
#include <zcode/ZcodeOutStream.hpp>
#include <persistence-ll/ZcodeFlashPersistence.hpp>
//#include <persistence-ll/ZcodeFlashPersistence.hpp>
#include "lowlevel/wiznet-arduino-library-src/Ethernet.h"

template<class ZP>
Expand Down Expand Up @@ -162,11 +162,11 @@ class ZcodeUdpChannel: public ZcodeCommandChannel<ZP> {
0), debugPort(0), port(port) {
uint8_t *mac;
uint8_t macHardCoded[6] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xad };
if (ZcodeFlashPersistence<LL>::persist.hasMac()) {
mac = ZcodeFlashPersistence<LL>::persist.getMac();
} else {
mac = macHardCoded;
}
// if (ZcodeFlashPersistence<LL>::persist.hasMac()) {
// mac = ZcodeFlashPersistence<LL>::persist.getMac();
// } else {
mac = macHardCoded;
// }
while (!Ethernet<LL> .begin(mac, 5000, 5000)) {
//TODO: not just loop forever, instead come back later...
}
Expand Down Expand Up @@ -223,7 +223,7 @@ class ZcodeUdpChannel: public ZcodeCommandChannel<ZP> {
slot.fail(BAD_PARAM, "MAC addresses must be 6 bytes long");
return;
} else if (slot.getBigField()->getLength() != 0) {
ZcodeFlashPersistence<LL>::persist.writeMac(slot.getBigField()->getData());
// ZcodeFlashPersistence<LL>::persist.writeMac(slot.getBigField()->getData());
}
out->writeStatus(OK);
}
Expand All @@ -233,11 +233,11 @@ class ZcodeUdpChannel: public ZcodeCommandChannel<ZP> {
Ethernet<LL> .init();
uint8_t *mac;
uint8_t macHardCoded[6] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xad };
if (ZcodeFlashPersistence<LL>::persist.hasMac()) {
mac = ZcodeFlashPersistence<LL>::persist.getMac();
} else {
mac = macHardCoded;
}
// if (ZcodeFlashPersistence<LL>::persist.hasMac()) {
// mac = ZcodeFlashPersistence<LL>::persist.getMac();
// } else {
mac = macHardCoded;
// }
while (!Ethernet<LL> .begin(mac, 5000, 5000)) {
}
udp.begin(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class DhcpClass {
// DHCP Library v0.3 - April 25, 2009
// Author: Jordan Terrell - blog.jordanterrell.com
#include <string.h>
#include <arm-no-os/system/clock/SystemMilliClock.hpp>
#include "../../../wiznet-udp/lowlevel/src/Ethernet.h"
#include "../../../wiznet-udp/lowlevel/src/utility/w5100.h"
#include <clock-ll/SystemMilliClock.hpp>
#include "Ethernet.h"
#include "utility/w5100.h"

template<class LL>
int DhcpClass<LL>::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class DNSClient {
// (c) Copyright 2009-2010 MCQN Ltd.
// Released under Apache License, version 2.0

#include "../../../wiznet-udp/lowlevel/src/Ethernet.h"
#include <arm-no-os/system/clock/SystemMilliClock.hpp>
#include "../../../wiznet-udp/lowlevel/src/utility/w5100.h"
#include "Ethernet.h"
#include <clock-ll/SystemMilliClock.hpp>
#include "utility/w5100.h"

#define SOCKET_NONE 255
// Various flags and header field values for a DNS message
Expand Down Expand Up @@ -139,7 +139,7 @@ int DNSClient<LL>::getHostByName(const char *aHostname, IPAddress &aResult, uint
}

// Find a socket to use
if (iUdp.begin(1024 + (SystemMilliClock < LL > ::getTimeMillis() & 0xF)) == 1) {
if (iUdp.begin(1024 + (SystemMilliClock<LL>::getTimeMillis() & 0xF)) == 1) {
// Try up to three times
int retries = 0;
// while ((retries < 3) && (ret <= 0)) {
Expand Down Expand Up @@ -193,7 +193,7 @@ uint16_t DNSClient<LL>::BuildRequest(const char *aName)
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// As we only support one request at a time at present, we can simplify
// some of this header
iRequestId = SystemMilliClock < LL > ::getTimeMillis(); // generate a random ID
iRequestId = SystemMilliClock<LL>::getTimeMillis(); // generate a random ID
uint16_t twoByteBuffer;

// FIXME We should also check that there's enough space available to write to, rather
Expand Down Expand Up @@ -252,14 +252,14 @@ uint16_t DNSClient<LL>::BuildRequest(const char *aName)
template<class LL>
uint16_t DNSClient<LL>::ProcessResponse(uint16_t aTimeout, IPAddress &aAddress)
{
uint32_t startTime = SystemMilliClock < LL > ::getTimeMillis();
uint32_t startTime = SystemMilliClock<LL>::getTimeMillis();

// Wait for a response packet
while (iUdp.parsePacket() <= 0) {
if ((SystemMilliClock < LL > ::getTimeMillis() - startTime) > aTimeout) {
if ((SystemMilliClock<LL>::getTimeMillis() - startTime) > aTimeout) {
return TIMED_OUT;
}
SystemMilliClock < LL > ::blockDelayMillis(50);
SystemMilliClock<LL>::blockDelayMillis(50);
}

// We've had a reply!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ extern EthernetClass<LL> Ethernet;

#define UDP_TX_PACKET_MAX_SIZE 24

#include "../../../wiznet-udp/lowlevel/src/socket.h"
#include "../../../wiznet-udp/lowlevel/src/Dhcp.h"
#include "../../../wiznet-udp/lowlevel/src/Dns.h"
#include "../../../wiznet-udp/lowlevel/src/EthernetUdp.h"
#include "../../../wiznet-udp/lowlevel/src/Ethernetcpp.h"
#include "socket.h"
#include "Dhcp.h"
#include "Dns.h"
#include "EthernetUdp.h"
#include "Ethernetcpp.h"
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class EthernetClient: public Client {
uint16_t _timeout;
};

#include "../../../wiznet-udp/lowlevel/src/Ethernet.h"
#include "../../../wiznet-udp/lowlevel/src/Client.h"
#include <arm-no-os/system/clock/SystemMilliClock.hpp>
#include "../../../wiznet-udp/lowlevel/src/Dns.h"
#include "../../../wiznet-udp/lowlevel/src/utility/w5100.h"
#include "Ethernet.h"
#include "Client.h"
#include <clock-ll/SystemMilliClock.hpp>
#include "Dns.h"
#include "utility/w5100.h"

template<class LL>
int EthernetClient<LL>::connect(const char *host, uint16_t port)
Expand Down Expand Up @@ -117,7 +117,7 @@ int EthernetClient<LL>::connect(IPAddress ip, uint16_t port)
if (sockindex >= MAX_SOCK_NUM)
return 0;
Ethernet<LL> .socketConnect(sockindex, rawIPAddress(ip), port);
uint32_t start = SystemMilliClock < LL > ::getTimeMillis();
uint32_t start = SystemMilliClock<LL>::getTimeMillis();
while (1) {
uint8_t stat = Ethernet<LL> .socketStatus(sockindex);
if (stat == SnSR::ESTABLISHED)
Expand All @@ -126,9 +126,9 @@ int EthernetClient<LL>::connect(IPAddress ip, uint16_t port)
return 1;
if (stat == SnSR::CLOSED)
return 0;
if (SystemMilliClock < LL > ::getTimeMillis() - start > _timeout)
if (SystemMilliClock<LL>::getTimeMillis() - start > _timeout)
break;
SystemMilliClock < LL > ::blockDelayMillis(1);
SystemMilliClock<LL>::blockDelayMillis(1);
}
Ethernet<LL> .socketClose(sockindex);
sockindex = MAX_SOCK_NUM;
Expand Down Expand Up @@ -220,16 +220,16 @@ void EthernetClient<LL>::stop()

// attempt to close the connection gracefully (send a FIN to other side)
Ethernet<LL> .socketDisconnect(sockindex);
unsigned long start = SystemMilliClock < LL > ::getTimeMillis();
unsigned long start = SystemMilliClock<LL>::getTimeMillis();

// wait up to a second for the connection to close
do {
if (Ethernet<LL> .socketStatus(sockindex) == SnSR::CLOSED) {
sockindex = MAX_SOCK_NUM;
return; // exit the loop
}
SystemMilliClock < LL > ::blockDelayMillis(1);
} while (SystemMilliClock < LL > ::getTimeMillis() - start < _timeout);
SystemMilliClock<LL>::blockDelayMillis(1);
} while (SystemMilliClock<LL>::getTimeMillis() - start < _timeout);

// if it hasn't closed, close it forcefully
Ethernet<LL> .socketClose(sockindex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class EthernetUDP: public UDP {
* [email protected] 12/30/2008
*/

#include "../../../wiznet-udp/lowlevel/src/Ethernet.h"
#include "../../../wiznet-udp/lowlevel/src/Dns.h"
#include "../../../wiznet-udp/lowlevel/src/utility/w5100.h"
#include "Ethernet.h"
#include "Dns.h"
#include "utility/w5100.h"

/* Start EthernetUDP socket, listening at local port PORT */
template<class LL>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "../../../../../../../../clock/src/main/c++/clock-ll/SystemMilliClock.hpp"
#include <clock-ll/SystemMilliClock.hpp>
#include "Dhcp.h"
#include "Ethernet.h"
#include "utility/w5100.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,4 @@ bool EthernetClass<LL>::socketSendUDP(uint8_t s)
return true;
}

#include "../../../wiznet-udp/lowlevel/src/EthernetServer.h"
#include "EthernetServer.h"
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,8 @@ class W5100Class {
* published by the Free Software Foundation.
*/

#include "../../../../../../../../wiznet-udp-ll/src/main/c++/wiznet-udp-ll/lowlevel/wiznet-arduino-library-src/Ethernet.h"
#include <arm-no-os/system/clock/SystemMilliClock.hpp>
#include "../../../../wiznet-udp/lowlevel/src/utility/w5100.h"
#include "../Ethernet.h"
#include <clock-ll/SystemMilliClock.hpp>
#include <string.h>

/***************************************************/
Expand Down Expand Up @@ -581,7 +580,7 @@ uint8_t W5100Class<LL>::init(void)
// case maximum 560 ms pulse length. This delay is meant to wait
// until the reset pulse is ended. If your hardware has a shorter
// reset time, this can be edited or removed.
SystemMilliClock < LL > ::blockDelayMillis(560);
SystemMilliClock<LL>::blockDelayMillis(560);
//Serial.println("w5100 init");

SPI<LL> .begin();
Expand Down Expand Up @@ -697,7 +696,7 @@ uint8_t W5100Class<LL>::softReset(void)
//Serial.println(mr, HEX);
if (mr == 0)
return 1;
SystemMilliClock < LL > ::blockDelayMillis(1);
SystemMilliClock<LL>::blockDelayMillis(1);
} while (++count < 20);
return 0;
}
Expand Down

0 comments on commit f742a5f

Please sign in to comment.