Update code due to new rules

This commit is contained in:
2020-01-15 10:56:04 +01:00
parent 6c4dba0929
commit a0c215e954
34 changed files with 614 additions and 239 deletions
+47
View File
@@ -0,0 +1,47 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file uart.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef UART_H_8AFC47F9_2953_42C1_A5C1_1AE5A1F52CD0
#define UART_H_8AFC47F9_2953_42C1_A5C1_1AE5A1F52CD0
#include "uart_mini.h"
#include "uart_qemu.h"
#define UART_MINI 0
#define UART_QEMU 1
#ifndef UART_DEFAULT
#define UART_DEFAULT UART_MINI
#endif
#if UART_DEFAULT == UART_MINI
#define UART_init(...) UARTMini_init(__VA_ARGS__)
#define UART_get(...) UARTMini_get(__VA_ARGS__)
#define UART_put(...) UARTMini_put(__VA_ARGS__)
#elif UART_DEFAULT == UART_QEMU
#define UART_init(...)
#define UART_get(...)
#define UART_put(...) UARTQEMU_put(__VA_ARGS__)
#else
#warning "Unsupported UART"
#endif
#endif /* !UART_H */
+84
View File
@@ -0,0 +1,84 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file UARTMini.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#include <aarch64/aarch64.h>
#include <aarch64/bcm2837.h>
#include "UARTMini.h"
int
UARTMini_init(void)
{
unsigned int sel;
/* Enable UART Mini and its registers*/
AArch64_setReg32(AUX_ENABLES, 1);
/* Disable TX and RX interrupts */
AArch64_setReg32(AUX_MU_IER_REG, 0);
/* Disable auto flow control, TX and RX */
AArch64_setReg32(AUX_MU_CNTL_REG, 0);
/* Set 8bit mode */
AArch64_setReg32(AUX_MU_LCR_REG, 3);
/* Set RTS line HIGH */
AArch64_setReg32(AUX_MU_MCR_REG, 0);
/* Set baud rate 115200 */
AArch64_setReg32(AUX_MU_IER_REG, 0);
AArch64_setReg32(AUX_MU_IIR_REG, 0xC6);
AArch64_setReg32(AUX_MU_BAUD_REG, 270);
sel = AArch64_getReg32(GPFSEL1);
/* clean and set ALT5 for GPIO14 */
sel &= ~(7 << 12);
sel |= (2 << 12);
/* clean and set ALT5 for GPIO15 */
sel &= ~(7 << 15);
sel |= (2 << 15);
AArch64_setReg32(GPFSEL1, sel);
AArch64_setReg32(GPPUD, 0);
AArch64_delay(150);
AArch64_setReg32(GPPUDCLK0, (1 << 14) | (1 << 15));
AArch64_delay(150);
AArch64_setReg32(GPPUDCLK0, 0);
/* Enable TX and RX */
AArch64_setReg32(AUX_MU_CNTL_REG, 3);
return 0;
}
int
UARTMini_put(char c)
{
while (1) {
if (AArch64_getReg32(AUX_MU_LSR_REG) & 0x20)
break;
}
AArch64_setReg32(AUX_MU_IO_REG, c);
return 0;
}
int
UARTMini_get(char *pc)
{
while (1) {
if (AArch64_getReg32(AUX_MU_LSR_REG) & 0x01)
break;
}
*pc = AArch64_getReg32(AUX_MU_IO_REG) & 0xFF;
return 0;
}
+28
View File
@@ -0,0 +1,28 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file UARTMini.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef UART_MINI_H_B0DFA3CF_5B4F_4EB0_B393_391C0069A04F
#define UART_MINI_H_B0DFA3CF_5B4F_4EB0_B393_391C0069A04F
int
UARTMini_init(void);
int
UARTMini_put(char c);
int
UARTMini_get(char *pc);
#endif /* !UART_MINI_H */
+28
View File
@@ -0,0 +1,28 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file uart.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#include "uart_qemu.h"
#define UARTQEMU_BASE 0x09000000;
volatile unsigned int *UART0 = (unsigned int *)UARTQEMU_BASE;
int
UARTQEMU_put(unsigned char c)
{
*UART0 = (unsigned int) c;
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file uart_qemu.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef UART_QEMU_H_EDB39A0E_9BED_4A47_91CD_E804A9B4E8ED
#define UART_QEMU_H_EDB39A0E_9BED_4A47_91CD_E804A9B4E8ED
int
UARTQEMU_put(unsigned char c);
#endif /* !UART_QEMU_H */