mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
thermosphere: rebase, fix some bugs
uart now works except for fifo flush
This commit is contained in:
parent
70a9caa7e9
commit
9d6089dc86
5 changed files with 39 additions and 96 deletions
|
@ -21,18 +21,18 @@ void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl)
|
|||
{
|
||||
#ifndef NDEBUG
|
||||
for (u32 i = 0; i < 30; i += 2) {
|
||||
serialLog("x%u\t\t%08llx\t\tx%u\t\t%08llx\r\n", i, frame->x[i], i + 1, frame->x[i + 1]);
|
||||
serialLog("x%u\t\t%016llx\t\tx%u\t\t%016llx\n", i, frame->x[i], i + 1, frame->x[i + 1]);
|
||||
}
|
||||
|
||||
serialLog("x30\t\t%08llx\r\n\r\n", frame->x[30]);
|
||||
serialLog("elr_el2\t\t%08llx\r\n", frame->elr_el2);
|
||||
serialLog("spsr_el2\t%08llx\r\n", frame->spsr_el2);
|
||||
serialLog("x30\t\t%016llx\n\n", frame->x[30]);
|
||||
serialLog("elr_el2\t\t%016llx\n", frame->elr_el2);
|
||||
serialLog("spsr_el2\t%016llx\n", frame->spsr_el2);
|
||||
if (sameEl) {
|
||||
serialLog("sp_el2\t\t%08llx\r\n", frame->sp_el2);
|
||||
serialLog("sp_el2\t\t%016llx\n", frame->sp_el2);
|
||||
} else {
|
||||
serialLog("sp_el0\t\t%08llx\r\n", frame->sp_el0);
|
||||
serialLog("sp_el0\t\t%016llx\n", frame->sp_el0);
|
||||
}
|
||||
serialLog("sp_el1\t\t%08llx\r\n", frame->sp_el1);
|
||||
serialLog("sp_el1\t\t%016llx\n", frame->sp_el1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeReg
|
|||
handleHypercall(frame, esr);
|
||||
break;
|
||||
default:
|
||||
serialLog("Lower EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\r\n", (u64)esr.ec, esr.il, esr.iss);
|
||||
serialLog("Lower EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", (u64)esr.ec, esr.il, esr.iss);
|
||||
dumpStackFrame(frame, false);
|
||||
break;
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeReg
|
|||
|
||||
void handleSameElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
||||
{
|
||||
serialLog("Same EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\r\n", (u64)esr.ec, esr.il, esr.iss);
|
||||
serialLog("Same EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", (u64)esr.ec, esr.il, esr.iss);
|
||||
dumpStackFrame(frame, true);
|
||||
}
|
||||
|
||||
void handleUnknownException(u32 offset)
|
||||
{
|
||||
serialLog("Unknown exception! (offset 0x%03lx)\r\n", offset);
|
||||
serialLog("Unknown exception! (offset 0x%03lx)\n", offset);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ void handleHypercall(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
|||
u32 id = esr.iss;
|
||||
switch (id) {
|
||||
default:
|
||||
serialLog("Unhandled hypercall: 0x%x.\r\n");
|
||||
serialLog("Unhandled hypercall: 0x%x.\n");
|
||||
dumpStackFrame(frame, false);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ int main(void)
|
|||
{
|
||||
uartInit(115200);
|
||||
|
||||
//uart_send(UART_C, "0123\n", 3);
|
||||
serialLog("Hello from Thermosphere!\r\n");
|
||||
serialLog("fifo flush fifo flush\n");
|
||||
serialLog("Hello from Thermosphere!\n");
|
||||
__builtin_trap();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -14,131 +14,71 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gpio.h"
|
||||
#include "../../utils.h"
|
||||
|
||||
/**
|
||||
* Returns a GPIO bank object that corresponds to the given GPIO pin,
|
||||
* which can be created using the TEGRA_GPIO macro or passed from the name macro.
|
||||
*
|
||||
* @param pin The GPIO to get the bank for.
|
||||
* @return The GPIO bank object to use for working with the given bank.
|
||||
*/
|
||||
static volatile tegra_gpio_bank_t *gpio_get_bank(uint32_t pin)
|
||||
{
|
||||
static volatile tegra_gpio_bank_t *gpio_get_bank(uint32_t pin) {
|
||||
volatile tegra_gpio_t *gpio = gpio_get_regs();
|
||||
uint32_t bank_number = pin >> GPIO_BANK_SHIFT;
|
||||
uint32_t bank_number = (pin >> GPIO_BANK_SHIFT);
|
||||
|
||||
return &gpio->bank[bank_number];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port number for working with the given GPIO.
|
||||
*/
|
||||
static volatile uint32_t gpio_get_port(uint32_t pin)
|
||||
{
|
||||
return (pin >> GPIO_PORT_SHIFT) & GPIO_PORT_MASK;
|
||||
static volatile uint32_t gpio_get_port(uint32_t pin) {
|
||||
return ((pin >> GPIO_PORT_SHIFT) & GPIO_PORT_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a mask to be used to work with the given GPIO
|
||||
*/
|
||||
static volatile uint32_t gpio_get_mask(uint32_t pin)
|
||||
{
|
||||
uint32_t pin_number = pin & GPIO_PIN_MASK;
|
||||
static volatile uint32_t gpio_get_mask(uint32_t pin) {
|
||||
uint32_t pin_number = (pin & GPIO_PIN_MASK);
|
||||
return (1 << pin_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a simple GPIO configuration operation.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param should_be_set True iff the relevant bit should be set; or false if it should be cleared.
|
||||
* @param offset The offset into a gpio_bank structure
|
||||
*/
|
||||
static void gpio_simple_register_set(uint32_t pin, bool should_be_set, uint32_t offset)
|
||||
{
|
||||
// Retrieve the register set that corresponds to the given pin and offset.
|
||||
static void gpio_simple_register_set(uint32_t pin, bool should_be_set, uint32_t offset) {
|
||||
/* Retrieve the register set that corresponds to the given pin and offset. */
|
||||
uintptr_t cluster_addr = (uintptr_t)gpio_get_bank(pin) + offset;
|
||||
uint32_t *cluster = (uint32_t *)cluster_addr;
|
||||
|
||||
// Figure out the offset into the cluster,
|
||||
// and the mask to be used.
|
||||
/* Figure out the offset into the cluster, and the mask to be used. */
|
||||
uint32_t port = gpio_get_port(pin);
|
||||
uint32_t mask = gpio_get_mask(pin);
|
||||
|
||||
// Set or clear the bit, as appropriate.
|
||||
/* Set or clear the bit, as appropriate. */
|
||||
if (should_be_set)
|
||||
cluster[port] |= mask;
|
||||
cluster[port] |= mask;
|
||||
else
|
||||
cluster[port] &= ~mask;
|
||||
|
||||
/* Dummy read. */
|
||||
(void)cluster[port];
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a simple GPIO configuration operation.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param should_be_set True iff the relevant bit should be set; or false if it should be cleared.
|
||||
* @param offset The offset into a gpio_bank structure
|
||||
*/
|
||||
static bool gpio_simple_register_get(uint32_t pin, uint32_t offset)
|
||||
{
|
||||
// Retrieve the register set that corresponds to the given pin and offset.
|
||||
static bool gpio_simple_register_get(uint32_t pin, uint32_t offset) {
|
||||
/* Retrieve the register set that corresponds to the given pin and offset. */
|
||||
uintptr_t cluster_addr = (uintptr_t)gpio_get_bank(pin) + offset;
|
||||
uint32_t *cluster = (uint32_t *)cluster_addr;
|
||||
|
||||
// Figure out the offset into the cluster,
|
||||
// and the mask to be used.
|
||||
/* Figure out the offset into the cluster, and the mask to be used. */
|
||||
uint32_t port = gpio_get_port(pin);
|
||||
uint32_t mask = gpio_get_mask(pin);
|
||||
|
||||
// Convert the given value to a boolean.
|
||||
/* Convert the given value to a boolean. */
|
||||
return !!(cluster[port] & mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a given pin as either GPIO or SFIO.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param mode The relevant mode.
|
||||
*/
|
||||
void gpio_configure_mode(uint32_t pin, uint32_t mode)
|
||||
{
|
||||
void gpio_configure_mode(uint32_t pin, uint32_t mode) {
|
||||
gpio_simple_register_set(pin, mode == GPIO_MODE_GPIO, offsetof(tegra_gpio_bank_t, config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a given pin as either INPUT or OUPUT.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param direction The relevant direction.
|
||||
*/
|
||||
void gpio_configure_direction(uint32_t pin, uint32_t dir)
|
||||
{
|
||||
void gpio_configure_direction(uint32_t pin, uint32_t dir) {
|
||||
gpio_simple_register_set(pin, dir == GPIO_DIRECTION_OUTPUT, offsetof(tegra_gpio_bank_t, direction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drives a relevant GPIO pin as either HIGH or LOW.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param mode The relevant mode.
|
||||
*/
|
||||
void gpio_write(uint32_t pin, uint32_t value)
|
||||
{
|
||||
void gpio_write(uint32_t pin, uint32_t value) {
|
||||
gpio_simple_register_set(pin, value == GPIO_LEVEL_HIGH, offsetof(tegra_gpio_bank_t, out));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drives a relevant GPIO pin as either HIGH or LOW.
|
||||
*
|
||||
* @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO.
|
||||
* @param mode The relevant mode.
|
||||
*/
|
||||
uint32_t gpio_read(uint32_t pin)
|
||||
{
|
||||
uint32_t gpio_read(uint32_t pin) {
|
||||
return gpio_simple_register_get(pin, offsetof(tegra_gpio_bank_t, in));
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ void uart_reset(UartDevice dev)
|
|||
gpio_configure_mode(TEGRA_GPIO(D, 1), GPIO_MODE_SFIO); // Change UART-C to SPIO
|
||||
// Fixme other uart?
|
||||
}
|
||||
|
||||
uart_config(dev);
|
||||
clkrst_reboot(uartCarDevs[dev]);
|
||||
}
|
||||
|
||||
|
@ -87,6 +89,7 @@ void uart_init(UartDevice dev, uint32_t baud, bool inverted) {
|
|||
/* Flush FIFO. */
|
||||
uart->UART_IIR_FCR = (UART_FCR_FCR_EN_FIFO | UART_FCR_RX_CLR | UART_FCR_TX_CLR); /* Enable and clear TX and RX FIFOs. */
|
||||
uart->UART_IRDA_CSR = inverted ? 2 : 0; /* Invert TX */
|
||||
uart->UART_SPR;
|
||||
udelay(3 * ((baud + 999999) / baud));
|
||||
|
||||
/* Wait for idle state. */
|
||||
|
@ -140,4 +143,4 @@ size_t uart_recv_max(UartDevice dev, void *buf, size_t max_len) {
|
|||
}
|
||||
|
||||
return 1 + i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue