硬中断代码注释

    百万汉字注解 + 百篇博客分析 -> 挖透鸿蒙内核源码
上级 a77332bb
......@@ -254,30 +254,30 @@ OsKernelTaskLoad: @内核任务的加载
ADD SP, SP, #4 @sp=SP+4
LDMFD SP!, {LR, PC}^ @返回地址赋给pc指针
OsIrqHandler:
OsIrqHandler: @中断处理
SUB LR, LR, #4
/* push r0-r3 to irq stack */
STMFD SP, {R0-R3}
SUB R0, SP, #(4 * 4)
MRS R1, SPSR
MRS R1, SPSR @获取程序状态控制寄存器
MOV R2, LR
/* disable irq, switch to svc mode */
CPSID i, #0x13
CPSID i, #0x13 @禁止中断,切换到SVC模式
/* push spsr and pc in svc stack */
STMFD SP!, {R1, R2}
STMFD SP, {LR}
AND R3, R1, #CPSR_MASK_MODE
CMP R3, #CPSR_USER_MODE
BNE OsIrqFromKernel
AND R3, R1, #CPSR_MASK_MODE
CMP R3, #CPSR_USER_MODE @中断是否发生在用户模式
BNE OsIrqFromKernel @中断不发生在用户模式下则跳转到OsIrqFromKernel
/* push user sp, lr in svc stack */
STMFD SP, {R13, R14}^
OsIrqFromKernel:
OsIrqFromKernel: @从内核发起中断
/* from svc not need save sp and lr */
SUB SP, SP, #(2 * 4)
......
......@@ -161,7 +161,7 @@ VOID OsInterrupt(UINT32 intNum)//中断实际处理函数
*intCnt = *intCnt + 1;
#ifdef LOSCFG_CPUP_INCLUDE_IRQ //开启查询系统CPU的占用率的中断
OsCpupIrqStart();
OsCpupIrqStart();//开始统计本次中断处理还是时间
#endif
#ifdef LOSCFG_KERNEL_TICKLESS
......@@ -191,10 +191,10 @@ VOID OsInterrupt(UINT32 intNum)//中断实际处理函数
*intCnt = *intCnt - 1; //@note_why 这里没看明白为什么要 -1
#ifdef LOSCFG_CPUP_INCLUDE_IRQ //开启查询系统CPU的占用率的中断
OsCpupIrqEnd(intNum);
OsCpupIrqEnd(intNum);//结束统计本次中断处理还是时间
#endif
}
//copy 硬中断参数
//申请内核空间拷贝硬中断参数
STATIC HWI_ARG_T OsHwiCpIrqParam(const HwiIrqParam *irqParam)
{
HwiIrqParam *paramByAlloc = NULL;
......@@ -236,7 +236,7 @@ STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode,
if (g_hwiForm[hwiNum].pfnHook == NULL) {
g_hwiForm[hwiNum].pfnHook = hwiHandler;//记录上回调函数
retParam = OsHwiCpIrqParam(irqParam);//参数copy一份出来记录
retParam = OsHwiCpIrqParam(irqParam);//获取中断处理函数的参数
if (retParam == LOS_NOK) {
HWI_UNLOCK(intSave);
return OS_ERRNO_HWI_NO_MEMORY;
......@@ -307,7 +307,7 @@ STATIC UINT32 OsHwiDelShared(HWI_HANDLE_T hwiNum, const HwiIrqParam *irqParam)
HWI_UNLOCK(intSave);
return LOS_OK;
}
//创建一个共享硬件中断
//创建一个共享硬件中断,共享中断就是一个中断能触发多个响应函数
STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode,
HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam)
{
......@@ -321,39 +321,39 @@ STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode,
return OS_ERRNO_HWI_SHARED_ERROR;
}
HWI_LOCK(intSave);
HWI_LOCK(intSave);//中断自旋锁
hwiForm = &g_hwiForm[hwiNum];
hwiForm = &g_hwiForm[hwiNum];//获取中断处理项
if ((hwiForm->pstNext != NULL) && ((modeResult == 0) || (!(hwiForm->uwParam & IRQF_SHARED)))) {
HWI_UNLOCK(intSave);
return OS_ERRNO_HWI_SHARED_ERROR;
}
while (hwiForm->pstNext != NULL) {
hwiForm = hwiForm->pstNext;
hwiParam = (HwiIrqParam *)(hwiForm->uwParam);
if (hwiParam->pDevId == irqParam->pDevId) {
while (hwiForm->pstNext != NULL) {//pstNext指向 共享中断的各处理函数节点,此处一直撸到最后一个
hwiForm = hwiForm->pstNext;//找下一个中断
hwiParam = (HwiIrqParam *)(hwiForm->uwParam);//获取中断参数,用于检测该设备ID是否已经有中断处理函数
if (hwiParam->pDevId == irqParam->pDevId) {//设备ID一致时,说明设备对应的中断处理函数已经存在了.
HWI_UNLOCK(intSave);
return OS_ERRNO_HWI_ALREADY_CREATED;
}
}
hwiFormNode = (HwiHandleForm *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiHandleForm));
hwiFormNode = (HwiHandleForm *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiHandleForm));//创建一个中断处理节点
if (hwiFormNode == NULL) {
HWI_UNLOCK(intSave);
return OS_ERRNO_HWI_NO_MEMORY;
}
hwiFormNode->uwParam = OsHwiCpIrqParam(irqParam);
hwiFormNode->uwParam = OsHwiCpIrqParam(irqParam);//获取中断处理函数的参数
if (hwiFormNode->uwParam == LOS_NOK) {
HWI_UNLOCK(intSave);
(VOID)LOS_MemFree(m_aucSysMem0, hwiFormNode);
return OS_ERRNO_HWI_NO_MEMORY;
}
hwiFormNode->pfnHook = hwiHandler;
hwiFormNode->pstNext = (struct tagHwiHandleForm *)NULL;
hwiForm->pstNext = hwiFormNode;
hwiFormNode->pfnHook = hwiHandler;//绑定中断处理函数
hwiFormNode->pstNext = (struct tagHwiHandleForm *)NULL;//指定下一个中断为NULL,用于后续遍历找到最后一个中断项(见于以上 while (hwiForm->pstNext != NULL)处)
hwiForm->pstNext = hwiFormNode;//共享中断
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
g_hwiFormName[hwiNum] = (CHAR *)irqParam->pName;
......@@ -373,7 +373,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)//硬件中断初始化
{
UINT32 hwiNum;
for (hwiNum = 0; hwiNum < OS_HWI_MAX_NUM; hwiNum++) {
for (hwiNum = 0; hwiNum < OS_HWI_MAX_NUM; hwiNum++) {//初始化中断向量表,默认128个中断
g_hwiForm[hwiNum].pfnHook = NULL;
g_hwiForm[hwiNum].uwParam = 0;
g_hwiForm[hwiNum].pstNext = NULL;
......
......@@ -105,7 +105,7 @@ extern size_t g_intCount[];
* Value: 0x02000901
*
* Solution: Pass in a valid non-null hardware interrupt handling function.
*/
*/ //创建中断时,传入的中断处理程序指针为空
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
/**
......@@ -115,7 +115,7 @@ extern size_t g_intCount[];
* Value: 0x02000902
*
* Solution: Increase the configured maximum number of supported hardware interrupts.
*/
*/ //无可用中断资源
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
/**
......@@ -125,7 +125,7 @@ extern size_t g_intCount[];
* Value: 0x02000903
*
* Solution: Expand the configured memory.
*/
*/ //创建中断时,出现内存不足的情况
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
/**
......@@ -135,7 +135,7 @@ extern size_t g_intCount[];
* Value: 0x02000904
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
*/ //创建中断时,发现要注册的中断号已经创建
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
/**
......@@ -145,7 +145,7 @@ extern size_t g_intCount[];
* Value: 0x02000905
*
* Solution: Ensure that the interrupt priority is valid.
*/
*/ //创建中断时,传入的中断优先级无效
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
/**
......@@ -156,7 +156,7 @@ extern size_t g_intCount[];
*
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of
* which the value can be 0 or 1.
*/
*/ //中断模式无效
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
/**
......@@ -166,7 +166,7 @@ extern size_t g_intCount[];
* Value: 0x02000907
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
*/ //创建硬中断时,发现要注册的中断号,已经创建为快速中断
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
/**
......@@ -176,7 +176,7 @@ extern size_t g_intCount[];
* Value: 0x02000908
*
* * Solution: Do not call the API during an interrupt.
*/
*/ //接口在中断中调用
#define OS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08)
/**
......@@ -187,7 +187,7 @@ extern size_t g_intCount[];
*
* * Solution: Check the input params hwiMode and irqParam of LOS_HwiCreate or
* LOS_HwiDelete whether adapt the current hwi.
*/
*/ //中断共享出现错误
#define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09)
/**
......@@ -197,7 +197,7 @@ extern size_t g_intCount[];
* Value: 0x0200090a
*
* * Solution: Check the interrupt Arg, Arg should not be NULL and pDevId should not be NULL.
*/
*/ //注册中断入参有误
#define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a)
/**
......@@ -207,7 +207,7 @@ extern size_t g_intCount[];
* Value: 0x0200090b
*
* * Solution: Check the hwi number or devid, make sure the hwi number or devid need to delete.
*/
*/ //中断共享情况下,删除中断时,中断号对应的链表中,无法匹配到相应的设备ID
#define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b)
/**
......@@ -252,7 +252,7 @@ typedef VOID (*HWI_PROC_FUNC)(VOID);
typedef struct tagHwiHandleForm {
HWI_PROC_FUNC pfnHook; //中断处理函数
HWI_ARG_T uwParam; //中断处理函数参数
struct tagHwiHandleForm *pstNext; //节点,指向下一个中断
struct tagHwiHandleForm *pstNext; //节点,指向下一个中断,用于共享中断的情况
} HwiHandleForm;
typedef struct tagIrqParam { //中断参数
......
......@@ -878,7 +878,7 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
#endif
#ifdef LOSCFG_KERNEL_CPUP //CPU性能统计开关,默认是打开的
OsCpupSet(processCB->processID);
OsCpupSet(processCB->processID);//初始化进程性能统计
#endif
return LOS_OK;
......
......@@ -61,7 +61,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
{
UINT32 intSave;
TICK_LOCK(intSave);
TICK_LOCK(intSave);//tick自旋锁
g_tickCount[ArchCurrCpuid()]++;// 累加当前CPU核tick数
TICK_UNLOCK(intSave);
......
......@@ -43,7 +43,7 @@
extern "C" {
#endif
#endif /* __cplusplus */
// Futex 是Fast Userspace muTexes的缩写 就是快速用户空间互斥体 ,注解简称它快锁
// Futex 是Fast Userspace muTexes的缩写 就是快速用户空间互斥体 ,注解简称它快锁
#define OS_FUTEX_FROM_FUTEXLIST(ptr) LOS_DL_LIST_ENTRY(ptr, FutexNode, futexList) //从 futexList 位置拿节点FutexNode
#define OS_FUTEX_FROM_QUEUELIST(ptr) LOS_DL_LIST_ENTRY(ptr, FutexNode, queueList) //从 queueList 位置拿节点FutexNode//
#define OS_FUTEX_KEY_BASE USER_ASPACE_BASE
......
此差异已折叠。
......@@ -37,7 +37,7 @@ STATIC_ASSERT(OS_USER_HWI_MAX <= 1020, "hwi max is too large!");
#ifdef LOSCFG_PLATFORM_BSP_GIC_V2
STATIC UINT32 g_curIrqNum = 0;
STATIC UINT32 g_curIrqNum = 0; //记录当前中断号
#if (LOSCFG_KERNEL_SMP == YES)
/*
......@@ -53,12 +53,12 @@ STATIC VOID GicWriteSgi(UINT32 vector, UINT32 cpuMask, UINT32 filter)
GIC_REG_32(GICD_SGIR) = val;
}
//向指定核发送核间中断
VOID HalIrqSendIpi(UINT32 target, UINT32 ipi)
{
GicWriteSgi(ipi, target, 0);
}
//设置中断的亲和性,即设置中断在固定核响应(该函数仅在SMP模式下支持)
VOID HalIrqSetAffinity(UINT32 vector, UINT32 cpuMask)
{
UINT32 offset = vector / 4;
......@@ -67,7 +67,7 @@ VOID HalIrqSetAffinity(UINT32 vector, UINT32 cpuMask)
GIC_REG_8(GICD_ITARGETSR(offset) + index) = cpuMask;
}
#endif
//获取当前中断号
UINT32 HalCurIrqGet(VOID)
{
return g_curIrqNum;
......@@ -90,7 +90,7 @@ VOID HalIrqUnmask(UINT32 vector)
GIC_REG_32(GICD_ISENABLER(vector >> 5)) = 1U << (vector % 32);
}
//挂起中断
VOID HalIrqPending(UINT32 vector)
{
if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) {
......@@ -155,7 +155,7 @@ VOID HalIrqInit(VOID)
VOID HalIrqHandler(VOID)
{
UINT32 iar = GIC_REG_32(GICC_IAR);
UINT32 vector = iar & 0x3FFU;
UINT32 vector = iar & 0x3FFU;//计算中断向量号
/*
* invalid irq number, mainly the spurious interrupts 0x3ff,
......@@ -167,7 +167,7 @@ VOID HalIrqHandler(VOID)
}
g_curIrqNum = vector;
OsInterrupt(vector);
OsInterrupt(vector);//调用上层中断处理函数
/* use orignal iar to do the EOI */
GIC_REG_32(GICC_EOIR) = iar;
......
......@@ -78,7 +78,7 @@ GICv3控制器由以下部分组成:
#ifdef LOSCFG_PLATFORM_BSP_GIC_V3
STATIC UINT32 g_curIrqNum = 0;
STATIC UINT32 g_curIrqNum = 0; //记录当前中断号
STATIC INLINE UINT64 MpidrToAffinity(UINT64 mpidr)
{
......@@ -363,10 +363,10 @@ UINT32 HalIrqSetPrio(UINT32 vector, UINT8 priority)
VOID HalIrqInitPercpu(VOID)
{
INT32 idx;
UINT32 cpu = ArchCurrCpuid();
UINT32 cpu = ArchCurrCpuid();//获取当前CPU
/* GICR init */
GicrSetWaker(cpu);
GicrSetWaker(cpu);//设置CPU为唤醒状态
GicrSetGroup(cpu);
GicWaitForRwp(GICR_CTLR(cpu));
......@@ -387,8 +387,8 @@ VOID HalIrqInitPercpu(VOID)
#ifdef LOSCFG_KERNEL_SMP
/* unmask ipi interrupts */
HalIrqUnmask(LOS_MP_IPI_WAKEUP);
HalIrqUnmask(LOS_MP_IPI_HALT);
HalIrqUnmask(LOS_MP_IPI_WAKEUP);//恢复CPU唤醒信号
HalIrqUnmask(LOS_MP_IPI_HALT);//恢复CPU停止信号
#endif
}
//硬中断初始化
......@@ -404,16 +404,16 @@ VOID HalIrqInit(VOID)
/* set externel interrupts to be level triggered, active low. */
for (i = 32; i < OS_HWI_MAX_NUM; i += 16) {//将外部中断设置为电平触发,低电平有效
GIC_REG_32(GICD_ICFGR(i / 16)) = 0;
GIC_REG_32(GICD_ICFGR(i / 16)) = 0;//设置16个私有外设中断
}
//SPI是串行外设接口(Serial Peripheral Interface)的缩写
/* config distributer, mask and clear all spis, set group x */
for (i = 32; i < OS_HWI_MAX_NUM; i += 32) {
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff;
GIC_REG_32(GICD_ICPENDR(i / 32)) = 0xffffffff;
GIC_REG_32(GICD_IGRPMODR(i / 32)) = 0;
for (i = 32; i < OS_HWI_MAX_NUM; i += 32) {//配置分配器,屏蔽并清除所有SPI,设置组
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff;//屏蔽中断使能寄存器
GIC_REG_32(GICD_ICPENDR(i / 32)) = 0xffffffff;////屏蔽中断挂起寄存器
GIC_REG_32(GICD_IGRPMODR(i / 32)) = 0;//清除中断组模式寄存器
GicdSetGroup(i);
GicdSetGroup(i);//设置中断组
}
/* set spi priority as default */
......@@ -424,7 +424,7 @@ VOID HalIrqInit(VOID)
GicWaitForRwp(GICD_CTLR);
/* disable all interrupts. */
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) {
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) {//让所有中断失效
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff;
}
......
......@@ -128,7 +128,7 @@ enum {
/*
* The preemption level is up to 128, and the maximum value corresponding to the interrupt priority is 254 [7:1].
* If the GIC_MAX_INTERRUPT_PREEMPTION_LEVEL is 0, the minimum priority is 0xff.
*/
*///中断优先级 最高中断优先级为 0 ,最低优先级为 255
#define MIN_INTERRUPT_PRIORITY ((UINT8)((GIC_MAX_INTERRUPT_PREEMPTION_LEVEL - 1) << PRIORITY_SHIFT))
#endif
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_event.h"
#include "hisoc/uart.h"
EVENT_CB_S g_uartEvent;
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
#ifdef LOSCFG_SHELL
#define UART_BUF 128
static UINT8 g_uart_buf[UART_BUF];
extern void shellCmdLineParse(CHAR c, pf_OUTPUT pf_put);
#endif
#endif
UINT8 uart_getc(void)
{
UINT8 ch = 0;
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x08)) { /*lint !e40*/
LOS_Msleep(100);
}
/* receive one char */
READ_UINT8(ch, UART_REG_BASE + UART_DR);
return ch;
}
#if defined(LOSCFG_COREDUMP) || defined(LOSCFG_LLTSER)
UINT8 uart_getc_interrupt(void)
{
UINT8 ch = 0;
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x08)) { /*lint !e40*/
}
/* receive one char */
READ_UINT8(ch, UART_REG_BASE + UART_DR);
return ch;
}
#endif
/* send */
char uart_putc (char c)
{
/* Wait until THRE is empyt */
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x02)); /*lint !e40*/
/* send one char */
WRITE_UINT8(c, UART_REG_BASE + UART_DR);
return c;
}
unsigned int g_uart_fputc_en __attribute__ ((section(".data"))) = 1;
char uart_fputc(char c, void *f)
{
if (g_uart_fputc_en == 1) {
if (c == '\n') {
uart_putc('\r'); /*lint !e534*/
}
return (uart_putc(c));
} else {
return 0;
}
}
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
#ifdef LOSCFG_SHELL
static void uart_notice_adapt(void)
{
LOS_EventWrite(&g_uartEvent, 0x112);
}
void uart_get_raw(void)
{
UINT8 ch;
static int cnt_ii = 0;
if (cnt_ii == 0) {
(VOID)memset_s(g_uart_buf, UART_BUF, 0, UART_BUF);
}
ch = uart_getc();
g_uart_buf[cnt_ii] = ch;
cnt_ii++;
switch (cnt_ii) {
case 1: // only one char
if (ch != 27) { // un special
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 2:
if (ch != 91) {
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 3:
switch (ch) {
default:
case 'A':
case 'B':
case 'C':
case 'D':
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 51:
case 49:
case 52:
break;
}
break;
case 4:
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
default:
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
}
}
extern void dprintf(const char *fmt, ...);
static void uart_irqhandle(void)
{
UINT8 ch;
shellCmdLineParse(0, dprintf);
}
int uart_hwiCreate(void)
{
UINT32 uwRet = 0;
if (uwRet != LOS_HwiCreate(NUM_HAL_INTERRUPT_UART, 0xa0, 0, uart_irqhandle, 0)) {
return uwRet;
}
uart_interrupt_unmask();
return 0;
}
#endif
#endif
void uart_init()
{
unsigned int temp;
unsigned int divider;
unsigned char dividerH, dividerL;
/* disable UART1 FIFO */
WRITE_UINT32(0, UART_REG_BASE + UART_FCR); /*lint !e40*/
/* reset and enable UART1 FIFO */
WRITE_UINT32(0x7, UART_REG_BASE + UART_FCR); /*lint !e40*/
/* disable UART1 interrupt */
WRITE_UINT32(0, UART_REG_BASE + UART_IER); /*lint !e40*/
/* enable DLL and DLH */
WRITE_UINT32(0x80, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* Caculate devide */
temp = 16 * CONSOLE_UART_BAUDRATE;
divider = CONFIG_UART_CLK_INPUT / temp;
dividerH = ((divider) & 0xff00) >> 8;
dividerL = ((divider) & 0x00ff);
/* configure DLL and DLH */
WRITE_UINT32(dividerL, UART_REG_BASE + UART_DLL); /*lint !e40*/
WRITE_UINT32(dividerH, UART_REG_BASE + UART_DLH); /*lint !e40*/
/* disable DLL and DLH */
WRITE_UINT32(0x0, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* 8bit data, 1bit stop,even parity */
WRITE_UINT32(0x1b, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* enable UART1 */
WRITE_UINT32(0x1, UART_REG_BASE + UART_IER); /*lint !e40*/
(VOID)LOS_EventInit(&g_uartEvent);
}
void uart_interrupt_unmask(void)
{
HalIrqUnmask(NUM_HAL_INTERRUPT_UART);
}
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_event.h"
#include "hisoc/uart.h"
EVENT_CB_S g_uartEvent;
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
#ifdef LOSCFG_SHELL
#define UART_BUF 128
static UINT8 g_uart_buf[UART_BUF];
extern void shellCmdLineParse(CHAR c, pf_OUTPUT pf_put);
#endif
#endif
UINT8 uart_getc(void)
{
UINT8 ch = 0;
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x08)) { /*lint !e40*/
LOS_Msleep(100);
}
/* receive one char */
READ_UINT8(ch, UART_REG_BASE + UART_DR);
return ch;
}
#if defined(LOSCFG_COREDUMP) || defined(LOSCFG_LLTSER)
UINT8 uart_getc_interrupt(void)
{
UINT8 ch = 0;
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x08)) { /*lint !e40*/
}
/* receive one char */
READ_UINT8(ch, UART_REG_BASE + UART_DR);
return ch;
}
#endif
/* send */
char uart_putc (char c)
{
/* Wait until THRE is empyt */
while (!(GET_UINT32(UART_REG_BASE + UART_USR) & 0x02)); /*lint !e40*/
/* send one char */
WRITE_UINT8(c, UART_REG_BASE + UART_DR);
return c;
}
unsigned int g_uart_fputc_en __attribute__ ((section(".data"))) = 1;
char uart_fputc(char c, void *f)
{
if (g_uart_fputc_en == 1) {
if (c == '\n') {
uart_putc('\r'); /*lint !e534*/
}
return (uart_putc(c));
} else {
return 0;
}
}
#ifdef LOSCFG_PLATFORM_UART_WITHOUT_VFS
#ifdef LOSCFG_SHELL
static void uart_notice_adapt(void)
{
LOS_EventWrite(&g_uartEvent, 0x112);
}
void uart_get_raw(void)
{
UINT8 ch;
static int cnt_ii = 0;
if (cnt_ii == 0) {
(VOID)memset_s(g_uart_buf, UART_BUF, 0, UART_BUF);
}
ch = uart_getc();
g_uart_buf[cnt_ii] = ch;
cnt_ii++;
switch (cnt_ii) {
case 1: // only one char
if (ch != 27) { // un special
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 2:
if (ch != 91) {
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 3:
switch (ch) {
default:
case 'A':
case 'B':
case 'C':
case 'D':
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
case 51:
case 49:
case 52:
break;
}
break;
case 4:
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
default:
{
uart_notice_adapt();
cnt_ii = 0;
}
break;
}
}
extern void dprintf(const char *fmt, ...);
//串口硬中断处理函数
static void uart_irqhandle(void)
{
UINT8 ch;
shellCmdLineParse(0, dprintf);//shell解析输入的内容
}
//创建串口硬中断
int uart_hwiCreate(void)
{
UINT32 uwRet = 0;
if (uwRet != LOS_HwiCreate(NUM_HAL_INTERRUPT_UART, 0xa0, 0, uart_irqhandle, 0)) {
return uwRet;
}
uart_interrupt_unmask();//取消中断屏蔽
return 0;
}
#endif
#endif
void uart_init()
{
unsigned int temp;
unsigned int divider;
unsigned char dividerH, dividerL;
/* disable UART1 FIFO */
WRITE_UINT32(0, UART_REG_BASE + UART_FCR); /*lint !e40*/
/* reset and enable UART1 FIFO */
WRITE_UINT32(0x7, UART_REG_BASE + UART_FCR); /*lint !e40*/
/* disable UART1 interrupt */
WRITE_UINT32(0, UART_REG_BASE + UART_IER); /*lint !e40*/
/* enable DLL and DLH */
WRITE_UINT32(0x80, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* Caculate devide */
temp = 16 * CONSOLE_UART_BAUDRATE;
divider = CONFIG_UART_CLK_INPUT / temp;
dividerH = ((divider) & 0xff00) >> 8;
dividerL = ((divider) & 0x00ff);
/* configure DLL and DLH */
WRITE_UINT32(dividerL, UART_REG_BASE + UART_DLL); /*lint !e40*/
WRITE_UINT32(dividerH, UART_REG_BASE + UART_DLH); /*lint !e40*/
/* disable DLL and DLH */
WRITE_UINT32(0x0, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* 8bit data, 1bit stop,even parity */
WRITE_UINT32(0x1b, UART_REG_BASE + UART_LCR); /*lint !e40*/
/* enable UART1 */
WRITE_UINT32(0x1, UART_REG_BASE + UART_IER); /*lint !e40*/
(VOID)LOS_EventInit(&g_uartEvent);//初始化串口事件
}
//取消串口中断屏蔽
void uart_interrupt_unmask(void)
{
HalIrqUnmask(NUM_HAL_INTERRUPT_UART);//参考见于 harmony\vendor\hisi\hi35xx\hi3516dv300\config\board\include\hisoc\uart.h
}
git add -A
git commit -m '鸿蒙内核源码分析(原子操作篇) | 是哪两条汇编指令在为原子操作保驾护航 ?
百万汉字注解 + 百篇博客分析 -> 透鸿蒙内核源码
git commit -m '硬中断代码注释
百万汉字注解 + 百篇博客分析 -> 透鸿蒙内核源码
'
git push origin master
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册