From c9dd1076d366323e4fdbdcbcf6cc92c05af90f51 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Sat, 10 Aug 2024 10:13:21 +0200 Subject: [PATCH] Makefile korrigiert --- software/nano-644/test_2024-07-23/Makefile | 30 +++-- .../nano-644/test_2024-07-23/src/main.cpp | 39 +++++++ .../nano-644/test_2024-07-23/src/main.hpp | 8 ++ .../src/units/{cc1011.cpp => cc1101.cpp} | 110 +++++++++++++++++- .../test_2024-07-23/src/units/cc1101.hpp | 26 +++++ 5 files changed, 198 insertions(+), 15 deletions(-) rename software/nano-644/test_2024-07-23/src/units/{cc1011.cpp => cc1101.cpp} (78%) diff --git a/software/nano-644/test_2024-07-23/Makefile b/software/nano-644/test_2024-07-23/Makefile index be31a04..4cdd455 100644 --- a/software/nano-644/test_2024-07-23/Makefile +++ b/software/nano-644/test_2024-07-23/Makefile @@ -4,8 +4,9 @@ $(shell mkdir -p build >/dev/null) $(shell mkdir -p sim >/dev/null) $(shell mkdir -p sim/build >/dev/null) -NAME="test_2024-07-23_nano-644" -SRC= $(wildcard src/*.c src/*.cpp src/*/*.cpp) +NAME=test_2024-07-23_nano-644 +SRC= $(wildcard src/*.c src/*.cpp src/*/*.c src/*/*.cpp) +HDR= $(wildcard src/*.h src/*.hpp src/*/*.h src/*/*.hpp) OBJ_CPP = $(SRC:src/%.cpp=build/%.o) OBJ = $(OBJ_CPP:src/%.c=build/%.o) OBJ_SIM_CPP = $(SRC:src/%.cpp=sim/build/%.o) @@ -24,19 +25,28 @@ LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,-u,vfprintf -lprin all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info dbg: - @echo "OBJ_CPP" $(OBJ_CPP) - @echo "OBJ" $(OBJ) - @echo "OBJ_SIM_CPP" $(OBJ_SIM_CPP) - @echo "OBJ_SIM" $(OBJ_SIM) + @echo --HDR--------------------------------- + @echo $(HDR) + @echo --SRC--------------------------------- + @echo $(SRC) + @echo --OBJ--------------------------------- + @echo $(OBJ) + @echo --OBJ_CPP----------------------------- + @echo $(OBJ_CPP) + @echo --OBJ--------------------------------- + @echo $(OBJ) + @echo =================================== + @echo info: - @echo @avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf -.depend: $(SRC) - $(CC) -MM $(SRC) > .depend +.depend: $(SRC) $(HDR) + $(CC) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend --include $(DEPENDFILE) +-include .depend + +# .depend solte auch auf Header Files achten! dist/$(NAME).elf: .depend $(OBJ) $(CC) $(LFLAGS) -o $@ $(OBJ) diff --git a/software/nano-644/test_2024-07-23/src/main.cpp b/software/nano-644/test_2024-07-23/src/main.cpp index 78fe57b..94a404f 100644 --- a/software/nano-644/test_2024-07-23/src/main.cpp +++ b/software/nano-644/test_2024-07-23/src/main.cpp @@ -77,6 +77,33 @@ extern "C" { static FILE mystdout = { 0, 0, _FDEV_SETUP_WRITE , 0, 0, uart_putchar, NULL, 0 }; static FILE mystdin = { 0, 0, _FDEV_SETUP_READ , 0, 0, NULL, uart_getchar, 0 }; + #ifdef __AVR_ATmega644P__ + static volatile uint16_t timerFlashGreenLed = 0; + static volatile uint16_t timerFlashRedLed = 0; + void flashRedLed (uint16_t ms) { + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + if (timerFlashRedLed == 0) { + PORTC |= (1 << PC2); + if (ms < 0xff80) { + ms += 0x80; // at least 128ms OFF after + } + timerFlashRedLed = ms; + } + } + } + void flashGreenLed (uint16_t ms) { + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + if (timerFlashGreenLed == 0) { + PORTC |= (1 << PC4); + if (ms < 0xff80) { + ms += 0x80; // at least 128ms OFF after + } + timerFlashGreenLed = ms; + } + } + } + #endif + static volatile uint32_t timer1ms = 0; static volatile int keyUart0 = EOF; @@ -273,6 +300,18 @@ ISR (TIMER2_COMPA_vect) { // every 100us i2cSlave.tick1ms(); i2cSparkfun.tick1ms(); cc1101.tick1ms(); + #ifdef __AVR_ATmega644P__ + if (timerFlashRedLed > 0) { + if (--timerFlashRedLed < 128) { + PORTC &= ~(1 << PC2); // red LED + } + } + if (timerFlashGreenLed > 0) { + if (--timerFlashGreenLed < 128 ) { + PORTC &= ~(1 << PC4); // green LED + } + } + #endif } timer500ms++; diff --git a/software/nano-644/test_2024-07-23/src/main.hpp b/software/nano-644/test_2024-07-23/src/main.hpp index bef51b6..e5bf840 100644 --- a/software/nano-644/test_2024-07-23/src/main.hpp +++ b/software/nano-644/test_2024-07-23/src/main.hpp @@ -10,6 +10,14 @@ extern int wait (uint32_t ms); extern uint64_t millis (); +#ifdef __AVR_ATmega644P__ + extern "C" { + extern void flashRedLed (uint16_t ms); + extern void flashGreenLed (uint16_t ms); + } +#endif + + class TestUnit { public: virtual int8_t run (uint8_t subtest) = 0; diff --git a/software/nano-644/test_2024-07-23/src/units/cc1011.cpp b/software/nano-644/test_2024-07-23/src/units/cc1101.cpp similarity index 78% rename from software/nano-644/test_2024-07-23/src/units/cc1011.cpp rename to software/nano-644/test_2024-07-23/src/units/cc1101.cpp index 962043d..6b6809b 100644 --- a/software/nano-644/test_2024-07-23/src/units/cc1011.cpp +++ b/software/nano-644/test_2024-07-23/src/units/cc1101.cpp @@ -158,7 +158,13 @@ bool Cc1101::waitForGD0High () { } bool Cc1101::waitForGD0Low () { - return !waitForGD0High(); + timer = 100; + while (isGd0High()) { + if (timer == 0) { + return false; + } + } + return true; } @@ -241,7 +247,7 @@ bool Cc1101::sendData (uint8_t *buffer, uint8_t length) { bool ok = true; ok &= writeRegister(CC1101_TXFIFO, length); ok &= writeRegisters(CC1101_TXFIFO, buffer, length); - ok &= strobe(CC1101_STX); // start sending bytes + ok &= strobe(CC1101_STX); // start sending bytes ok &= waitForGD0High(); ok &= waitForGD0Low(); ok &= strobe(CC1101_SFTX); //flush TXfifo @@ -270,18 +276,26 @@ bool Cc1101::receiveData (uint8_t *buffer, uint8_t *receivedLength, uint8_t maxB uint8_t length; ok &= readStatus(CC1101_RXBYTES, status); +// printf(" 1-%d", ok); if (ok && status[0] & BYTES_IN_RXFIFO) { +// printf(" 2-%d", ok); ok &= readRegister(CC1101_RXFIFO, &length); +// printf(" 3-%d", ok); if (ok && length > 0 && length <= maxBufferSize) { +// printf(" 4-%d", ok); ok &= readRegisters(CC1101_RXFIFO, buffer, length); +// printf(" 5-%d", ok); ok &= readRegisters(CC1101_RXFIFO, status, 2); +// printf(" 6-%d", ok); ok &= strobe(CC1101_SFRX); +// printf(" 7-%d", ok); if (ok) { *receivedLength = length; return ok; } } } +// printf(" 8-%d", ok); strobe(CC1101_SFRX); *receivedLength = 0; return false; @@ -388,16 +402,102 @@ int8_t Cc1101::run (uint8_t subtest) { return 0; } else if (subtest == 2) { + do { + uint8_t data[16]; + for (uint8_t i = 0; i < sizeof(data); i++) { + data[i] = i; + } + printf_P(PSTR("\n => send 16 bytes ...")); + triggerOn(); + if (sendData(data, sizeof(data))) { + flashGreenLed(100); + printf_P(PSTR("OK")); + } else { + flashRedLed(100); + printf_P(PSTR("E4")); + } + triggerOff(); + + } while (wait(2000) == EOF); + return 0; + + } else if (subtest == 3) { + setReceive(); + int key = EOF; + uint8_t state; + while (key == EOF) { + printf_P(PSTR("\n => receive: ")); + if (!readStatus(CC1101_MARCSTATE, &state)) { + flashRedLed(100); + _delay_ms(500); + continue; + } + if (state == 0x01) { + uint8_t states[8] = { 0x01 }; + uint8_t statesIndex = 1; + printf_P(PSTR("start ")); + setReceive(); + for (uint16_t i = 0; i < 1000; i++) { + uint8_t s; + if (!readStatus(CC1101_MARCSTATE, &s)) { + continue; + } + if (statesIndex == 0 || (states[statesIndex - 1] != s && statesIndex < sizeof(states))) { + states[statesIndex++] = s; + } + if (s == 0x13) { + break; + } + } + printf_P(PSTR(" State:")); + for (uint8_t i = 0; i < statesIndex; i++) { + printf_P(PSTR(" 0x%02x"), states[i]); + } + } + + key = wait(0); + + while (key == EOF && state != 0x01) { + uint8_t length; + uint8_t data[16]; + printf_P(PSTR(" -> receive ... ")); + + while (key == EOF) { + if (receiveData(data, &length, sizeof(data))) { + flashGreenLed(100); + printf_P(PSTR("OK, %d bytes received: "), length); + for (uint8_t i = 0; i < length; i++) { + printf_P(PSTR(" 0x%02x"), data[i]); + } + break; + } else { + state = 0; + if (!readStatus(CC1101_MARCSTATE, &state) || state == 0x01 || state == 0x13) { + printf_P(PSTR(" -> cancelled state=0x%02x"), state); + break; + } + if (state != 0x0d) { + printf_P(PSTR(" -> state=0x%02x "), state); + } + } + key = wait(0); + } + } + } + return 0; + + } else if (subtest == 4) { + return 0; + + } else if (subtest == 5) { do { uint8_t status; printf_P(PSTR("\n => status: ")); - triggerOn(); if (readStatus(CC1101_MARCSTATE, &status)) { printf_P(PSTR("0x%02x"), status); } else { - printf_P(PSTR("E4")); + printf_P(PSTR("E6")); } - triggerOff(); } while (wait(2000) == EOF); } diff --git a/software/nano-644/test_2024-07-23/src/units/cc1101.hpp b/software/nano-644/test_2024-07-23/src/units/cc1101.hpp index 64dd578..b362314 100644 --- a/software/nano-644/test_2024-07-23/src/units/cc1101.hpp +++ b/software/nano-644/test_2024-07-23/src/units/cc1101.hpp @@ -51,6 +51,32 @@ class Cc1101 : public TestUnit { private: + enum MainRadioControlState { + SLEEP = 0, + IDLE = 1, + XOFF = 2, + MANCAL_VCOON = 3, + MANCAL_REGON = 4, + MANCAL = 5, + FS_WAKEUP_VCOON = 6, + FS_WAKEUP_REGON = 7, + CALIBRATE_START = 8, + SETTLING_BWBOOST = 9, + SETTLING_FS_LOCK = 10, + SETTLIN_IFADCON = 11, + CALIBRATE_END = 12, + RX = 13, + RX_END = 14, + RX_RST = 15, + TXRX_SETTLING = 16, + RXFIFO_OVERFLOW = 17, + FXTXON = 18, + TX = 19, + TX_END = 20, + RXTX_SETTLING = 21, + TXFIFO_UNDERFLOW = 22 + }; + #define WRITE_BURST 0x40 #define READ_SINGLE 0x80 -- 2.39.5