remote set and get register by address

This commit is contained in:
Tristan Krause 2019-05-29 10:13:36 +02:00
parent 2c47159df3
commit 2e88b9c980
69 changed files with 1595 additions and 117 deletions

View file

@ -0,0 +1,30 @@
# Name: Makefile
# Project: B15F (board15 Famulus Edition)
# Author: Tristan Krause
# Creation Date: 2019-05-15
# Environment
COMPILER_PATH = g++
# Options
CFLAGS = -std=c++17 -O3 -Wall -Wextra
LDFLAGS = -lb15fdrv
OBJECTS = main.o
OUT = main.elf
COMPILE = $(COMPILER_PATH) $(CFLAGS)
main: $(OBJECTS)
$(COMPILE) $(OBJECTS) -o $(OUT) $(LDFLAGS)
help:
@echo "This Makefile has the following targets:"
@echo "make main .... to compile"
@echo "make clean ... to delete objects and executables"
clean:
@echo "Cleaning..."
rm -f $(OBJECTS) $(OUT) *.bin gnuplotscript.gp
.cpp.o:
$(COMPILE) -c $< -o $@

View file

@ -0,0 +1,35 @@
#include <iostream>
#include <cmath>
#include <b15f/b15f.h>
#include <b15f/plottyfile.h>
const char PLOT_FILE[] = "plot.bin";
constexpr uint8_t SFR_OFFSET = 0x20;
constexpr uint8_t SFR_DDRB = 0x04;
constexpr uint8_t SFR_WDTCSR = 0x60;
constexpr uint8_t SFR_PORTB = 0x05;
/*
* Dieses Beispiel erzeugt einen 300ms langen Impuls an PB0.
*
*/
int main()
{
uint8_t DDRB, PORTB;
B15F& drv = B15F::getInstance();
DDRB = drv.getRegister(SFR_DDRB + SFR_OFFSET);
DDRB |= (1<<0);
drv.setRegister(SFR_DDRB + SFR_OFFSET, DDRB);
PORTB = drv.getRegister(SFR_PORTB + SFR_OFFSET);
PORTB |= (1<<0);
drv.setRegister(SFR_PORTB + SFR_OFFSET, PORTB);
drv.delay_ms(300);
PORTB = drv.getRegister(SFR_PORTB + SFR_OFFSET);
PORTB &= ~(1<<0);
drv.setRegister(SFR_PORTB + SFR_OFFSET, PORTB);
}

View file

@ -330,6 +330,46 @@ bool B15F::pwmSetValue(uint8_t value)
return aw == MSG_OK;
}
bool B15F::setRegister(uint8_t adr, uint8_t val)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_SET_REG,
adr,
val
};
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
if(n_sent != sizeof(rq))
abort("Sent failed");
uint8_t byte = usart.readByte();
delay_us(10);
return byte == val;
}
uint8_t B15F::getRegister(uint8_t adr)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_GET_REG,
adr
};
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
if(n_sent != sizeof(rq))
abort("Sent failed");
uint8_t aw = usart.readByte();
delay_us(10);
return aw;
}
void B15F::delay_ms(uint16_t ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));

View file

@ -210,6 +210,22 @@ public:
*/
bool pwmSetValue(uint8_t value);
/**
* Setzt direkt den Wert eines MCU Registers.
* *Wichtig:* bei einer falschen Adresse kann das Board 15 ernsthaften Schaden nehmen!
* \param adr Speicheradresse des Registers
* \param val Neuer Wert für das Register
* \throws DriverException
*/
bool setRegister(uint8_t adr, uint8_t val);
/**
* Liefert den Wert eines MCU Registers.
* \param adr Speicheradresse des Registers
* \throws DriverException
*/
uint8_t getRegister(uint8_t adr);
/*************************/
@ -248,9 +264,11 @@ private:
constexpr static uint8_t RQ_AA0 = 10;
constexpr static uint8_t RQ_AA1 = 11;
constexpr static uint8_t RQ_ADC = 12;
constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
constexpr static uint8_t RQ_SET_REG = 16;
constexpr static uint8_t RQ_GET_REG = 17;
};
#endif // B15F_H