New ML support - debug output, bootloader

bootapp - automaticaly erase flash when necessary
+test code
This commit is contained in:
Robert Pelnar 2018-05-30 19:29:52 +02:00
parent 966c826c82
commit 37e575f4bc
6 changed files with 78 additions and 42 deletions

View File

@ -1007,7 +1007,7 @@ void setup()
lcd_init();
fdev_setup_stream(lcdout, lcd_putchar, NULL, _FDEV_SETUP_WRITE); //setup lcdout stream
// upgrade_sec_lang_from_external_flash();
upgrade_sec_lang_from_external_flash();
lcd_splash();
setup_killpin();
@ -1309,27 +1309,9 @@ void setup()
lcd_mylang();
}
lang_select(lang_selected);
puts_P(_n("\nNew ML support"));
printf_P(_n(" lang_selected = %d\n"), lang_selected);
printf_P(_n(" &_SEC_LANG = 0x%04x\n"), &_SEC_LANG);
printf_P(_n(" sizeof(_SEC_LANG) = 0x%04x\n"), sizeof(_SEC_LANG));
uint16_t ptr_lang_table0 = ((uint16_t)(&_SEC_LANG) + 0xff) & 0xff00;
printf_P(_n(" &_lang_table0 = 0x%04x\n"), ptr_lang_table0);
uint32_t _lt_magic = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 0)));
uint16_t _lt_size = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 4)));
uint16_t _lt_count = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 6)));
uint16_t _lt_chsum = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 8)));
uint16_t _lt_resv0 = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 10)));
uint32_t _lt_resv1 = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 12)));
printf_P(_n(" _lt_magic = 0x%08lx %S\n"), _lt_magic, (_lt_magic==0x4bb45aa5)?_n("OK"):_n("NA"));
printf_P(_n(" _lt_size = 0x%04x (%d)\n"), _lt_size, _lt_size);
printf_P(_n(" _lt_count = 0x%04x (%d)\n"), _lt_count, _lt_count);
printf_P(_n(" _lt_chsum = 0x%04x\n"), _lt_chsum);
printf_P(_n(" _lt_resv0 = 0x%04x\n"), _lt_resv0);
printf_P(_n(" _lt_resv1 = 0x%08lx\n"), _lt_resv1);
puts_P(_n("\n"));
#ifdef DEBUG_SEC_LANG
lang_print_sec_lang(uartout);
#endif //DEBUG_SEC_LANG
if (eeprom_read_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE) == 255) {
eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0);

View File

@ -20,10 +20,17 @@ void bootapp_print_vars()
void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size)
{
cli();
// uint16_t ui; for (ui = 0; ui < size; ui++)
// ram_array[ui+rptr] = 0xff;
boot_app_magic = 0x55aa55aa;
boot_app_flags = BOOT_APP_FLG_ERASE | BOOT_APP_FLG_COPY;
boot_app_flags |= BOOT_APP_FLG_COPY;
uint16_t ui; for (ui = 0; ui < size; ui++)
{
uint8_t uc = ram_array[ui+rptr];
if (pgm_readbyte(ui+fptr) & uc != uc)
{
boot_app_flags |= BOOT_APP_FLG_ERASE;
break;
}
}
boot_copy_size = (uint16_t)size;
boot_src_addr = (uint32_t)rptr;
boot_dst_addr = (uint32_t)fptr;

View File

@ -1,12 +1,11 @@
//language.c
#include "language.h"
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "bootapp.h"
// Currectly active language selection.
unsigned char lang_selected = 0;
uint8_t lang_selected = 0;
#if (LANG_MODE == 0) //primary language only
#else //(LANG_MODE == 0)
@ -19,12 +18,12 @@ typedef struct
{
struct
{
uint32_t magic;
uint16_t size;
uint16_t count;
uint16_t checksum;
uint16_t reserved0;
uint32_t reserved1;
uint32_t magic; //+0
uint16_t size; //+4
uint16_t count; //+6
uint16_t checksum; //+8
uint16_t reserved0; //+10
uint32_t reserved1; //+12
} header;
uint16_t table[];
} lang_table_t;
@ -57,7 +56,13 @@ const char* lang_get_sec_lang_str(const char* s)
return (const char*)((char*)_lang_table + ui); //return calculated pointer
}
const char* lang_select(unsigned char lang)
const char* lang_get_sec_lang_str_by_id(uint16_t id)
{
uint16_t ui = ((((uint16_t)&_SEC_LANG) + 0x00ff) & 0xff00); //table pointer
return ui + pgm_read_word(((uint16_t*)(ui + 16 + id * 2))); //read relative offset and return calculated pointer
}
const char* lang_select(uint8_t lang)
{
#if (LANG_MODE == 0) //primary language only
return 0;
@ -77,7 +82,7 @@ const char* lang_select(unsigned char lang)
#endif //(LANG_MODE == 0)
}
unsigned char lang_get_count()
uint8_t lang_get_count()
{
uint16_t ui = (uint16_t)&_SEC_LANG; //pointer to _SEC_LANG reserved space
ui += 0x00ff; //add 1 page
@ -87,11 +92,40 @@ unsigned char lang_get_count()
return 1;
}
const char* lang_get_name(unsigned char lang)
const char* lang_get_name(uint8_t lang)
{
if (lang == 0) return MSG_LANGUAGE_NAME + 2;
return lang_get_sec_lang_str(MSG_LANGUAGE_NAME);
}
#ifdef DEBUG_SEC_LANG
uint16_t lang_print_sec_lang(FILE* out)
{
printf_P(_n("&_SEC_LANG = 0x%04x\n"), &_SEC_LANG);
printf_P(_n("sizeof(_SEC_LANG) = 0x%04x\n"), sizeof(_SEC_LANG));
uint16_t ptr_lang_table0 = ((uint16_t)(&_SEC_LANG) + 0xff) & 0xff00;
printf_P(_n("&_lang_table0 = 0x%04x\n"), ptr_lang_table0);
uint32_t _lt_magic = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 0)));
uint16_t _lt_size = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 4)));
uint16_t _lt_count = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 6)));
uint16_t _lt_chsum = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 8)));
uint16_t _lt_resv0 = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 10)));
uint32_t _lt_resv1 = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 12)));
printf_P(_n(" _lt_magic = 0x%08lx %S\n"), _lt_magic, (_lt_magic==0x4bb45aa5)?_n("OK"):_n("NA"));
printf_P(_n(" _lt_size = 0x%04x (%d)\n"), _lt_size, _lt_size);
printf_P(_n(" _lt_count = 0x%04x (%d)\n"), _lt_count, _lt_count);
printf_P(_n(" _lt_chsum = 0x%04x\n"), _lt_chsum);
printf_P(_n(" _lt_resv0 = 0x%04x\n"), _lt_resv0);
printf_P(_n(" _lt_resv1 = 0x%08lx\n"), _lt_resv1);
if (_lt_magic != 0x4bb45aa5) return 0;
puts_P(_n(" strings:\n"));
uint16_t ui = ((((uint16_t)&_SEC_LANG) + 0x00ff) & 0xff00); //table pointer
for (ui = 0; ui < _lt_count; ui++)
fprintf_P(out, _n(" %3d %S\n"), ui, lang_get_sec_lang_str_by_id(ui));
return _lt_count;
}
#endif //DEBUG_SEC_LANG
const char MSG_LANGUAGE_NAME[] PROGMEM_I1 = ISTR("English"); ////c=0 r=0

View File

@ -3,6 +3,8 @@
#define LANGUAGE_H
#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#define PROTOCOL_VERSION "1.0"
@ -64,7 +66,7 @@ extern "C" {
#endif //defined(__cplusplus)
// Currectly active language selection.
extern unsigned char lang_selected;
extern uint8_t lang_selected;
#if (LANG_MODE != 0)
extern const char _SEC_LANG[LANG_SIZE_RESERVED];
@ -72,9 +74,11 @@ extern const char _SEC_LANG[LANG_SIZE_RESERVED];
extern const char* lang_get_translation(const char* s);
extern const char* lang_get_sec_lang_str(const char* s);
extern const char* lang_select(unsigned char lang);
extern unsigned char lang_get_count();
extern const char* lang_get_name(unsigned char lang);
extern const char* lang_get_sec_lang_str_by_id(uint16_t id);
extern const char* lang_select(uint8_t lang);
extern uint8_t lang_get_count();
extern const char* lang_get_name(uint8_t lang);
extern uint16_t lang_print_sec_lang(FILE* out);
#if defined(__cplusplus)

View File

@ -1722,8 +1722,8 @@ static void lcd_menu_temperatures()
static void lcd_menu_voltages()
{
float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
//float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
//fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
// float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
// fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
fprintf_P(lcdout, PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
if (lcd_clicked())
{
@ -5653,6 +5653,13 @@ void lcd_confirm_print()
}
extern void __test();
static void lcd_test_menu()
{
__test();
}
static void lcd_main_menu()
{
@ -5822,6 +5829,7 @@ static void lcd_main_menu()
#endif
MENU_ITEM(submenu, _i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
// MENU_ITEM(submenu, _i("Test"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
END_MENU();

View File

@ -148,6 +148,7 @@
#define MINTEMP_MINAMBIENT_RAW 978
//#define DEBUG_BUILD
//#define DEBUG_SEC_LANG //secondary language debug output at startup
#ifdef DEBUG_BUILD
//#define _NO_ASM
#define DEBUG_DCODES //D codes