fix a bug of uart input problem for gap8
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user