Skip to content

[samd] fixing https://github.com/arduino/ArduinoCore-samd/issues/28 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
328f838
[samd] fixing https://github.com/arduino/ArduinoCore-samd/issues/28
aethaniel Sep 9, 2015
7dfd77f
Fix two bugs that can cause deadlock conditions when i2c bus errors o…
pixelpixi Jul 25, 2015
b4378a1
[zero] prepare variant for SPI and Wire board parameters
aethaniel Aug 10, 2015
de9a555
[zero] Bring more customization to SPI class
aethaniel Aug 10, 2015
6773245
[zero] Bring more customization to Wire class
aethaniel Aug 10, 2015
5eea80b
[zero/SPI] adding missing library properties
aethaniel Aug 11, 2015
faa6490
[zero/Wire] adding missing library properties
aethaniel Aug 11, 2015
f81f69c
[zero/SPI] Adding default values for SPI custom definitions
aethaniel Aug 13, 2015
a3a0ff3
[zero/Wire] Adding default values for Wire custom definitions
aethaniel Aug 13, 2015
00f1d73
delay.h is included outside __cplusplus guards
cmaglie Aug 13, 2015
e3c69a2
[Wire] simplified coding unnecessarily complex (hfvogt)
cmaglie Aug 13, 2015
02d6750
relax digitalWrite parameter check
facchinm Aug 14, 2015
7a3d29d
Updated IPAddress class to the latest version
cmaglie Aug 24, 2015
2fd415a
implement Wire.end() for SAMD core
sandeepmistry Aug 25, 2015
c413e4d
Fixed EXT_INT numbers in variant for pin 8 and 9
cmaglie Sep 4, 2015
67f74b9
WInterrupts.c cosmetic fix
cmaglie Sep 4, 2015
7edab1a
NMI interrupts are now correctly ignored by attach/detachInterrupt
cmaglie Sep 4, 2015
4e83b1d
Simplified "callbacksInt" structure in WInterrupts.c
cmaglie Sep 4, 2015
6fd2090
Cosmetic changes in WInterrupt.*
cmaglie Sep 4, 2015
6600304
Removed redundant #ifdef __cplusplus in WInterrupts.c
cmaglie Sep 4, 2015
7f435b8
WInterrupts: optimized use of digitalPinToInterrupt()
cmaglie Sep 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void loop( void ) ;

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif

// The following headers are for C++ only compilation
#ifdef __cplusplus
Expand All @@ -72,9 +72,11 @@ void loop( void ) ;
#include "WMath.h"
#include "HardwareSerial.h"
#include "pulse.h"
#include "delay.h"
#endif
#include "delay.h"
#ifdef __cplusplus
#include "Uart.h"
#endif // __cplusplus
#endif

// Include board variant
#include "variant.h"
Expand Down
31 changes: 16 additions & 15 deletions cores/arduino/IPAddress.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
IPAddress.cpp - Base class that provides IPAddress
Copyright (c) 2011 Adrian McEwen. 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
Expand All @@ -8,8 +9,8 @@

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.
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
Expand All @@ -21,53 +22,53 @@

IPAddress::IPAddress()
{
memset(_address, 0, sizeof(_address));
_address.dword = 0;
}

IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
{
_address[0] = first_octet;
_address[1] = second_octet;
_address[2] = third_octet;
_address[3] = fourth_octet;
_address.bytes[0] = first_octet;
_address.bytes[1] = second_octet;
_address.bytes[2] = third_octet;
_address.bytes[3] = fourth_octet;
}

IPAddress::IPAddress(uint32_t address)
{
memcpy(_address, &address, sizeof(_address));
_address.dword = address;
}

IPAddress::IPAddress(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
memcpy(_address.bytes, address, sizeof(_address.bytes));
}

IPAddress& IPAddress::operator=(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
memcpy(_address.bytes, address, sizeof(_address.bytes));
return *this;
}

IPAddress& IPAddress::operator=(uint32_t address)
{
memcpy(_address, (const uint8_t *)&address, sizeof(_address));
_address.dword = address;
return *this;
}

bool IPAddress::operator==(const uint8_t* addr) const
{
return memcmp(addr, _address, sizeof(_address)) == 0;
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
}

size_t IPAddress::printTo(Print& p) const
{
size_t n = 0;
for (int i =0; i < 3; i++)
{
n += p.print(_address[i], DEC);
n += p.print(_address.bytes[i], DEC);
n += p.print('.');
}
n += p.print(_address[3], DEC);
n += p.print(_address.bytes[3], DEC);
return n;
}

24 changes: 15 additions & 9 deletions cores/arduino/IPAddress.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
IPAddress.h - Base class that provides IPAddress
Copyright (c) 2011 Adrian McEwen. 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
Expand All @@ -8,8 +9,8 @@

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.
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
Expand All @@ -19,18 +20,23 @@
#ifndef IPAddress_h
#define IPAddress_h

#include <stdint.h>
#include <Printable.h>

// A class to make it easier to handle and pass around IP addresses

class IPAddress : public Printable {
private:
uint8_t _address[4]; // IPv4 address
union {
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
} _address;

// Access the raw byte array containing the address. Because this returns a pointer
// to the internal structure rather than a copy of the address this function should only
// be used when you know that the usage of the returned uint8_t* will be transient and not
// stored.
uint8_t* raw_address() { return _address; };
uint8_t* raw_address() { return _address.bytes; };

public:
// Constructors
Expand All @@ -41,13 +47,13 @@ class IPAddress : public Printable {

// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator uint32_t() const { return *((uint32_t*)_address+0); };
bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
operator uint32_t() const { return _address.dword; };
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
bool operator==(const uint8_t* addr) const;

// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address[index]; };
uint8_t& operator[](int index) { return _address[index]; };
uint8_t operator[](int index) const { return _address.bytes[index]; };
uint8_t& operator[](int index) { return _address.bytes[index]; };

// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
Expand Down
15 changes: 14 additions & 1 deletion cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag
{
while( !sercom->I2CM.INTFLAG.bit.SB )
{
// If the slave NACKS the address, the MB bit will be set.
// In that case, send a stop condition and return false.
if (sercom->I2CM.INTFLAG.bit.MB) {
sercom->I2CM.CTRLB.bit.CMD = 3; // Stop condition
return false;
}
// Wait transmission complete
}

Expand All @@ -518,7 +524,14 @@ bool SERCOM::sendDataMasterWIRE(uint8_t data)
sercom->I2CM.DATA.bit.DATA = data;

//Wait transmission successful
while(!sercom->I2CM.INTFLAG.bit.MB);
while(!sercom->I2CM.INTFLAG.bit.MB) {

// If a bus error occurs, the MB bit may never be set.
// Check the bus error bit and bail if it's set.
if (sercom->I2CM.STATUS.bit.BUSERR) {
return false;
}
}

//Problems on line? nack received?
if(sercom->I2CM.STATUS.bit.RXNACK)
Expand Down
Loading