Compare commits
2 Commits
e6a3815dc2
...
d964ebea37
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d964ebea37 | ||
|
|
bf3753a012 |
@ -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 = CLEAR_BULK_FAN_SPEED;
|
context.command = READ_BULK_FAN_SPEED;
|
||||||
break;
|
break;
|
||||||
default: // Unrecognized command
|
default: // Unrecognized command
|
||||||
context.command = UNKNOWN_COMMAND;
|
context.command = UNKNOWN_COMMAND;
|
||||||
@ -132,27 +132,35 @@ 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) {
|
||||||
WRITE_CONFIG:
|
case WRITE_CONFIG:
|
||||||
return WRITE_CONFIG;
|
return WRITE_CONFIG;
|
||||||
break;
|
case READ_CONFIG:
|
||||||
READ_CONFIG:
|
return READ_CONFIG;
|
||||||
return READ_CONFIG;
|
case READ_VOLTAGE:
|
||||||
break;
|
return READ_VOLTAGE;
|
||||||
READ_VOLTAGE:
|
case READ_TERMPERATURE:
|
||||||
return READ_VOLTAGE;
|
return READ_TERMPERATURE;
|
||||||
break;
|
case READ_FAN_SPEED:
|
||||||
READ_TERMPERATURE:
|
if (context.fan == FAN1) {
|
||||||
return READ_TERMPERATURE;
|
return fan1_history[0];
|
||||||
break;
|
} else if (context.fan == FAN2) {
|
||||||
READ_FAN_SPEED:
|
return fan2_history[0];
|
||||||
return READ_FAN_SPEED;
|
} else {
|
||||||
break;
|
return 0;
|
||||||
CLEAR_BULK_FAN_SPEED:
|
}
|
||||||
return CLEAR_BULK_FAN_SPEED;
|
break;
|
||||||
break;
|
case READ_BULK_FAN_SPEED:
|
||||||
UNKNOWN_COMMAND:
|
if (context.fan == FAN1) {
|
||||||
return 0xFF;
|
return fan1_history[pos];
|
||||||
break;
|
} else if (context.fan == FAN2) {
|
||||||
|
return fan2_history[pos];
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UNKNOWN_COMMAND:
|
||||||
|
default:
|
||||||
|
return 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
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>
|
||||||
@ -45,8 +46,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, // The first fan
|
FAN1 = 1, // The first fan
|
||||||
FAN2, // The second fan
|
FAN2 = 2, // The second fan
|
||||||
FAN_NONE // No fan
|
FAN_NONE // No fan
|
||||||
} fans_t;
|
} fans_t;
|
||||||
|
|
||||||
@ -59,6 +60,10 @@ 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);
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
|
||||||
// The start address for the controller data
|
// The start address for the controller data
|
||||||
uint8_t EEMEM start_address_controller = 0x00;
|
uint16_t EEMEM start_address_controller = 0x1400;
|
||||||
|
|
||||||
// Where the writing of the fans points start
|
// Where the writing of the fans points start
|
||||||
uint8_t EEMEM start_address_fan1 = 0x30;
|
uint16_t EEMEM start_address_fan1 = 0x1400 + 0x30;
|
||||||
uint8_t EEMEM start_address_fan2 = 0x60;
|
uint16_t EEMEM start_address_fan2 = 0x1400 + 0x60;
|
||||||
|
|
||||||
// The placement for the next datapoint form the fans.
|
// The placement for the next datapoint form the fans.
|
||||||
uint8_t EEMEM current_address_fan1 = 0x30;
|
uint16_t EEMEM current_address_fan1 = 0x1400 + 0x30;
|
||||||
uint8_t EEMEM current_address_fan2 = 0x60;
|
uint16_t EEMEM current_address_fan2 = 0x1400 + 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_update_byte(current_address_fan1, byte);
|
eeprom_write_byte(0x30, byte);
|
||||||
current_address_fan1++;
|
current_address_fan1++;
|
||||||
return 1;
|
return 1;
|
||||||
} else if (fan_num == 2){
|
} else if (fan_num == 2){
|
||||||
@ -97,3 +97,17 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -36,11 +36,13 @@ 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_from_EEPROM(uint8_t byte, uint8_t fan_num);
|
int write_data_point_in_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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,24 +4,28 @@
|
|||||||
*
|
*
|
||||||
* 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 <util/delay.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "themistor-temp.h"
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
// Fan history variables
|
||||||
|
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);
|
||||||
@ -33,8 +37,6 @@ 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);
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,8 @@
|
|||||||
<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>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user