]> jspc29.x-matter.uni-frankfurt.de Git - electronics.git/commitdiff
latest firmware version
authorJan Michel <j.michel@gsi.de>
Tue, 3 Jun 2014 13:38:58 +0000 (15:38 +0200)
committerJan Michel <j.michel@gsi.de>
Tue, 3 Jun 2014 13:38:58 +0000 (15:38 +0200)
Power/firmware/PowerSwitch.c

index 99a5db161ac0d3f870484c1889ecae926bac9406..0c54c6fd4641db88b14b74102db8679bc81ea698 100755 (executable)
@@ -100,7 +100,7 @@ void switchoutput(uint8_t chan, int8_t to) {
        output_error  &= ~(1<<chan);\r
        }\r
 \r
-  if(to >= -1) {settings_changed = 3;}\r
+  if(to >= -1) {settings_changed |= 4;}\r
   \r
   uint8_t en1 = ((output_enable & 1) && !(output_error & 1))?0:1;\r
   uint8_t en2 = ((output_enable & 2) && !(output_error & 2))?0:1;\r
@@ -226,7 +226,7 @@ ISR(USART1_RX_vect) {
           limit[rxbuf[2]] = lim;\r
           }\r
         send_answer_hex(limit[rxbuf[2]]); \r
-        settings_changed = rxbuf[2]+1;        \r
+        settings_changed |= rxbuf[2]+1;        \r
         }\r
       else {\r
         forward_msg(7);\r
@@ -238,6 +238,8 @@ ISR(USART1_RX_vect) {
     \r
 } \r
 \r
+#define EEPROM_DIS() while(EECR & (1<<EEPE)); EEARL = 0\r
+\r
 void eeprom_write(uint8_t addr, uint8_t data){\r
   while(EECR & (1<<EEPE));\r
   EECR = (0<<EEPM0);\r
@@ -303,19 +305,23 @@ __attribute__((naked)) int main(void) {
   \r
   \r
   while(1) {\r
-    if (settings_changed == 1) {\r
-      settings_changed = 0;\r
-      eeprom_write(0x10,limit[0]&0xFF);\r
-      eeprom_write(0x11,(limit[0]>>8)&0xFF);\r
-      }\r
-    if (settings_changed == 2) {\r
-      settings_changed = 0;\r
-      eeprom_write(0x12,limit[1]&0xFF);\r
-      eeprom_write(0x13,(limit[1]>>8)&0xFF);\r
-      }\r
-    if (settings_changed == 3) {\r
-      settings_changed = 0;\r
-      eeprom_write(0x14,output_enable);\r
-      }\r
+       _delay_ms(3000);  \r
+       if(settings_changed != 0) {\r
+               if (settings_changed & 1) {\r
+                       settings_changed &= ~1;\r
+                       eeprom_write(0x10,limit[0]&0xFF);\r
+                       eeprom_write(0x11,(limit[0]>>8)&0xFF);\r
+               }\r
+               if (settings_changed & 2) {\r
+                       settings_changed &= ~2;\r
+                       eeprom_write(0x12,limit[1]&0xFF);\r
+                       eeprom_write(0x13,(limit[1]>>8)&0xFF);\r
+               }\r
+               if (settings_changed & 4) {\r
+                       settings_changed &= ~4;\r
+                       eeprom_write(0x14,output_enable);\r
+               }\r
+               EEPROM_DIS();\r
+               }\r
     }\r
   }
\ No newline at end of file