Commit 245f7939a2c160a5df9fb93e2d55f22408cfc2b1
receivedFri, 8. Nov 2024, 18:00:14 (by user sx)
Fri, 8 Nov 2024 17:00:14 +0000 (18:00 +0100)
authorManfred Steiner <sx@htl-kaindorf.at>
Fri, 8 Nov 2024 17:00:08 +0000 (18:00 +0100)
committerManfred Steiner <sx@htl-kaindorf.at>
Fri, 8 Nov 2024 17:00:08 +0000 (18:00 +0100)
7 files changed:
software/test-software/.vscode/c_cpp_properties.json
software/test-software/nano-1284/Makefile
software/test-software/nano-328/Makefile
software/test-software/nano-644/Makefile
software/test-software/src/main.cpp
software/test-software/src/units/cc1101.cpp
software/test-software/src/units/cc1101.hpp

index 3a57c79326df94a4b38d4c4175115b610d0f897c..87fd0ec1ea12e301504ebd30c59f0275e9191d54 100644 (file)
@@ -7,8 +7,8 @@
                 "/usr/lib/gcc/avr/**"
             ],
             "defines": [],
-            "compilerPath": "/usr/bin/avr-gcc",
-            "compilerArgs": [ "-mmcu=atmega644p", "-DF_CPU=12000000", "-Os" ],
+            "compilerPath": "/usr/bin/avr-g++",
+            "compilerArgs": [ "-mmcu=atmega1284p", "-DF_CPU=12000000", "-Os" ],
             "cStandard": "gnu11",
             "cppStandard": "gnu++11",
             "intelliSenseMode": "linux-gcc-x64"
index 8485c676973370ddcd2923a1a77990686ab790a1..5edd2d25ea2452bf2fa0200d17c30a49267f3512 100644 (file)
@@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
 
 CC= avr-g++
 CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY)  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
 
 CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
 
 # --------------------------------------------------------------------------------
 # make targets
index be62feca42e20b9ed9bfc4974fdd405330f4ec2b..e0fb4c6c763429227f386d85a4eba74ae722d0fd 100644 (file)
@@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
 
 CC= avr-g++
 CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY)  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
 
 CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
 
 # --------------------------------------------------------------------------------
 # make targets
index 75c25e3c124fd344a08e7077c57f81d42714934f..6d0033e92abdc2b96336697059819e806568904a 100644 (file)
@@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
 
 CC= avr-g++
 CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY)  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS)
 
 CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g  -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
-#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm
-LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm
+#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS)
 
 # --------------------------------------------------------------------------------
 # make targets
index 2a7faecdda6bbab5152d0c0b30604b056316c710..4f0fbb0370495a0f97b98c8c98006095f35cc4b5 100644 (file)
@@ -205,12 +205,13 @@ uint8_t detectHardwareVersion () {
 
    if (hardwareVersion < 1 || hardwareVersion > 2) {
       #ifdef __AVR_ATmega644P__
-         printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega644P, 3.3V)\n"), ADCH);
+         printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega644P, 3.3V)\n"), ADCH);
       #elif __AVR_ATmega1284P__
-         printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega1284P, 3.3V)\n"), ADCH);
+         printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega1284P, 3.3V)\n"), ADCH);
       #elif __AVR_ATmega328P__
-         printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega328P, 5V)\n"), ADCH);
+         printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega328P, 5V)\n"), ADCH);
       #endif
+      hardwareVersion = 0;
    } else {
       // const char *pHw; memcpy_P(&pHw, PSTR_HARDWARE + hardwareVersion - 1, sizeof(const char *));
       printf_P(PSTR("\n\nHardware %S detected (ADC7H=0x%02X)"), hardwareVersionPStr(hardwareVersion), ADCH);
@@ -279,21 +280,26 @@ int main () {
 
    sei();
 
+   detectHardwareVersion();
+
+   uint8_t units;
    #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
       TestUnit *unit[] = {
-         &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, &uart1, &modbus, &ieee485,
-         &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive
+         &uart1, &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive,
+         &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd,  &modbus, &ieee485
       };
+      units = hardwareVersion == 0 ? 7 : sizeof(unit) / sizeof(unit[0]);
    #endif
 
    #ifdef __AVR_ATmega328P__
       TestUnit *unit[] = {
-         &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd,
-         &i2cMaster, &i2cSlave, &i2cSparkfun
+         &i2cMaster, &i2cSlave, &i2cSparkfun,
+         &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd
       };
+      units = hardwareVersion == 0 ? 3 : sizeof(unit) / sizeof(unit[0]);
    #endif
 
-   detectHardwareVersion();
+
 
    while (1) {
       uint16_t i;
@@ -306,15 +312,14 @@ int main () {
          printf_P(MAIN_CPP_TIME);
          printf_P(PSTR_DIVIDER);
          if (hardwareVersion >= 1 && hardwareVersion <= 2) {
-            printf_P(PSTR("Hardware: %S"), hardwareVersionPStr(hardwareVersion)); 
+            printf_P(PSTR("Nano-X-Base: %S"), hardwareVersionPStr(hardwareVersion)); 
          } else {
-            printf_P(PSTR("ERROR: Invalid Hardware (%d)"), hardwareVersion); 
-            for(;;);
+            printf_P(PSTR("No Nano-X-Base detected"));
          }
          printf_P(PSTR_DIVIDER);
          printf_P(PSTR_LINEFEED);
          printf_P(PSTR("Available units:\n\n"));
-         for (i = 0; i < sizeof(unit) / sizeof(unit[0]); i++) {
+         for (i = 0; i < units; i++) {
             TestUnit *pu = unit[i];
             printf_P(PSTR("%3x ... "), i);
             printf_P(pu->getName());
@@ -323,7 +328,7 @@ int main () {
          printf_P(PSTR("\nSelect unit: "));
          rIndex = 0; wIndex = 0;
          fgets(s, sizeof(s), stdin);
-      } while (sscanf(s, "%x", &i) != 1 || i < 0 || i >= sizeof(unit) / sizeof(unit[0]) );
+      } while (sscanf(s, "%x", &i) != 1 || i < 0 || i >= units );
       
       TestUnit *pu = unit[i];
       printf_P(PSTR("\n\n[")); printf_P(pu->getName()); printf_P(PSTR("]: "));
index aebe71398f97d66b1bec6431f595afa692911389..039c94d67b19a5d15b502239635d55979dcd2fae 100644 (file)
 
 
    int8_t Cc1101::run (uint8_t subtest) {
+      if (!initDone) {
+         return -1;
+      }
       switch (mode) {
          case Send: return runSend(subtest);
          case Receive: return runReceive(subtest);
 
    void Cc1101::init () {
 
+      // trigger for debugging
+      PORTB &= ~(1 << PB0);
+      DDRB |= ( 1 << PB0);
+
       #ifdef __AVR_ATmega1284P__
          // Nano-1284
+         triggerOn();
          DDRC |= (1 << PC6);
          PORTC |= (1 << PC6); // modem voltage 3.3V ON
+         _delay_us(100);
+         triggerOff();
       #endif
 
-      // trigger for debugging
-      PORTB &= ~(1 << PB0);
-      DDRB |= ( 1 << PB0);
-
       PRR0 &= (1 << PRSPI);
       
       // nCs
          return;
       }
       printf_P(PSTR("OK"));
+      initDone = true;
 
       debugPrint.byte = 0xff; // print all
       printRegisters();
          DDRC &= ~(1 << PC6);
          PORTC &= ~(1 << PC6); // modem voltage 3.3V OFF
       #endif
+
+      initDone = false;
    }
 
    void Cc1101::setChipEnableLow () {
+      triggerOn();
       PORTA &= ~(1 << PA4);
+      // _delay_us(20); // measurement shows -> delay not needed
    }
 
    void Cc1101::setChipEnableHigh () {
+      triggerOff();
+      _delay_us(40); // measurement shows -> delay needed before(!) signal rises high
       PORTA |= (1 << PA4);
    }
 
       ok &= waitForMisoLow();
       ok &= strobe(SRES);
       ok &= waitForMisoLow();
-      
-
       return ok;
    }
 
index a861f09de62ecc45de319712ec8b8874406d04dd..3a51cccdf7392d9acd0acd7532c3d5bde4147e2a 100644 (file)
@@ -32,7 +32,7 @@ class Cc1101 : public TestUnit {
       } status;
 
    public:
-      Cc1101 (Cc1101Mode mode) { timer = 0; this->mode = mode; status.dword = 0; }
+      Cc1101 (Cc1101Mode mode) { timer = 0; this->mode = mode; status.dword = 0; initDone = false; }
       virtual void init ();
       virtual void cleanup ();
       virtual int8_t run (uint8_t subtest);
@@ -77,8 +77,9 @@ class Cc1101 : public TestUnit {
       
 
    private:
+      bool initDone;
       Cc1101Mode mode;
-      uint8_t timer;
+      volatile uint8_t timer;
       union {
          DebugPrint_t print;
          uint8_t byte;