|
@@ -31,15 +31,21 @@
|
|
|
#include "spi.h"
|
|
|
#include "utils.h"
|
|
|
#include "registers.h"
|
|
|
+#include "generation.h"
|
|
|
|
|
|
+/* FLASH */
|
|
|
#define FLASH_MAILBOX_STORAGE 0x0F0000
|
|
|
|
|
|
+static uint32_t copy_array[16];
|
|
|
+
|
|
|
/*
|
|
|
double dupa;
|
|
|
float kupa;
|
|
|
*/
|
|
|
|
|
|
-static uint32_t copy_array[16];
|
|
|
+/* Local generation params for tweaking actual HW generation params */
|
|
|
+static tweaked_params_union_s out_params;
|
|
|
+
|
|
|
|
|
|
static inline uint32_t rdcycle(void)
|
|
|
{
|
|
@@ -50,7 +56,7 @@ static inline uint32_t rdcycle(void)
|
|
|
|
|
|
/* Timer fuction */
|
|
|
#define CYCLES_DIV 24000000.0f
|
|
|
-#define UPDATE_MS 3.0f
|
|
|
+#define UPDATE_MS 0.1f
|
|
|
// TODO: integers not floats?
|
|
|
|
|
|
static uint32_t last_rdcycle;
|
|
@@ -65,18 +71,12 @@ static bool timer_expired()
|
|
|
if (elapsed_seconds > UPDATE_MS)
|
|
|
{
|
|
|
last_rdcycle = current;
|
|
|
- printf("Timer expired!\n");
|
|
|
+ //printf("Timer expired!\n");
|
|
|
success = true;;
|
|
|
}
|
|
|
return success;
|
|
|
}
|
|
|
|
|
|
-/* three signal generation params */
|
|
|
-static void update_three_signal_values()
|
|
|
-{
|
|
|
- //printf("Updating 3signal values\n");
|
|
|
-}
|
|
|
-
|
|
|
static void print_mailbox_contents()
|
|
|
{
|
|
|
int i = 0;
|
|
@@ -85,12 +85,22 @@ static void print_mailbox_contents()
|
|
|
printf("Mailbox[%d]: %d\n", i, mailbox_regs->data[i]);
|
|
|
}
|
|
|
|
|
|
-static void store_mailbox_regs_flash()
|
|
|
+static void read_generation_values_from_flash()
|
|
|
{
|
|
|
+ flash_read((void*)copy_array, FLASH_MAILBOX_STORAGE, sizeof(copy_array));
|
|
|
+
|
|
|
+ // Copy data to actual registers
|
|
|
+ for (int i = 0; i < 14; ++i)
|
|
|
+ out_params.data[i] = copy_array[i];
|
|
|
+}
|
|
|
+
|
|
|
+static void store_generation_values_flash()
|
|
|
+{
|
|
|
+ // TODO: can we remove it already as we don't read directly to mailbox
|
|
|
// Copy current mailbox array to a temporary array for bulk memory write
|
|
|
// our Wishbone implementation does not support bulk writes
|
|
|
for (int i = 0; i < 16; ++i)
|
|
|
- copy_array[i] = mailbox_regs->data[i];
|
|
|
+ copy_array[i] = out_params.data[i];
|
|
|
|
|
|
flash_write_enable();
|
|
|
flash_sector_erase(FLASH_MAILBOX_STORAGE);
|
|
@@ -102,15 +112,7 @@ static void store_mailbox_regs_flash()
|
|
|
while (flash_read_sr() & 0x01) /* WIP bit */;
|
|
|
}
|
|
|
|
|
|
-static void read_mailbox_regs_flash()
|
|
|
-{
|
|
|
- flash_read((void*)copy_array, FLASH_MAILBOX_STORAGE, sizeof(copy_array));
|
|
|
-
|
|
|
- // Copy data to actual mailbox
|
|
|
- for (int i = 0; i < 16; ++i)
|
|
|
- mailbox_regs->data[i] = copy_array[i];
|
|
|
-}
|
|
|
-
|
|
|
+/*
|
|
|
static void dummy_write_to_flash()
|
|
|
{
|
|
|
printf("Dummy writing to flash\n");
|
|
@@ -123,6 +125,7 @@ static void dummy_write_to_flash()
|
|
|
print_mailbox_contents();
|
|
|
store_mailbox_regs_flash();
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
static void
|
|
|
serial_no_init()
|
|
@@ -156,7 +159,7 @@ static void write_period1()
|
|
|
printf("Done writing\n");
|
|
|
|
|
|
print_mailbox_contents();
|
|
|
- store_mailbox_regs_flash();
|
|
|
+ //store_mailbox_regs_flash();
|
|
|
}
|
|
|
|
|
|
static void write_period1_2()
|
|
@@ -166,7 +169,7 @@ static void write_period1_2()
|
|
|
printf("Done writing\n");
|
|
|
|
|
|
print_mailbox_contents();
|
|
|
- store_mailbox_regs_flash();
|
|
|
+ //store_mailbox_regs_flash();
|
|
|
}
|
|
|
|
|
|
static void write_period1_4()
|
|
@@ -177,7 +180,7 @@ static void write_period1_4()
|
|
|
printf("Reading now \n");
|
|
|
printf("value: %d\n", mailbox_regs->regs.period1);
|
|
|
print_mailbox_contents();
|
|
|
- store_mailbox_regs_flash();
|
|
|
+ //store_mailbox_regs_flash();
|
|
|
}
|
|
|
|
|
|
static void clear_period1()
|
|
@@ -192,7 +195,7 @@ static void write_delay1()
|
|
|
printf("Writing delay1 0x1234\n");
|
|
|
mailbox_regs->regs.delay1 = 0x1234;
|
|
|
printf("Done writing\n");
|
|
|
- store_mailbox_regs_flash();
|
|
|
+ //store_mailbox_regs_flash();
|
|
|
}
|
|
|
|
|
|
static void clear_delay1()
|
|
@@ -204,7 +207,7 @@ static void clear_delay1()
|
|
|
|
|
|
static void print_flash_contents()
|
|
|
{
|
|
|
- read_mailbox_regs_flash();
|
|
|
+ read_generation_values_from_flash();
|
|
|
print_mailbox_contents();
|
|
|
}
|
|
|
|
|
@@ -243,13 +246,24 @@ void main()
|
|
|
/* Enable USB directly */
|
|
|
serial_no_init();
|
|
|
|
|
|
+ /* Read generation reg values from flash */
|
|
|
+ read_generation_values_from_flash();
|
|
|
+
|
|
|
+ /* If values are wrong - fill defaults */
|
|
|
+ validate_generation_values(&out_params.regs);
|
|
|
+
|
|
|
/* Main loop */
|
|
|
while (1)
|
|
|
{
|
|
|
/* Run the timer for button updates periodically */
|
|
|
if (timer_expired())
|
|
|
+ {
|
|
|
update_three_signal_values();
|
|
|
+ // TODO: need a new value to write contents to flash ( probably +1 mailbox?)
|
|
|
+ //write_to_flash();
|
|
|
+ }
|
|
|
|
|
|
+#ifdef USE_KEYBOARD
|
|
|
/* Prompt ? */
|
|
|
if (cmd >= 0)
|
|
|
printf("Command> ");
|
|
@@ -297,5 +311,6 @@ void main()
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
}
|
|
|
}
|