mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-07 13:28:48 +00:00
[fix][drivers] fix hal driver and entry.s bug when main return
This commit is contained in:
parent
d9413fae45
commit
5a811531e9
9 changed files with 185 additions and 178 deletions
|
@ -52,7 +52,6 @@ _enter:
|
|||
/* Intial the mtvt, MUST BE 64 bytes aligned*/
|
||||
.weak __Vectors
|
||||
la t0, __Vectors
|
||||
// From drivers/bl702_driver/risc-v/Core/Include/riscv_encoding.h
|
||||
csrw CSR_MTVT, t0
|
||||
|
||||
#ifdef __riscv_float_abi_single
|
||||
|
@ -87,21 +86,10 @@ _enter:
|
|||
li a2, 0
|
||||
call main
|
||||
|
||||
/* If we've made it back here then there's probably something wrong. We
|
||||
* allow the METAL to register a handler here. */
|
||||
.weak __metal_after_main
|
||||
la ra, __metal_after_main
|
||||
beqz ra, 1f
|
||||
jalr ra
|
||||
1:
|
||||
csrci mstatus, (1 << 3)
|
||||
|
||||
/* If that handler returns then there's not a whole lot we can do. Just
|
||||
* try to make some noise. */
|
||||
la t0, 1f
|
||||
csrw mtvec, t0
|
||||
1:
|
||||
lw t1, 0(x0)
|
||||
j 1b
|
||||
__exit:
|
||||
j __exit
|
||||
|
||||
.cfi_endproc
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ typedef struct i2s_device {
|
|||
void *rx_dma;
|
||||
} i2s_device_t;
|
||||
|
||||
#define UART_DEV(dev) ((uart_device_t *)dev)
|
||||
#define I2S_DEV(dev) ((i2s_device_t *)dev)
|
||||
|
||||
int i2s_register(enum i2s_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
|
|
|
@ -27,19 +27,13 @@
|
|||
#include "ring_buffer.h"
|
||||
#include "bl702_config.h"
|
||||
|
||||
#define DEVICE_CTRL_USB_DC_SET_ADDR 0X10
|
||||
#define DEVICE_CTRL_USB_DC_SET_ACK 0X11
|
||||
#define DEVICE_CTRL_USB_DC_SET_NACK 0X12
|
||||
#define DEVICE_CTRL_USB_DC_SET_STALL 0X13
|
||||
#define DEVICE_CTRL_USB_DC_CLR_STALL 0X14
|
||||
#define DEVICE_CTRL_USB_DC_GET_STALL 0X15
|
||||
#define DEVICE_CTRL_USB_DC_CLR_NACK 0X16
|
||||
#define DEVICE_CTRL_USB_DC_CHECK_EPCAP 0X17
|
||||
#define DEVICE_CTRL_USB_DC_GET_TX_FIFO_CNT 0x18
|
||||
#define DEVICE_CTRL_USB_DC_GET_RX_FIFO_CNT 0x19
|
||||
#define DEVICE_CTRL_USB_DC_GET_EP_FREE 0x20
|
||||
#define DEVICE_CTRL_USB_DC_SET_TX_DMA 0x21
|
||||
#define DEVICE_CTRL_USB_DC_SET_RX_DMA 0x22
|
||||
#define DEVICE_CTRL_USB_DC_SET_ACK 0X10
|
||||
#define DEVICE_CTRL_USB_DC_ENUM_ON 0X11
|
||||
#define DEVICE_CTRL_USB_DC_ENUM_OFF 0X12
|
||||
#define DEVICE_CTRL_USB_DC_GET_EP_TX_FIFO_CNT 0x13
|
||||
#define DEVICE_CTRL_USB_DC_GET_EP_RX_FIFO_CNT 0x14
|
||||
#define DEVICE_CTRL_USB_DC_SET_TX_DMA 0x15
|
||||
#define DEVICE_CTRL_USB_DC_SET_RX_DMA 0x16
|
||||
|
||||
enum usb_index_type {
|
||||
#ifdef BSP_USING_USB
|
||||
|
@ -166,8 +160,9 @@ enum usb_error_type {
|
|||
USB_DC_EP_DIR_ERR = 1,
|
||||
USB_DC_EP_EN_ERR = 2,
|
||||
USB_DC_EP_TIMEOUT_ERR = 3,
|
||||
USB_DC_RB_SIZE_SMALL_ERR = 4,
|
||||
USB_DC_ZLP_ERR = 5,
|
||||
USB_DC_ADDR_ERR = 4,
|
||||
USB_DC_RB_SIZE_SMALL_ERR = 5,
|
||||
USB_DC_ZLP_ERR = 6,
|
||||
};
|
||||
/**
|
||||
* @brief USB Endpoint Configuration.
|
||||
|
@ -210,7 +205,11 @@ typedef struct usb_dc_device {
|
|||
|
||||
int usb_dc_register(enum usb_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
int usb_dc_set_dev_address(const uint8_t addr);
|
||||
int usb_dc_ep_open(struct device *dev, const struct usb_dc_ep_cfg *ep_cfg);
|
||||
int usb_dc_ep_close(const uint8_t ep);
|
||||
int usb_dc_ep_set_stall(const uint8_t ep);
|
||||
int usb_dc_ep_clear_stall(const uint8_t ep);
|
||||
int usb_dc_ep_is_stalled(struct device *dev, const uint8_t ep, uint8_t *stalled);
|
||||
int usb_dc_ep_write(struct device *dev, const uint8_t ep, const uint8_t *data, uint32_t data_len, uint32_t *ret_bytes);
|
||||
int usb_dc_ep_read(struct device *dev, const uint8_t ep, uint8_t *data, uint32_t data_len, uint32_t *read_bytes);
|
||||
|
|
|
@ -147,8 +147,7 @@ void peripheral_clock_init(void)
|
|||
#endif
|
||||
|
||||
#if defined(BSP_USING_I2S0)
|
||||
GLB_Set_Chip_Out_0_CLK_Sel(GLB_CHIP_CLK_OUT_I2S_REF_CLK);
|
||||
GLB_Set_I2S_CLK(ENABLE, GLB_I2S_OUT_REF_CLK_SRC);
|
||||
GLB_Set_I2S_CLK(ENABLE, GLB_I2S_OUT_REF_CLK_NONE);
|
||||
#endif
|
||||
#if defined(BSP_USING_ADC0)
|
||||
#if BSP_ADC_CLOCK_SOURCE == ROOT_CLOCK_SOURCE_AUPLL
|
||||
|
|
|
@ -89,7 +89,8 @@ int dma_open(struct device *dev, uint16_t oflag)
|
|||
DMA_Enable();
|
||||
|
||||
Interrupt_Handler_Register(DMA_ALL_IRQn, DMA0_IRQ);
|
||||
|
||||
/* Enable uart interrupt*/
|
||||
NVIC_EnableIRQ(DMA_ALL_IRQn);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
|
@ -110,8 +111,6 @@ int dma_control(struct device *dev, int cmd, void *args)
|
|||
DMA_IntMask(dma_device->ch, DMA_INT_TCOMPLETED, UNMASK);
|
||||
DMA_IntMask(dma_device->ch, DMA_INT_ERR, UNMASK);
|
||||
|
||||
/* Enable uart interrupt*/
|
||||
NVIC_EnableIRQ(DMA_ALL_IRQn);
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_CLR_INT /* constant-expression */:
|
||||
|
@ -119,8 +118,6 @@ int dma_control(struct device *dev, int cmd, void *args)
|
|||
DMA_IntMask(dma_device->ch, DMA_INT_TCOMPLETED, MASK);
|
||||
DMA_IntMask(dma_device->ch, DMA_INT_ERR, MASK);
|
||||
|
||||
/* Enable uart interrupt*/
|
||||
NVIC_DisableIRQ(DMA_ALL_IRQn);
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_GET_INT /* constant-expression */:
|
||||
|
|
|
@ -39,7 +39,7 @@ int i2s_open(struct device *dev, uint16_t oflag)
|
|||
I2S_FifoCfg_Type fifoCfg = { 0 };
|
||||
|
||||
GLB_Set_Chip_Out_0_CLK_Sel(GLB_CHIP_CLK_OUT_I2S_REF_CLK);
|
||||
GLB_Set_I2S_CLK(ENABLE, GLB_I2S_OUT_REF_CLK_SRC);
|
||||
GLB_Set_I2S_CLK(ENABLE, GLB_I2S_OUT_REF_CLK_NONE);
|
||||
|
||||
/*Finding the right frequency*/
|
||||
if (12288000 % (i2s_device->sampl_freq_hz) == 0) {
|
||||
|
|
|
@ -278,8 +278,10 @@ int uart_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t si
|
|||
dma_channel_start(dma_ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else if (dev->oflag & DEVICE_OFLAG_STREAM_TX) {
|
||||
return UART_SendData(uart_device->id, (uint8_t *)buffer, size);
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
|
@ -290,7 +292,7 @@ int uart_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t si
|
|||
* @param size
|
||||
* @return int
|
||||
*/
|
||||
int ATTR_TCM_SECTION uart_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size)
|
||||
int uart_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size)
|
||||
{
|
||||
uart_device_t *uart_device = (uart_device_t *)dev;
|
||||
if (dev->oflag & DEVICE_OFLAG_DMA_RX) {
|
||||
|
@ -305,8 +307,15 @@ int ATTR_TCM_SECTION uart_read(struct device *dev, uint32_t pos, void *buffer, u
|
|||
dma_reload(dma_ch, (uint32_t)DMA_ADDR_UART1_RDR, (uint32_t)buffer, size);
|
||||
dma_channel_start(dma_ch);
|
||||
}
|
||||
return 0;
|
||||
} else if (dev->oflag & DEVICE_OFLAG_STREAM_RX) {
|
||||
uint32_t rx_len = 0;
|
||||
while (rx_len < size) {
|
||||
rx_len += UART_ReceiveData(uart_device->id, (uint8_t *)buffer + rx_len, size - rx_len);
|
||||
}
|
||||
return UART_ReceiveData(uart_device->id, (uint8_t *)buffer, size);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
|
@ -342,7 +351,7 @@ int uart_register(enum uart_index_type index, const char *name, uint16_t flag)
|
|||
*
|
||||
* @param handle
|
||||
*/
|
||||
void ATTR_TCM_SECTION uart_isr(uart_device_t *handle)
|
||||
void uart_isr(uart_device_t *handle)
|
||||
{
|
||||
uint32_t tmpVal = 0;
|
||||
uint32_t maskVal = 0;
|
||||
|
|
|
@ -333,72 +333,33 @@ int usb_control(struct device *dev, int cmd, void *args)
|
|||
|
||||
offset++;
|
||||
}
|
||||
} break;
|
||||
|
||||
break;
|
||||
}
|
||||
case DEVICE_CTRL_CLR_INT /* constant-expression */:
|
||||
/* code */
|
||||
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_GET_INT /* constant-expression */:
|
||||
/* code */
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_CONFIG /* constant-expression */:
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_GET_CONFIG /* constant-expression */:
|
||||
break;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_SET_ADDR /* constant-expression */:
|
||||
USB_Set_Device_Addr(((uint32_t)args) & 0x7f);
|
||||
return 0;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_SET_ACK /* constant-expression */:
|
||||
USB_Set_EPx_Status(USB_EP_GET_IDX(((uint32_t)args) & 0x7f), USB_EP_STATUS_ACK);
|
||||
return 0;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_SET_NACK /* constant-expression */:
|
||||
USB_Set_EPx_Status(USB_EP_GET_IDX(((uint32_t)args) & 0x7f), USB_EP_STATUS_NACK);
|
||||
case DEVICE_CTRL_USB_DC_ENUM_ON: {
|
||||
uint32_t tmpVal;
|
||||
tmpVal = BL_RD_REG(GLB_BASE, GLB_USB_XCVR);
|
||||
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, GLB_USB_ENUM, 1);
|
||||
BL_WR_REG(GLB_BASE, GLB_USB_XCVR, tmpVal);
|
||||
return 0;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_SET_STALL /* constant-expression */: {
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(((uint32_t)args) & 0x7f);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(((uint32_t)args) & 0x7f)) {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_STALL);
|
||||
usb_fs_device.out_ep[ep_idx].is_stalled = 1U;
|
||||
} else {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_STALL);
|
||||
usb_fs_device.in_ep[ep_idx].is_stalled = 1U;
|
||||
}
|
||||
}
|
||||
|
||||
case DEVICE_CTRL_USB_DC_ENUM_OFF: {
|
||||
uint32_t tmpVal;
|
||||
tmpVal = BL_RD_REG(GLB_BASE, GLB_USB_XCVR);
|
||||
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, GLB_USB_ENUM, 0);
|
||||
BL_WR_REG(GLB_BASE, GLB_USB_XCVR, tmpVal);
|
||||
return 0;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_CLR_STALL /* constant-expression */: {
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(((uint32_t)args) & 0x7f);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(((uint32_t)args) & 0x7f)) {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_NSTALL);
|
||||
usb_fs_device.out_ep[ep_idx].is_stalled = 0;
|
||||
} else {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_NSTALL);
|
||||
usb_fs_device.in_ep[ep_idx].is_stalled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case DEVICE_CTRL_USB_DC_GET_TX_FIFO_CNT:
|
||||
case DEVICE_CTRL_USB_DC_GET_EP_TX_FIFO_CNT:
|
||||
return USB_Get_EPx_TX_FIFO_CNT(((uint32_t)args) & 0x7f);
|
||||
|
||||
case DEVICE_CTRL_USB_DC_GET_RX_FIFO_CNT:
|
||||
case DEVICE_CTRL_USB_DC_GET_EP_RX_FIFO_CNT:
|
||||
return USB_Get_EPx_RX_FIFO_CNT(((uint32_t)args) & 0x7f);
|
||||
|
||||
case DEVICE_CTRL_USB_DC_GET_EP_FREE:
|
||||
return USB_Is_EPx_RDY_Free(((uint32_t)args) & 0x7f);
|
||||
|
||||
case DEVICE_CTRL_ATTACH_TX_DMA /* constant-expression */:
|
||||
usb_device->tx_dma = (struct device *)args;
|
||||
break;
|
||||
|
@ -501,6 +462,19 @@ int usb_dc_register(enum usb_index_type index, const char *name, uint16_t flag)
|
|||
return device_register(dev, name, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set USB device address
|
||||
*
|
||||
* @param[in] addr Device address
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usb_dc_set_dev_address(const uint8_t addr)
|
||||
{
|
||||
USB_Set_Device_Addr(addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief configure and enable endpoint
|
||||
* This function sets endpoint configuration according to one specified in USB
|
||||
|
@ -581,6 +555,54 @@ int usb_dc_ep_open(struct device *dev, const struct usb_dc_ep_cfg *ep_cfg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_ep_close(const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set stall condition for the selected endpoint
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usb_dc_ep_set_stall(const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_STALL);
|
||||
usb_fs_device.out_ep[ep_idx].is_stalled = 1U;
|
||||
} else {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_STALL);
|
||||
usb_fs_device.in_ep[ep_idx].is_stalled = 1U;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @brief Clear stall condition for the selected endpoint
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usb_dc_ep_clear_stall(const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_NSTALL);
|
||||
usb_fs_device.out_ep[ep_idx].is_stalled = 0;
|
||||
} else {
|
||||
USB_Set_EPx_Status(ep_idx, USB_EP_STATUS_NSTALL);
|
||||
usb_fs_device.in_ep[ep_idx].is_stalled = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the selected endpoint is stalled
|
||||
*
|
||||
|
@ -643,12 +665,12 @@ int usb_dc_ep_write(struct device *dev, const uint8_t ep, const uint8_t *data, u
|
|||
|
||||
/* Check if IN ep */
|
||||
if (USB_EP_GET_DIR(ep) != USB_EP_DIR_IN) {
|
||||
return -1;
|
||||
return -USB_DC_EP_DIR_ERR;
|
||||
}
|
||||
|
||||
/* Check if ep enabled */
|
||||
if (!usb_ep_is_enabled(ep)) {
|
||||
return -2;
|
||||
return -USB_DC_EP_EN_ERR;
|
||||
}
|
||||
|
||||
while (!USB_Is_EPx_RDY_Free(ep_idx)) {
|
||||
|
@ -656,21 +678,20 @@ int usb_dc_ep_write(struct device *dev, const uint8_t ep, const uint8_t *data, u
|
|||
|
||||
if (!timeout) {
|
||||
USB_DC_LOG_ERR("ep%d wait free timeout\r\n", ep);
|
||||
return -3;
|
||||
return -USB_DC_EP_TIMEOUT_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
// key = irq_lock();
|
||||
if (!data) {
|
||||
if (!data_len) {
|
||||
/* Zero length packet */
|
||||
/* Clear NAK and enable ep */
|
||||
USB_Set_EPx_Status(USB_EP_GET_IDX(ep), USB_EP_STATUS_ACK);
|
||||
return 0;
|
||||
} else {
|
||||
USB_DC_LOG_ERR("data is null\r\n");
|
||||
return -4;
|
||||
return USB_DC_OK;
|
||||
}
|
||||
|
||||
if (!data && data_len) {
|
||||
USB_DC_LOG_ERR("data is null\r\n");
|
||||
return -USB_DC_ADDR_ERR;
|
||||
}
|
||||
|
||||
if (data_len > usb_fs_device.in_ep[ep_idx].ep_cfg.ep_mps) {
|
||||
|
@ -716,7 +737,7 @@ int usb_dc_ep_write(struct device *dev, const uint8_t ep, const uint8_t *data, u
|
|||
*ret_bytes = data_len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return USB_DC_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -748,13 +769,13 @@ int usb_dc_ep_read(struct device *dev, const uint8_t ep, uint8_t *data, uint32_t
|
|||
/* Check if OUT ep */
|
||||
if (USB_EP_GET_DIR(ep) != USB_EP_DIR_OUT) {
|
||||
USB_DC_LOG_ERR("Wrong endpoint direction\r\n");
|
||||
return -1;
|
||||
return -USB_DC_EP_DIR_ERR;
|
||||
}
|
||||
|
||||
/* Check if ep enabled */
|
||||
if (!usb_ep_is_enabled(ep)) {
|
||||
USB_DC_LOG_ERR("Not enabled endpoint\r\n");
|
||||
return -1;
|
||||
return -USB_DC_EP_EN_ERR;
|
||||
}
|
||||
|
||||
/*common process for other ep out*/
|
||||
|
@ -784,7 +805,12 @@ int usb_dc_ep_read(struct device *dev, const uint8_t ep, uint8_t *data, uint32_t
|
|||
if (!data_len) {
|
||||
/* Clear NAK and enable ep */
|
||||
USB_Set_EPx_Status(USB_EP_GET_IDX(ep), USB_EP_STATUS_ACK);
|
||||
return 0;
|
||||
return USB_DC_OK;
|
||||
}
|
||||
|
||||
if (!data && data_len) {
|
||||
USB_DC_LOG_ERR("data is null\r\n");
|
||||
return -USB_DC_ADDR_ERR;
|
||||
}
|
||||
|
||||
read_count = USB_Get_EPx_RX_FIFO_CNT(ep_idx);
|
||||
|
@ -799,7 +825,7 @@ int usb_dc_ep_read(struct device *dev, const uint8_t ep, uint8_t *data, uint32_t
|
|||
*read_bytes = read_count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return USB_DC_OK;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
|
|
|
@ -87,21 +87,10 @@ _enter:
|
|||
li a2, 0
|
||||
call main
|
||||
|
||||
/* If we've made it back here then there's probably something wrong. We
|
||||
* allow the METAL to register a handler here. */
|
||||
.weak __metal_after_main
|
||||
la ra, __metal_after_main
|
||||
beqz ra, 1f
|
||||
jalr ra
|
||||
1:
|
||||
csrci mstatus, (1 << 3)
|
||||
|
||||
/* If that handler returns then there's not a whole lot we can do. Just
|
||||
* try to make some noise. */
|
||||
la t0, 1f
|
||||
csrw mtvec, t0
|
||||
1:
|
||||
lw t1, 0(x0)
|
||||
j 1b
|
||||
__exit:
|
||||
j __exit
|
||||
|
||||
.cfi_endproc
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue