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 */
|
||||
|
||||
#include "boot.h"
|
||||
#define EXCEPTION_STACK_SIZE 4*38
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -112,7 +112,7 @@
|
|||
csrrw x0, 0x7B0, x28
|
||||
csrrw x0, 0x7B1, x29
|
||||
csrrw x0, 0x7B2, x30
|
||||
li s0, 0x1890 /* machine mode, UPIE & MPIE enabled */
|
||||
li s0, 0x1880 /* machine mode, UPIE & MPIE enabled */
|
||||
csrrw x0, mstatus, s0
|
||||
lw x3, 3*4(sp) /* gp */
|
||||
lw x4, 4*4(sp) /* tp */
|
||||
|
@ -149,31 +149,22 @@
|
|||
lw sp, 2*4(sp) /* restore original sp */
|
||||
.endm
|
||||
|
||||
/* wrapper for IRQ vector */
|
||||
|
||||
.macro WRAP_IRQ Routine, IRQn
|
||||
.macro WRAP_IRQ Routine, IRQn
|
||||
wrap_irq_\Routine :
|
||||
SAVE_REGS
|
||||
|
||||
csrr s0, mepc
|
||||
sw s0, 0(sp) /* exception PC */
|
||||
SAVE_X_REGISTERS
|
||||
|
||||
mv fp, sp
|
||||
|
||||
li a0, \IRQn /* irq = IRQn */
|
||||
mv a1, sp /* context = sp */
|
||||
jal x1, gap8_dispatch_irq
|
||||
call gap8_dispatch_irq
|
||||
|
||||
/* If context switch is needed, return
|
||||
* a new sp
|
||||
*/
|
||||
mv sp, fp
|
||||
mv a0, fp
|
||||
call KTaskOsAssignAfterIrq
|
||||
j SwitchKTaskContextExit
|
||||
|
||||
mv sp, a0
|
||||
|
||||
lw s0, 0(sp) /* restore ePC */
|
||||
csrw mepc, s0
|
||||
|
||||
RESTORE_REGS
|
||||
|
||||
mret
|
||||
.endm
|
||||
|
||||
|
||||
|
|
|
@ -121,14 +121,14 @@ static inline void up_ack_irq(int irq)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline uint32_t _current_privilege(void)
|
||||
{
|
||||
uint32_t result;
|
||||
// static inline uint32_t _current_privilege(void)
|
||||
// {
|
||||
// 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
|
||||
*
|
||||
|
@ -137,21 +137,21 @@ static inline uint32_t _current_privilege(void)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void up_irq_restore(unsigned int pri)
|
||||
{
|
||||
if (_current_privilege())
|
||||
{
|
||||
/* Machine mode - mstatus */
|
||||
// static inline void up_irq_restore(unsigned int pri)
|
||||
// {
|
||||
// if (_current_privilege())
|
||||
// {
|
||||
// /* Machine mode - mstatus */
|
||||
|
||||
asm volatile("csrw 0x300, %0" : /* no output */ : "r" (pri));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* User mode - ustatus */
|
||||
// asm volatile("csrw 0x300, %0" : /* no output */ : "r" (pri));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// /* 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
|
||||
*
|
||||
|
@ -160,30 +160,30 @@ static inline void up_irq_restore(unsigned int pri)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
x_base up_irq_save(void)
|
||||
{
|
||||
x_base oldstat;
|
||||
x_base newstat;
|
||||
// x_base up_irq_save(void)
|
||||
// {
|
||||
// x_base oldstat;
|
||||
// x_base newstat;
|
||||
|
||||
if (_current_privilege())
|
||||
{
|
||||
/* Machine mode: Unset MIE and UIE */
|
||||
// if (_current_privilege())
|
||||
// {
|
||||
// /* Machine mode: Unset MIE and UIE */
|
||||
|
||||
asm volatile ("csrr %0, 0x300": "=r" (oldstat));
|
||||
newstat = oldstat & ~(0x9);
|
||||
asm volatile("csrw 0x300, %0" : /* no output */ : "r" (newstat));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* User mode: Unset UIE */
|
||||
// asm volatile ("csrr %0, 0x300": "=r" (oldstat));
|
||||
// newstat = oldstat & ~(0x9);
|
||||
// asm volatile("csrw 0x300, %0" : /* no output */ : "r" (newstat));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// /* User mode: Unset UIE */
|
||||
|
||||
asm volatile ("csrr %0, 0x000": "=r" (oldstat));
|
||||
newstat = oldstat & ~(1L << 0);
|
||||
asm volatile("csrw 0x000, %0" : /* no output */ : "r" (newstat));
|
||||
}
|
||||
// asm volatile ("csrr %0, 0x000": "=r" (oldstat));
|
||||
// newstat = oldstat & ~(1L << 0);
|
||||
// asm volatile("csrw 0x000, %0" : /* no output */ : "r" (newstat));
|
||||
// }
|
||||
|
||||
return oldstat;
|
||||
}
|
||||
// return oldstat;
|
||||
// }
|
||||
/****************************************************************************
|
||||
* 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)
|
||||
// {
|
||||
// FCEU->MASK_OR = event_mask;
|
||||
// __builtin_pulp_event_unit_read((void *)&FCEU->EVENT_WAIT_CLEAR, 0);
|
||||
// FCEU->MASK_AND = event_mask;
|
||||
// }
|
||||
void gap8_sleep_wait_sw_evnt(uint32_t event_mask)
|
||||
{
|
||||
FCEU->MASK_OR = event_mask;
|
||||
// __builtin_pulp_event_unit_read((void *)&FCEU->EVENT_WAIT_CLEAR, 0);
|
||||
FCEU->MASK_AND = event_mask;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
|
@ -334,28 +334,17 @@ void *gap8_dispatch_irq(uint32_t vector, void *current_regs)
|
|||
/* Clear pending bit and trigger a software event.
|
||||
* GAP8 would sleep on sw event 3 on up_idle().
|
||||
*/
|
||||
|
||||
|
||||
FCEU->BUFFER_CLEAR = (1 << vector);
|
||||
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;
|
||||
// irq_dispatch(vector, current_regs);
|
||||
|
||||
|
||||
isrManager.done->incCounter();
|
||||
isrManager.done->handleIrq(vector);
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
udma_reg_t *regs; /* Hardware config regs */
|
||||
volatile udma_reg_t *regs; /* Hardware config regs */
|
||||
uint32_t id; /* GAP8_UDMA_ID_x */
|
||||
void (*on_tx)(void *arg); /* tx callback */
|
||||
void (*on_rx)(void *arg); /* rx callback */
|
||||
|
|
|
@ -101,7 +101,7 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf
|
|||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
static char g_uart1rxbuffer[128];
|
||||
static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operation_cmd)
|
||||
{
|
||||
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_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);
|
||||
} 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;
|
||||
|
||||
uint8_t rx_buf[4] = {0};
|
||||
uint8_t ch = rx_buf[0];
|
||||
uint8_t ch = g_uart1rxbuffer[0];
|
||||
|
||||
/* 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)
|
||||
return -ERROR;
|
||||
|
||||
memset(g_uart1rxbuffer,0,128);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -201,9 +204,9 @@ static const struct SerialDataCfg data_cfg_init =
|
|||
.serial_buffer_size = SERIAL_RB_BUFSZ,
|
||||
};
|
||||
|
||||
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,
|
||||
.on_tx = NONE,//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 oldstat;
|
||||
int newstat;
|
||||
|
||||
struct gap8_udma_peripheral *the_peripheral;
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue