diff --git a/.Makefile.prev.swp b/.Makefile.prev.swp new file mode 100644 index 0000000..6d9baad Binary files /dev/null and b/.Makefile.prev.swp differ diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..6c8de42 --- /dev/null +++ b/src/common.c @@ -0,0 +1 @@ +void *TODO; diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..3d70c03 --- /dev/null +++ b/src/common.h @@ -0,0 +1,9 @@ +#ifndef MAD_COMMON_H +#define MAD_COMMON_H + +#define UNUSED(s) (void)(s) + +#include +#define Sleep(ms) _delay_ms(ms) + +#endif // MAD_COMMON_H diff --git a/src/main.c b/src/main.c index 97a7dd6..8a139f6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,50 +1,22 @@ -#include -#include -#include +#include "common.h" +#include "uart.h" + #include -#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) - -void UART_Init(long USART_BAUDRATE) -{ - UCSRB |= (1 << RXEN) | (1 << TXEN); - UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); - UBRRL = BAUD_PRESCALE; - UBRRH = (BAUD_PRESCALE >> 8); -} - -unsigned char UART_RxChar() -{ - while ((UCSRA & (1 << RXC)) == 0); - return UDR; -} - -void UART_TxChar(char ch) -{ - while ((UCSRA & (1 << UDRE)) == 0); - UDR = ch; -} - -void UART_SendString(char *str) -{ - unsigned char j = 0; - - while (str[j] != 0) { - UART_TxChar(str[j++]); - } -} - int main(void) { - char buf[64]; + unsigned long i; + char buf[128]; - UART_Init(9600); + UART_Init(); - for (unsigned long i = 1;; i++) { + for (i = 1;; i++) { if (i >= 99999) i = 1; + sprintf(buf, "[CORE] Fetching sensors #%05lu...\r\n", i); - UART_SendString(buf); - _delay_ms(3000); + UART_Write(buf); + + Sleep(3000); } return 0; diff --git a/src/uart.c b/src/uart.c new file mode 100644 index 0000000..e2f4f38 --- /dev/null +++ b/src/uart.c @@ -0,0 +1,47 @@ +#include "common.h" +#include + +#define BAUD_RATE 9600 +#define BAUD_PRESCALE (((F_CPU / (BAUD_RATE * 16UL))) - 1) + +static char UART_Rx(void); +static void UART_Tx(char ch); + +void UART_Init(void) +{ + UCSRB |= (1 << RXEN) | (1 << TXEN); + UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); + UBRRH = (BAUD_PRESCALE >> 8); + UBRRL = BAUD_PRESCALE; +} + +void UART_Read(char **buf) +{ + // do { + // p[n++] = UART_Rx(); + // } while (p[n] != '\n'); + + UNUSED(UART_Rx); + UNUSED(buf); +} + +void UART_Write(const char *buf) +{ + int n = 0; + + while (buf[n] != '\0') { + UART_Tx(buf[n++]); + } +} + +static char UART_Rx(void) +{ + while ((UCSRA & (1 << RXC)) == 0); + return UDR; +} + +static void UART_Tx(char ch) +{ + while ((UCSRA & (1 << UDRE)) == 0); + UDR = ch; +} diff --git a/src/uart.h b/src/uart.h new file mode 100644 index 0000000..ae85b9f --- /dev/null +++ b/src/uart.h @@ -0,0 +1,8 @@ +#ifndef MAD_UART_H +#define MAD_UART_H + +void UART_Init(void); +void UART_Read(char **buf); +void UART_Write(const char *buf); + +#endif // MAD_UART_H