This commit is contained in:
zhuyunfan 2021-03-03 16:28:23 +08:00
commit 8897a1cde3
26 changed files with 833 additions and 400 deletions

5
.gitattributes vendored
View File

@ -1,3 +1,8 @@
*.c linguist-language=C
*.C linguist-language=C
*.h linguist-language=C
*.H linguist-language=C
* text=auto
*.S text

View File

@ -1,7 +1,7 @@
/*
* File : interrupt.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
* COPYRIGHT (C) 2017-2021, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
* Change Logs:
* Date Author Notes
* 2018-02-08 RT-Thread the first version
* 2020-03-02 Howard Su Use structure to access registers
*/
#include <rthw.h>
@ -38,9 +39,6 @@ static void rt_hw_interrupt_handler(int vector, void *param)
rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
}
#define readl(addr) (*(volatile unsigned int *)(addr))
#define writel(value,addr) (*(volatile unsigned int *)(addr) = (value))
/**
* This function will initialize hardware interrupt
*/
@ -63,20 +61,20 @@ void rt_hw_interrupt_init(void)
/* set base_addr reg */
INTC->base_addr_reg = 0x00000000;
/* clear enable */
INTC->en_reg0 = 0x00000000;
INTC->en_reg1 = 0x00000000;
INTC->en_reg[0] = 0x00000000;
INTC->en_reg[1] = 0x00000000;
/* mask interrupt */
INTC->mask_reg0 = 0xFFFFFFFF;
INTC->mask_reg1 = 0xFFFFFFFF;
INTC->mask_reg[0] = 0xFFFFFFFF;
INTC->mask_reg[1] = 0xFFFFFFFF;
/* clear pending */
INTC->pend_reg0 = 0x00000000;
INTC->pend_reg1 = 0x00000000;
INTC->pend_reg[0] = 0x00000000;
INTC->pend_reg[1] = 0x00000000;
/* set priority */
INTC->resp_reg0 = 0x00000000;
INTC->resp_reg1 = 0x00000000;
INTC->resp_reg[0] = 0x00000000;
INTC->resp_reg[1] = 0x00000000;
/* close fiq interrupt */
INTC->ff_reg0 = 0x00000000;
INTC->ff_reg1 = 0x00000000;
INTC->ff_reg[0] = 0x00000000;
INTC->ff_reg[1] = 0x00000000;
}
/**
@ -85,20 +83,16 @@ void rt_hw_interrupt_init(void)
*/
void rt_hw_interrupt_mask(int vector)
{
rt_uint32_t mask_addr, data;
int index;
if ((vector < 0) || (vector > INTERRUPTS_MAX))
{
return;
}
mask_addr = (rt_uint32_t)(&INTC->mask_reg0);
mask_addr += vector & 0xE0 ? sizeof(rt_uint32_t *) : 0;
index = (vector & 0xE0) != 0;
vector = (vector & 0x1F);
vector &= 0x1F;
data = readl(mask_addr);
data |= 0x1 << vector;
writel(data, mask_addr);
INTC->mask_reg[index] |= 1 << vector;
}
/**
@ -108,20 +102,16 @@ void rt_hw_interrupt_mask(int vector)
*/
void rt_hw_interrupt_umask(int vector)
{
rt_uint32_t mask_addr, data;
int index;
if ((vector < 0) || (vector > INTERRUPTS_MAX))
{
return;
}
mask_addr = (rt_uint32_t)(&INTC->mask_reg0);
mask_addr += vector & 0xE0 ? sizeof(rt_uint32_t *) : 0;
index = (vector & 0xE0) != 0;
vector = (vector & 0x1F);
vector &= 0x1F;
data = readl(mask_addr);
data &= ~(0x1 << vector);
writel(data, mask_addr);
INTC->mask_reg[index] &= ~(1 << vector);
}
/**
@ -136,7 +126,7 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
void *param, const char *name)
{
rt_isr_handler_t old_handler = RT_NULL;
rt_uint32_t pend_addr, en_addr, data;
int index;
if ((vector < 0) || (vector > INTERRUPTS_MAX))
{
@ -151,19 +141,11 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
isr_table[vector].handler = handler;
isr_table[vector].param = param;
pend_addr = (rt_uint32_t)(&INTC->pend_reg0);
en_addr = (rt_uint32_t)(&INTC->en_reg0);
pend_addr += vector & 0xE0 ? sizeof(rt_uint32_t *) : 0;
en_addr += vector & 0xE0 ? sizeof(rt_uint32_t *) : 0;
index = (vector & 0xE0) != 0;
vector = (vector & 0x1F);
vector &= 0x1F;
data = readl(pend_addr);
data &= ~(0x1 << vector);
writel(data, pend_addr);
data = readl(en_addr);
data |= 0x1 << vector;
writel(data, en_addr);
INTC->pend_reg[index] &= ~(0x1 << vector);
INTC->en_reg[index] |= 0x1 << vector;
return old_handler;
}
@ -173,7 +155,7 @@ void rt_interrupt_dispatch(rt_uint32_t fiq_irq)
void *param;
int vector;
rt_isr_handler_t isr_func;
rt_uint32_t pend_addr, data;
int index;
vector = INTC->vector_reg - INTC->base_addr_reg;
vector = vector >> 2;
@ -184,13 +166,11 @@ void rt_interrupt_dispatch(rt_uint32_t fiq_irq)
/* jump to fun */
isr_func(vector, param);
/* clear pend bit */
pend_addr = (rt_uint32_t)(&INTC->pend_reg0);
pend_addr += vector & 0xE0 ? sizeof(rt_uint32_t *) : 0;
vector &= 0x1F;
data = readl(pend_addr);
data &= ~(0x1 << vector);
writel(data, pend_addr);
index = (vector & 0xE0) != 0;
vector = (vector & 0x1F);
INTC->pend_reg[index] &= ~(0x1 << vector);
#ifdef RT_USING_INTERRUPT_INFO
isr_table[vector].counter ++;

View File

@ -1,7 +1,7 @@
/*
* File : interrupt.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
* COPYRIGHT (C) 2017-2021, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
* Change Logs:
* Date Author Notes
* 2018-02-08 RT-Thread the first version
* 2020-03-2 Howard Su Define same regsiters as an array
*/
#ifndef __INTERRUPT_H__
#define __INTERRUPT_H__
@ -74,34 +75,21 @@ struct tina_intc
volatile rt_uint32_t base_addr_reg; /* 0x04 */
volatile rt_uint32_t reserved0;
volatile rt_uint32_t nmi_ctrl_reg; /* 0x0C */
volatile rt_uint32_t pend_reg0; /* 0x10 */
volatile rt_uint32_t pend_reg1; /* 0x14 */
volatile rt_uint32_t pend_reg[2]; /* 0x10, 0x14 */
volatile rt_uint32_t reserved1[2];
volatile rt_uint32_t en_reg0; /* 0x20 */
volatile rt_uint32_t en_reg1; /* 0x24 */
volatile rt_uint32_t en_reg[2]; /* 0x20, 0x24 */
volatile rt_uint32_t reserved2[2];
volatile rt_uint32_t mask_reg0; /* 0x30 */
volatile rt_uint32_t mask_reg1; /* 0x34 */
volatile rt_uint32_t mask_reg[2]; /* 0x30, 0x34 */
volatile rt_uint32_t reserved3[2];
volatile rt_uint32_t resp_reg0; /* 0x40 */
volatile rt_uint32_t resp_reg1; /* 0x44 */
volatile rt_uint32_t resp_reg[2]; /* 0x40, 0x44 */
volatile rt_uint32_t reserved4[2];
volatile rt_uint32_t ff_reg0; /* 0x50 */
volatile rt_uint32_t ff_reg1; /* 0x54 */
volatile rt_uint32_t ff_reg[2]; /* 0x50, 0x54 */
volatile rt_uint32_t reserved5[2];
volatile rt_uint32_t prio_reg0; /* 0x60 */
volatile rt_uint32_t prio_reg1; /* 0x64 */
volatile rt_uint32_t prio_reg2; /* 0x68 */
volatile rt_uint32_t prio_reg3; /* 0x6C */
volatile rt_uint32_t prio_reg[4]; /* 0x60 - 0x6c */
} ;
typedef struct tina_intc *tina_intc_t;
#define INTC ((tina_intc_t)INTC_BASE_ADDR)
void rt_hw_interrupt_init(void);
void rt_hw_interrupt_mask(int vector);
void rt_hw_interrupt_umask(int vector);
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, void *param, const char *name);
#endif /* __INTERRUPT_H__ */

View File

@ -194,7 +194,6 @@ int MMC_SetCardWidth(struct fh_mmc_obj *mmc_obj, int width)
default:
rt_kprintf("ERROR: %s, card width %d is not supported\n", __func__, width);
return -RT_ERROR;
break;
}
return 0;
}

7
bsp/nrf5x/nrf52832/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# vscode common config
.vscode/*
!.vscode/launch.json
!.vscode/tasks.json
# OS X icon info
.DS_Store

15
bsp/nrf5x/nrf52832/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "cortex-debug",
"request": "launch",
"servertype": "jlink",
"cwd": "${workspaceRoot}",
"executable": "rt-thread.elf",
"name": "Cortex Debug",
"device": "nrf52",
"interface": "swd"
}
]
}

54
bsp/nrf5x/nrf52832/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,54 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "config",
"type": "shell",
"command": "RTT_ROOT=../../.. scons --pyconfig",
"problemMatcher": []
},
{
"label": "build",
"type": "shell",
"command": "scons",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "clean",
"type": "shell",
"command": "scons -c",
"problemMatcher": []
},
{
"label": "flash",
"type": "shell",
"command": "nrfjprog -f nrf52 --program rt-thread.hex --sectorerase",
"group": "build",
"problemMatcher": []
},
{
"label": "flash_softdevice",
"type": "shell",
"command": "nrfjprog -f nrf52 --program packages/nrf5x_sdk-latest/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex --sectorerase",
"problemMatcher": []
},
{
"label": "erase",
"type": "shell",
"command": "nrfjprog -f nrf52 --eraseall",
"problemMatcher": []
},
{
"label": "reset",
"type": "shell",
"command": "nrfjprog -f nrf52 --reset",
"problemMatcher": []
}
]
}

View File

@ -2,7 +2,7 @@
## 简介
该文件夹主要存放所有主芯片为nRF52840的板级支持包。目前默认支持的开发板是官方[PCA10040](https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF52-DK)
该文件夹主要存放所有主芯片为nRF52832的板级支持包。目前默认支持的开发板是官方[PCA10040](https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF52-DK)
主要内容如下:
- 开发板资源介绍
@ -61,6 +61,30 @@ PCA10040-nrf52832开发板常用 **板载资源** 如下:
4. 输入`scons --target=mdk4/mdk5/iar` 命令重新生成工程。
### VS Code开发支持
配置步骤:
1. 在命令行设置以下两个环境变量:
```bash
export RTT_CC=gcc
export RTT_EXEC_PATH=<工具链路径/bin>
```
2. 搜索插件`Cortex-debug`并安装。
3. 安装[nRF Command Line Tools](https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools)以支持`nrfjprog`命令。
4. 在.vscode/settings.json内配置工具链和`JlinkGDBServer`sample
```json
{
"cortex-debug.armToolchainPath": "/usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/",
"cortex-debug.armToolchainPrefix": "arm-none-eabi",
"cortex-debug.JLinkGDBServerPath": "/Applications/SEGGER/JLink/JLinkGDBServer"
}
```
5. 点击`终端`->`运行任务`->`build`编译,点击`终端`->`运行任务`->`flash`烧录,点击左侧`debug`->`run`使用VS Code进行debug。
## 支持其他开发板

View File

@ -54,7 +54,9 @@ if PLATFORM == 'gcc':
else:
CFLAGS += ' -O2'
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
POST_ACTION = OBJCPY + ' -O binary $TARGET rt-thread.bin\n'
POST_ACTION += OBJCPY + ' -O ihex $TARGET rt-thread.hex\n'
POST_ACTION += SIZE + ' $TARGET \n'
elif PLATFORM == 'armcc':
# toolchains

View File

@ -119,6 +119,10 @@ if GetDepend(['BSP_USING_CRYP']):
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_cryp.c']
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_cryp_ex.c']
if GetDepend(['BSP_USING_RTC']):
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_rtc.c']
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_rtc_ex.c']
path = [cwd + '/STM32MP1xx_HAL_Driver/Inc',
cwd + '/CMSIS/Device/ST/STM32MP1xx/Include',
cwd + '/CMSIS/Core/Include',

View File

@ -60,7 +60,7 @@
#define HAL_SAI_MODULE_ENABLED
#define HAL_SD_MODULE_ENABLED
/*#define HAL_MMC_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPDIFRX_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED

View File

@ -1003,7 +1003,66 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
/* USER CODE END SDMMC1_MspInit 1 */
}
if(hsd->Instance==SDMMC2)
{
/* USER CODE BEGIN SDMMC2_MspInit 0 */
if (IS_ENGINEERING_BOOT_MODE())
{
/** Initializes the peripherals clock
*/
PeriphClkInit.Sdmmc12ClockSelection = RCC_SDMMC12CLKSOURCE_PLL4;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC12;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE END SDMMC2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SDMMC2_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/**SDMMC2 GPIO Configuration
PB14 ------> SDMMC2_D0
PB15 ------> SDMMC2_D1
PB3 ------> SDMMC2_D2
PB4 ------> SDMMC2_D3
PE3 ------> SDMMC2_CK
PG6 ------> SDMMC2_CMD
*/
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_SDIO2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_SDIO2;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_SDIO2;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
__HAL_RCC_SDMMC2_FORCE_RESET();
__HAL_RCC_SDMMC2_RELEASE_RESET();
/* SDMMC2 interrupt Init */
HAL_NVIC_SetPriority(SDMMC2_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(SDMMC2_IRQn);
/* USER CODE BEGIN SDMMC2_MspInit 1 */
/* USER CODE END SDMMC2_MspInit 1 */
}
}
/**
@ -1312,6 +1371,65 @@ void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* hcryp)
}
#endif
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN SDMMC1_MspInit 0 */
if (IS_ENGINEERING_BOOT_MODE())
{
/** Initializes the peripherals clock
*/
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
/**
* @brief RTC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None

View File

@ -58,10 +58,23 @@ menu "Onboard Peripheral Drivers"
select RT_USING_LWIP
config BSP_USING_SDMMC
bool "Enable SDMMC (SD card)"
bool "Enable SDMMC (sd card or sdio wifi)"
default n
select RT_USING_SDIO
select RT_USING_DFS
select RT_USING_DFS_ELMFAT
if BSP_USING_SDMMC
config BSP_USING_SDIO1
bool "Enable SDIO1 (sd card)"
default n
config BSP_USING_SDIO2
select BSP_USING_RTC
bool "Enable SDIO2 (sdio wifi)"
default n
endif
config BSP_USING_RTC
bool "Enable RTC"
default n
menuconfig BSP_USING_AUDIO

View File

@ -10,11 +10,17 @@
#include "board.h"
#include "drv_sdio.h"
#ifdef BSP_USING_SDIO1
#include <dfs_fs.h>
#endif
#ifdef BSP_USING_SDMMC
//#define DRV_DEBUG
#ifdef BSP_USING_SDIO2
#define DRV_DEBUG
#endif
#define DBG_TAG "drv.sdio"
#ifdef DRV_DEBUG
#define DBG_LVL DBG_LOG
@ -23,8 +29,9 @@
#endif /* DRV_DEBUG */
#include <rtdbg.h>
static SD_HandleTypeDef hsd;
static struct rt_mmcsd_host *host;
static struct rt_mmcsd_host *host1;
static struct rt_mmcsd_host *host2;
#define SDIO_TX_RX_COMPLETE_TIMEOUT_LOOPS (100000)
#define RTHW_SDIO_LOCK(_sdio) rt_mutex_take(&_sdio->mutex, RT_WAITING_FOREVER)
@ -47,13 +54,14 @@ struct rthw_sdio
};
/* SYSRAM SDMMC1/2 accesses */
#define SDCARD_ADDR 0x2FFC0000
#if defined(__CC_ARM) || defined(__CLANG_ARM)
rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((at(0x2FFC0000)));
__attribute__((at(SDCARD_ADDR))) static rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
#elif defined ( __GNUC__ )
static rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((section(".SdCardSection")));
#elif defined(__ICCARM__)
#pragma location=0x2FFC0000
rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
#elif defined(__GNUC__)
rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((at(0x2FFC0000)));
#pragma location = SDCARD_ADDR
__no_init static rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
#endif
/**
@ -461,10 +469,20 @@ struct rt_mmcsd_host *sdio_host_create(struct stm32_sdio_des *sdio_des)
rt_memcpy(&sdio->sdio_des, sdio_des, sizeof(struct stm32_sdio_des));
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO_BASE_ADDRESS;
if(sdio_des->hsd.Instance == SDMMC1)
{
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO1_BASE_ADDRESS;
rt_event_init(&sdio->event, "sdio1", RT_IPC_FLAG_FIFO);
rt_mutex_init(&sdio->mutex, "sdio1", RT_IPC_FLAG_FIFO);
}
if(sdio_des->hsd.Instance == SDMMC2)
{
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO2_BASE_ADDRESS;
rt_event_init(&sdio->event, "sdio2", RT_IPC_FLAG_FIFO);
rt_mutex_init(&sdio->mutex, "sdio2", RT_IPC_FLAG_FIFO);
}
rt_event_init(&sdio->event, "sdio", RT_IPC_FLAG_FIFO);
rt_mutex_init(&sdio->mutex, "sdio", RT_IPC_FLAG_FIFO);
/* set host default attributes */
host->ops = &ops;
host->freq_min = 400 * 1000;
@ -503,29 +521,83 @@ void SDMMC1_IRQHandler(void)
{
rt_interrupt_enter();
/* Process All SDIO Interrupt Sources */
rthw_sdio_irq_process(host);
rthw_sdio_irq_process(host1);
rt_interrupt_leave();
}
void SDMMC2_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* Process All SDIO Interrupt Sources */
rthw_sdio_irq_process(host2);
/* leave interrupt */
rt_interrupt_leave();
}
#ifdef BSP_USING_SDIO2
static RTC_HandleTypeDef hrtc;
static void MX_RTC_Init(void)
{
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Instance->CFGR = 0x02 << 1;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
}
static int LBEE5KL1DX_init(void)
{
#define LBEE5KL1DX_WL_REG_ON GET_PIN(H, 4)
/* enable the WLAN REG pin */
rt_pin_mode(LBEE5KL1DX_WL_REG_ON, PIN_MODE_OUTPUT);
rt_pin_write(LBEE5KL1DX_WL_REG_ON, PIN_HIGH);
return 0;
}
#endif
int rt_hw_sdio_init(void)
{
struct stm32_sdio_des sdio_des;
hsd.Instance = SDMMC1;
HAL_SD_MspInit(&hsd);
#ifdef BSP_USING_SDIO1
struct stm32_sdio_des sdio_des1;
sdio_des1.hsd.Instance = SDMMC1;
HAL_SD_MspInit(&sdio_des1.hsd);
host = sdio_host_create(&sdio_des);
if (host == RT_NULL)
host1 = sdio_host_create(&sdio_des1);
if (host1 == RT_NULL)
{
LOG_E("host create fail");
return RT_NULL;
}
#endif
#ifdef BSP_USING_SDIO2
MX_RTC_Init();
LBEE5KL1DX_init();
struct stm32_sdio_des sdio_des2;
sdio_des2.hsd.Instance = SDMMC2;
HAL_SD_MspInit(&sdio_des2.hsd);
host2 = sdio_host_create(&sdio_des2);
if (host2 == RT_NULL)
{
LOG_E("host2 create fail");
return RT_NULL;
}
#endif
return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_sdio_init);
#ifdef BSP_USING_SDIO1
int mnt_init(void)
{
rt_device_t sd = RT_NULL;
@ -552,4 +624,6 @@ int mnt_init(void)
}
INIT_ENV_EXPORT(mnt_init);
#endif /* BSP_USING_SDIO1 */
#endif /* BSP_USING_SDMMC */

View File

@ -19,11 +19,12 @@
#include <drivers/mmcsd_core.h>
#include <drivers/sdio.h>
#define SDIO_BUFF_SIZE 4096
#define SDIO_ALIGN_LEN 32
#ifndef SDIO1_BASE_ADDRESS
#define SDIO1_BASE_ADDRESS (SDMMC1)
#endif
#ifndef SDIO_BASE_ADDRESS
#define SDIO_BASE_ADDRESS (SDMMC1)
#ifndef SDIO2_BASE_ADDRESS
#define SDIO2_BASE_ADDRESS (SDMMC2)
#endif
#ifndef SDIO_CLOCK_FREQ
@ -39,7 +40,7 @@
#endif
#ifndef SDIO_MAX_FREQ
#define SDIO_MAX_FREQ (50 * 1000 * 1000)
#define SDIO_MAX_FREQ (25 * 1000 * 1000)
#endif
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
@ -102,6 +103,7 @@ struct stm32_sdio_des
{
struct stm32_sdio *hw_sdio;
sdio_clk_get clk_get;
SD_HandleTypeDef hsd;
};
/* stm32 sdio dirver class */

View File

@ -232,6 +232,8 @@
<state>STM32MP157Axx</state>
<state>__LOG_TRACE_IO_</state>
<state>__RTTHREAD__</state>
<state>RT_USING_DLIBC</state>
<state>_DLIB_FILE_DESCRIPTOR</state>
<state>USE_HAL_DRIVER</state>
</option>
<option>
@ -358,23 +360,28 @@
<option>
<name>CCIncludePath2</name>
<state />
<state>$PROJ_DIR$\..\..\..\components\dfs\filesystems\devfs</state>
<state>$PROJ_DIR$\..\..\..\components\finsh</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\common</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\cortex-m4</state>
<state>$PROJ_DIR$\board\CubeMX_Config\CM4\Inc</state>
<state>$PROJ_DIR$\board\ports</state>
<state>$PROJ_DIR$\..\..\..\components\drivers\include</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Inc</state>
<state>$PROJ_DIR$\.</state>
<state>$PROJ_DIR$\applications</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Core\Include</state>
<state>$PROJ_DIR$\..\..\..\components\drivers\include</state>
<state>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib</state>
<state>$PROJ_DIR$\board\ports\audio</state>
<state>$PROJ_DIR$\..\..\..\components\libc\compilers\common</state>
<state>$PROJ_DIR$\.</state>
<state>$PROJ_DIR$\board\CubeMX_Config\CM4\Inc</state>
<state>$PROJ_DIR$\..\..\..\components\dfs\include</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers\config</state>
<state>$PROJ_DIR$\board</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers</state>
<state>$PROJ_DIR$\board\ports</state>
<state>$PROJ_DIR$\applications</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Include</state>
<state>$PROJ_DIR$\board\ports\audio</state>
<state>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat</state>
<state>$PROJ_DIR$\..\..\..\include</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Device\ST\STM32MP1xx\Include</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\common</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\cortex-m4</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Inc</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -1309,6 +1316,8 @@
<state>STM32MP157Axx</state>
<state>__LOG_TRACE_IO_</state>
<state>__RTTHREAD__</state>
<state>RT_USING_DLIBC</state>
<state>_DLIB_FILE_DESCRIPTOR</state>
<state>USE_HAL_DRIVER</state>
</option>
<option>
@ -1435,23 +1444,28 @@
<option>
<name>CCIncludePath2</name>
<state />
<state>$PROJ_DIR$\..\..\..\components\dfs\filesystems\devfs</state>
<state>$PROJ_DIR$\..\..\..\components\finsh</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\common</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\cortex-m4</state>
<state>$PROJ_DIR$\board\CubeMX_Config\CM4\Inc</state>
<state>$PROJ_DIR$\board\ports</state>
<state>$PROJ_DIR$\..\..\..\components\drivers\include</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Inc</state>
<state>$PROJ_DIR$\.</state>
<state>$PROJ_DIR$\applications</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Core\Include</state>
<state>$PROJ_DIR$\..\..\..\components\drivers\include</state>
<state>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib</state>
<state>$PROJ_DIR$\board\ports\audio</state>
<state>$PROJ_DIR$\..\..\..\components\libc\compilers\common</state>
<state>$PROJ_DIR$\.</state>
<state>$PROJ_DIR$\board\CubeMX_Config\CM4\Inc</state>
<state>$PROJ_DIR$\..\..\..\components\dfs\include</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers\config</state>
<state>$PROJ_DIR$\board</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers</state>
<state>$PROJ_DIR$\board\ports</state>
<state>$PROJ_DIR$\applications</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Include</state>
<state>$PROJ_DIR$\board\ports\audio</state>
<state>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat</state>
<state>$PROJ_DIR$\..\..\..\include</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Device\ST\STM32MP1xx\Include</state>
<state>$PROJ_DIR$\..\libraries\HAL_Drivers</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\common</state>
<state>$PROJ_DIR$\..\..\..\libcpu\arm\cortex-m4</state>
<state>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Inc</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -2183,6 +2197,21 @@
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\misc\pin.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\sdio\block_dev.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\sdio\mmcsd_core.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\sdio\sd.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\sdio\sdio.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\sdio\mmc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\drivers\serial\serial.c</name>
</file>
@ -2219,6 +2248,9 @@
<file>
<name>$PROJ_DIR$\board\CubeMX_Config\CM4\Src\stm32mp1xx_hal_msp.c</name>
</file>
<file>
<name>$PROJ_DIR$\board\ports\drv_sdio.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\CMSIS\Device\ST\STM32MP1xx\Source\Templates\iar\startup_stm32mp15xx.s</name>
</file>
@ -2232,6 +2264,39 @@
<name>$PROJ_DIR$\..\libraries\HAL_Drivers\drv_common.c</name>
</file>
</group>
<group>
<name>Filesystem</name>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_file.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_fs.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_posix.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\poll.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\src\select.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\devfs\devfs.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat\dfs_elm.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat\ff.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat\ffunicode.c</name>
</file>
</group>
<group>
<name>finsh</name>
<file>
@ -2243,6 +2308,9 @@
<file>
<name>$PROJ_DIR$\..\..\..\components\finsh\msh.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\finsh\msh_file.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\finsh\finsh_compiler.c</name>
</file>
@ -2309,9 +2377,6 @@
<file>
<name>$PROJ_DIR$\..\..\..\src\scheduler.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\src\signal.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\src\thread.c</name>
</file>
@ -2319,6 +2384,54 @@
<name>$PROJ_DIR$\..\..\..\src\timer.c</name>
</file>
</group>
<group>
<name>libc</name>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\common\stdlib.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\common\time.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\common\unistd.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\environ.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\libc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\rmtx.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\stdio.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_close.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_lseek.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_mem.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_open.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_read.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_remove.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscall_write.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\..\components\libc\compilers\dlib\syscalls.c</name>
</file>
</group>
<group>
<name>Libraries</name>
<file>
@ -2393,5 +2506,20 @@
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_hal_uart_ex.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_ll_sdmmc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_hal_sd.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_ll_delayblock.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_hal_rtc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\libraries\STM32MPxx_HAL\STM32MP1xx_HAL_Driver\Src\stm32mp1xx_hal_rtc_ex.c</name>
</file>
</group>
</project>

View File

@ -642,6 +642,14 @@ menu "Using USB"
string "Udisk mount dir"
default "/"
endif
config RT_USBH_HID
bool "Enable HID Drivers"
default n
if RT_USBH_HID
config RT_USBH_HID_MOUSE
bool "Enable HID mouse protocol"
default n
endif
endif
config RT_USING_USB_DEVICE
bool "Using USB device"

View File

@ -375,6 +375,8 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
rt_int32_t i, ret;
rt_uint16_t ignore_nack;
if (num == 0) return 0;
for (i = 0; i < num; i++)
{
msg = &msgs[i];

View File

@ -29,6 +29,7 @@ enum
struct rt_workqueue
{
rt_list_t work_list;
rt_list_t delayed_list;
struct rt_work *work_current; /* current work */
struct rt_semaphore sem;
@ -62,6 +63,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time);
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
#ifdef RT_USING_SYSTEM_WORKQUEUE
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);

View File

@ -58,15 +58,17 @@ static void _workqueue_thread_entry(void *parameter)
while (1)
{
level = rt_hw_interrupt_disable();
if (rt_list_isempty(&(queue->work_list)))
{
/* no software timer exist, suspend self. */
rt_thread_suspend(rt_thread_self());
rt_hw_interrupt_enable(level);
rt_schedule();
continue;
}
/* we have work to do with. */
level = rt_hw_interrupt_disable();
work = rt_list_entry(queue->work_list.next, struct rt_work, list);
rt_list_remove(&(work->list));
queue->work_current = work;
@ -76,175 +78,134 @@ static void _workqueue_thread_entry(void *parameter)
/* do work */
work->work_func(work, work->work_data);
level = rt_hw_interrupt_disable();
/* clean current work */
queue->work_current = RT_NULL;
rt_hw_interrupt_enable(level);
/* ack work completion */
_workqueue_work_completion(queue);
}
}
static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work)
static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
struct rt_work *work, rt_tick_t ticks)
{
rt_base_t level;
rt_err_t err;
level = rt_hw_interrupt_disable();
if (work->flags & RT_WORK_STATE_PENDING)
{
rt_hw_interrupt_enable(level);
return -RT_EBUSY;
}
if (queue->work_current == work)
{
rt_hw_interrupt_enable(level);
return -RT_EBUSY;
}
/* NOTE: the work MUST be initialized firstly */
/* remove list */
rt_list_remove(&(work->list));
rt_list_insert_after(queue->work_list.prev, &(work->list));
work->flags |= RT_WORK_STATE_PENDING;
/* whether the workqueue is doing work */
if (queue->work_current == RT_NULL)
work->flags &= ~RT_WORK_STATE_PENDING;
/* */
if (ticks == 0)
{
if (queue->work_current != work)
{
rt_list_insert_after(queue->work_list.prev, &(work->list));
work->flags |= RT_WORK_STATE_PENDING;
work->workqueue = queue;
err = RT_EOK;
}
else
{
err = -RT_EBUSY;
}
/* whether the workqueue is doing work */
if (queue->work_current == RT_NULL &&
((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
}
return err;
}
else if (ticks < RT_TICK_MAX / 2)
{
/* Timer started */
if (work->flags & RT_WORK_STATE_SUBMITTING)
{
rt_timer_stop(&work->timer);
rt_timer_control(&work->timer, RT_TIMER_CTRL_SET_TIME, &ticks);
}
else
{
rt_timer_init(&(work->timer), "work", _delayed_work_timeout_handler,
work, ticks, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER);
work->flags |= RT_WORK_STATE_SUBMITTING;
}
work->workqueue = queue;
/* insert delay work list */
rt_list_insert_after(queue->delayed_list.prev, &(work->list));
rt_hw_interrupt_enable(level);
rt_timer_start(&(work->timer));
return RT_EOK;
}
rt_hw_interrupt_enable(level);
return -RT_ERROR;
}
static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
{
rt_base_t level;
rt_err_t err;
level = rt_hw_interrupt_disable();
rt_list_remove(&(work->list));
work->flags &= ~RT_WORK_STATE_PENDING;
/* Timer started */
if (work->flags & RT_WORK_STATE_SUBMITTING)
{
rt_timer_stop(&(work->timer));
rt_timer_detach(&(work->timer));
work->flags &= ~RT_WORK_STATE_SUBMITTING;
}
err = queue->work_current != work ? RT_EOK : -RT_EBUSY;
work->workqueue = RT_NULL;
rt_hw_interrupt_enable(level);
return err;
}
static void _delayed_work_timeout_handler(void *parameter)
{
struct rt_work *work;
struct rt_workqueue *queue;
rt_base_t level;
work = (struct rt_work *)parameter;
queue = work->workqueue;
RT_ASSERT(queue != RT_NULL);
level = rt_hw_interrupt_disable();
rt_timer_detach(&(work->timer));
work->flags &= ~RT_WORK_STATE_SUBMITTING;
/* remove delay list */
rt_list_remove(&(work->list));
/* insert work queue */
if (queue->work_current != work)
{
rt_list_insert_after(queue->work_list.prev, &(work->list));
work->flags |= RT_WORK_STATE_PENDING;
}
/* whether the workqueue is doing work */
if (queue->work_current == RT_NULL &&
((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
}
return RT_EOK;
}
static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
if (queue->work_current == work)
{
rt_hw_interrupt_enable(level);
return -RT_EBUSY;
}
rt_list_remove(&(work->list));
work->flags &= ~RT_WORK_STATE_PENDING;
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t _workqueue_cancel_delayed_work(struct rt_work *work)
{
rt_base_t level;
int ret = RT_EOK;
if (!work->workqueue)
{
ret = -EINVAL;
goto __exit;
}
if (work->flags & RT_WORK_STATE_PENDING)
{
/* Remove from the queue if already submitted */
ret = _workqueue_cancel_work(work->workqueue, work);
if (ret)
{
goto __exit;
}
}
else
{
if (work->flags & RT_WORK_STATE_SUBMITTING)
{
level = rt_hw_interrupt_disable();
rt_timer_stop(&(work->timer));
rt_timer_detach(&(work->timer));
work->flags &= ~RT_WORK_STATE_SUBMITTING;
rt_hw_interrupt_enable(level);
}
}
level = rt_hw_interrupt_disable();
/* Detach from workqueue */
work->workqueue = RT_NULL;
work->flags &= ~(RT_WORK_STATE_PENDING);
rt_hw_interrupt_enable(level);
__exit:
return ret;
}
static rt_err_t _workqueue_submit_delayed_work(struct rt_workqueue *queue,
struct rt_work *work, rt_tick_t ticks)
{
rt_base_t level;
rt_err_t ret = RT_EOK;
/* Work cannot be active in multiple queues */
if (work->workqueue && work->workqueue != queue)
{
ret = -RT_EINVAL;
goto __exit;
}
/* Cancel if work has been submitted */
if (work->workqueue == queue)
{
ret = _workqueue_cancel_delayed_work(work);
if (ret < 0)
{
goto __exit;
}
}
level = rt_hw_interrupt_disable();
/* Attach workqueue so the timeout callback can submit it */
work->workqueue = queue;
rt_hw_interrupt_enable(level);
if (!ticks)
{
/* Submit work if no ticks is 0 */
ret = _workqueue_submit_work(work->workqueue, work);
}
else
{
level = rt_hw_interrupt_disable();
/* Add timeout */
work->flags |= RT_WORK_STATE_SUBMITTING;
rt_timer_init(&(work->timer), "work", _delayed_work_timeout_handler, work, ticks,
RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER);
rt_hw_interrupt_enable(level);
rt_timer_start(&(work->timer));
}
__exit:
return ret;
}
static void _delayed_work_timeout_handler(void *parameter)
{
struct rt_work *delayed_work;
rt_base_t level;
delayed_work = (struct rt_work *)parameter;
level = rt_hw_interrupt_disable();
rt_timer_stop(&(delayed_work->timer));
rt_timer_detach(&(delayed_work->timer));
delayed_work->flags &= ~RT_WORK_STATE_SUBMITTING;
delayed_work->type &= ~RT_WORK_TYPE_DELAYED;
rt_hw_interrupt_enable(level);
_workqueue_submit_work(delayed_work->workqueue, delayed_work);
}
struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority)
@ -256,6 +217,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz
{
/* initialize work list */
rt_list_init(&(queue->work_list));
rt_list_init(&(queue->delayed_list));
queue->work_current = RT_NULL;
rt_sem_init(&(queue->sem), "wqueue", 0, RT_IPC_FLAG_FIFO);
@ -277,7 +239,9 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue)
{
RT_ASSERT(queue != RT_NULL);
rt_workqueue_cancel_all_work(queue);
rt_thread_delete(queue->work_thread);
rt_sem_detach(&(queue->sem));
RT_KERNEL_FREE(queue);
return RT_EOK;
@ -288,7 +252,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work)
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(work != RT_NULL);
return _workqueue_submit_work(queue, work);
return _workqueue_submit_work(queue, work, 0);
}
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time)
@ -296,19 +260,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(work != RT_NULL);
if (time > 0)
{
work->type |= RT_WORK_TYPE_DELAYED;
}
if (work->type & RT_WORK_TYPE_DELAYED)
{
return _workqueue_submit_delayed_work(queue, work, time);
}
else
{
return _workqueue_submit_work(queue, work);
}
return _workqueue_submit_work(queue, work, time);
}
rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work)
@ -318,51 +270,38 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *
RT_ASSERT(work != RT_NULL);
level = rt_hw_interrupt_disable();
if (queue->work_current == work)
{
rt_hw_interrupt_enable(level);
return -RT_EBUSY;
}
/* NOTE: the work MUST be initialized firstly */
rt_list_remove(&(work->list));
rt_list_insert_after(queue->work_list.prev, &(work->list));
if (queue->work_current == RT_NULL)
rt_list_insert_after(&queue->work_list, &(work->list));
/* whether the workqueue is doing work */
if (queue->work_current == RT_NULL &&
((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
{
rt_hw_interrupt_enable(level);
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_schedule();
}
else rt_hw_interrupt_enable(level);
else
{
rt_hw_interrupt_enable(level);
}
return RT_EOK;
}
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
{
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(work != RT_NULL);
if (work->type & RT_WORK_TYPE_DELAYED)
{
return _workqueue_cancel_delayed_work(work);
}
else
{
return _workqueue_cancel_work(queue, work);
}
RT_ASSERT(queue != RT_NULL);
return _workqueue_cancel_work(queue, work);
}
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work)
{
rt_base_t level;
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(work != RT_NULL);
level = rt_hw_interrupt_disable();
if (queue->work_current == work) /* it's current work in the queue */
{
/* wait for work completion */
@ -370,24 +309,30 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor
}
else
{
rt_list_remove(&(work->list));
_workqueue_cancel_work(queue, work);
}
work->flags &= ~RT_WORK_STATE_PENDING;
rt_hw_interrupt_enable(level);
return RT_EOK;
}
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue)
{
struct rt_list_node *node, *next;
struct rt_work *work;
RT_ASSERT(queue != RT_NULL);
/* cancel work */
rt_enter_critical();
for (node = queue->work_list.next; node != &(queue->work_list); node = next)
while (rt_list_isempty(&queue->work_list) == RT_FALSE)
{
next = node->next;
rt_list_remove(node);
work = rt_list_first_entry(&queue->work_list, struct rt_work, list);
_workqueue_cancel_work(queue, work);
}
/* cancel delay work */
while (rt_list_isempty(&queue->delayed_list) == RT_FALSE)
{
work = rt_list_first_entry(&queue->delayed_list, struct rt_work, list);
_workqueue_cancel_work(queue, work);
}
rt_exit_critical();
@ -416,14 +361,14 @@ rt_err_t rt_work_cancel(struct rt_work *work)
int rt_work_sys_workqueue_init(void)
{
if (sys_workq != RT_NULL)
return 0;
return RT_EOK;
sys_workq = rt_workqueue_create("sys_work", RT_SYSTEM_WORKQUEUE_STACKSIZE,
RT_SYSTEM_WORKQUEUE_PRIORITY);
RT_ASSERT(sys_workq != RT_NULL);
return RT_EOK;
}
INIT_PREV_EXPORT(rt_work_sys_workqueue_init);
#endif
#endif

View File

@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
* 2021-02-23 Leslie Lee update with current usb api
*/
#include <rtthread.h>
@ -26,7 +27,7 @@ static rt_list_t _protocal_list;
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id)
rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id)
{
struct urequest setup;
struct uinstance* device;
@ -40,14 +41,15 @@ rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id)
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_INTERFACE;
setup.request = USB_REQ_SET_IDLE;
setup.index = 0;
setup.length = 0;
setup.value = (duration << 8 )| report_id;
setup.bRequest = USB_REQ_SET_IDLE;
setup.wIndex = 0;
setup.wLength = 0;
setup.wValue = (duration << 8 )| report_id;
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
timeout) == 0) return RT_EOK;
else return -RT_FALSE;
if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
return RT_EOK;
else
return -RT_FALSE;
}
/**
@ -59,7 +61,7 @@ rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id)
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type,
rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type,
rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size)
{
struct urequest setup;
@ -74,14 +76,24 @@ rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type,
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_INTERFACE;
setup.request = USB_REQ_GET_REPORT;
setup.index = intf->intf_desc->bInterfaceNumber;
setup.length = size;
setup.value = (type << 8 ) + id;
setup.bRequest = USB_REQ_GET_REPORT;
setup.wIndex = intf->intf_desc->bInterfaceNumber;
setup.wLength = size;
setup.wValue = (type << 8 ) + id;
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size,
timeout) == size) return RT_EOK;
else return -RT_FALSE;
if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
{
if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size)
{
if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0)
{
return RT_EOK;
}
}
}
else
return -RT_FALSE;
return -RT_FALSE;
}
/**
@ -93,7 +105,7 @@ rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type,
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size)
rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size)
{
struct urequest setup;
struct uinstance* device;
@ -107,14 +119,15 @@ rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_INTERFACE;
setup.request = USB_REQ_SET_REPORT;
setup.index = intf->intf_desc->bInterfaceNumber;
setup.length = size;
setup.value = 0x02 << 8;
setup.bRequest = USB_REQ_SET_REPORT;
setup.wIndex = intf->intf_desc->bInterfaceNumber;
setup.wLength = size;
setup.wValue = 0x02 << 8;
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size,
timeout) == size) return RT_EOK;
else return -RT_FALSE;
if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
return RT_EOK;
else
return -RT_FALSE;
}
/**
@ -125,7 +138,7 @@ rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol)
rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol)
{
struct urequest setup;
struct uinstance* device;
@ -139,14 +152,15 @@ rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol)
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_INTERFACE;
setup.request = USB_REQ_SET_PROTOCOL;
setup.index = 0;
setup.length = 0;
setup.value = protocol;
setup.bRequest = USB_REQ_SET_PROTOCOL;
setup.wIndex = 0;
setup.wLength = 0;
setup.wValue = protocol;
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
timeout) == 0) return RT_EOK;
else return -RT_FALSE;
if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
return RT_EOK;
else
return -RT_FALSE;
}
/**
@ -159,7 +173,7 @@ rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol)
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf,
rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf,
rt_uint8_t *buffer, rt_size_t size)
{
struct urequest setup;
@ -174,14 +188,24 @@ rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf,
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_STANDARD|
USB_REQ_TYPE_INTERFACE;
setup.request = USB_REQ_GET_DESCRIPTOR;
setup.index = 0;
setup.length = size;
setup.value = USB_DESC_TYPE_REPORT << 8;
setup.bRequest = USB_REQ_GET_DESCRIPTOR;
setup.wIndex = 0;
setup.wLength = size;
setup.wValue = USB_DESC_TYPE_REPORT << 8;
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size,
timeout) == size) return RT_EOK;
else return -RT_FALSE;
if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
{
if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size)
{
if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0)
{
return RT_EOK;
}
}
}
else
return -RT_FALSE;
return -RT_FALSE;
}
/**
@ -220,16 +244,16 @@ static void rt_usbh_hid_callback(void* context)
RT_ASSERT(context != RT_NULL);
pipe = (upipe_t)context;
hid = (struct uhid*)pipe->intf->user_data;
hid = (struct uhid*)((struct uhintf*)pipe->inst)->user_data;
/* invoke protocal callback function */
hid->protocal->callback((void*)hid);
/* parameter check */
RT_ASSERT(pipe->intf->device->hcd != RT_NULL);
RT_ASSERT(((struct uhintf*)pipe->inst)->device->hcd != RT_NULL);
rt_usb_hcd_int_xfer(pipe->intf->device->hcd, pipe, hid->buffer,
pipe->ep.wMaxPacketSize, timeout);
rt_usb_hcd_pipe_xfer(((struct uhintf*)pipe->inst)->device->hcd, pipe,
hid->buffer, pipe->ep.wMaxPacketSize, timeout);
}
/**
@ -268,9 +292,7 @@ static rt_err_t rt_usbh_hid_enable(void* arg)
int i = 0, pro_id;
uprotocal_t protocal;
struct uhid* hid;
struct uintf* intf = (struct uintf*)arg;
int timeout = USB_TIMEOUT_BASIC;
upipe_t pipe;
struct uhintf* intf = (struct uhintf*)arg;
/* parameter check */
if(intf == RT_NULL)
@ -319,19 +341,13 @@ static rt_err_t rt_usbh_hid_enable(void* arg)
if(!(ep_desc->bEndpointAddress & USB_DIR_IN)) continue;
ret = rt_usb_hcd_alloc_pipe(intf->device->hcd, &hid->pipe_in,
intf, ep_desc, rt_usbh_hid_callback);
intf, ep_desc);
if(ret != RT_EOK) return ret;
}
/* initialize hid protocal */
hid->protocal->init((void*)intf);
pipe = hid->pipe_in;
hid->protocal->init((void*)intf);
/* parameter check */
RT_ASSERT(pipe->intf->device->hcd != RT_NULL);
rt_usb_hcd_int_xfer(pipe->intf->device->hcd, hid->pipe_in,
hid->buffer, hid->pipe_in->ep.wMaxPacketSize, timeout);
return RT_EOK;
}
@ -346,7 +362,7 @@ static rt_err_t rt_usbh_hid_enable(void* arg)
static rt_err_t rt_usbh_hid_disable(void* arg)
{
struct uhid* hid;
struct uintf* intf = (struct uintf*)arg;
struct uhintf* intf = (struct uhintf*)arg;
RT_ASSERT(intf != RT_NULL);
@ -364,9 +380,6 @@ static rt_err_t rt_usbh_hid_disable(void* arg)
/* free the hid instance */
rt_free(hid);
}
/* free the instance */
rt_free(intf);
return RT_EOK;
}

View File

@ -31,11 +31,11 @@ typedef struct uhid uhid_t;
#define USB_HID_KEYBOARD 1
#define USB_HID_MOUSE 2
rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id);
rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol);
rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id);
rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol);
rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size);
rt_err_t rt_usbh_hid_protocal_register(uprotocal_t protocal);
#endif
#endif

View File

@ -126,15 +126,36 @@ static rt_err_t rt_usbh_hid_mouse_callback(void* arg)
return RT_EOK;
}
rt_thread_t mouse_thread;
void mouse_task(void* param)
{
struct uhintf* intf = (struct uhintf*)param;
while (1)
{
if (rt_usb_hcd_pipe_xfer(intf->device->hcd, ((struct uhid*)intf->user_data)->pipe_in,
((struct uhid*)intf->user_data)->buffer, ((struct uhid*)intf->user_data)->pipe_in->ep.wMaxPacketSize,
USB_TIMEOUT_BASIC) == 0)
{
break;
}
rt_usbh_hid_mouse_callback(intf->user_data);
}
}
static rt_err_t rt_usbh_hid_mouse_init(void* arg)
{
struct uintf* intf = (struct uintf*)arg;
struct uhintf* intf = (struct uhintf*)arg;
RT_ASSERT(intf != RT_NULL);
rt_usbh_hid_set_protocal(intf, 0);
rt_usbh_hid_set_idle(intf, 10, 0);
rt_usbh_hid_set_idle(intf, 0, 0);
mouse_thread = rt_thread_create("mouse0", mouse_task, intf, 500, 8, 100);
rt_thread_startup(mouse_thread);
RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb mouse\n"));
#ifdef RT_USING_RTGUI

View File

@ -434,20 +434,18 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
{
rt_err_t result = RT_EOK;
__retry:
result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout));
if (result != RT_EOK)
while (rt_device_read(client->device, 0, ch, 1) == 0)
{
return result;
}
if(rt_device_read(client->device, 0, ch, 1) == 1)
{
return RT_EOK;
}
else
{
goto __retry;
result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout));
if (result != RT_EOK)
{
return result;
}
rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
}
return RT_EOK;
}
/**

View File

@ -667,6 +667,9 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s
rt_size_t i, j;
rt_size_t log_len = 0, name_len = rt_strlen(tag);
#ifdef ULOG_OUTPUT_TIME
rt_size_t time_head_len = 0;
#endif
char *log_buf = NULL, dump_string[8];
int fmt_result;
@ -703,6 +706,35 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s
/* package header */
if (i == 0)
{
#ifdef ULOG_OUTPUT_TIME
/* add time info */
#ifdef ULOG_TIME_USING_TIMESTAMP
static time_t now;
static struct tm *tm, tm_tmp;
now = time(NULL);
tm = gmtime_r(&now, &tm_tmp);
#ifdef RT_USING_SOFT_RTC
rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, "%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, rt_tick_get() % 1000);
#else
rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, "%02d-%02d %02d:%02d:%02d ", tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
#endif /* RT_USING_SOFT_RTC */
#else
static rt_size_t tick_len = 0;
log_buf[log_len] = '[';
tick_len = ulog_ultoa(log_buf + log_len + 1, rt_tick_get());
log_buf[log_len + 1 + tick_len] = ']';
log_buf[log_len + 2 + tick_len] = ' ';
log_buf[log_len + 3 + tick_len] = '\0';
#endif /* ULOG_TIME_USING_TIMESTAMP */
time_head_len = rt_strlen(log_buf + log_len);
log_len += time_head_len;
#endif /* ULOG_OUTPUT_TIME */
log_len += ulog_strcpy(log_len, log_buf + log_len, "D/HEX ");
log_len += ulog_strcpy(log_len, log_buf + log_len, tag);
log_len += ulog_strcpy(log_len, log_buf + log_len, ": ");
@ -710,6 +742,9 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s
else
{
log_len = 6 + name_len + 2;
#ifdef ULOG_OUTPUT_TIME
log_len += time_head_len;
#endif
rt_memset(log_buf, ' ', log_len);
}
fmt_result = rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE, "%04X-%04X: ", i, i + width - 1);

View File

@ -473,17 +473,13 @@ exit
#elif defined(__CLANG_ARM)
int __rt_ffs(int value)
{
__asm volatile(
"CMP r0, #0x00 \n"
"BEQ 1f \n"
if (value == 0) return value;
__asm volatile(
"RBIT r0, r0 \n"
"CLZ r0, r0 \n"
"ADDS r0, r0, #0x01 \n"
"1: \n"
"BX lr \n"
: "=r"(value)
: "r"(value)
);