From e2aa0533141f1bc05e4d3c3111ae77c8c9bca2d9 Mon Sep 17 00:00:00 2001 From: klaute Date: Sun, 18 Sep 2016 11:41:59 +0200 Subject: [PATCH] The command control interpreter seemes to be working now. --- firmware/Arduino.mk | 1 + firmware/Makefile | 6 + firmware/command_config.h | 65 ---------- firmware/command_ctrl.h | 39 ------ firmware/{command_ctrl.c => command_ctrl.ino} | 116 ++++++++++++++++-- firmware/command_functions.c | 12 -- firmware/firmware.ino | 23 +++- firmware/globals.h | 58 +++++++-- 8 files changed, 182 insertions(+), 138 deletions(-) create mode 120000 firmware/Arduino.mk create mode 100644 firmware/Makefile delete mode 100644 firmware/command_config.h delete mode 100644 firmware/command_ctrl.h rename firmware/{command_ctrl.c => command_ctrl.ino} (53%) delete mode 100644 firmware/command_functions.c diff --git a/firmware/Arduino.mk b/firmware/Arduino.mk new file mode 120000 index 0000000..9c9fac1 --- /dev/null +++ b/firmware/Arduino.mk @@ -0,0 +1 @@ +/usr/share/arduino/Arduino.mk \ No newline at end of file diff --git a/firmware/Makefile b/firmware/Makefile new file mode 100644 index 0000000..fa30db0 --- /dev/null +++ b/firmware/Makefile @@ -0,0 +1,6 @@ +# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile + +BOARD_TAG = nano328 +#MCU = atmega328 + +include Arduino.mk diff --git a/firmware/command_config.h b/firmware/command_config.h deleted file mode 100644 index b74e044..0000000 --- a/firmware/command_config.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de - * Date: 09/2016 - * License: GPLv3 - */ - -#ifndef __COMMAND_CONFIG_H__ -#define __COMMAND_CONFIG_H__ - -/*****************************************************************************/ - -#include -#include - -#include - -#include "globals.h" - -/*****************************************************************************/ - -void cc_setStartFreq(void); -void cc_setEndFreq(void); -void cc_setIntervall(void); -void cc_setDriveStrength(void); -void cc_startMeasurement(void); - -/*****************************************************************************/ - -//#define CC_CMD_GET_CONFIG 0x0A - -/*****************************************************************************/ - -//#define CC_CMD_GET_CONFIG_FUNC &cc_getConfig - -/*****************************************************************************/ - -//#define CC_CMD_GET_CONFIG_DATA_TO_READ 0 - -/*****************************************************************************/ - -#define CC_READ_DATA_MAX 64 - -/*****************************************************************************/ - -uint8_t cc_commands[] = { -// CC_CMD_GET_CONFIG, - - }; - -void (*cc_cmd_functions[])() = { -// CC_CMD_GET_CONFIG_FUNC, - - }; - -uint8_t cc_cmd_data_to_read[] = { -// CC_CMD_GET_CONFIG_DATA_TO_READ, - - }; - -uint8_t cc_read_data[CC_READ_DATA_MAX]; - -/*****************************************************************************/ - -#endif - diff --git a/firmware/command_ctrl.h b/firmware/command_ctrl.h deleted file mode 100644 index 896ee53..0000000 --- a/firmware/command_ctrl.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de - * Date: 09/2016 - * License: GPLv3 - */ - -#ifndef __COMMAND_CTRL_H__ -#define __COMMAND_CTRL_H__ - -#include - -/*****************************************************************************/ - -#define CC_STATE_READ_SOM1 20 -#define CC_STATE_READ_SOM2 30 -#define CC_STATE_READ_CMD 40 -#define CC_STATE_READ_DATA 50 -#define CC_STATE_READ_EOM1 60 -#define CC_STATE_READ_EOM2 70 - -/*****************************************************************************/ - -#define CC_CMD_NO_CMD 0 - -#define MSG_INCOMPLETE 10 -#define MSG_COMPLETE 20 - -/*****************************************************************************/ - -extern void USB_serialStreamWrite(char*); - -void cc_init(void); -void cc_abort(void); -void cc_processData(uint8_t); -void cc_clearReadDataBuffer(void); - -/*****************************************************************************/ - -#endif diff --git a/firmware/command_ctrl.c b/firmware/command_ctrl.ino similarity index 53% rename from firmware/command_ctrl.c rename to firmware/command_ctrl.ino index 5f9878b..746b557 100644 --- a/firmware/command_ctrl.c +++ b/firmware/command_ctrl.ino @@ -1,18 +1,65 @@ /* * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de - * Date: 08/2016 + * Date: 09/2016 * License: GPLv3 */ /*****************************************************************************/ -#include "command_ctrl.h" +#include +#include +#include -#include "command_config.h" +#include -// include user specific command control configuration and function definition -#include "command_config.h" -#include "command_functions.c" +/*****************************************************************************/ + +void cc_init(void); +void cc_abort(void); +void cc_processData(uint8_t); +void cc_clearReadDataBuffer(void); + +/*****************************************************************************/ + +void cc_setStartFreq(void); +void cc_setEndFreq(void); +void cc_setIntervall(void); +void cc_setDriveStrength(void); +void cc_startMeasurement(void); + +/*****************************************************************************/ + +extern "C" { + #include "globals.h" +} + +/*****************************************************************************/ + +uint8_t cc_commands[] = { + CC_CMD_SET_START_FREQ, + CC_CMD_SET_END_FREQ, + CC_CMD_SET_INTERVALL, + CC_CMD_SET_DRIVE_STRENGTH, + CC_CMD_START_MEASUREMENT, + }; + +void (*cc_cmd_functions[])() = { + CC_CMD_SET_START_FREQ_FUNC, + CC_CMD_SET_END_FREQ_FUNC, + CC_CMD_SET_INTERVALL_FUNC, + CC_CMD_SET_DRIVE_STRENGTH_FUNC, + CC_CMD_START_MEASUREMENT_FUNC, + }; + +uint8_t cc_cmd_data_to_read[] = { + CC_CMD_SET_START_FREQ_DATA_TO_READ, + CC_CMD_SET_END_FREQ_DATA_TO_READ, + CC_CMD_SET_INTERVALL_DATA_TO_READ, + CC_CMD_SET_DRIVE_STRENGTH_DATA_TO_READ, + CC_CMD_START_MEASUREMENT_DATA_TO_READ, + }; + +uint8_t cc_read_data[CC_READ_DATA_MAX]; /*****************************************************************************/ @@ -26,6 +73,53 @@ uint8_t cc_cmd_data_read_cnt = 0; /*****************************************************************************/ +void cc_setStartFreq() +{ + char* tmp = " "; + sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, + MSG_TYPE_ANSWER_NOK, + MSG_EOM1, MSG_EOM2); + Serial.write(tmp); +} + +void cc_setEndFreq() +{ + char* tmp = " "; + sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, + MSG_TYPE_ANSWER_NOK, + MSG_EOM1, MSG_EOM2); + Serial.write(tmp); +} + +void cc_setIntervall() +{ + char* tmp = " "; + sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, + MSG_TYPE_ANSWER_NOK, + MSG_EOM1, MSG_EOM2); + Serial.write(tmp); +} + +void cc_setDriveStrength() +{ + char* tmp = " "; + sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, + MSG_TYPE_ANSWER_NOK, + MSG_EOM1, MSG_EOM2); + Serial.write(tmp); +} + +void cc_startMeasurement() +{ + char* tmp = " "; + sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, + 123, + MSG_EOM1, MSG_EOM2); + Serial.write(tmp); +} + +/*****************************************************************************/ + void cc_init() { cc_state = CC_STATE_READ_SOM1; @@ -43,7 +137,7 @@ void cc_abort() sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, MSG_TYPE_ANSWER_NOK, MSG_EOM1, MSG_EOM2); - USB_serialStreamWrite(tmp); + Serial.write(tmp); cc_init(); } @@ -51,6 +145,8 @@ void cc_abort() void cc_processData(uint8_t c) { + uint8_t i = 0; + switch (cc_state) { //*********************************// @@ -71,7 +167,7 @@ void cc_processData(uint8_t c) //*********************************// case CC_STATE_READ_CMD:; - for (uint8_t i = 0; i < sizeof(cc_commands)/sizeof(uint8_t); i++) + for (i = 0; i < sizeof(cc_commands)/sizeof(uint8_t); i++) { if (cc_commands[i] == c) { @@ -137,10 +233,12 @@ void cc_processData(uint8_t c) void cc_clearReadDataBuffer() { - for (uint8_t i = 0; i < CC_READ_DATA_MAX; i++) + uint8_t i = 0; + for (i = 0; i < CC_READ_DATA_MAX; i++) { cc_read_data[i] = 0x00; } } /*****************************************************************************/ + diff --git a/firmware/command_functions.c b/firmware/command_functions.c deleted file mode 100644 index d262279..0000000 --- a/firmware/command_functions.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de - * Date: 09/2016 - * License: GPLv3 - */ - -/*****************************************************************************/ - - - -/*****************************************************************************/ - diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 1fef515..0d704a7 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -4,10 +4,6 @@ #include #include "Wire.h" -extern "C" { - #include "command_ctrl.h" -} - extern "C" { #include "globals.h" } @@ -16,8 +12,13 @@ Si5351 si5351; void setup() { - // Start serial and initialize the Si5351 + // Init the serial connection Serial.begin(57600); + + // initialize the command control module + cc_init(); + + // init the Si5351 si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0); // Set CLK0 to output 14 MHz with a fixed PLL frequency @@ -35,6 +36,8 @@ void loop() { // Read the Status Register and print it every 10 seconds si5351.update_status(); + + /* Serial.print("SYS_INIT: "); Serial.print(si5351.dev_status.SYS_INIT); Serial.print(" LOL_A: "); @@ -45,6 +48,14 @@ void loop() Serial.print(si5351.dev_status.LOS); Serial.print(" REVID: "); Serial.println(si5351.dev_status.REVID); + */ - delay(10000); + if (Serial.available() > 0) + { + uint8_t c = Serial.read() & 0xff; + cc_processData(c); + } + + delay(100); } + diff --git a/firmware/globals.h b/firmware/globals.h index a05c5db..a6a1d29 100644 --- a/firmware/globals.h +++ b/firmware/globals.h @@ -1,14 +1,58 @@ /*****************************************************************************/ - /* Message byte definitions: */ - #define MSG_SOM1 0x3c - #define MSG_SOM2 0x3e - #define MSG_EOM1 0x0d - #define MSG_EOM2 0x0a +/* Message byte definitions: */ +#define MSG_SOM1 0x3c +#define MSG_SOM2 0x3e +#define MSG_EOM1 0x0d +#define MSG_EOM2 0x0a - #define MSG_TYPE_ANSWER_OK 0x01 - #define MSG_TYPE_ANSWER_NOK 0x02 +#define MSG_TYPE_ANSWER_OK 0x01 +#define MSG_TYPE_ANSWER_NOK 0x02 + +/*****************************************************************************/ + +#define CC_STATE_READ_SOM1 20 +#define CC_STATE_READ_SOM2 30 +#define CC_STATE_READ_CMD 40 +#define CC_STATE_READ_DATA 50 +#define CC_STATE_READ_EOM1 60 +#define CC_STATE_READ_EOM2 70 + +/*****************************************************************************/ + +#define CC_CMD_NO_CMD 0 + +#define MSG_INCOMPLETE 10 +#define MSG_COMPLETE 20 + +/*****************************************************************************/ + +#define CC_CMD_SET_START_FREQ 0x01 +#define CC_CMD_SET_END_FREQ 0x02 +#define CC_CMD_SET_INTERVALL 0x03 +#define CC_CMD_SET_DRIVE_STRENGTH 0x04 +#define CC_CMD_START_MEASUREMENT 0x05 + +/*****************************************************************************/ + +#define CC_CMD_SET_START_FREQ_FUNC &cc_setStartFreq +#define CC_CMD_SET_END_FREQ_FUNC &cc_setEndFreq +#define CC_CMD_SET_INTERVALL_FUNC &cc_setIntervall +#define CC_CMD_SET_DRIVE_STRENGTH_FUNC &cc_setDriveStrength +#define CC_CMD_START_MEASUREMENT_FUNC &cc_startMeasurement + +/*****************************************************************************/ + +#define CC_CMD_SET_START_FREQ_DATA_TO_READ 4 // up to 32 bit = 4 byte => 2 ** 32 = >500000000Hz +#define CC_CMD_SET_END_FREQ_DATA_TO_READ 4 // up to 32 bit = 4 byte => 2 ** 32 = >500000000Hz +#define CC_CMD_SET_INTERVALL_DATA_TO_READ 3 // up to 24 bit = 3 byte => 2 ** 24 = >1000000Hz +#define CC_CMD_SET_DRIVE_STRENGTH_DATA_TO_READ 1 +#define CC_CMD_START_MEASUREMENT_DATA_TO_READ 0 + +/*****************************************************************************/ + +#define CC_READ_DATA_MAX 64 /*****************************************************************************/