⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_cpu_asm.c

📁 freesacle的实时操作系统UCOS的开发程序
💻 C
字号:
/*
*********************************************************************************
*
*文件名 :OS_CPU_ASM.c
*
*说明 :  用于移植UCOS操作系统的接口函数的实现..
*
*任务的堆栈:       高地址
*               -----------
*               |  PC	   |
*               |----------|
*               |  Y       |
*               |----------|
*               |  X       |
*               |----------|
*               |  A       |
*               |----------|
*               |  B       |                    任务TCB
*               |----------|		  |-------------------
*               |  CCR     |	 |--------| SP =(OSTCB)的头.. |
*               |----------|	 |	  |-------------------|
*               |  PPAGE   |	 |	  |		      |
*               |----------|	 |	  |		      |
*               | ?D(无)  |<-----	  |	   :	      |
*               |----------|
*               			  |		      |
*                   低地址
*						   :	      |
*					  |		      |
*					  |		      |
*					  |-------------------|
*
*************************************************************************
*/
#include "includes.h"
#include "MC9S12DG128.h"
#include "PWM.h"
#include "ATD.h"
#include "display.h"
#include "ctrl.h"
#include "Uart.h"




 void do_change(void);
 int tem,f_tem=1000,d_tem=10;
 char tem1;
 char tem2;
 char counter=0;
 char buf[6];
 char num_buf;
 unsigned int ATD_reslut; 
 
 extern  unsigned int f_num;
 
 extern  char f[300];
 
extern  void SP_RL(char temp); 
 extern unsigned int Speed(void);
extern  void IOC_ISR(void) ;
extern  void SysCLK_ISR(void);


//extern   unsigned char data[300][13] ;
//extern    unsigned int data_p;


/*-----------------------------------------------------------------------  */

void OSStartHighRdy(void)
{
#if OS_CPU_HOOKS_EN>1    
         OSTaskSwHook();
#endif         
         asm{
                 ldx OSTCBCur	    //(OSTCBCur)-->X
                 lds 0,x	    //((OSTCBCur))-->SP
                 ldaa OSRunning	    //(OSRunning)-->A
                 inca
                 staa OSRunning	     // A-->(OSRunning)
                 pula
                 staa $30	      //(30)=PPAGE是页寄存器的地址..
                 nop
                 rti		        //高优先级的任务全部出栈...
        }
        
}         
/*----------------------------------------------------------------------------*/ 
// KO

void near OS_TASK_SW(void)
{
          asm{
               
                pshy
                pshx
                pshb
                psha
                pshc
                ldaa $30
                psha
                ldx   OSTCBCur
                sts 0, x				//保存SP
        }
#if OS_TASK_SW_HOOK_EN>1        
        OSTaskSwHook();
#endif        
        OSTCBCur=OSTCBHighRdy;
        OSPrioCur= OSPrioHighRdy;
                asm{
                        ldx OSTCBCur	  //(OSTCBCur)-->X
                        lds 0,x	         //((OSTCBCur))-->SP
                        pula
                        staa  $30
                        rti
                }
                
}

/*-----------------------------------------------------------------------*/

void  OSIntCtxSw(void)
{
        OSTCBCur=OSTCBHighRdy;
        OSPrioCur=OSPrioHighRdy;
        asm{
                ldx OSTCBCur
                lds 0,x
                pula
                staa $30
                nop
                rti
        }
}
            
/*------------------------------------------------------------------------------- */
         
 void   OSTickISR(void)           //对于CS12中断发生的时候就已经自动保存好了寄存器了PC---CCR...
{			                            //整个过程是关闭了中断,并且中断的优先级是最高的..即时钟中断是不允许嵌套的........
        asm{
                ldaa $30
                psha
                ldaa OSIntNesting	 //(OSIntNecting)-->A
                inca
                staa OSIntNesting	 // A-->(OSIntNecting)           
                ldx   OSTCBCur	     
                sts 0, x       
        }    
        SysCLK_ISR();	              //清除时钟中断的中断标志位,跳到中断服务函数..      
        OSIntExit();			          //因为中断处理函数都完整退出了,SP相当于没有变
        asm{
                pula
                staa $30
                nop
                rti
             }
}               
/*------------------------------------------------------------------------              
*.所有的中断的发生时的入口点....
* 然后的相应的处理.程序,,,中断服务程序.... (允许中断嵌套的).... 
*/        
void  PAover_Int(void)
  {
         asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }    
                PAFLG|=0x02;	 //清除中断标志位
                uart_putchar('\n');
                uart_putchar('v');
                display2(PACN32);
               
                OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                }
}
/*--------------------------------------------------------------------------
*
*/                                                                 
  void  IOC_Int(void)
  {
         asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }    
                TFLG1|=0x01;	 //清除中断标志位
 								//test_Speed();
 								
 								//test_rgz(1);
 								IOC_ISR();   
                OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                        
                }
}
               

void SCI_Int(void ){
         asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }
                
                		 
                     SCI0SR1|=20;
                  
                     tem1= SCI0DRL;
										 if (tem1=='f'||tem1=='F') {
										  tem2=1;
										  uart_putchar(tem1);
										  uart_putchar(' ');
										  num_buf=0;
										  
										 } 
										 else if (tem1=='d'||tem1=='D') { 
										  tem2=2;
										  uart_putchar(tem1);
										  uart_putchar(' ');
										  num_buf=0;
										 }
										 else if (tem1=='a'||tem1=='A') { 
										  tem2=3;
										  uart_putchar(tem1);
										  uart_putchar(' ');
										  num_buf=0;
										 }
										 else if (tem1=='s'||tem1=='S') { 
										  tem2=4;
										  uart_putchar(tem1);
										  uart_putchar(' ');
										  num_buf=0;
										 }
										 else if (tem1=='r'||tem1=='R') 
										 {		/*
										  	  for(f_num=0;f_num<300;f_num++) 
										  	  
										  	  {
										  	   if(f[f_num]<0)
										  	   
										  	   {
										  	    uart_putchar('-');
										  	    uart_putchar(f[f_num]*(-1)+0x30);
										  	    
										  	   } else
										  	   uart_putchar(f[f_num]+0x30);
										  	   
										  	   uart_putchar('\n');
										  	   uart_putchar('\r');
										  	   
										  	  }
												 */
										  	 
										  	 asm{
										  	  jsr 0xef80
										  	 }
										  
										 }
										 else if (tem1=='\n'||tem1=='\r') {
										  
										  uart_putchar(tem1);
										  uart_putchar(' ');
										  do_change();
										  num_buf=0;
										  tem2=0;
										 
										 }else
										 {
										   if((tem1>='0')&&(tem1<='9')) {
										   
										    
										   buf[num_buf]=tem1-0x30;
										   uart_putchar(tem1);
										   //uart_putchar(' ');
										   //uart_putchar(num_buf+0x30);
										   num_buf++;
										   }
										   else {
										   if((tem2==2)&&(tem1=='-')){
										    buf[num_buf]=tem1;
										    uart_putchar(tem1);
										    //uart_putchar(' ');
										    num_buf++;
										   }else
										    uart_putchar('e');
										    uart_putchar(tem1);
										    uart_putchar(' ');
										   }
										  
										 }

               		  
                   
               		
              
                OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                }
}

void ATD0_Int(void){
  
  				          asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }
                					  	                  //清除中断标志位
								uart_putchar('A');	
                ATD_reslut = ATD0DR0H;              //读取转换后的结果2 (注:右齐方式,无符号位编码 )
				        display2((unsigned long )ATD_reslut);
			        	uart_putchar('\n');
			        	uart_putchar('\r');	
                						   
								OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                }
}
void ATD1_Int(void){
  
  				          asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }
                					  	                  //清除中断标志位
								uart_putchar('A');	
                ATD_reslut = ATD1DR0H;              //读取转换后的结果2 (注:右齐方式,无符号位编码 )
				        display2((unsigned long )ATD_reslut);
			        	uart_putchar('\n');
			        	uart_putchar('\r');	
                						   
								OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                }
}

void  IRQ_Int(void){
  
							     asm{
                        ldaa $30
                        psha
                        ldaa OSIntNesting	     //(OSIntNecting)-->A
                        inca
                        staa OSIntNesting	     // A-->(OSIntNecting)          
                        ldx   OSTCBCur	               
                        sts 0, x 
                }
                uart_putchar ('\n');							 //P1_55 IRQ extend input
                uart_putchar ('\r');
                uart_putchar ('I');
                uart_putchar ('R');
                uart_putchar ('Q'); 
                
              	OSIntExit();
                asm{		//出棧的前后的SP值会自动恢复
                       
                        pula
                        staa   $30
                        nop
                        rti
                        
                }
}


void do_change(void) {
char i;
//unsigned int temp;
if(buf[0]=='-'){
  
i=1;
buf[1]=buf[1]*(-1);
}
else
i=0;
tem=0;
//uart_putchar(' ');
 for(;i<num_buf;i++) {
 //uart_putchar(buf[i]+0x30);
 tem=tem*10+buf[i];
 }
 //uart_putchar(' ');
 //display2((unsigned long)tem);
 if(tem2==1) {
 f_tem=tem;
 PWM3outPut((unsigned long)tem,d_tem);
}
else if(tem2==2) {
 d_tem=tem;
 PWM3outPut((unsigned long)f_tem,tem);
// ATD0_ChannelX((unsigned char )tem);

}
else if(tem2==3) {
//test_rgz(tem) ;
  turn_R_L((float )tem) ;
//test_ad_ch=tem;
/*
for(data_p=0;data_p<300;data_p++)
  {
   uart_putchar('\n');
   //uart_putchar('\r');  
   for (i=0;i<13;i++)
    {
      display2((unsigned long)data[data_p][i]);
      uart_putchar(' ');
      uart_putchar(' ');
    }

  } */
  
}
else if(tem2==4) {
//test_rgz(tem) ;

i=tem;
i=i*(-1);
  turn_R_L((float)i);
//test_ad_ch=tem;

}
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -