From: Manfred Steiner Date: Sat, 10 Aug 2024 17:37:24 +0000 (+0200) Subject: ... X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=0c64ac44bed91b2c17508051074e47f338ccc9e3;p=nano-x-base.git ... --- diff --git a/software/nano-644/test_2024-07-23/Makefile b/software/nano-644/test_2024-07-23/Makefile index 4cdd455..41a8b6e 100644 --- a/software/nano-644/test_2024-07-23/Makefile +++ b/software/nano-644/test_2024-07-23/Makefile @@ -42,7 +42,7 @@ info: @avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf .depend: $(SRC) $(HDR) - $(CC) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend + $(CC) -mmcu=$(DEVICE) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend -include .depend @@ -86,6 +86,9 @@ simuc: sim/$(NAME).elf gdb: sim/$(NAME).elf avr-gdb $< +flash: dist/$(NAME).elf all + avrdude -c arduino -P /dev/ttyUSB0 -p m644p -e -U flash:w:$< + isp-644p: avrdude -c usbasp -p m644p @@ -98,7 +101,7 @@ flash-644p: dist/$(NAME).elf all picocom: # picocom sends CR for ENTER -> convert cr (\r) to lf (\n) - picocom -b 115200 --omap crlf /dev/ttyUSB0 + picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0 isp-fuse-644p: avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m -U lock:w:0xFF:m 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 94a404f..14b9399 100644 --- a/software/nano-644/test_2024-07-23/src/main.cpp +++ b/software/nano-644/test_2024-07-23/src/main.cpp @@ -124,7 +124,8 @@ extern "C" { I2c i2cMaster(I2c::Master); I2c i2cSlave(I2c::Slave); Rtc8563 rtc8563; - Cc1101 cc1101; + Cc1101 cc1101Send(Cc1101::Send); + Cc1101 cc1101Receive(Cc1101::Receive); } @@ -181,7 +182,7 @@ int main () { #ifdef __AVR_ATmega644P__ TestUnit *unit[] = { &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, &uart1, &modbus, &ieee485, - &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101 + &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive }; #endif @@ -299,7 +300,8 @@ ISR (TIMER2_COMPA_vect) { // every 100us i2cMaster.tick1ms(); i2cSlave.tick1ms(); i2cSparkfun.tick1ms(); - cc1101.tick1ms(); + cc1101Send.tick1ms(); + cc1101Receive.tick1ms(); #ifdef __AVR_ATmega644P__ if (timerFlashRedLed > 0) { if (--timerFlashRedLed < 128) { diff --git a/software/nano-644/test_2024-07-23/src/units/cc1101.cpp b/software/nano-644/test_2024-07-23/src/units/cc1101.cpp index 6b6809b..59cdb1e 100644 --- a/software/nano-644/test_2024-07-23/src/units/cc1101.cpp +++ b/software/nano-644/test_2024-07-23/src/units/cc1101.cpp @@ -78,6 +78,14 @@ const uint8_t PMEM_CC1101_PA_TABLE[8] PROGMEM = { 0x60 ,0x60 ,0x60 ,0x60 ,0x60 , PORTB &= ~(1 << PB0); } + PGM_P Cc1101::getName () { + switch (mode) { + case Send: return PSTR("CC-1101-Send"); + case Receive: return PSTR("CC-1101-Receive"); + default: return PSTR("CC-1101-?"); + } + } + void Cc1101::init () { // trigger for debugging PORTB &= ~(1 << PB0); @@ -401,104 +409,112 @@ int8_t Cc1101::run (uint8_t subtest) { return 0; - } else if (subtest == 2) { + } else if (subtest == 2 && mode == Send) { + uint16_t cnt = 0; do { - uint8_t data[16]; + MainRadioControlState state = UNKNOWN; + uint8_t data[48]; + printf_P(PSTR("\n [%04x]: state="), cnt++); + if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) { + printf_P(PSTR("E1")); + } else { + printf_P(PSTR("0x%02x"), state); + } 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 { + printf_P(PSTR(" --> send 48 bytes ... ")); + if (!sendData(data, sizeof(data))) { flashRedLed(100); - printf_P(PSTR("E4")); + printf_P(PSTR("E1")); + continue; + } + flashGreenLed(100); + printf_P(PSTR("OK -> state=")); + if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) { + printf_P(PSTR("E1")); + } else { + printf_P(PSTR("0x%02x"), state); } - triggerOff(); - } while (wait(2000) == EOF); return 0; - } else if (subtest == 3) { - setReceive(); + // ------------------------------------------------------------------------ + + } else if (subtest == 2 && mode == Receive) { int key = EOF; - uint8_t state; + uint16_t cnt = 0; + MainRadioControlState 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("\n [%04x] => start ... "), cnt++); + setReceive(); + do { + state = UNKNOWN; + if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) { + printf_P(PSTR("E1")); + _delay_ms(500); + break; } - printf_P(PSTR(" State:")); - for (uint8_t i = 0; i < statesIndex; i++) { - printf_P(PSTR(" 0x%02x"), states[i]); + if (wait(0) != EOF) { + printf_P(PSTR("cancelled")); + _delay_ms(500); + break; } + if (state == IDLE) { + printf_P(PSTR("? (IDLE)")); + _delay_ms(500); + break; + } + + } while (state != RX && state != RXFIFO_OVERFLOW); + + if (state != RX && state != RXFIFO_OVERFLOW) { + continue; } - key = wait(0); + printf_P(PSTR("OK, receive ... ")); - while (key == EOF && state != 0x01) { + do { 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); - } + if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) { + printf_P(PSTR("E2")); + _delay_ms(500); + continue; + } + if (wait(0) != EOF) { + printf_P(PSTR("cancelled")); + _delay_ms(500); + continue; + } + 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]); } - key = wait(0); + printf_P(PSTR(" ... ")); } - } - } - return 0; - } else if (subtest == 4) { + } while (state == RX || state == RXFIFO_OVERFLOW); + + printf_P(PSTR("done (state=0x%02x)"), state); + } return 0; - } else if (subtest == 5) { - do { - uint8_t status; - printf_P(PSTR("\n => status: ")); - if (readStatus(CC1101_MARCSTATE, &status)) { - printf_P(PSTR("0x%02x"), status); - } else { - printf_P(PSTR("E6")); - } - } while (wait(2000) == EOF); + // } else if (subtest == 4) { + // return 0; + + // } else if (subtest == 5) { + // do { + // uint8_t status; + // printf_P(PSTR("\n => status: ")); + // if (readStatus(CC1101_MARCSTATE, &status)) { + // printf_P(PSTR("0x%02x"), status); + // } else { + // printf_P(PSTR("E6")); + // } + // } while (wait(2000) == EOF); } return -1; 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 b362314..2893591 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 @@ -8,13 +8,14 @@ class Cc1101 : public TestUnit { public: typedef enum { MHZ915, MHZ433, MHZ868 } InitFrequency; - + typedef enum { Send, Receive } Cc1101Mode; + public: - Cc1101 () {}; + Cc1101 (Cc1101Mode mode) { this->mode = mode; }; virtual void init (); virtual void cleanup (); virtual int8_t run (uint8_t subtest); - virtual PGM_P getName () { return PSTR("CC-1101"); } + virtual PGM_P getName (); public: void tick1ms () { if (timer > 0) timer--; }; @@ -44,6 +45,7 @@ class Cc1101 : public TestUnit { //bool isReceiveFlagSet (); private: + Cc1101Mode mode; uint8_t timer; public: @@ -74,7 +76,8 @@ class Cc1101 : public TestUnit { TX = 19, TX_END = 20, RXTX_SETTLING = 21, - TXFIFO_UNDERFLOW = 22 + TXFIFO_UNDERFLOW = 22, + UNKNOWN = 255 };