Added three new functions to enable/disable clock output and save the current settings as default values to thr EEPROM. The firmware reads out those values on startup.

This commit is contained in:
klaute 2016-09-28 14:43:05 +02:00
parent 6a4c134ca4
commit 1e4e3d22d8
4 changed files with 192 additions and 7 deletions

View file

@ -28,6 +28,9 @@ void cc_setFreqStep(void);
void cc_setDriveStrength(void);
void cc_startMeasurement(void);
void cc_getConfig(void);
void cc_enableClk(void);
void cc_disableClk(void);
void cc_saveDefaults(void);
/*****************************************************************************/
@ -45,6 +48,9 @@ uint8_t cc_commands[] = {
CC_CMD_SET_FREQ_STEP,
CC_CMD_START_MEASUREMENT,
CC_CMD_GET_CONFIG,
CC_CMD_EN_CLK,
CC_CMD_DIS_CLK,
CC_CMD_SAV_DFLT,
};
void (*cc_cmd_functions[])() = {
@ -55,6 +61,9 @@ void (*cc_cmd_functions[])() = {
CC_CMD_SET_FREQ_STEP_FUNC,
CC_CMD_START_MEASUREMENT_FUNC,
CC_CMD_GET_CONFIG_FUNC,
CC_CMD_EN_CLK_FUNC,
CC_CMD_DIS_CLK_FUNC,
CC_CMD_SAV_DFLT_FUNC,
};
uint8_t cc_cmd_data_to_read[] = {
@ -65,6 +74,9 @@ uint8_t cc_cmd_data_to_read[] = {
CC_CMD_SET_FREQ_STEP_DATA_TO_READ,
CC_CMD_START_MEASUREMENT_DATA_TO_READ,
CC_CMD_GET_CONFIG_DATA_TO_READ,
CC_CMD_EN_CLK_DATA_TO_READ,
CC_CMD_DIS_CLK_DATA_TO_READ,
CC_CMD_SAV_DFLT_DATA_TO_READ,
};
uint8_t cc_read_data[CC_READ_DATA_MAX];
@ -305,6 +317,74 @@ void cc_getConfig()
/*****************************************************************************/
void cc_enableClk(void)
{
Serial.write(MSG_SOM1);
Serial.write(MSG_SOM2);
if (cc_read_data[0] == SI5351_CLK0)
{
si5351.output_enable(SI5351_CLK0, 1); // enable clock output 0
Serial.write(MSG_TYPE_ANSWER_OK);
}
else if (cc_read_data[0] == SI5351_CLK1)
{
si5351.output_enable(SI5351_CLK1, 1); // enable clock output 1
Serial.write(MSG_TYPE_ANSWER_OK);
}
else if (cc_read_data[0] == SI5351_CLK2)
{
si5351.output_enable(SI5351_CLK2, 1); // enable clock output 2
Serial.write(MSG_TYPE_ANSWER_OK);
} else {
Serial.write(MSG_TYPE_ANSWER_NOK);
}
Serial.write(MSG_EOM1);
Serial.write(MSG_EOM2);
}
/*****************************************************************************/
void cc_disableClk(void)
{
Serial.write(MSG_SOM1);
Serial.write(MSG_SOM2);
if (cc_read_data[0] == SI5351_CLK0)
{
si5351.output_enable(SI5351_CLK0, 0); // disable clock output 0
Serial.write(MSG_TYPE_ANSWER_OK);
}
else if (cc_read_data[0] == SI5351_CLK1)
{
si5351.output_enable(SI5351_CLK1, 0); // disable clock output 1
Serial.write(MSG_TYPE_ANSWER_OK);
}
else if (cc_read_data[0] == SI5351_CLK2)
{
si5351.output_enable(SI5351_CLK2, 0); // disable clock output 2
Serial.write(MSG_TYPE_ANSWER_OK);
} else {
Serial.write(MSG_TYPE_ANSWER_NOK);
}
Serial.write(MSG_EOM1);
Serial.write(MSG_EOM2);
}
/*****************************************************************************/
void cc_saveDefaults(void)
{
Serial.write(MSG_SOM1);
Serial.write(MSG_SOM2);
saveEEPValues();
Serial.write(MSG_TYPE_ANSWER_OK);
Serial.write(MSG_EOM1);
Serial.write(MSG_EOM2);
}
/*****************************************************************************/
void cc_init()
{
cc_state = CC_STATE_READ_SOM1;

View file

@ -4,13 +4,19 @@
* License: GPLv3
*/
/*****************************************************************************/
#include <si5351.h>
#include "Wire.h"
#include <EEPROM.h>
extern "C" {
#include "globals.h"
}
/*****************************************************************************/
Si5351 si5351;
uint32_t start_freq = 10000;
@ -19,6 +25,8 @@ uint32_t step_freq = 1000000; // 1 MHz default step size
uint16_t intervall = 1000; // intervall to change the frequency as milli seconds
enum si5351_drive drive_str = SI5351_DRIVE_2MA;
/*****************************************************************************/
void setup()
{
// manage the analog pins
@ -51,8 +59,12 @@ void setup()
analogReference(DEFAULT); // 5V reference
readEEPValues();
}
/*****************************************************************************/
void loop()
{
// Read the Status Register and print it every 10 seconds
@ -83,3 +95,84 @@ void loop()
delay(100);
}
/*****************************************************************************/
void saveEEPValues()
{
EEPROM.write( 0, (uint8_t)((start_freq & 0xff000000) >> 24));
EEPROM.write( 1, (uint8_t)((start_freq & 0x00ff0000) >> 16));
EEPROM.write( 2, (uint8_t)((start_freq & 0x0000ff00) >> 8));
EEPROM.write( 3, (uint8_t) (start_freq & 0x000000ff));
EEPROM.write( 4, (uint8_t)((end_freq & 0xff000000) >> 24));
EEPROM.write( 5, (uint8_t)((end_freq & 0x00ff0000) >> 16));
EEPROM.write( 6, (uint8_t)((end_freq & 0x0000ff00) >> 8));
EEPROM.write( 7, (uint8_t) (end_freq & 0x000000ff));
EEPROM.write( 8, (uint8_t)((step_freq & 0xff000000) >> 24));
EEPROM.write( 9, (uint8_t)((step_freq & 0x00ff0000) >> 16));
EEPROM.write(10, (uint8_t)((step_freq & 0x0000ff00) >> 8));
EEPROM.write(11, (uint8_t) (step_freq & 0x000000ff));
EEPROM.write(12, (uint8_t)((intervall & 0xff00) >> 8));
EEPROM.write(13, (uint8_t) (intervall & 0x00ff));
EEPROM.write(14, (uint8_t) drive_str);
}
void readEEPValues()
{
uint32_t tmp_start_freq = (uint32_t)EEPROM.read(0) << 24;
tmp_start_freq += (uint32_t)EEPROM.read(1) << 16;
tmp_start_freq += (uint32_t)EEPROM.read(2) << 8;
tmp_start_freq += (uint32_t)EEPROM.read(3);
if (tmp_start_freq < 1)
tmp_start_freq = 1;
if (tmp_start_freq > 150000000)
tmp_start_freq = 150000000;
start_freq = tmp_start_freq;
uint32_t tmp_end_freq = (uint32_t)EEPROM.read(4) << 24;
tmp_end_freq += (uint32_t)EEPROM.read(5) << 16;
tmp_end_freq += (uint32_t)EEPROM.read(6) << 8;
tmp_end_freq += (uint32_t)EEPROM.read(7);
if (tmp_end_freq < 1)
tmp_end_freq = 1;
if (tmp_end_freq > 150000000)
tmp_end_freq = 150000000;
end_freq = tmp_end_freq;
uint32_t tmp_step_freq = (uint32_t)EEPROM.read( 8) << 24;
tmp_step_freq += (uint32_t)EEPROM.read( 9) << 16;
tmp_step_freq += (uint32_t)EEPROM.read(10) << 8;
tmp_step_freq += (uint32_t)EEPROM.read(11);
if (tmp_step_freq < 1)
tmp_step_freq = 1;
if (tmp_step_freq > 150000000)
tmp_step_freq = 150000000;
step_freq = tmp_step_freq;
uint16_t tmp_intervall = (uint16_t)EEPROM.read(12) << 8;
tmp_intervall += (uint16_t)EEPROM.read(13);
if (tmp_intervall < 1)
tmp_intervall = 1;
if (tmp_intervall > 150000000)
tmp_intervall = 150000000;
intervall = tmp_intervall;
enum si5351_drive tmp_ds = (enum si5351_drive)EEPROM.read(14);
if (tmp_ds == SI5351_DRIVE_2MA ||
tmp_ds == SI5351_DRIVE_4MA ||
tmp_ds == SI5351_DRIVE_6MA ||
tmp_ds == SI5351_DRIVE_8MA)
{
drive_str = tmp_ds;
} else {
drive_str = SI5351_DRIVE_2MA;
}
}
/*****************************************************************************/

View file

@ -42,6 +42,9 @@
#define CC_CMD_SET_FREQ_STEP 0x05
#define CC_CMD_START_MEASUREMENT 0x06
#define CC_CMD_GET_CONFIG 0x10
#define CC_CMD_EN_CLK 0x20
#define CC_CMD_DIS_CLK 0x21
#define CC_CMD_SAV_DFLT 0x22
/*****************************************************************************/
@ -52,6 +55,9 @@
#define CC_CMD_SET_FREQ_STEP_FUNC &cc_setFreqStep
#define CC_CMD_START_MEASUREMENT_FUNC &cc_startMeasurement
#define CC_CMD_GET_CONFIG_FUNC &cc_getConfig
#define CC_CMD_EN_CLK_FUNC &cc_enableClk
#define CC_CMD_DIS_CLK_FUNC &cc_disableClk
#define CC_CMD_SAV_DFLT_FUNC &cc_saveDefaults
/*****************************************************************************/
@ -62,6 +68,9 @@
#define CC_CMD_SET_FREQ_STEP_DATA_TO_READ 4
#define CC_CMD_START_MEASUREMENT_DATA_TO_READ 0
#define CC_CMD_GET_CONFIG_DATA_TO_READ 0
#define CC_CMD_EN_CLK_DATA_TO_READ 1
#define CC_CMD_DIS_CLK_DATA_TO_READ 1
#define CC_CMD_SAV_DFLT_DATA_TO_READ 0
/*****************************************************************************/

View file

@ -32,7 +32,7 @@ parser.add_argument("-o", "--output_file", type=str, help="")
# show graphical results
parser.add_argument("-g", "--show_graph", default=False, help="", action='store_true')
# get config
#parser.add_argument("-c", "--get_config", default=False, help="", action='store_true')
parser.add_argument("-c", "--get_config", default=False, help="", action='store_true')
###############################################################################
@ -401,11 +401,6 @@ if __name__ == "__main__":
time.sleep(1.5)
# 3. get and process the commandline arguments/parameter
#if args.get_config == True and args.start_meas == False:
# print "sent: GET_CONFIG"
# sendSerialData([CC_CMD_GET_CONFIG])
# dataSend = dataSend + 1
if args.start_freq != None:
print "Set start frequency to: " + user_friendly_freq(args.start_freq)
sendSerialData([CC_CMD_SET_START_FREQ,
@ -451,6 +446,11 @@ if __name__ == "__main__":
sendSerialData([CC_CMD_START_MEASUREMENT])
dataSend = dataSend + 1
if args.get_config == True and args.start_meas == False:
print "Read configuration values..."
sendSerialData([CC_CMD_GET_CONFIG])
dataSend = dataSend + 1
# 4. start main loop
while dataSend > 0 and timeout < TIMEOUT_CNT_MAX:
@ -488,7 +488,10 @@ if __name__ == "__main__":
elif e[1] == MSG_TYPE_CONFIG:
#print "recv: CONFIG"
print "\nConfiguration used for measurement:"
if args.start_meas == True:
print "\nConfiguration used for measurement:"
else:
print "\nConfiguration:"
start_freq = e[3][0] << 24
start_freq += e[3][1] << 16
start_freq += e[3][2] << 8