Skip to content

Commit

Permalink
hal/sparcv8leon3: refactor console driver
Browse files Browse the repository at this point in the history
JIRA: RTOS-885
  • Loading branch information
lukileczo committed Aug 7, 2024
1 parent cbfee0e commit 0e833a0
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions hal/sparcv8leon3/gaisler/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* HAL console
*
* Copyright 2022 Phoenix Systems
* Copyright 2022-2024 Phoenix Systems
* Author: Lukasz Leczkowski
*
* This file is part of Phoenix-RTOS.
Expand Down Expand Up @@ -48,19 +48,61 @@ extern unsigned int _end;


enum {
uart_data, /* Data register : 0x00 */
uart_status, /* Status register : 0x04 */
uart_ctrl, /* Control register : 0x08 */
uart_scaler, /* Scaler reload register : 0x0C */
uart_dbg /* FIFO debug register : 0x10 */
uart_data = 0, /* Data register : 0x00 */
uart_status, /* Status register : 0x04 */
uart_ctrl, /* Control register : 0x08 */
uart_scaler, /* Scaler reload register : 0x0C */
uart_dbg /* FIFO debug register : 0x10 */
};


struct {
static struct {
volatile u32 *uart;
} halconsole_common;


/* CPU-specific functions */

#if defined(__CPU_GR716)

static void console_cguClkEnable(void)
{
_gr716_cguClkEnable(cgu_primary, CONSOLE_CGU);
}


static int console_cguClkStatus(void)
{
return _gr716_cguClkStatus(cgu_primary, CONSOLE_CGU);
}


static void console_iomuxCfg(void)
{
gaisler_setIomuxCfg(CONSOLE_TX, 0x1, 0, 0);
gaisler_setIomuxCfg(CONSOLE_RX, 0x1, 0, 0);
}

#else

static void console_cguClkEnable(void)
{
}


static int console_cguClkStatus(void)
{
return 1;
}


static void console_iomuxCfg(void)
{
}

#endif


static void _hal_consolePrint(const char *s)
{
for (; *s; s++) {
Expand Down Expand Up @@ -108,14 +150,16 @@ void hal_consolePrint(int attr, const char *s)

void _hal_consoleInit(void)
{
gaisler_setIomuxCfg(CONSOLE_TX, 0x1, 0, 0);
gaisler_setIomuxCfg(CONSOLE_RX, 0x1, 0, 0);
#ifdef __CPU_GR716
_gr716_cguClkEnable(cgu_primary, CONSOLE_CGU);
#endif
halconsole_common.uart = VADDR_CONSOLE;

*(halconsole_common.uart + uart_ctrl) = 0;

console_iomuxCfg();

if (console_cguClkStatus() == 0) {
console_cguClkEnable();
}

/* Clear UART FIFO */
while ((*(halconsole_common.uart + uart_status) & (1 << 0)) != 0) {
(void)*(halconsole_common.uart + uart_data);
Expand Down

0 comments on commit 0e833a0

Please sign in to comment.