diff --git a/docs/LICENSE.md b/docs/LICENSE.md deleted file mode 100644 index 0febbf8..0000000 --- a/docs/LICENSE.md +++ /dev/null @@ -1,26 +0,0 @@ -## License - -All Rights Reserved - -Copyright (c) 2024 Madcow Software -Copyright (c) 2024 Carlos Krieg - -THE CONTENTS OF THIS PROJECT ARE PROPRIETARY AND CONFIDENTIAL. -UNAUTHORIZED COPYING, TRANSFERRING OR REPRODUCTION OF THE -CONTENTS OF THIS PROJECT, VIA ANY MEDIUM IS STRICTLY PROHIBITED. - -The receipt or possession of the source code and/or any parts -thereof does not convey or imply any right to use them for any -purpose other than the purpose for which they were provided to you. - -The software is provided "AS IS", without warranty of any kind, -express or implied, including but not limited to the warranties of -merchantability, fitness for a particular purpose and non -infringement. In no event shall the authors or copyright holders -be liable for any claim, damages or other liability, whether in an -action of contract, tort or otherwise, arising from, out of or in -connection with the software or the use or other dealings in the -software. - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the software. diff --git a/src/bus/usart.c b/src/bus/uart.c similarity index 60% rename from src/bus/usart.c rename to src/bus/uart.c index 156bf7d..8e47467 100644 --- a/src/bus/usart.c +++ b/src/bus/uart.c @@ -1,24 +1,24 @@ #include "common.h" -#include "bus/usart.h" +#include "bus/uart.h" #include #include -#define USART_BAUDRATE 9600 -#define USART_RXBUF_SIZE 128 -#define USART_TXBUF_SIZE 128 +#define UART_BAUDRATE 9600 +#define UART_RXBUF_SIZE 128 +#define UART_TXBUF_SIZE 128 -#define USART_RXBUF_MASK (USART_RXBUF_SIZE - 1) -#define USART_TXBUF_MASK (USART_TXBUF_SIZE - 1) -#define USART_BAUD_PRESCALE ((((F_CPU / 16) + \ - (USART_BAUDRATE / 2)) / (USART_BAUDRATE)) - 1) +#define UART_RXBUF_MASK (UART_RXBUF_SIZE - 1) +#define UART_TXBUF_MASK (UART_TXBUF_SIZE - 1) +#define UART_BAUD_PRESCALE ((((F_CPU / 16) + \ + (UART_BAUDRATE / 2)) / (UART_BAUDRATE)) - 1) -static volatile char rxbuf[USART_RXBUF_SIZE]; // RX ring buffer -static volatile char txbuf[USART_TXBUF_SIZE]; // TX ring buffer +static volatile char rxbuf[UART_RXBUF_SIZE]; // RX ring buffer +static volatile char txbuf[UART_TXBUF_SIZE]; // TX ring buffer static volatile short rxhead, txhead; // Current write position static volatile short rxtail, txtail; // Current read position -int USART_Init(void) +int UART_Init(void) { rxhead = 0; rxtail = 0; @@ -28,29 +28,29 @@ int USART_Init(void) UCSR0B = BIT(RXCIE0); // Handle RXC interrupts UCSR0B |= BIT(RXEN0) | BIT(TXEN0); // Enable RX and TX circuitry UCSR0C = BIT(UCSZ01) | BIT(UCSZ00); // 8-bit data, 1-bit stop, no parity - UBRR0H = (USART_BAUD_PRESCALE >> 8); // Set baud rate upper byte - UBRR0L = USART_BAUD_PRESCALE; // Set baud rate lower byte + UBRR0H = (UART_BAUD_PRESCALE >> 8); // Set baud rate upper byte + UBRR0L = UART_BAUD_PRESCALE; // Set baud rate lower byte return 0; } -char USART_Getc(void) +char UART_Getc(void) { if (rxhead == rxtail) { return -1; } - rxtail = (rxtail + 1) & USART_RXBUF_MASK; + rxtail = (rxtail + 1) & UART_RXBUF_MASK; return rxbuf[rxtail]; } -void USART_Putc(char ch) +void UART_Putc(char ch) { short head; // Wrap around if end of buffer reached - head = (txhead + 1) & USART_TXBUF_MASK; + head = (txhead + 1) & UART_TXBUF_MASK; while (head == txtail); // Wait for space txbuf[head] = ch; @@ -69,7 +69,7 @@ ISR(USART0_RX_vect) data = UDR0; // Next byte ready // Wrap around if end of buffer reached - head = (rxhead + 1) & USART_RXBUF_MASK; + head = (rxhead + 1) & UART_RXBUF_MASK; // Free space in RX buffer? // Otherwise discard overflow @@ -87,7 +87,7 @@ ISR(USART0_UDRE_vect) // Anything in TX buffer? if (txhead != txtail) { // Write next byte to data register - tail = (txtail + 1) & USART_TXBUF_MASK; + tail = (txtail + 1) & UART_TXBUF_MASK; UDR0 = txbuf[tail]; txtail = tail; } else { diff --git a/src/bus/uart.h b/src/bus/uart.h new file mode 100644 index 0000000..e00ea45 --- /dev/null +++ b/src/bus/uart.h @@ -0,0 +1,8 @@ +#ifndef MAD_CORE_BUS_UART_H +#define MAD_CORE_BUS_UART_H + +int UART_Init(void); +void UART_Putc(char ch); +char UART_Getc(void); + +#endif // MAD_CORE_BUS_UART_H diff --git a/src/bus/usart.h b/src/bus/usart.h deleted file mode 100644 index 7b1d879..0000000 --- a/src/bus/usart.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MAD_CORE_BUS_USART_H -#define MAD_CORE_BUS_USART_H - -int USART_Init(void); -void USART_Putc(char ch); -char USART_Getc(void); - -#endif // MAD_CORE_BUS_USART_H diff --git a/src/common/common.c b/src/common/common.c index b1aaa3a..cc1b08b 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -1,5 +1,5 @@ #include "common.h" -#include "bus/usart.h" +#include "bus/uart.h" #include @@ -42,7 +42,7 @@ void Error(const char *fmt, ...) static void Puts(const char *str) { while (*str != '\0') { - USART_Putc(*str++); + UART_Putc(*str++); } } diff --git a/src/main.c b/src/main.c index a9a01d3..1c61d3d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ #include "common.h" -#include "bus/usart.h" +#include "bus/uart.h" #include "bus/mosfet.h" #include "bus/pwm.h" #include "bus/i2c.h" @@ -52,7 +52,7 @@ static int Init(void) // IRQs, so we need to initialize it as soon as // possible and make sure to enable interrupts. - USART_Init(); + UART_Init(); sei(); Info("Initializing..."); @@ -134,7 +134,7 @@ static void Update(void) cmd_t cmd; // Parse serial commands - while ((ch = USART_Getc()) >= 0) { + while ((ch = UART_Getc()) >= 0) { if (!CMD_Parse(ch, &cmd)) { continue; }