Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
### Releases v1.0.1

1. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
2. Using cpp code besides Impl.h code to use if Multiple-Definition linker error3. 
3. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers based on just 1 Hardware Timer.
  • Loading branch information
khoih-prog authored Nov 8, 2020
0 parents commit 74f80ef
Show file tree
Hide file tree
Showing 49 changed files with 17,463 additions and 0 deletions.
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Contributing to SAMDUE_TimerInterrupt

### Reporting Bugs

Please report bugs in SAMDUE_TimerInterrupt if you find them.

However, before reporting a bug please check through the following:

* [Existing Open Issues](https://github.com/khoih-prog/SAMDUE_TimerInterrupt/issues) - someone might have already encountered this.

If you don't find anything, please [open a new issue](https://github.com/khoih-prog/SAMDUE_TimerInterrupt/issues/new).

### How to submit a bug report

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.13) or Platform.io version
* `SAMDUE` Core Version (e.g. Arduino SAMDUE_ core v1.6.12)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
* Network configuration


### Example

```
Arduino IDE version: 1.8.13
Arduino SAMDUE Core Version 1.6.12
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```
### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/SAMDUE_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Khoi Hoang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
320 changes: 320 additions & 0 deletions LibraryPatches/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
/****************************************************************************************************************************
Ethernet.cpp
EthernetWebServer is a library for the Ethernet shields to run WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer
Licensed under MIT license
Version: 1.0.9
Copyright 2018 Paul Stoffregen
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries
1.0.1 K Hoang 20/02/2020 Add support to lambda functions
1.0.2 K Hoang 20/02/2020 Add support to UIPEthernet library for ENC28J60
1.0.3 K Hoang 23/02/2020 Add support to SAM DUE / SAMD21 boards
1.0.4 K Hoang 16/04/2020 Add support to SAMD51 boards
1.0.5 K Hoang 24/04/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense,
Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B30_ublox, etc.
More Custom Ethernet libraries supported such as Ethernet2, Ethernet3, EthernetLarge
1.0.6 K Hoang 27/04/2020 Add support to ESP32/ESP8266 boards
1.0.7 K Hoang 30/04/2020 Add ENC28J60 support to ESP32/ESP8266 boards
1.0.8 K Hoang 12/05/2020 Fix W5x00 support for ESP8266 boards.
1.0.9 K Hoang 15/05/2020 Add EthernetWrapper.h for easier W5x00 support as well as more Ethernet libs in the future.
*****************************************************************************************************************************/

#include <Arduino.h>
#include "Ethernet.h"
#include "utility/w5100.h"
#include "Dhcp.h"

#define ETHERNET_DEBUG 1


IPAddress EthernetClass::_dnsServerAddress;
DhcpClass* EthernetClass::_dhcp = NULL;

// KH
void EthernetClass::setRstPin(uint8_t pinRST)
{
_pinRST = pinRST;
pinMode(_pinRST, OUTPUT);
digitalWrite(_pinRST, HIGH);
}
void EthernetClass::setCsPin(uint8_t pinCS)
{
_pinCS = pinCS;
W5100.setSS(pinCS);

#if ( ETHERNET_DEBUG > 0 )
Serial.print("Input pinCS = ");
Serial.println(pinCS);
Serial.print("_pinCS = ");
Serial.println(_pinCS);
#endif
}

void EthernetClass::initMaxSockNum(uint8_t maxSockNum)
{
_maxSockNum = maxSockNum;
}

uint8_t EthernetClass::softreset()
{
return W5100.softReset();
}

void EthernetClass::hardreset()
{
if(_pinRST != 0)
{
digitalWrite(_pinRST, LOW);
delay(1);
digitalWrite(_pinRST, HIGH);
delay(150);
}
}

int EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
{
DhcpClass s_dhcp;
_dhcp = &s_dhcp;

#if ( ETHERNET_DEBUG > 0 )
Serial.print("_pinCS = ");
Serial.print(_pinCS);
#endif

// Initialise the basic info
if (W5100.init() == 0)
return 0;

SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac);
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, timeout, responseTimeout);
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();
socketPortRand(micros());
}
return ret;
}

void EthernetClass::begin(uint8_t *mac, IPAddress ip)
{
// Assume the DNS server will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress dns = ip;
dns[3] = 1;
begin(mac, ip, dns);
}

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns)
{
// Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress gateway = ip;
gateway[3] = 1;
begin(mac, ip, dns, gateway);
}

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway)
{
IPAddress subnet(255, 255, 255, 0);
begin(mac, ip, dns, gateway, subnet);
}

void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet)
{
// Initialise the basic info
if (W5100.init() == 0)
return;

SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac);

#if ( defined(ESP8266) || defined(ESP32) )
W5100.setIPAddress(ip.raw_address());
W5100.setGatewayIp(gateway.raw_address());
W5100.setSubnetMask(subnet.raw_address());
#elif (ARDUINO > 106 || TEENSYDUINO > 121)
W5100.setIPAddress(ip._address.bytes);
W5100.setGatewayIp(gateway._address.bytes);
W5100.setSubnetMask(subnet._address.bytes);
#else
W5100.setIPAddress(ip._address);
W5100.setGatewayIp(gateway._address);
W5100.setSubnetMask(subnet._address);
#endif

SPI.endTransaction();
_dnsServerAddress = dns;
}

void EthernetClass::init(uint8_t sspin)
{
W5100.setSS(sspin);
}

EthernetLinkStatus EthernetClass::linkStatus()
{
switch (W5100.getLinkStatus()) {
case UNKNOWN: return Unknown;
case LINK_ON: return LinkON;
case LINK_OFF: return LinkOFF;
default: return Unknown;
}
}

EthernetHardwareStatus EthernetClass::hardwareStatus()
{
switch (W5100.getChip()) {
case 51: return EthernetW5100;
case 52: return EthernetW5200;
case 55: return EthernetW5500;
default: return EthernetNoHardware;
}
}

int EthernetClass::maintain()
{
int rc = DHCP_CHECK_NONE;
if (_dhcp != NULL) {
// we have a pointer to dhcp, use it
rc = _dhcp->checkLease();
switch (rc)
{
case DHCP_CHECK_NONE:
//nothing done
break;
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:
//this is actually an error, it will retry though
break;
}
}
return rc;
}


void EthernetClass::MACAddress(uint8_t *mac_address)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getMACAddress(mac_address);
SPI.endTransaction();
}

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;
}

void EthernetClass::setMACAddress(const uint8_t *mac_address)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac_address);
SPI.endTransaction();
}

void EthernetClass::setLocalIP(const IPAddress local_ip)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
IPAddress ip = local_ip;
W5100.setIPAddress(ip.raw_address());
SPI.endTransaction();
}

void EthernetClass::setSubnetMask(const IPAddress subnet)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
IPAddress ip = subnet;
W5100.setSubnetMask(ip.raw_address());
SPI.endTransaction();
}

void EthernetClass::setGatewayIP(const IPAddress gateway)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
IPAddress ip = gateway;
W5100.setGatewayIp(ip.raw_address());
SPI.endTransaction();
}

void EthernetClass::setRetransmissionTimeout(uint16_t milliseconds)
{
if (milliseconds > 6553) milliseconds = 6553;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setRetransmissionTime(milliseconds * 10);
SPI.endTransaction();
}

void EthernetClass::setRetransmissionCount(uint8_t num)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setRetransmissionCount(num);
SPI.endTransaction();
}

EthernetClass Ethernet;
Loading

0 comments on commit 74f80ef

Please sign in to comment.