Skip to content

Possible direction for __ARDUINO_CI_SFR_MOCK #201

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 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
11 changes: 11 additions & 0 deletions SampleProjects/TestSomething/test/defines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ unittest(binary)
assertEqual(100, B1100100);
}

#define DDRE _SFR_IO8(0x02)

unittest(SFR_IO8)
{
// in normal arduino code, you can do this. in arduino_ci, you might get an
// error like: cannot take the address of an rvalue of type 'int'
//
// this tests that directly
auto foo = &DDRE; // avoid compiler warning by using the result of an expression
}

unittest_main()
2 changes: 2 additions & 0 deletions cpp/arduino/Godmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ SPIClass SPI = SPIClass(&GODMODE()->spi.dataIn, &GODMODE()->spi.dataOut);

// defined in Wire.h
TwoWire Wire = TwoWire();

volatile long long __ARDUINO_CI_SFR_MOCK[1024];
9 changes: 7 additions & 2 deletions cpp/arduino/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@

class SPISettings {
public:
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode){};
uint8_t bitOrder;
SPISettings(uint32_t clock, uint8_t bitOrder = MSBFIRST, uint8_t dataMode = SPI_MODE0){
this->bitOrder = bitOrder;
};
SPISettings(){};
};

Expand Down Expand Up @@ -68,6 +71,7 @@ class SPIClass: public ObservableDataStream {
// and configure the correct settings.
void beginTransaction(SPISettings settings)
{
this->bitOrder = settings.bitOrder;
#ifdef SPI_TRANSACTION_MISMATCH_LED
if (inTransactionFlag) {
pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT);
Expand All @@ -94,7 +98,7 @@ class SPIClass: public ObservableDataStream {
uint16_t transfer16(uint16_t data) {
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out;
in.val = data;
if (!(SPCR & (1 << DORD))) {
if (bitOrder == MSBFIRST) {
out.msb = transfer(in.msb);
out.lsb = transfer(in.lsb);
} else {
Expand Down Expand Up @@ -143,6 +147,7 @@ class SPIClass: public ObservableDataStream {
#endif

bool isStarted = false;
uint8_t bitOrder;
String* dataIn;
String* dataOut;
};
Expand Down
8 changes: 7 additions & 1 deletion cpp/arduino/avr/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@
#ifndef _AVR_IO_H_
#define _AVR_IO_H_

#define _SFR_IO8(io_addr) (io_addr) // this macro is all we need from the sfr file
// hardware mocks
extern volatile long long __ARDUINO_CI_SFR_MOCK[1024];
#define _SFR_IO8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) // this macro is all we need from the sfr file
#define _SFR_IO16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) // this macro is all we need from the sfr file
#define _SFR_MEM8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) // this macro is all we need from the sfr file
#define _SFR_MEM16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) // this macro is all we need from the sfr file
#define _SFR_MEM32(io_addr) (*(volatile uint32_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) // this macro is all we need from the sfr file

#if defined (__AVR_AT94K__)
# include "ioat94k.h"
Expand Down