µC/OS-IIÊÇÒ»¸öÍêÕûµÄ£¬¿ÉÒÆÖ²¡¢¿É¹Ì»¯¡¢¿É²Ã¼õµÄÕ¼ÏÈʽʵʱ¶àÈÎÎñÄںˣ¬Ëü¹¦ÄÜÇ¿´ó£¬Ö§³Ö56¸öÓû§ÈÎÎñ£¬Ö§³ÖÐźÅÁ¿¡¢ÓÊÏä¡¢ÏûÏ¢¶ÓÁеȶàÖÖ³£ÓõĽø³Ì¼äͨÐÅ»úÖÆ¡£¹«¿ªÔ´´úÂ룬³ÌÐò¿É¶ÁÐÔÇ¿¡¢ÒÆÖ²ÐԺã¬Í¬Ê±¿ÉÃâ·Ñ»ñµÃ¡£
LPC2119ÊÇÓÉPHILIPSÉú²úµÄÒ»¿î32λARM7TDMI-S΢´¦ÀíÆ÷£¬ÆäºËÐÄΪ¸ßÐÔÄܵÄ32λRISCÌåϵ½á¹¹£¬²¢¾ßÓиßÃܶȵÄ16λָÁºÍ¼«µÍµÄ¹¦ºÄ¡£¾ßÓÐÁãµÈ´ý128K×Ö½ÚµÄƬÄÚFLASH£¬16KµÄSRAM£¬ÎÞÐèÀ©Õ¹´æ´¢Æ÷£¬Ê¹ÏµÍ³¸üΪ¼òµ¥¡¢¿É¿¿¡£
±í1
±¾ÎÄÖ÷ÒªÌÖÂÛµC/OS-IIÔÚLPC2119ÉϵÄÒÆÖ²£¬Í¬Ê±¶ÔÒÆֲǰÐèÒªÕÆÎյĻù±¾ÖªÊ¶½øÐÐÁË·ÖÎö£¬ÌرðÊǶÔÓëÒÆÖ²ÃÜÇÐÏà¹ØµÄÈý¸öÎļþ½øÐÐÁËÏêϸ·ÖÎö£¬»¹¶ÔÓõ½µÄоƬµÄÖØÓ³Éä¸ÅÄî½øÐÐÁËÏêϸ˵Ã÷¡£
LPC2119¼ò½é
LPC2119ƬÉÏ×ÊÔ´³ýÁËÉÏÃæ½éÉܵĴ洢Æ÷Í⣬»¹ÓÐ2¸öUART¡¢¸ßËÙI2C½Ó¿Ú¡¢2¸öSPI½Ó¿Ú¡¢6·Êä³öµÄPWMµ¥Ôª¡¢4·10λADת»»Æ÷¡¢2¸ö32λ¶¨Ê±Æ÷¡¢2¸öCANͨµÀ¡¢ÊµÊ±Ê±ÖÓ¼°¿´ÃŹ·µÈ£¬Í¨¹ýƬÄÚPLL¿ÉʵÏÖ×î´óΪ60MHzµÄCPU²Ù×÷ƵÂÊ¡£
ÓÉÓÚÏÂÎÄÆô¶¯´úÂëµÄ±àдҪÓõ½ÖØÓ³Éä(remap)µÄ¸ÅÄLPC2119ÒÔ¼°ÆäËüϵÁеÄоƬÈçAT91µÈÒ²¶¼ÓÐÖØÓ³ÉäµÄ¹¦ÄÜ£¬ËùÒÔÔڴ˼ÓÒÔ˵Ã÷¶ÔÆäËüARMоƬµÄѧϰ¾ßÓнè¼ø×÷Óá£
ÔÚARMоƬµÄ´æ´¢Æ÷ÖУ¬Òì³£ÏòÁ¿±íÈç±í1Ëùʾ¡£
µ±ÏµÍ³Éϵçºó£¬³ÌÐò½«×Ô¶¯´Ó0µØÖ·´¦¿ªÊ¼Ö´ÐУ¬Òò´ËÔÚϵͳµÄ³õʼ״̬£¬ÒªÇó0µØÖ·´¦µÄ´æ´¢Æ÷ÊÇ·ÇÒ×ÐÔµÄROM»òFlashµÈ¡£µ«ÊÇROM»òFlashµÄ·ÃÎÊËÙ¶ÈÏà¶Ô½ÏÂý£¬Ã¿´ÎÖжϷ¢Éúºó£¬¶¼Òª´Ó¶ÁÈ¡ROM»òFlashÉϵÄÏòÁ¿±í¿ªÊ¼£¬Ó°ÏìÁËÖжÏÏìÓ¦Ëٶȡ£Òò´Ë£¬LPC2119ÌṩһÖÖÁé»îµÄµØÖ·ÖØÓ³Éä·½·¨£¬¸Ã·½·¨¿ÉÒÔ½«ÄÚ²¿RAMµÄµØÖ·ÖØÐÂÓ³Éäµ½0x0µÄλÖá£ÔÚϵͳִÐÐÖØÓ³ÉäÃüÁî֮ǰ£¬ÐèÒª½«FlashÖеÄÖжÏÏòÁ¿´úÂ뿽±´µ½ÄÚ²¿RAMÖС£ÕâÑùÔÚÖØÓ³ÉäÃüÁîÖ´ÐÐÖ®ºóÏ൱ÓÚ´ÓÄÚ²¿RAMÖÐ0x0µÄλÖÃÕÒµ½ÖжÏÏòÁ¿£¬¶øʵ¼ÊÉÏÊǽ«RAMµÄÆðʼµØÖ·0x40000000Ó³ÉäΪ0x0ÁË¡£ÕâÑù£¬ÖжÏÖ´ÐÐʱÏ൱ÓÚÔÚRAMÖÐÕÒµ½¶ÔÓ¦ÖжÏÏòÁ¿£¬ÊµÏÖÒì³£´¦Àíµ÷ÊÔ¡£
µC/OS-IIµÄ½éÉÜ
µC/OS-IIʵ¼ÊÉÏÊÇÒ»¸öǶÈëʽ²Ù×÷ϵͳÄںˣ¬ÄÚºËÌṩµÄ»ù±¾·þÎñ¾ÍÊÇÈÎÎñÇл»¡£ÔÚµC/OS-IIÖУ¬ÎªÃ¿¸öÈÎÎñ·ÖÅäרÃŵĶÑÕ»¿Õ¼ä¡£µC/OS-II½øÐÐÈÎÎñÇл»µÄʱºò£¬»á°Ñµ±Ç°ÈÎÎñµÄCPU¼Ä´æÆ÷·Åµ½´ËÈÎÎñµÄ¶ÑÕ»ÖУ¬È»ºóÔÙ´ÓÁíÒ»¸öÈÎÎñµÄ¶ÑÕ»Öлָ´ÔÀ´µÄ¹¤×÷¼Ä´æÆ÷£¬¼ÌÐøÔËÐÐÁíÒ»¸öÈÎÎñ¡£ËùÒÔ£¬¼Ä´æÆ÷µÄÈëÕ»ºÍ³öÕ»ÊǵC/OS-II¶àÈÎÎñµ÷¶ÈµÄ»ù´¡¡£
ͼ1 µC/OS-IIÓ²¼þºÍÈí¼þÌåϵ½á¹¹
µC/OS-IIµÄ½á¹¹Èçͼ1Ëùʾ¡£
Èçͼ1Ëùʾ£¬Óë´¦ÀíÆ÷Ïà¹ØµÄ´úÂëÖ»ÓÐÈý¸öÎļþ£¬Ò»°ãÒÆÖ²µÄʱºòÖ»ÒªÐÞ¸ÄÕâÈý¸öÎļþ¾Í¿ÉÒÔÁË¡£
±àдÆô¶¯´úÂë
Æô¶¯´úÂëÊÇоƬ¸´Î»ºó½øÈëCÓïÑÔµÄmain()º¯ÊýÇ°Ö´ÐеÄÒ»¶Î´úÂ룬Ö÷ÒªÊÇΪÔËÐÐCÓïÑÔ³ÌÐòÌṩ»ù±¾ÔËÐл·¾³£¬Èç³õʼ»¯ÍâΧ²¿¼þ¡¢´æ´¢Æ÷ϵͳµÈ¡£Òò´ËÆô¶¯´úÂëµÄ¹¦ÄÜÓÐЩÀàËÆPC»úÖеÄBIOSºÍVxWorksÖеÄBootloader¡£ÓÉÓÚ·ÉÀûÆÖδÌṩ¸ÃоƬµÄÆô¶¯´úÂ룬ËùÒÔÐèÒª×Ô¼º±àдÆô¶¯´úÂë¡£
Æô¶¯´úÂë¿ÉÒÔ»®·ÖΪÎå¸öÎļþ£ºStartup.s¡¢IRQ.s¡¢stack.s¡¢heap.sºÍtarget.c¡£Startup.s°üº¬ÁËÇ°ÃæÌáµ½µÄÒì³£ÏòÁ¿±íºÍϵͳ³õʼ»¯´úÂ룬һ°ãÎÞÐè¸Ä¶¯£»IRQ.s°üº¬ÖжϷþÎñ³ÌÐòÓëC³ÌÐòµÄ½Ó¿Ú´úÂ룬¿É¸ù¾Ýʵ¼ÊʹÓõÄÖжÏÇé¿ö½øÐÐÉÙÁ¿Ð޸ģ»stack.sºÍheap.s±£´æCÓïÑÔʹÓõĶѺÍÕ»µÄ¿ªÊ¼Î»Öã»target.c°üº¬Ä¿±ê°åÌØÊâµÄ´úÂ룬°üÀ¨Òì³£´¦Àí³ÌÐòºÍÄ¿±ê°å³õʼ»¯³ÌÐò£¬¿É¸ù¾Ý³ÌÐòµÄÐèÒªÐ޸ġ£
ͼ2 ϵͳ»ù±¾³õʼ»¯Tar get Peset1 ni t()Á÷³Ìͼ
ÓÉÓÚÆô¶¯´úÂëµÄ±àдºÜ³¤£¬¶ø±¾ÎÄÖ»ÊÇÏëÖ¸³ö±àдÆô¶¯´úÂëÊÇÒÆֲǰ±ØÐë×öµÄ×¼±¸¹¤×÷²¢¶ÔÆä½øÐмòҪ˵Ã÷£¬Òò´ËÔÚÕâÀï¾Í²»¾ßÌåÁгöËùÓдúÂë(¾ßÌåµÄÆô¶¯´úÂë¼û²Î¿¼ÎÄÏ×[1])£¬¶ø¸ø³öÒ»¸öºÜÖØÒªµÄÄ¿±ê°å³õʼ»¯³ÌÐòÖеĺ¯ÊýTargetResetInit()µÄÁ÷³Ìͼ£¬´ÓÖпÉÒÔ¿´³öÔÚ½øÈëmain()º¯ÊýÇ°¶Ôϵͳ½øÐеĻù±¾³õʼ»¯¹¤×÷µÄ¾ßÌå²½Öè¡£
ÒÆÖ²
ÓÐÁËÉÏÃæµÄ֪ʶºÍ±àдÆô¶¯´úÂëÕâÏî×¼±¸¹¤×÷Íê³Éºó£¬¾Í¿ÉÒÔ½øÈë¾ßÌåÒÆÖ²½×¶ÎÁË¡£Ö÷ÒªÍê³ÉÒÔϹ¤×÷£º
¢Ù ΪÁËÔöÇ¿´úÂëµÄ¿ÉÒÆÖ²ÐÔ£¬ËùÓÐCÎļþÌí¼ÓÍ·Îļþincludes.h¡£
¢Ú Óû§³ÌÐòÌí¼Óconfig.h¡£
¢Û ÔÚÎļþOS_CPU.HÖÐÐèÒªÌí¼Ó»òÐ޸ĵÄÖ÷Òª´úÂëÓУº
¶¨Òå²»ÒÀÀµÓÚ±àÒëÆ÷µÄÊý¾ÝÀàÐÍ£º
typedef unsigned char INT8U;
typedef unsigned short INT16U;
typedef unsigned int INT32U;
typedef INT32U OS_STK;
ÿÿÿ
ʹÓÃÈíÖжÏSWI×÷µ×²ã½Ó¿Ú£º
__swi(0x00) void OS_TASK_SW(void); /* ÈÎÎñ¼¶ÈÎÎñÇл»º¯Êý */
__swi(0x01) void _OSStartHighRdy(void); /* ÔËÐÐÓÅÏȼ¶×î¸ßµÄÈÎÎñ */
__swi(0x02) void OS_ENTER_CRITICAL(void); /*¹ØÖÐ¶Ï */
__swi(0x03) void OS_EXIT_CRITICAL(void); /* ¿ªÖÐ¶Ï */
ÿÿÿ
__swi(0x80) void ChangeToSYSMode(void); /* ÈÎÎñÇл»µ½ÏµÍ³Ä£Ê½ */
__swi(0x81) void ChangeToUSRMode(void); /* ÈÎÎñÇл»µ½Óû§Ä£Ê½ */
#define OS_STK_GROWTH 1 /* ¶ÑÕ»ÊÇ´ÓÉÏÍùϳ¤µÄ*/
¶¨Ò幤×÷ģʽ£º
#define USR32Mode 0x10 /* Óû§Ä£Ê½ */
#define SYS32Mode 0x1f /* ϵͳģʽ*/
#define NoInt 0x80
#ifndef USER_USING_MODE
#define USER_USING_MODE USR32Mode /* ÈÎÎñȱʡģʽ*/
#endif
¶¨Ò忪¹ØÐźÅÁ¿£º extern OS_STK OsEnterSum
¢Ü ÔÚÎļþOS_CPU_C.CÖÐÐèÒªÌí¼Ó»òÐ޸ĵĴúÂ룺
OS_ENTER_CRITICAL()´úÂë
__asm
{ MRS R0, SPSR
ORR R0, R0, #NoInt
MSR SPSR_c, R0
}
OsEnterSum++;
OS_EXIT_CRITICAL()´úÂë
if (--OsEnterSum == 0)
{ __asm
{ MRS R0, SPSR
BIC R0, R0, #NoInt
MSR SPSR_c, R0
}
}
±àдÈÎÎñ¶ÑÕ»µÄ³õʼ»¯´úÂ룺
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{ OS_STK *stk;
opt = opt; /* 'opt' ûÓÐʹÓá£×÷ÓÃÊDZÜÃâ±àÒëÆ÷¾¯¸æ */
stk = ptos; /* »ñÈ¡¶ÑÕ»Ö¸Õë*/
/* ½¨Á¢ÈÎÎñ»·¾³£¬Ê¹ÓÃÂúµÝ¼õ¶ÑÕ» */
*stk = (OS_STK) task; /* pc */
*--stk = (OS_STK) task; /* lr */
*--stk = 0; /* r12 */
ÿÿ /*r11ÿr2*/
*--stk = 0; /* r1 */
*--stk = (unsigned int) pdata; /* r0,µÚÒ»¸ö²ÎÊýʹÓÃR0´«µÝ */
*--stk = (USER_USING_MODE|0x00); /* spsr£¬ÔÊÐí IRQ, FIQ ÖÐ¶Ï */
*--stk = 0; /* ¹ØÖжϼÆÊýÆ÷OsEnterSum; */
return (stk);
}
±àдÈçvoid OSInitHookBegin ( )¡¢void OSInitHookEnd ( )¡¢void OSTaskCreateHook ( )¡¢void OSTaskDelHook ( )µÈ¹³×Óº¯Êý£¬Óû§¿É¸ù¾ÝÐèÒª×ÔÐÐÌí¼Ó´úÂë¡£
¢Ý ÔÚÎļþOS_CPU_A.SÖÐÐèÒªÌí¼Ó»òÐ޸ĵĴúÂ룺
±àдÔËÐÐÓÅÏȼ¶×î¸ßµÄ¾ÍÐ÷ÈÎÎñº¯ÊýOSStartHighRdy()µ÷ÓõÄ__OSStartHighRdy´úÂë
__OSStartHighRdy
MSR CPSR_c, #(NoInt | SYS32Mode)
LDR R4, =OSRunning
MOV R5, #1
STRB R5, [R4]
BL OSTaskSwHook
LDR R6, =OSTCBHighRdy
LDR R6, [R6]
B OSIntCtxSw_1
±àдOSIntCtxSw´úÂë
ÓÉÓÚƪ·ùËùÏÞ£¬ÕâÀï¸ø³öOSIntCtxSwº¯ÊýÔÐÍ£¬¿ÉÓɴ˱àд´úÂë¡£Ô´´úÂëÏê¼û²Î¿¼ÎÄÏ×[1]¡£
void OSIntCtxSw(void)
{
µ÷ÓÃÓû§¶¨ÒåµÄOSTaskSwHook()£»
OSTCBCur=OSTCBHighRdy;
OSPrioCur=OSPrioHighRdy;
µÃµ½ÐèÒª»Ö¸´µÄÈÎÎñµÄ¶ÑÕ»Ö¸Õ룻
¶ÑÕ»Ö¸Õë=OSTCBHighRdy->OSTCBStkPtr;
½«ËùÓд¦ÀíÆ÷¼Ä´æÆ÷´ÓÐÂÈÎÎñµÄ¶ÑÕ»Öлָ´³öÀ´£»
Ö´ÐÐÖжϷµ»ØÖ¸Á
}
ÓÉÓÚƪ·ùËùÏÞ£¬ÒÔÉϸø³öÁËÒÆֲʱÐèÒªÐ޸ĵÄÓë´¦ÀíÆ÷Ïà¹ØµÄÈý¸öÎļþÖеÄÖ÷Òª´úÂ룬µ±È»¸üÏêϸµÄÒÆֲ˵Ã÷¿É¼û²Î¿¼ÎÄÏ×[1].ΪÁËÑéÖ¤ÒÆÖ²³É¹¦Óë·ñ£¬Äã¿ÉÒÔ±àдһ¸ö¼òµ¥Óû§³ÌÐò(ÀýÈçͨ¹ý´®¿ÚͨѶÔÚPC½çÃæÏÔʾ×Ö·û)ÓëmC/OS-IIÒ»Æð±àÒëÉÕд½øоƬÀ´¼ìÑ飬±ÊÕßÒѾÊÔÑé³É¹¦¡£
ÐèÒª±ÜÃâµÄ´íÎó
Óû§³ÌÐòÖеÄincludes.hÒªÐÞ¸ÄΪconfig.h£¬ÕâÊÇÒòΪºóÕß°üº¬ÁËÇ°ÕߺÍÌض¨µÄÍ·ÎļþÒÔ¼°ÅäÖÃÏî¡£
Êý¾ÝÀàÐ͵Ķ¨Òå²»ÄÜÖ±½ÓʹÓÃCÖеÄshort¡¢int¡¢longµÈ£¬ÒòΪËüÃÇÓë´¦ÀíÆ÷ÀàÐÍÓйأ¬Òþº¬×Ų»¿ÉÒÆÖ²ÐÔ£¬ËùÒÔÔÚOS_CPU.HÖж¨ÒåÒÆÖ²ÐÔÇ¿µÄ²»ÒÀÀµÓÚ±àÒëÆ÷µÄÊý¾ÝÀàÐÍ¡£
±ØÐ붨Òå¶ÑÕ»µÄÉú³¤·½Ïò£¬1±íʾ¶ÑÕ»´ÓÉÏÍùϳ¤£¬0±íʾ¶ÑÕ»´ÓÏÂÍùÉϳ¤£¬ARM´¦ÀíÆ÷Á½ÖÖ·½Ê½¶¼Ö§³Ö£¬µ«Ê¹ÓõÄADS±àÒëÆ÷½öÖ§³Ö´ÓÉÏÍùϳ¤µÄ·½Ê½£¬Òò´Ë±ØÐ붨ÒåΪ1£¬·ñÔò«·¢Éú¼Ä´æÆ÷ÖµÈëÕ»´íÎó¡?/P>
×¢ÒâÈÎÎñ¶ÑÕ»³õʼ»¯º¯ÊýÖеÄstkÖ¸Õ붨Òå³ÉINT32U£¬ÕâÊÇÒòΪÎÒÃǵĴ¦ÀíÆ÷ÊÇ32λµÄ£¬¶Ô¶ÑÕ»²Ù×÷Ò²ÊÇ4×Ö½Ú¶ÔÆëµÄ¡£Èç¹û´¦ÀíÆ÷ÊÇ16λµÄ£¬ÇÒ¶Ô¶ÑÕ»·ÃÎÊÒ²ÊÇ2×Ö½Ú¶ÔÆëµÄ£¬¾ÍÒª½«stk¶¨Òå³ÉINT16U£¬·ñÔò½«»á·¢ÉúÑÏÖØ´íÎó¡£
½áÓï
µC/OS-II¾ßÓкܺõĿɿ¿ÐÔ¡¢ÊµÊ±ÐԺͿɲüõÐÔ£¬ºÜÊʺÏÓÚ¹¤Òµ¿ØÖÆ¡¢Í¨ÐŵȶÔʵʱÐÔ¡¢¿É¿¿ÐÔÒªÇó¸ßµÄÁìÓò¡£±ÊÕß²ÉÓùãÖÝÖÜÁ¢¹¦¹«Ë¾µÄEASYARN2100ÊÔÑ鿪·¢°å£¬ÒѾ³É¹¦°ÑµC/OS-IIÒÆÖ²µ½¸Ã¿ª·¢°åÉÏ¡£Èç¹ûÓû§¶ÔARM´¦ÀíÆ÷¼°Ïà¹Øµ×²ãÓ²¼þºÍµC/OS-IIÓÐÒ»¶¨Á˽⣬²ÎÕÕ±¾ÎÄ£¬¶Ô½«µC/OS-IIÒÆÖ²µ½LPC21xxϵÁÐARM´¦ÀíÆ÷ÉÏ´óÓаïÖú¡£