eive_arduino_interface/main.cpp

53 lines
1.4 KiB
C++
Raw Normal View History

2020-04-02 18:32:37 +02:00
#include <Arduino.h>
2020-10-13 01:05:02 +02:00
#include "IOBoard.h"
2020-10-12 23:49:49 +02:00
#include "ArduinoConfig.h"
2020-04-02 18:32:37 +02:00
2020-10-13 02:00:04 +02:00
// TODO: Copy this header into arduino_core, so it can be used without
// Eclipse Sloeber as well.
#include <arduino-timer.h>
2020-04-15 17:50:30 +02:00
#include <avr/io.h>
2020-04-02 18:32:37 +02:00
//SPI is formally a library, so it is not part of the objects compiled
//from the core and we need to include it explicitly
2020-10-12 23:24:39 +02:00
#include <SPI.h>
2020-04-02 18:32:37 +02:00
2020-10-13 12:32:15 +02:00
// Crete default timer which is able to manage 10 concurrent tasks
// and uses milliseconds as a timebase.
2020-10-13 02:00:04 +02:00
auto timer = timer_create_default();
2020-10-13 12:32:15 +02:00
bool periodicHandler1(void* args);
2020-04-02 18:32:37 +02:00
void setup() {
2020-10-13 00:37:09 +02:00
// Set data direction of selected port to output.
2020-10-13 01:05:02 +02:00
CS_DDR = 0xff;
// Drive all the slave selects high as required for the SPI protocol
// if no transfer is going on.
CS_PORT = 0xff;
Serial.begin(BAUD_RATE);
#if PROGRAMMING_OUTPUT == 1
2020-10-13 01:05:02 +02:00
Serial.println("-AI- Setting up Arduino IO interface board.");
Serial.print("-AI- Configured baud rate for serial communication: ");
Serial.println(BAUD_RATE, DEC);
Serial.print("-AI- Size of serial receiver buffer: ");
Serial.print(SERIAL_RX_BUFFER_SIZE, DEC);
Serial.println(" bytes");
#endif
2020-10-13 01:05:02 +02:00
SPI.begin();
2020-10-13 12:32:15 +02:00
// Call periodic handler with certain interval
timer.every(RING_BUFFER_CHECK_INTVL, periodicHandler1);
2020-04-02 18:32:37 +02:00
}
2020-10-13 02:00:04 +02:00
bool periodicHandler1(void* args) {
if(args) {};
2020-10-13 12:32:15 +02:00
Serial.println("Handling new data!");
2020-10-13 01:05:02 +02:00
IOBoard::handleNewData();
2020-10-13 12:32:15 +02:00
// repeat action
return true;
2020-10-13 02:00:04 +02:00
}
void loop() {
timer.tick();
2020-04-02 18:32:37 +02:00
}
2020-10-13 01:05:02 +02:00