]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
fix in script for direct Read and Write in register; fixed read and set of informatio...
authorAdrian Weber <adrian.a.weber@physik.uni-giessen.de>
Fri, 21 Feb 2020 10:47:33 +0000 (11:47 +0100)
committerAdrian Weber <adrian.a.weber@physik.uni-giessen.de>
Fri, 21 Feb 2020 10:47:33 +0000 (11:47 +0100)
atmega32u4/dcdc_rich/dcdc.pl
atmega32u4/dcdc_rich/main.c

index d1d518368dad841422a71bf657698be3671b3cb4..d579376c0001fb4b89272befa1b54326743fdc6b 100755 (executable)
@@ -150,7 +150,7 @@ if($args > 1) {
 if ($mode == 1) {
     
     # direct register access
-    if($args == 6) {
+    if($args == 6 || $args == 5) {
 
         # microcontroller number in chain
         $uC = $ARGV[1];
@@ -172,6 +172,9 @@ if ($mode == 1) {
             $rw = "R";
         } elsif ($rw eq "w" || $rw eq "W") {
             $rw = "W";
+            if ($args == 5) {
+                die "Not all arguements were specified!\n";
+            }
         } else {
             die "This register does not exist\n";
         }
@@ -184,7 +187,11 @@ if ($mode == 1) {
         }
 
         # Value
-        $val = $ARGV[5];
+        if ($rw eq "R") {
+            $val = 0x0;
+        } else {
+            $val = $ARGV[5];
+        }
         if (substr($val,0,2) eq "0x") {$val= hex(substr($val,2));}
         if ($val > 0xFFFF) {
             die "The value is greater than 16 bit! Only 16 bit are allowed\n";
index 7b96ad90a9190be85fe86038069ece53f4d60ba2..859666f4677c993e99432c7a5ed78c2057d819c6 100644 (file)
@@ -25,6 +25,9 @@
 #define SHIFT_EN_OUTPUT()  PORTF &= ~(1<<PF0)
 #define SHIFT_DIS_OUTPUT() PORTF |= (1<<PF0)
 
+#define SEL_ON()  PORTC &= ~(1<<PC6)
+#define SEL_OFF() PORTC |= (1<<PC6)
+
 #define ISMYADDR() (rxbuf[1] == '0' && (rxbuf[2] == '0' )) //|| rxbuf[2] == '1' || rxbuf[2] == '2' || rxbuf[2] == '3') )
 
 uint8_t  settings_changed;
@@ -37,6 +40,7 @@ uint8_t dcdc_settings[4][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
 uint16_t adc_volt = 0;
 uint16_t adc_curr = 0;
 uint16_t adc_temp = 0;
+uint16_t information = 0;
 
 uint8_t nib_to_hex(uint16_t in, uint8_t nib) {
   uint8_t t = (in >> (nib*4)) & 0xF;
@@ -142,8 +146,13 @@ void setDCDC(uint8_t chan, uint8_t val) {
 }
 
 void setInfo(uint8_t chan, uint8_t val){
-  if ((val & 0x1) == 1)  LED_ON();  // LED on
-  if ((val & 0x1) == 0)  LED_OFF(); // LED off
+  if ((val & 0x1) == 1)  { LED_ON();  information |=  (1<<0);}// LED on
+  if ((val & 0x1) == 0)  { LED_OFF(); information &= ~(1<<0);}// LED off
+
+  if (((val>>1) & 0x1) == 1)  { SEL_ON();  information |=  (1<<1);}// Switch activated 
+  if (((val>>1) & 0x1) == 0)  { SEL_OFF(); information &= ~(1<<1);}// Switch deactivated
+
+  information |= (FIRMWARE_VERSION<<4);
 }
 
 uint16_t conversion_ADC(uint8_t mode) {
@@ -249,33 +258,30 @@ void getdata(uint8_t buf) {
         
         switch (hex_to_int(rxbuf[5])) {
           // switch DCDC channel On/Off
-          case 0: {switchDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
-                  uint8_t answer[] = "FFFFFF";
-                  send_answer_hex(&answer[0],0xFFFF);
+          case 0: switchDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
+                  send_answer_hex(&rxbuf[0],hex_to_int(rxbuf[9]));
                   break;
-                  }
+                  
 
           // set voltage of DCDC-Converter
-          case 1: {setDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
-                  //eeprom_update_byte((uint8_t*)(0x20+hex_to_int(rxbuf[4])),hex_to_int(rxbuf[9])&0xF);
-                  uint8_t answer[] = "FFFFFF";
-                  send_answer_hex(&answer[0],0xFFFF);
-                  break;}
-
-          // switch DCDC channel On
-          case 5: {//setInfo(hex_to_int(rxbuf[4]),/* hex_to_int(rxbuf[6])*4096
-                   //                             +hex_to_int(rxbuf[7])*256
-                   //                              +hex_to_int(rxbuf[8])*16
-                   //                            +*/hex_to_int(rxbuf[9]));
-                  uint8_t answer[] = "FFFFFF";
-                  send_answer_hex(&answer[0],0xFFFF);
-                  break;}
-
-          default:  {  
-                      uint8_t answer[] = "FFFFFF";
-                      send_answer_hex(&answer[0],0xFFFF);
-                      break;                
-                    }  
+          case 1: if (hex_to_int(rxbuf[4]) < 4) {
+                    setDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
+                    eeprom_update_byte((uint8_t*)(0x20+hex_to_int(rxbuf[4])),hex_to_int(rxbuf[9])&0xF);
+                  }   
+                  send_answer_hex(&rxbuf[0],hex_to_int(rxbuf[9]));
+                  break;
+
+          // set Infos register
+          case 5: setInfo(hex_to_int(rxbuf[4]),/* hex_to_int(rxbuf[6])*4096
+                                                +hex_to_int(rxbuf[7])*256
+                                                +hex_to_int(rxbuf[8])*16
+                                                +*/hex_to_int(rxbuf[9]));
+                                                
+                  send_answer_hex(&rxbuf[0],information);
+                  break;
+
+          default:  send_answer_hex(&rxbuf[0],0xFFFF);
+                    break;
           
         }
       }
@@ -289,12 +295,12 @@ void getdata(uint8_t buf) {
 
         // get DCDC selection
         if (hex_to_int(rxbuf[5]) == 1) {
-          uint8_t setting = 0xFF;
-          if (hex_to_int(rxbuf[4]) < 4) setting = ((dcdc_settings[hex_to_int(rxbuf[4])][3]&0x1<<12) |
-                                                   (dcdc_settings[hex_to_int(rxbuf[4])][2]&0x1<< 8) |
-                                                   (dcdc_settings[hex_to_int(rxbuf[4])][1]&0x1<< 4) |
-                                                   (dcdc_settings[hex_to_int(rxbuf[4])][0]&0x1)
-                                                  );
+          uint16_t setting = 0xFFFF;
+          if (hex_to_int(rxbuf[4]) < 4) setting = ((dcdc_settings[hex_to_int(rxbuf[4])][3]<<12) |
+                                                   (dcdc_settings[hex_to_int(rxbuf[4])][2]<< 8) |
+                                                   (dcdc_settings[hex_to_int(rxbuf[4])][1]<< 4) |
+                                                   (dcdc_settings[hex_to_int(rxbuf[4])][0])
+                                                  ) & 0xFFFF;
           send_answer_hex(&rxbuf[0],setting);
         }
 
@@ -315,8 +321,8 @@ void getdata(uint8_t buf) {
 
         // get info
         if (hex_to_int(rxbuf[5]) == 5) {
-          uint16_t res = ((FIRMWARE_VERSION<<4) | (0<<1) | (0<<0))&0xFFFF;
-          send_answer_hex(&rxbuf[0],res);
+          information |= (FIRMWARE_VERSION<<4);
+          send_answer_hex(&rxbuf[0],information);
         }
       }
     }