Compare commits

..

No commits in common. "d964ebea372d212143b15aa72bab31cc56b14306" and "e6a3815dc2c8cb7f7e73b4efea9c16760a3a8cbe" have entirely different histories.

6 changed files with 39 additions and 72 deletions

View File

@ -38,7 +38,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
context.command = WRITE_CONFIG; context.command = WRITE_CONFIG;
break; break;
case 0x22: // Clear stored fan speed data case 0x22: // Clear stored fan speed data
context.command = READ_BULK_FAN_SPEED; context.command = CLEAR_BULK_FAN_SPEED;
break; break;
default: // Unrecognized command default: // Unrecognized command
context.command = UNKNOWN_COMMAND; context.command = UNKNOWN_COMMAND;
@ -133,34 +133,26 @@ void parse_command(uint8_t command[], uint8_t command_len) {
uint8_t route_command(int pos) { uint8_t route_command(int pos) {
switch (context.command) { switch (context.command) {
case WRITE_CONFIG: WRITE_CONFIG:
return WRITE_CONFIG; return WRITE_CONFIG;
case READ_CONFIG: break;
READ_CONFIG:
return READ_CONFIG; return READ_CONFIG;
case READ_VOLTAGE: break;
READ_VOLTAGE:
return READ_VOLTAGE; return READ_VOLTAGE;
case READ_TERMPERATURE: break;
READ_TERMPERATURE:
return READ_TERMPERATURE; return READ_TERMPERATURE;
case READ_FAN_SPEED:
if (context.fan == FAN1) {
return fan1_history[0];
} else if (context.fan == FAN2) {
return fan2_history[0];
} else {
return 0;
}
break; break;
case READ_BULK_FAN_SPEED: READ_FAN_SPEED:
if (context.fan == FAN1) { return READ_FAN_SPEED;
return fan1_history[pos];
} else if (context.fan == FAN2) {
return fan2_history[pos];
} else {
return 0;
}
break; break;
case UNKNOWN_COMMAND: CLEAR_BULK_FAN_SPEED:
default: return CLEAR_BULK_FAN_SPEED;
break;
UNKNOWN_COMMAND:
return 0xFF; return 0xFF;
break;
} }
} }

View File

@ -12,7 +12,6 @@
extern "C" { extern "C" {
#endif #endif
#include "eeprom.h"
#include <avr/io.h> #include <avr/io.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -46,8 +45,8 @@ typedef enum {
// Enum of all valid fans // Enum of all valid fans
// TODO: Consider moving into it's own fan page // TODO: Consider moving into it's own fan page
typedef enum { typedef enum {
FAN1 = 1, // The first fan FAN1, // The first fan
FAN2 = 2, // The second fan FAN2, // The second fan
FAN_NONE // No fan FAN_NONE // No fan
} fans_t; } fans_t;
@ -60,10 +59,6 @@ typedef struct {
// TODO: Add config value field for writing // TODO: Add config value field for writing
} command_context_t; } command_context_t;
// Fan history variables
extern volatile uint16_t fan1_history[512];
extern volatile uint16_t fan2_history[512];
// Parses the input string and outputs one of the valid commands // Parses the input string and outputs one of the valid commands
void parse_command(uint8_t *command, uint8_t command_len); void parse_command(uint8_t *command, uint8_t command_len);

View File

@ -1,15 +1,15 @@
#include "eeprom.h" #include "eeprom.h"
// The start address for the controller data // The start address for the controller data
uint16_t EEMEM start_address_controller = 0x1400; uint8_t EEMEM start_address_controller = 0x00;
// Where the writing of the fans points start // Where the writing of the fans points start
uint16_t EEMEM start_address_fan1 = 0x1400 + 0x30; uint8_t EEMEM start_address_fan1 = 0x30;
uint16_t EEMEM start_address_fan2 = 0x1400 + 0x60; uint8_t EEMEM start_address_fan2 = 0x60;
// The placement for the next datapoint form the fans. // The placement for the next datapoint form the fans.
uint16_t EEMEM current_address_fan1 = 0x1400 + 0x30; uint8_t EEMEM current_address_fan1 = 0x30;
uint16_t EEMEM current_address_fan2 = 0x1400 + 0x60; uint8_t EEMEM current_address_fan2 = 0x60;
// Checks if the EEPROM memory is ready to be written in. // Checks if the EEPROM memory is ready to be written in.
void check_eeprom_is_ready(){ void check_eeprom_is_ready(){
@ -58,7 +58,7 @@ int write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num){
check_eeprom_is_ready(); check_eeprom_is_ready();
if (fan_num == 1){ if (fan_num == 1){
eeprom_write_byte(0x30, byte); eeprom_update_byte(current_address_fan1, byte);
current_address_fan1++; current_address_fan1++;
return 1; return 1;
} else if (fan_num == 2){ } else if (fan_num == 2){
@ -97,17 +97,3 @@ uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array){
} }
return sizeof(array); return sizeof(array);
} }
// Reads all the datapoints to the choosen data.
// it writes the data points in the USART stream.
uint8_t read_single_data_point_speed_info(uint8_t fan_num, uint8_t pos){
uint8_t byte = 0;
if (fan_num == 1){
check_eeprom_is_ready();
return eeprom_read_byte(0x30 + pos);
} else if (fan_num == 2){
check_eeprom_is_ready();
return eeprom_read_byte(start_address_fan2 + pos);
}
}

View File

@ -36,13 +36,11 @@ void write_struct_from_EEPROM(config_t write_struct);
config_t read_struct_from_EEPROM(); config_t read_struct_from_EEPROM();
// Writes a datapoint in EEPROM // Writes a datapoint in EEPROM
int write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num); int write_data_point_from_EEPROM(uint8_t byte, uint8_t fan_num);
// Reads all the dataPoints form EEPROM // Reads all the dataPoints form EEPROM
uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array); uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array);
uint8_t read_single_data_point_speed_info(uint8_t fan_num, uint8_t pos);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -4,28 +4,24 @@
* *
* Created on March 6, 2024, 12:34 PM * Created on March 6, 2024, 12:34 PM
*/ */
#include <stdbool.h>
#include "uart.h" #include "uart.h"
#include "voltage.h" #include "voltage.h"
#define RTC_PERIOD (511) #define RTC_PERIOD (511)
#define DELAY_TIME 1000 #define DELAY_TIME 1000
#include "eeprom.h" #include "eeprom.h"
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define F_CPU 4E6 #define F_CPU 4E6
#include "command-handler.h" #include "command-handler.h"
#include "i2c.h" #include "i2c.h"
#include "themistor-temp.h"
#include "uart.h" #include "uart.h"
#include <avr/io.h> #include <avr/io.h>
#include <stdint.h>
#include <util/delay.h> #include <util/delay.h>
#include <stdint.h>
// Fan history variables #include "themistor-temp.h"
volatile uint16_t fan1_history[512] = {1, 2, 3, 4};
volatile uint16_t fan2_history[512] = {2, 3, 4, 5};
int main() { int main() {
init_uart((uint16_t)9600); init_uart((uint16_t)9600);
@ -37,6 +33,8 @@ int main() {
sei(); sei();
while (1) { while (1) {
// uint16_t adcVal = ADC0_read();
// printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal);
; ;
} }
} }

View File

@ -27,8 +27,6 @@
<itemPath>uart.c</itemPath> <itemPath>uart.c</itemPath>
<itemPath>eeprom.c</itemPath> <itemPath>eeprom.c</itemPath>
<itemPath>voltage.c</itemPath> <itemPath>voltage.c</itemPath>
<itemPath>i2c.c</itemPath>
<itemPath>command-handler.c</itemPath>
</logicalFolder> </logicalFolder>
</logicalFolder> </logicalFolder>
<projectmakefile>Makefile</projectmakefile> <projectmakefile>Makefile</projectmakefile>