forked from xuos/xiuos
fix a bug of uart input problem for gap8
This commit is contained in:
parent
2fcb4ad3ad
commit
b22f9a3851
|
@ -40,7 +40,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Exception context size: EPC + 31 common regs + 6 loop regs */
|
/* Exception context size: EPC + 31 common regs + 6 loop regs */
|
||||||
|
#include "boot.h"
|
||||||
#define EXCEPTION_STACK_SIZE 4*38
|
#define EXCEPTION_STACK_SIZE 4*38
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
csrrw x0, 0x7B0, x28
|
csrrw x0, 0x7B0, x28
|
||||||
csrrw x0, 0x7B1, x29
|
csrrw x0, 0x7B1, x29
|
||||||
csrrw x0, 0x7B2, x30
|
csrrw x0, 0x7B2, x30
|
||||||
li s0, 0x1890 /* machine mode, UPIE & MPIE enabled */
|
li s0, 0x1880 /* machine mode, UPIE & MPIE enabled */
|
||||||
csrrw x0, mstatus, s0
|
csrrw x0, mstatus, s0
|
||||||
lw x3, 3*4(sp) /* gp */
|
lw x3, 3*4(sp) /* gp */
|
||||||
lw x4, 4*4(sp) /* tp */
|
lw x4, 4*4(sp) /* tp */
|
||||||
|
@ -149,31 +149,22 @@
|
||||||
lw sp, 2*4(sp) /* restore original sp */
|
lw sp, 2*4(sp) /* restore original sp */
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/* wrapper for IRQ vector */
|
|
||||||
|
|
||||||
.macro WRAP_IRQ Routine, IRQn
|
.macro WRAP_IRQ Routine, IRQn
|
||||||
wrap_irq_\Routine :
|
wrap_irq_\Routine :
|
||||||
SAVE_REGS
|
|
||||||
|
|
||||||
csrr s0, mepc
|
SAVE_X_REGISTERS
|
||||||
sw s0, 0(sp) /* exception PC */
|
|
||||||
|
mv fp, sp
|
||||||
|
|
||||||
li a0, \IRQn /* irq = IRQn */
|
li a0, \IRQn /* irq = IRQn */
|
||||||
mv a1, sp /* context = sp */
|
mv a1, sp /* context = sp */
|
||||||
jal x1, gap8_dispatch_irq
|
call gap8_dispatch_irq
|
||||||
|
|
||||||
/* If context switch is needed, return
|
mv sp, fp
|
||||||
* a new sp
|
mv a0, fp
|
||||||
*/
|
call KTaskOsAssignAfterIrq
|
||||||
|
j SwitchKTaskContextExit
|
||||||
|
|
||||||
mv sp, a0
|
|
||||||
|
|
||||||
lw s0, 0(sp) /* restore ePC */
|
|
||||||
csrw mepc, s0
|
|
||||||
|
|
||||||
RESTORE_REGS
|
|
||||||
|
|
||||||
mret
|
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,14 +121,14 @@ static inline void up_ack_irq(int irq)
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline uint32_t _current_privilege(void)
|
// static inline uint32_t _current_privilege(void)
|
||||||
{
|
// {
|
||||||
uint32_t result;
|
// uint32_t result;
|
||||||
|
|
||||||
asm volatile ("csrr %0, 0xC10" : "=r" (result));
|
// asm volatile ("csrr %0, 0xC10" : "=r" (result));
|
||||||
|
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_irq_restore
|
* Name: up_irq_restore
|
||||||
*
|
*
|
||||||
|
@ -137,21 +137,21 @@ static inline uint32_t _current_privilege(void)
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline void up_irq_restore(unsigned int pri)
|
// static inline void up_irq_restore(unsigned int pri)
|
||||||
{
|
// {
|
||||||
if (_current_privilege())
|
// if (_current_privilege())
|
||||||
{
|
// {
|
||||||
/* Machine mode - mstatus */
|
// /* Machine mode - mstatus */
|
||||||
|
|
||||||
asm volatile("csrw 0x300, %0" : /* no output */ : "r" (pri));
|
// asm volatile("csrw 0x300, %0" : /* no output */ : "r" (pri));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
/* User mode - ustatus */
|
// /* User mode - ustatus */
|
||||||
|
|
||||||
asm volatile("csrw 0x000, %0" : /* no output */ : "r" (pri));
|
// asm volatile("csrw 0x000, %0" : /* no output */ : "r" (pri));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_irq_save
|
* Name: up_irq_save
|
||||||
*
|
*
|
||||||
|
@ -160,30 +160,30 @@ static inline void up_irq_restore(unsigned int pri)
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
x_base up_irq_save(void)
|
// x_base up_irq_save(void)
|
||||||
{
|
// {
|
||||||
x_base oldstat;
|
// x_base oldstat;
|
||||||
x_base newstat;
|
// x_base newstat;
|
||||||
|
|
||||||
if (_current_privilege())
|
// if (_current_privilege())
|
||||||
{
|
// {
|
||||||
/* Machine mode: Unset MIE and UIE */
|
// /* Machine mode: Unset MIE and UIE */
|
||||||
|
|
||||||
asm volatile ("csrr %0, 0x300": "=r" (oldstat));
|
// asm volatile ("csrr %0, 0x300": "=r" (oldstat));
|
||||||
newstat = oldstat & ~(0x9);
|
// newstat = oldstat & ~(0x9);
|
||||||
asm volatile("csrw 0x300, %0" : /* no output */ : "r" (newstat));
|
// asm volatile("csrw 0x300, %0" : /* no output */ : "r" (newstat));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
/* User mode: Unset UIE */
|
// /* User mode: Unset UIE */
|
||||||
|
|
||||||
asm volatile ("csrr %0, 0x000": "=r" (oldstat));
|
// asm volatile ("csrr %0, 0x000": "=r" (oldstat));
|
||||||
newstat = oldstat & ~(1L << 0);
|
// newstat = oldstat & ~(1L << 0);
|
||||||
asm volatile("csrw 0x000, %0" : /* no output */ : "r" (newstat));
|
// asm volatile("csrw 0x000, %0" : /* no output */ : "r" (newstat));
|
||||||
}
|
// }
|
||||||
|
|
||||||
return oldstat;
|
// return oldstat;
|
||||||
}
|
// }
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_irq_save
|
* Name: up_irq_save
|
||||||
*
|
*
|
||||||
|
@ -265,12 +265,12 @@ void EnableLocalInterrupt(x_base oldstat)
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
// static inline void gap8_sleep_wait_sw_evnt(uint32_t event_mask)
|
void gap8_sleep_wait_sw_evnt(uint32_t event_mask)
|
||||||
// {
|
{
|
||||||
// FCEU->MASK_OR = event_mask;
|
FCEU->MASK_OR = event_mask;
|
||||||
// __builtin_pulp_event_unit_read((void *)&FCEU->EVENT_WAIT_CLEAR, 0);
|
// __builtin_pulp_event_unit_read((void *)&FCEU->EVENT_WAIT_CLEAR, 0);
|
||||||
// FCEU->MASK_AND = event_mask;
|
FCEU->MASK_AND = event_mask;
|
||||||
// }
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
|
@ -338,24 +338,13 @@ void *gap8_dispatch_irq(uint32_t vector, void *current_regs)
|
||||||
FCEU->BUFFER_CLEAR = (1 << vector);
|
FCEU->BUFFER_CLEAR = (1 << vector);
|
||||||
EU_SW_EVNT_TRIG->TRIGGER_SET[3] = 0;
|
EU_SW_EVNT_TRIG->TRIGGER_SET[3] = 0;
|
||||||
|
|
||||||
/* Call nuttx kernel, which may change curr_regs, to perform
|
|
||||||
* a context switch
|
|
||||||
*/
|
|
||||||
|
|
||||||
g_current_regs = current_regs;
|
g_current_regs = current_regs;
|
||||||
// irq_dispatch(vector, current_regs);
|
|
||||||
|
|
||||||
isrManager.done->incCounter();
|
isrManager.done->incCounter();
|
||||||
isrManager.done->handleIrq(vector);
|
isrManager.done->handleIrq(vector);
|
||||||
|
|
||||||
isrManager.done->decCounter();
|
isrManager.done->decCounter();
|
||||||
|
|
||||||
KTaskOsAssignAfterIrq(current_regs);
|
|
||||||
|
|
||||||
current_regs = (void *)g_current_regs;
|
|
||||||
g_current_regs = NONE;
|
|
||||||
|
|
||||||
return current_regs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ struct gap8_udma_peripheral
|
||||||
{
|
{
|
||||||
/* Public */
|
/* Public */
|
||||||
|
|
||||||
udma_reg_t *regs; /* Hardware config regs */
|
volatile udma_reg_t *regs; /* Hardware config regs */
|
||||||
uint32_t id; /* GAP8_UDMA_ID_x */
|
uint32_t id; /* GAP8_UDMA_ID_x */
|
||||||
void (*on_tx)(void *arg); /* tx callback */
|
void (*on_tx)(void *arg); /* tx callback */
|
||||||
void (*on_rx)(void *arg); /* rx callback */
|
void (*on_rx)(void *arg); /* rx callback */
|
||||||
|
|
|
@ -101,7 +101,7 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
static char g_uart1rxbuffer[128];
|
||||||
static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operation_cmd)
|
static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operation_cmd)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(serial_drv);
|
NULL_PARAM_CHECK(serial_drv);
|
||||||
|
@ -117,7 +117,7 @@ static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operat
|
||||||
|
|
||||||
gap8_udma_rx_setirq(uart_udma, 1);
|
gap8_udma_rx_setirq(uart_udma, 1);
|
||||||
|
|
||||||
gap8_udma_rx_start(uart_udma, serial_dev->serial_fifo.serial_rx->serial_rx_buffer, 1, 1);
|
gap8_udma_rx_start(uart_udma, g_uart1rxbuffer, 1, 1);
|
||||||
|
|
||||||
ENABLE_INTERRUPT(lock);
|
ENABLE_INTERRUPT(lock);
|
||||||
} else if (OPER_CLR_INT == serial_operation_cmd) {
|
} else if (OPER_CLR_INT == serial_operation_cmd) {
|
||||||
|
@ -179,14 +179,17 @@ static int SerialGetChar(struct SerialHardwareDevice *serial_dev)
|
||||||
struct gap8_udma_peripheral *uart_udma = (struct gap8_udma_peripheral *)serial_cfg->hw_cfg.private_data;
|
struct gap8_udma_peripheral *uart_udma = (struct gap8_udma_peripheral *)serial_cfg->hw_cfg.private_data;
|
||||||
|
|
||||||
uint8_t rx_buf[4] = {0};
|
uint8_t rx_buf[4] = {0};
|
||||||
uint8_t ch = rx_buf[0];
|
uint8_t ch = g_uart1rxbuffer[0];
|
||||||
|
|
||||||
/* Then trigger another reception */
|
/* Then trigger another reception */
|
||||||
|
gap8_udma_rx_setirq(uart_udma, 1);
|
||||||
|
gap8_udma_rx_start(uart_udma, g_uart1rxbuffer, 1, 1);
|
||||||
|
|
||||||
gap8_udma_rx_start(uart_udma, rx_buf, 1, 1);
|
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
return -ERROR;
|
return -ERROR;
|
||||||
|
|
||||||
|
memset(g_uart1rxbuffer,0,128);
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +206,7 @@ static const struct SerialDataCfg data_cfg_init =
|
||||||
|
|
||||||
static struct gap8_udma_peripheral gap8_udma =
|
static struct gap8_udma_peripheral gap8_udma =
|
||||||
{
|
{
|
||||||
.regs = (udma_reg_t *)UART,
|
.regs = (volatile udma_reg_t *)UART,
|
||||||
.id = GAP8_UDMA_ID_UART,
|
.id = GAP8_UDMA_ID_UART,
|
||||||
.on_tx = NONE,//UartRxIsr??
|
.on_tx = NONE,//UartRxIsr??
|
||||||
// .on_tx = UartTxIsr,//UartRxIsr??
|
// .on_tx = UartTxIsr,//UartRxIsr??
|
||||||
|
|
|
@ -309,6 +309,9 @@ int gap8_udma_rx_poll(struct gap8_udma_peripheral *instance)
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
int gap8_udma_doirq(int irq, void *context, void *arg)
|
int gap8_udma_doirq(int irq, void *context, void *arg)
|
||||||
{
|
{
|
||||||
|
int oldstat;
|
||||||
|
int newstat;
|
||||||
|
|
||||||
struct gap8_udma_peripheral *the_peripheral;
|
struct gap8_udma_peripheral *the_peripheral;
|
||||||
uint32_t event = SOC_EVENTS->CURRENT_EVENT & 0xff;
|
uint32_t event = SOC_EVENTS->CURRENT_EVENT & 0xff;
|
||||||
|
|
||||||
|
@ -383,5 +386,9 @@ int gap8_udma_doirq(int irq, void *context, void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asm volatile ("csrr %0, 0x300": "=r" (oldstat));
|
||||||
|
newstat = oldstat | (0x80) ;
|
||||||
|
asm volatile("csrw 0x300, %0" : /* no output */ : "r" (newstat));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue