Skip to content
Browse files

- solved some warnings

- changed optimizisation due compile problems
- added startup_values which are send when controller is powered up. Start up values are saved in eeprom.
  • Loading branch information...
1 parent ccfc32b commit 2c22bc0d1cb2e51c104f941c0b67eb599d3d0756 Timm committed
View
21 firmware/DaliMaster.c
@@ -7,6 +7,7 @@
#include "dali.h"
#include "suart.h"
#include "Interpreter.h"
+#include "startup_values.h"
const char* username = "";
const char* password = "";
@@ -18,8 +19,7 @@ int main()
fifo_t fifo;
word frame;
int ret;
- int i = 0;
- int temp2;
+ int i = 0;
//buffer for temporary strings
byte temp[MAX_BUFFER_LENGTH+1];
@@ -29,14 +29,19 @@ int main()
dali_init();
fifo_init(&fifo, buffer, MAX_BUFFER_LENGTH);
+ load_startup_values();
+ send_startup_values();
+
sei();
- //wait until 4 sec no messages via uart --> boot time has ended
- for(i = 0; i < 400; i++)
+ //wait until 7 sec no messages via uart --> boot time has ended
+ for(i = 0; i < 7000; i++)
{
- if(suart_getc_nowait () > -1)
+ while(suart_getc_nowait () > -1)
+ {
i = 0;
+ }
- _delay_ms(10);
+ _delay_ms(1);
}
//now login
@@ -62,9 +67,9 @@ int main()
if(c == '\n' || c == '\r') // '\n' is end of command
{
_inline_fifo_get_chars( &fifo, temp, fifo.count);
- if(strlen(temp) > 2)
+ if(strlen((const char*)temp) > 2)
{
- ret = decode_command_to_frame(temp, &frame);
+ ret = decode_command_to_frame((char*)temp, &frame);
if(ret > 0)
{
if(_MODE_SIMPLE_ == ret)
View
27 firmware/Interpreter.c
@@ -1,5 +1,6 @@
#include "Interpreter.h"
#include "dali_encode.h"
+#include "startup_values.h"
#include "dali.h"
#include <ctype.h>
@@ -104,6 +105,9 @@ const char command_query_scene_level[] _PROGMEM = "query_scene_level";
const char NACK[] _PROGMEM = "NACK";
const char ACK[] _PROGMEM = "ACK";
+const char internal_command_save_current_as_default[] = "save_current_as_default";
+const char internal_command_clear_default_values[] = "clear_default_values";
+
typedef struct key_value_mode
{
const char* key;
@@ -203,9 +207,9 @@ char nibble_to_ascii(uint8_t nibble)
return nibble + '0';
else
return nibble + 'A' - 0x0A;
-}
+}
-char ascii_to_nibble(char nibble)
+/*char ascii_to_nibble(char nibble)
{
if(isdigit(nibble))
return nibble - '0';
@@ -213,7 +217,7 @@ char ascii_to_nibble(char nibble)
return nibble - 'A' + 0x0A;
else
return -1;
-}
+}*/
inline int parse_int(char* string, int16_t* integer)
{
@@ -334,7 +338,10 @@ int decode_command_to_frame(char* token, word* output)
{
ret = dali_slave_direct_arc(output, (byte)param1, (byte)param2);
if(ret == _ERR_OK_)
+ {
+ arc_device[param1] = param2;
return _MODE_SIMPLE_;
+ }
else return ret;
}
return _ERR_PARAMETER_MISSING_;
@@ -346,7 +353,10 @@ int decode_command_to_frame(char* token, word* output)
{
ret = dali_group_direct_arc(output, (byte)param1, (byte)param2);
if(ret == _ERR_OK_)
+ {
+ arc_group[param1] = param2;
return _MODE_SIMPLE_;
+ }
else return ret;
}
return _ERR_PARAMETER_MISSING_;
@@ -486,6 +496,17 @@ int decode_command_to_frame(char* token, word* output)
if(!strcmp_P(command, ACK))
return _ERR_ACK;
+ if(!strcmp(command, internal_command_save_current_as_default))
+ {
+ save_startup_values();
+ return _ERR_ACK;
+ }
+
+ if(!strcmp(command, internal_command_clear_default_values))
+ {
+ clear_startup_values();
+ return _ERR_ACK;
+ }
return _ERR_UNIMPLEMENTED_;
}
View
4 firmware/Interpreter.h
@@ -20,9 +20,7 @@ extern "C"
#define _ERR_ACK 9000
#define _ERR_NACK 9001
-inline char nibble_to_ascii(uint8_t nibble);
-
-inline char ascii_to_nibble(char nibble);
+char nibble_to_ascii(uint8_t nibble);
int decode_command_to_frame(char* token, word* output);
View
4 firmware/SConstruct
@@ -8,7 +8,7 @@ mcu="at90pwm316"
F_CPU=16000000
# Add all additional source files to compile
-src="""dali.c dali_encode.c eusart_lib.c fifo.c Interpreter.c suart.c"""
+src="""dali.c dali_encode.c eusart_lib.c fifo.c Interpreter.c startup_values.c suart.c"""
# Add Source Path here
cpppath=""" . """
@@ -18,7 +18,7 @@ cpath = """ . """
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-opt = "s"
+opt = "1"
# Add Additional Compiler Flags
flags=""" """
View
5 firmware/dali.c
@@ -8,6 +8,8 @@ void dali_init()
eusart_init (MSK_EUSART_TX_16BIT, MSK_EUSART_RX_8BIT, MANCHESTER, MSB_FIRST, 16000000, 600, PARITY_NONE, 2, 2);
+ eusart_disable_rx();
+
}
int dali_send(word frame)
@@ -35,6 +37,7 @@ int dali_query(word frame, byte* result)
if(frame == INVALID_FRAME)
return _ERR_INVALID_FRAME_;
eusart_put(frame);
+ eusart_enable_rx();
_delay_ms(20);
for(i = 0; i < 50; i++)
{
@@ -42,4 +45,6 @@ int dali_query(word frame, byte* result)
if(eusart_rx_ready())
*result = eusart_get();
}
+ eusart_disable_rx();
+ return _ERR_OK_;
}
View
11 firmware/euart.c
@@ -151,12 +151,21 @@ void euart_init()
UART_set_two_tx_stop();
EUSART_set_two_rx_stop();
- EUSART_enable_rx();
+ //EUSART_enable_rx();
+ EUSART_disable_rx();
EUSART_enable_tx();
//EUSART_enable_rx_interrupt();
}
+Bool euart_enable_rx(Bool enable)
+{
+ if(enable)
+ EUSART_enable_rx();
+ else
+ EUSART_disable_rx();
+}
+
Bool euart_tx_done(void)
{
if (EUSART_tx_complete()!=0)
View
2 firmware/euart.h
@@ -55,6 +55,8 @@ extern Uint8 eusart_rx_error;
Bool euart_init();
+Bool euart_enable_rx(Bool enable);
+
Bool euart_tx_done(void);
Uint16 euart_put(Uint16 uc_wr_byte);
View
97 firmware/startup_values.c
@@ -0,0 +1,97 @@
+#include "startup_values.h"
+#include "dali.h"
+
+#ifdef TEST
+word temp;
+#define uint8_t unsigned char
+#define PROGMEM
+#define EEMEM
+#define strcmp_P strcmp
+#define strcpy_P strcpy
+#define eeprom_read_byte(a) a
+#define eeprom_update_byte(a,b) *a = b
+#define dali_send(a) temp=a
+#else
+#include <avr/eeprom.h>
+#endif
+
+#ifndef TEST
+#include <util/delay.h>
+#endif
+
+
+uint8_t arc_device[64] = {[0 ... 63] = 255};
+uint8_t arc_group[16] = {[0 ... 15] = 255};
+
+uint8_t arc_device_eeprom[64] EEMEM = {[0 ... 63] = 255};
+uint8_t arc_group_eeprom[16] EEMEM = {[0 ... 15] = 255};
+
+void load_startup_values()
+{
+ int i;
+ for(i = 0; i < 64; i++)
+ {
+ arc_device[i] = eeprom_read_byte (&arc_device_eeprom[i]);
+ }
+ for(i = 0; i < 16; i++)
+ {
+ arc_group[i] = eeprom_read_byte (&arc_group_eeprom[i]);
+ }
+}
+
+void save_startup_values()
+{
+ int i;
+ for(i = 0; i < 64; i++)
+ {
+ eeprom_update_byte(&arc_device_eeprom[i], arc_device[i]);
+ }
+ for(i = 0; i < 16; i++)
+ {
+ eeprom_update_byte(&arc_group_eeprom[i], arc_group[i]);
+ }
+}
+
+void clear_startup_values()
+{
+ int i;
+ for(i = 0; i < 64; i++)
+ {
+ arc_device[i] = 0xFF;
+ eeprom_update_byte(&arc_device_eeprom[i], arc_device[i]);
+ }
+ for(i = 0; i < 16; i++)
+ {
+ arc_group[i] = 0xFF;
+ eeprom_update_byte(&arc_group_eeprom[i], arc_group[i]);
+ }
+}
+
+void send_startup_values()
+{
+ int i;
+ word frame;
+ for(i = 0; i < 64; i++)
+ {
+ if(arc_device[i] != 255)
+ {
+ dali_slave_direct_arc(&frame, i, arc_device[i]);
+ dali_send(frame);
+#ifndef TEST
+ _delay_ms(40);
+#endif
+ }
+ }
+ for(i = 0; i < 16; i++)
+ {
+ if(arc_group[i] != 255)
+ {
+ dali_group_direct_arc(&frame, i, arc_group[i]);
+ dali_send(frame);
+#ifndef TEST
+ _delay_ms(40);
+#endif
+ }
+ }
+}
+
View
12 firmware/startup_values.h
@@ -0,0 +1,12 @@
+#ifndef _STARTUP_VALUES_H_
+#define _STARTUP_VALUES_H_
+
+extern unsigned char arc_device[64];
+extern unsigned char arc_group[16];
+
+void load_startup_values();
+void save_startup_values();
+void send_startup_values();
+void clear_startup_values();
+
+#endif
View
2 firmware/suart.c
@@ -99,7 +99,7 @@ void suart_putc (const char c)
#ifdef SUART_TXD
-void suart_putstring(char* s)
+void suart_putstring(const char* s)
{
while(*s)
{
View
2 firmware/suart.h
@@ -17,7 +17,7 @@ extern void suart_init();
#ifdef SUART_TXD
extern void suart_putc (const char);
- extern void suart_putstring(char*);
+ extern void suart_putstring(const char*);
#endif // SUART_RXD
#ifdef SUART_RXD
View
1 firmware/tests/firmware_test/CMakeLists.txt
@@ -17,6 +17,7 @@ SET ( SOURCE_FILES
firmware_tests.cpp
../../dali_encode.c
../../Interpreter.c
+ ../../startup_values.c
)
add_definitions( -DTEST -Dgtest_build_tests=ON )
View
6 firmware/tests/firmware_test/firmware_tests.cpp
@@ -171,6 +171,12 @@ TEST(ParserTestValidInputString, POSITIVE)
EXPECT_EQ(frame2, frame);
+ EXPECT_EQ(_MODE_SIMPLE_, decode_command_to_frame("go_to_scene_b 5", &frame));
+
+ EXPECT_EQ(_ERR_OK_,dali_broadcast_command_with_param(&frame2, DALI_GO_TO_SCENE, 5));
+
+ EXPECT_EQ(frame2, frame);
+
EXPECT_EQ(_MODE_SIMPLE_, decode_command_to_frame("up_b", &frame));
EXPECT_EQ(_ERR_OK_, dali_broadcast_command(&frame2, DALI_UP_200MS));

0 comments on commit 2c22bc0

Please sign in to comment.
Something went wrong with that request. Please try again.