diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 21:00:05 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 21:00:05 +0200 |
commit | 6f93f6b1adefa0f541b6e81d37b7677a4cb34460 (patch) | |
tree | 1afcb738ea103a473543f6acc34678e2e74ddedc /lib | |
parent | build spl doxygen if available (diff) |
fix linking to external libs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serialio.c | 48 | ||||
-rw-r--r-- | lib/serialio.h | 30 | ||||
-rw-r--r-- | lib/util.c | 10 |
3 files changed, 87 insertions, 1 deletions
diff --git a/lib/serialio.c b/lib/serialio.c new file mode 100644 index 0000000..899ca3e --- /dev/null +++ b/lib/serialio.c @@ -0,0 +1,48 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2014-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils 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 3 of the License, or + * any later version. + * + * spreadspace stm8 utils 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 spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stm8s.h> + +#include "serialio.h" + +void putchar(char c) { + while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET); + UART2_SendData8(c); +} + +char getchar(void) { + return UART2_ReceiveData8(); +} + +void serialio_init(const uint32_t baudrate) +{ + UART2_Init(baudrate, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); +} + +void serialio_task(void) +{ +} + +uint8_t serialio_bytes_received(void) +{ + return (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET) ? 0 : 1; +} diff --git a/lib/serialio.h b/lib/serialio.h new file mode 100644 index 0000000..9cfaae9 --- /dev/null +++ b/lib/serialio.h @@ -0,0 +1,30 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2014-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils 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 3 of the License, or + * any later version. + * + * spreadspace stm8 utils 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 spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPREADSTM8_serialio_h_INCLUDED +#define SPREADSTM8_serialio_h_INCLUDED + +void serialio_init(const uint32_t baudrate); +void serialio_task(void); +uint8_t serialio_bytes_received(void); + +#endif @@ -26,7 +26,15 @@ void cpu_init(void) { - CLK->CKDIVR = 0; +#ifdef F_XTAL + CLK_HSECmd(ENABLE); + CLK_HSICmd(DISABLE); +#else + CLK_HSICmd(ENABLE); + CLK_HSECmd(DISABLE); + CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); +#endif + CLK_LSICmd(DISABLE); } void swim_disable(void) |