1
0
mirror of https://github.com/sjlongland/cluster-powerctl.git synced 2025-09-13 12:03:14 +10:00

Drop UART support.

Not being used, and bitrotten.
This commit is contained in:
Stuart Longland 2018-09-22 14:26:26 +10:00
parent a7c86401e7
commit caf3e27565
Signed by: stuartl
GPG Key ID: 6AA32EFB18079BAA
5 changed files with 1 additions and 264 deletions

View File

@ -46,9 +46,8 @@ clean:
$(CC) $(LDFLAGS) -o $@ $^
$(SIZE) -d $@
powerctl.elf: powerctl.o uart.o
powerctl.elf: powerctl.o
powerctl.o: board.h setpoints.h
uart.o: uartcfg.h uart.h
setpoints.h: setpoints.h.dist
@if [ -f $@ ] ; then \
if cmp $^ $@ ; then \

View File

@ -3,11 +3,6 @@
#include <stdint.h>
#include <avr/pgmspace.h>
#ifdef DEBUG
/*! If enabled, the warning LED doubles as UART Tx pin */
#include "uart.h"
#endif
#include "board.h"
#include "setpoints.h"
@ -119,40 +114,6 @@ static volatile uint8_t hal_state = 0;
*/
static volatile uint8_t led_blink = 0;
/* Debug messages */
#ifdef DEBUG
const char STR_INIT[] PROGMEM = {"INIT "};
const char STR_SELECT_SRC[] PROGMEM = {"SOURCE="};
const char STR_SRC_NONE[] PROGMEM = {"NONE"};
const char STR_SRC_SOLAR[] PROGMEM = {"SOLAR"};
const char STR_SRC_MAINS[] PROGMEM = {"MAINS"};
const char STR_DIS[] PROGMEM = {"\r\nDISCHARGE "};
const char STR_CHG[] PROGMEM = {"\r\nCHARGE "};
const char STR_CHK[] PROGMEM = {"CHECK\r\n"};
const char STR_WAIT[] PROGMEM = {"WAIT\r\n"};
const char STR_V_BN_GE_V_H[] PROGMEM = {"V_BN >= V_H? "};
const char STR_V_BN_GT_V_L[] PROGMEM = {"V_BN > V_L? "};
const char STR_V_BN_LE_V_CL[] PROGMEM = {"V_BN <= V_CL? "};
const char STR_V_BN_GE_V_CH[] PROGMEM = {"V_BN <= V_CH? "};
const char STR_V_BN_LE_V_BL[] PROGMEM = {"V_BN <= V_BL? "};
const char STR_HAVE_SOURCE[] PROGMEM = {"HAVE SOURCE? "};
const char STR_T_CHARGER[] PROGMEM = {"T_CHARGER EXPIRED? "};
const char STR_YES[] PROGMEM = {"YES\r\n"};
const char STR_NO[] PROGMEM = {"NO\r\n"};
const char STR_ADC[] PROGMEM = {"ADC "};
const char STR_START[] PROGMEM = {"START "};
const char STR_READ[] PROGMEM = {"READ "};
const char STR_NL[] PROGMEM = {"\r\n"};
static inline void uart_tx_bool(const char* msg, uint8_t val) {
uart_tx_str(msg);
if (val)
uart_tx_str(STR_YES);
else
uart_tx_str(STR_NO);
}
#endif
/*!
* Switch to charging from mains power.
*/
@ -336,14 +297,7 @@ int main(void) {
| (1 << ADPS1)
| (1 << ADPS0);
/* Configure UART */
sei();
#ifdef DEBUG
uart_init();
uart_tx_str(STR_INIT);
uart_tx_hex_byte(MCUSR);
uart_tx_str(STR_NL);
#endif
MCUSR = 0;
while(1) {
/* One second passed, tick down the 1-second timers. */
@ -478,9 +432,6 @@ int main(void) {
}
ISR(TIM1_COMPA_vect) {
#ifdef DEBUG
uart_tick();
#endif
/* One-second timer for longer events */
if (t_second)
t_second--;

116
uart.c
View File

@ -1,116 +0,0 @@
/*!
* Very simple software UART for AVR microcontrollers
* (C) 2016 Stuart Longland
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "uart.h"
#include "uartcfg.h"
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include <avr/pgmspace.h>
#define TX_BIT (1 << UART_TX_BIT)
#define BIT_US (1000000/UART_BAUD) /*!< Bit period in microseconds */
static volatile uint8_t uart_ticks = 0;
/*!
* Configure the UART pins.
*/
void uart_init() {
UART_TX_DDR |= TX_BIT;
UART_TX_PORT |= TX_BIT;
}
static void uart_wait(uint8_t ticks) {
uart_ticks = ticks;
while(uart_ticks);
}
void uart_tick() {
if (uart_ticks)
uart_ticks--;
}
/*!
* Send a raw byte to the UART.
*/
void uart_tx(uint8_t byte) {
uint8_t mask = 1;
/* Start bit */
UART_TX_PORT &= ~TX_BIT; uart_wait(1);
while(mask) {
if (mask & byte)
UART_TX_PORT |= TX_BIT;
else
UART_TX_PORT &= ~TX_BIT;
uart_wait(1);
mask <<= 1;
}
/* Stop bit */
UART_TX_PORT |= TX_BIT; uart_wait(1);
}
/*!
* Send a text string (in pgmspace) to the UART.
* String shall be null-terminated!
*/
void uart_tx_str(const char* str) {
char c = pgm_read_byte(str);
while (c) {
str++;
uart_tx(c);
c = pgm_read_byte(str);
}
}
/*!
* Send a 4-bit nybble to the UART.
*/
void uart_tx_hex(uint8_t nybble) {
if (nybble >= 10)
uart_tx(nybble - 10 + 'a');
else
uart_tx(nybble + '0');
}
/*!
* Send a 8-bit byte to the UART.
*/
void uart_tx_hex_byte(uint8_t byte) {
uart_tx_hex(byte >> 4);
uart_tx_hex(byte & 0x0f);
}
/*!
* Send a 16-bit word to the UART.
*/
void uart_tx_hex_word(uint16_t word) {
uart_tx_hex_byte(word >> 8);
uart_tx_hex_byte(word & 0xff);
}
/*!
* Send a 32-bit long word to the UART.
*/
void uart_tx_hex_lword(uint32_t lword) {
uart_tx_hex_word(lword >> 16);
uart_tx_hex_word(lword & 0xffff);
}

60
uart.h
View File

@ -1,60 +0,0 @@
#ifndef _UART_H
#define _UART_H
/*!
* Very simple software UART for AVR microcontrollers
* (C) 2016 Stuart Longland
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdint.h>
/*!
* Configure the UART pins.
*/
void uart_init();
/*!
* UART tick timer
*/
void uart_tick();
/*!
* Send a raw byte to the UART.
*/
void uart_tx(uint8_t byte);
/*!
* Send a text string (in pgmspace) to the UART.
* String shall be null-terminated!
*/
void uart_tx_str(const char* str);
/*!
* Send a 8-bit byte to the UART.
*/
void uart_tx_hex_byte(uint8_t byte);
/*!
* Send a 16-bit word to the UART.
*/
void uart_tx_hex_word(uint16_t word);
/*!
* Send a 32-bit long word to the UART.
*/
void uart_tx_hex_lword(uint32_t lword);
#endif

View File

@ -1,37 +0,0 @@
#ifndef _UARTCFG_H
#define _UARTCFG_H
/*!
* Very simple software UART for AVR microcontrollers
* (C) 2016 Stuart Longland
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* The following defines the configuration for the UART driver. */
/*!
* UART BAUD rate. This is the speed that we transmit at. For the 1MHz
* RC clock, 4800 is the maximum speed (out of the "standard" ones) that
* will work. If you're running at 8MHz or with an external crystal, you
* may go higher.
*/
#define UART_BAUD (300)
/* Port settings */
#define UART_TX_PORT PORTA /*!< GPIO port register for Tx */
#define UART_TX_DDR DDRA /*!< GPIO direction register for Tx */
#define UART_TX_BIT 4 /*!< GPIO pin for Tx */
#endif