port.c port.c 中主要实现了几个函数: pxPortInitialiseStack() xPortStartScheduler() vPortEndScheduler() vPortYield() vPortTickInterrupt() 还定义了个全局变量:uxCriticalNesting uxCriticalNesting 定义全局变量uxCriticalNesting 的代码如下。 /*
port.c
port.c 中主要实现了几个函数:
pxPortInitialiseStack()
xPortStartScheduler()
vPortEndScheduler()
vPortYield()
vPortTickInterrupt()
还定义了个全局变量:uxCriticalNesting
uxCriticalNesting
定义全局变量uxCriticalNesting 的代码如下。
/* Calls to portENTER_CRITICAL() can be nested. When they are nested the critical div should not be left (i.e. interrupts should not be re-enabled) until the nesting depth reaches 0. This variable simply tracks the nesting depth. Each task maintains it's own critical nesting depth variable so uxCriticalNesting is saved and restored from the task stack during a context switch. */ volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;
uxCriticalNesting 的初始值并不重要,因为每个任务的堆栈中存了uxCriticalNesting 各自的初始值0。
pxPortInitialiseStack
第一个介绍的是pxPortInitialiseStack()。这个函数的作用与uC/OS-II 中 OS_STK*OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt) 函数的作用是相同的,实现代码也大同小异。
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { /* Place a few bytes of known values on the bottom of the stack. This can be uncommented to provide useful stack markers when debugging. *pxTopOfStack = ( portSTACK_TYPE ) 0x11; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x22; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x33; pxTopOfStack--; */ /* Setup the initial stack of the task. The stack is set exactly as expected by the portRESTORE_CONTEXT() macro. In this case the stack as expected by the HCS12 RTI instruction. */ /* The address of the task function is placed in the stack byte at a time. */ *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 ); pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 ); pxTopOfStack--; /* Next are all the registers that form part of the task context. */ /* Y register */ *pxTopOfStack = ( portSTACK_TYPE ) 0xff; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xee; pxTopOfStack--; /* X register */ *pxTopOfStack = ( portSTACK_TYPE ) 0xdd; pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0xcc; pxTopOfStack--; /* A register contains parameter high byte. */ *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 ); pxTopOfStack--; /* B register contains parameter low byte. */ *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 ); pxTopOfStack--; /* CCR: Note that when the task starts interrupts will be enabled since "I" bit of CCR is cleared */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; pxTopOfStack--; #ifdef BANKED_MODEL /* The page of the task. */ *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode ); pxTopOfStack--; #endif /* Finally the critical nesting depth is initialised with 0 (not within a critical div). */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; return pxTopOfStack; }上面的代码并不复杂,如果有不明白的地方,可以参考我写的关于 uC/OS-II 移植的文章中相应代码的解释。
xPortStartScheduler
xPortStartScheduler()函数对应于uC/OS-II 中的OSStartHighRdy() 函数。FreeRTOS的移植代码中并没有直接在xPortStartScheduler() 函数中实现具体功能,而是将真正的工作放到了xBankedStartScheduler()函数中,xPortStartScheduler()函数只是简单的调用xBankedStartScheduler()函数。之所以这样处理是因为相应的代码需放到64K以内的地址空间中。具体可以参看下面代码中的注释部分。
#pragma CODE_SEG __NEAR_SEG NON_BANKED /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not start the scheduler directly because the header file containing the xPortStartScheduler() prototype is part of the common kernel code, and therefore cannot use the CODE_SEG pragma. */ static portBASE_TYPE xBankedStartScheduler( void ); #pragma CODE_SEG DEFAULT portBASE_TYPE xPortStartScheduler( void ) { /* xPortStartScheduler() does not start the scheduler directly because the header file containing the xPortStartScheduler() prototype is part of the common kernel code, and therefore cannot use the CODE_SEG pragma. Instead it simply calls the locally defined xBankedStartScheduler() - which does use the CODE_SEG pragma. */ return xBankedStartScheduler(); } /*-----------------------------------------------------------*/ #pragma CODE_SEG __NEAR_SEG NON_BANKED static portBASE_TYPE xBankedStartScheduler( void ) { /* Configure the timer that will generate the RTOS tick. Interrupts are disabled when this function is called. */ prvSetupTimerInterrupt(); /* Restore the context of the first task. */ portRESTORE_CONTEXT(); /* Simulate the end of an interrupt to start the scheduler off. */ __asm( "rti" ); /* Should not get here! */ return pdFALSE; }
上面代码中调用了prvSetupTimerInterrupt() 函数,这在 uC/OS-II中是没有对应代码的。prvSetupTimerInterrupt()函数的功能是设置定时中断的频率。在这里放这个函数从程序逻辑上来看并不是太好。我本人还是倾向于uC/OS-II 作者的做法,应该将prvSetupTimerInterrupt() 函数放到第一个运行的任务的代码中,虽然这里的做法也没错误。
vPortEndScheduler
这个函数在uC/OS-II 没有对应的函数,因为uC/OS-II 不允许退出。这个移植代码中也没有实现什么具体的功能,就是个空函数。
void vPortEndScheduler( void ) { /* It is unlikely that the HCS12 port will get stopped. */ }
vPortYield
vPortYield()函数等价于uC/OS-II 中的OSCtxSw()函数。具体代码如下:
/* * Manual context switch forced by calling portYIELD(). This is the SWI * handler. */ void interrupt vPortYield( void ) { portSAVE_CONTEXT(); vTaskSwitchContext(); portRESTORE_CONTEXT(); }
FreeRTOS中少了与 uC/OS-II 中 OSIntCtxSw()函数对应的函数,这时因为FreeRTOS 中相应的功能用一个宏定义来实现了:portRESTORE_CONTEXT() ,因此就不需要这个函数了。
vPortTickInterrupt()
最后一个函数是vPortTickInterrupt() 这个函数是定时中断处理函数,等价于uC/OS-II 移植代码中的:interrupt VectorNumber_Vrti void OSTickISR (void)
由于 FreeRTOS既支持抢占式多任务,也支持协作式多任务,所以vPortTickInterrupt()函数相对uC/OS-II 移植代码中的OSTickISR()来说要复杂些。
/* * RTOS tick interrupt service routine. If the cooperative scheduler is * being used then this simply increments the tick count. If the * preemptive scheduler is being used a context switch can occur. */ void interrupt vPortTickInterrupt( void ) { #if configUSE_PREEMPTION == 1 { /* A context switch might happen so save the context. */ portSAVE_CONTEXT(); /* Increment the tick ... */ vTaskIncrementTick(); /* ... then see if the new tick value has necessitated a context switch. */ vTaskSwitchContext(); TFLG1 = 1; /* Restore the context of a task - which may be a different task to that interrupted. */ portRESTORE_CONTEXT(); } #else { vTaskIncrementTick(); TFLG1 = 1; } #endif }
至此,所有移植代码就都分析完了。
实时操作系统内核其实都大同小异,掌握了一种再学习其余的很容易就能入门。从入门难度来说,uC/OS-II无疑是入门学习的首选。之所以这么说并不是因为uC/OS-II本身很简单,而是国内介绍uC/OS-II的资料非常多。相比起来,介绍FreeRTOS的资料就少的可怜了。我建议想要学习FreeRTOS的人还是应该先学习uC/OS-II,学懂了uC/OS-II,然后对比着学习FreeRTOS,这样会事半功倍。这也是我学习FreeRTOS的路径。

MySQL Index Cardinality는 쿼리 성능에 중대한 영향을 미칩니다. 1. 높은 카디널리티 인덱스는 데이터 범위를보다 효과적으로 좁히고 쿼리 효율성을 향상시킬 수 있습니다. 2. 낮은 카디널리티 인덱스는 전체 테이블 스캔으로 이어질 수 있으며 쿼리 성능을 줄일 수 있습니다. 3. 관절 지수에서는 쿼리를 최적화하기 위해 높은 카디널리티 시퀀스를 앞에 놓아야합니다.

MySQL 학습 경로에는 기본 지식, 핵심 개념, 사용 예제 및 최적화 기술이 포함됩니다. 1) 테이블, 행, 열 및 SQL 쿼리와 같은 기본 개념을 이해합니다. 2) MySQL의 정의, 작업 원칙 및 장점을 배우십시오. 3) 인덱스 및 저장 절차와 같은 기본 CRUD 작업 및 고급 사용량을 마스터합니다. 4) 인덱스의 합리적 사용 및 최적화 쿼리와 같은 일반적인 오류 디버깅 및 성능 최적화 제안에 익숙합니다. 이 단계를 통해 MySQL의 사용 및 최적화를 완전히 파악할 수 있습니다.

MySQL의 실제 응용 프로그램에는 기본 데이터베이스 설계 및 복잡한 쿼리 최적화가 포함됩니다. 1) 기본 사용 : 사용자 정보 삽입, 쿼리, 업데이트 및 삭제와 같은 사용자 데이터를 저장하고 관리하는 데 사용됩니다. 2) 고급 사용 : 전자 상거래 플랫폼의 주문 및 재고 관리와 같은 복잡한 비즈니스 로직을 처리합니다. 3) 성능 최적화 : 인덱스, 파티션 테이블 및 쿼리 캐시를 사용하여 합리적으로 성능을 향상시킵니다.

MySQL의 SQL 명령은 DDL, DML, DQL 및 DCL과 같은 범주로 나눌 수 있으며 데이터베이스 및 테이블을 작성, 수정, 삭제, 삽입, 업데이트, 데이터 삭제 및 복잡한 쿼리 작업을 수행하는 데 사용됩니다. 1. 기본 사용에는 CreateTable 생성 테이블, InsertInto 삽입 데이터 및 쿼리 데이터 선택이 포함됩니다. 2. 고급 사용에는 테이블 조인, 하위 쿼리 및 데이터 집계에 대한 GroupBy 조인이 포함됩니다. 3. 구문 검사, 데이터 유형 변환 및 권한 관리를 통해 구문 오류, 데이터 유형 불일치 및 권한 문제와 같은 일반적인 오류를 디버깅 할 수 있습니다. 4. 성능 최적화 제안에는 인덱스 사용, 전체 테이블 스캔 피하기, 조인 작업 최적화 및 트랜잭션을 사용하여 데이터 일관성을 보장하는 것이 포함됩니다.

Innodb는 잠금 장치 및 MVCC를 통한 Undolog, 일관성 및 분리를 통해 원자력을 달성하고, Redolog를 통한 지속성을 달성합니다. 1) 원자력 : Undolog를 사용하여 원래 데이터를 기록하여 트랜잭션을 롤백 할 수 있는지 확인하십시오. 2) 일관성 : 행 수준 잠금 및 MVCC를 통한 데이터 일관성을 보장합니다. 3) 격리 : 다중 격리 수준을지지하고 반복적 인 방사선이 기본적으로 사용됩니다. 4) 지속성 : Redolog를 사용하여 수정을 기록하여 데이터가 오랫동안 저장되도록하십시오.

데이터베이스 및 프로그래밍에서 MySQL의 위치는 매우 중요합니다. 다양한 응용 프로그램 시나리오에서 널리 사용되는 오픈 소스 관계형 데이터베이스 관리 시스템입니다. 1) MySQL은 웹, 모바일 및 엔터프라이즈 레벨 시스템을 지원하는 효율적인 데이터 저장, 조직 및 검색 기능을 제공합니다. 2) 클라이언트 서버 아키텍처를 사용하고 여러 스토리지 엔진 및 인덱스 최적화를 지원합니다. 3) 기본 사용에는 테이블 작성 및 데이터 삽입이 포함되며 고급 사용에는 다중 테이블 조인 및 복잡한 쿼리가 포함됩니다. 4) SQL 구문 오류 및 성능 문제와 같은 자주 묻는 질문은 설명 명령 및 느린 쿼리 로그를 통해 디버깅 할 수 있습니다. 5) 성능 최적화 방법에는 인덱스의 합리적인 사용, 최적화 된 쿼리 및 캐시 사용이 포함됩니다. 모범 사례에는 거래 사용 및 준비된 체계가 포함됩니다

MySQL은 소규모 및 대기업에 적합합니다. 1) 소기업은 고객 정보 저장과 같은 기본 데이터 관리에 MySQL을 사용할 수 있습니다. 2) 대기업은 MySQL을 사용하여 대규모 데이터 및 복잡한 비즈니스 로직을 처리하여 쿼리 성능 및 트랜잭션 처리를 최적화 할 수 있습니다.

InnoDB는 팬텀 읽기를 차세대 점화 메커니즘을 통해 효과적으로 방지합니다. 1) Next-Keylocking은 Row Lock과 Gap Lock을 결합하여 레코드와 간격을 잠그기 위해 새로운 레코드가 삽입되지 않도록합니다. 2) 실제 응용 분야에서 쿼리를 최적화하고 격리 수준을 조정함으로써 잠금 경쟁을 줄이고 동시성 성능을 향상시킬 수 있습니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

드림위버 CS6
시각적 웹 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
