126 lines
2.5 KiB
C
126 lines
2.5 KiB
C
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include "board.h"
|
|
#include "../../regdef.h"
|
|
|
|
extern uart_if_t uart_if[];
|
|
|
|
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
|
|
|
const con_if_entry_t con_if_entry[] =
|
|
{
|
|
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
|
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
|
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
|
{3, "UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
|
{4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
|
|
};
|
|
|
|
con_if_t con_if =
|
|
{
|
|
con_if_entry, ARRAYSIZE(con_if_entry)
|
|
};
|
|
|
|
static uart_if_t const *dbg_uart = NULL;
|
|
static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA;
|
|
static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR;
|
|
static uint32_t led_count = 0;
|
|
|
|
extern int dbg_handler(struct xcptcontext * xcp);
|
|
extern void handle_exception (unsigned long *registers);
|
|
|
|
int gdb_stub(struct xcptcontext * xcp)
|
|
{
|
|
handle_exception((unsigned long *)xcp);
|
|
return 0;
|
|
}
|
|
|
|
void dbg_uart_isr(struct xcptcontext *xcp)
|
|
{
|
|
if(SYS_UART_BIT_RX_AVAIL & *dbg_uart->pCTRL)
|
|
{
|
|
char c = *dbg_uart->pDATA;
|
|
if (c == 3)
|
|
{
|
|
gdb_stub(xcp);
|
|
}
|
|
}
|
|
}
|
|
|
|
void dbg_uart_setup()
|
|
{
|
|
const int UART_INT = SYS_INT_UART1;
|
|
dbg_uart = (uart_if_t*)con_getInterfaceByName("UART-1")->pInst;
|
|
|
|
*dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN;
|
|
interrupt_register(UART_INT, dbg_uart_isr);
|
|
interrupt_enable(UART_INT);
|
|
}
|
|
|
|
inline void _dbg_writechar(uart_if_t const *pUart, char c)
|
|
{
|
|
while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0);
|
|
|
|
*pUart->pDATA = (uint32_t)c;
|
|
|
|
}
|
|
|
|
inline char _dbg_readchar(uart_if_t const *pUart)
|
|
{
|
|
// busy read
|
|
while(!(SYS_UART_BIT_RX_AVAIL & *pUart->pCTRL))
|
|
{
|
|
(*pGpioData) = (led_count++) >> 16;
|
|
}
|
|
led_count = 0;
|
|
return (*pUart->pDATA & 0xFF);
|
|
|
|
}
|
|
|
|
void dbg_putchar(char c)
|
|
{
|
|
if (c == 0x0A)
|
|
{
|
|
_dbg_writechar(dbg_uart, 0x0D);
|
|
}
|
|
_dbg_writechar(dbg_uart, c);
|
|
}
|
|
|
|
char dbg_getchar()
|
|
{
|
|
return (char)_dbg_readchar(dbg_uart);
|
|
}
|
|
|
|
void dbg_init()
|
|
{
|
|
xcpt_register(EXC_BP, gdb_stub);
|
|
}
|
|
|
|
void board_init(void)
|
|
{
|
|
uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL;
|
|
|
|
// Disable timers
|
|
*pITIM_ctrl = 0;
|
|
|
|
// Setup syscall support
|
|
syscalls_init();
|
|
|
|
// Setup Uart ISR
|
|
dbg_uart_setup();
|
|
|
|
// Setup debugger
|
|
dbg_init();
|
|
|
|
// Setup interrupt support
|
|
interrupt_init();
|
|
|
|
// Do some initializations here
|
|
*pGpioDir = 0xFF;
|
|
}
|