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

📄 os_cpu_c.c

📁 此文件是硬盘自伺服刻录代码
💻 C
📖 第 1 页 / 共 2 页
字号:
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSTCBInitHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                                           /* Prevent Compiler warning                 */
}
#endif


/*
*********************************************************************************************************
*                                               TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TIME_TICK_HOOK_EN > 0)
void  OSTimeTickHook (void)
{
#if OS_VIEW_MODULE > 0
    OSView_TickHook();
#endif
}
#endif


/*
*********************************************************************************************************
*                             INTERRUPT DISABLE TIME MEASUREMENT, START
*********************************************************************************************************
*/

#if OS_CPU_INT_DIS_MEAS_EN > 0
void  OS_CPU_IntDisMeasInit (void)
{
    OS_CPU_IntDisMeasNestingCtr = 0;
    OS_CPU_IntDisMeasCntsEnter  = 0;
    OS_CPU_IntDisMeasCntsExit   = 0;
    OS_CPU_IntDisMeasCntsMax    = 0;
    OS_CPU_IntDisMeasCntsDelta  = 0;
    OS_CPU_IntDisMeasCntsOvrhd  = 0;
    OS_CPU_IntDisMeasStart();                              /* Measure the overhead of the functions    */
    OS_CPU_IntDisMeasStop();
    OS_CPU_IntDisMeasCntsOvrhd  = OS_CPU_IntDisMeasCntsDelta;
}


void  OS_CPU_IntDisMeasStart (void)
{
    OS_CPU_IntDisMeasNestingCtr++;
    if (OS_CPU_IntDisMeasNestingCtr == 1) {                /* Only measure at the first nested level   */
        OS_CPU_IntDisMeasCntsEnter = OS_CPU_IntDisMeasTmrRd();
    }
}


void  OS_CPU_IntDisMeasStop (void)
{
    OS_CPU_IntDisMeasNestingCtr--;                                         /* Decrement nesting ctr    */
    if (OS_CPU_IntDisMeasNestingCtr == 0) {
        OS_CPU_IntDisMeasCntsExit  = OS_CPU_IntDisMeasTmrRd();
        OS_CPU_IntDisMeasCntsDelta = OS_CPU_IntDisMeasCntsExit - OS_CPU_IntDisMeasCntsEnter;
        if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsOvrhd) {     /* Ensure overhead < delta  */
            OS_CPU_IntDisMeasCntsDelta -= OS_CPU_IntDisMeasCntsOvrhd;
        } else {
            OS_CPU_IntDisMeasCntsDelta  = OS_CPU_IntDisMeasCntsOvrhd;
        }
        if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsMax) {       /* Track MAXIMUM            */
            OS_CPU_IntDisMeasCntsMax = OS_CPU_IntDisMeasCntsDelta;
        }
    }
}
#endif

/////////////////////////////////
INT16U CaculateMAXBst()
{
     BurstA = *(INT16U *) 0x100026b4;
     BurstB = *(INT16U *) 0x100026b6;
     BurstC = *(INT16U *) 0x100026b8;
     BurstD = *(INT16U *) 0x100026ba;
     // get the biggest burst
     if(BurstA >= BurstB)
     {
       Big_Burst = BurstA;
       Burst = 0;
     }
     else
     {
       Big_Burst = BurstB;
       Burst = 1;
     }
     if(Big_Burst <= BurstC)
     {
       Big_Burst = BurstC;
       Burst = 2;
     }
     if(Big_Burst <= BurstD)
     {
       Big_Burst = BurstD;
       Burst = 3;
     }
     return Burst;
}
void WriteSerPattern()
{
     SectorNum =  *(INT8U *)0x100026d8;
     if(SectorNum == 100)
     {     
        *(INT8U *) 0x10002544 = 0x14;//index
        *(INT8U *) 0x100025B2 = 0x0; //sector number
     }        
     else
     {
        *(INT8U *) 0x10002544 = 0x27;
        *(INT8U *) 0x100025B2 = SectorNum+1;//sector number
     }
          
     // caculate servo track number
     ReadGrayCode = *(INT32U *) 0x100026DC;
     ReadGrayCode = (ReadGrayCode>>8)*2;
     // write burst
     Burst =  CaculateMAXBst();     
     switch(Burst)
     {
       case 0:       
           Track_Num = ReadGrayCode;
           SSW_PES_SECQUENCY = 0x31;//write burst A and erasure burst B
           break;
       case 1:
           Track_Num = ReadGrayCode-1;
           SSW_PES_SECQUENCY = 0x32;//write burst B and erasure burst A
           break;
       case 2:
           Track_Num = ReadGrayCode;
           SSW_PES_SECQUENCY = 0xc4;//write burst C and erasure burst D
           break;
       case 3:
           Track_Num = ReadGrayCode-1;
           SSW_PES_SECQUENCY = 0xc8;//write burst D and erasure burst C
           break;       
     }
     // Write Gray Code
     GrayCode = ChangeToGrayCode(Track_Num)<<8;
     *(INT8U *) 0x100025B4 = GrayCode>>24;
     *(INT8U *) 0x10002570 = (GrayCode<<8)>>24;
     *(INT8U *) 0x10002572 = (GrayCode<<16)>>31;
}

////////////////////////////////////

void       OS_CPU_IRQ_ISR_Handler(void)
{
  /*-------------Timer interrupt---------------------------------*/

/*  if(    (OS_CPU_GetIntNumber() & 0x10) !=0  //Timer0 interrupt
      || (OS_CPU_GetIntNumber() & 0x20) !=0  //Timer1 interrupt
      || (OS_CPU_GetIntNumber() & 0x40) !=0  //Timer2 interrupt
      || (OS_CPU_GetIntNumber() & 0x800) !=0  //Timer3 interrupt
      || (OS_CPU_GetIntNumber() & 0x1000) !=0) //Timer4 interrupt
  {
     OSTickISR();     
  }
  */
  /*--------------SSW interrupt-------------------------------------*/
  // get interrupt source
  INT16U ServoIntStat;
  INT8U J;

  ServoIntStat = SSW_SERVOSTATUS;
  ServoIntStat &=0x4000;// 14th bit is servo interrupt
  if(ServoIntStat == 0x4000)
  {
     //clear servo interrupt
     SSW_SERVOSTATUS |= 0x4000;
     if(WriteSecCunt <7000)  
     {   
          
        SSW_MAINCTRL = 0xAF;
        SSW_WGOUT_EN |= 0x01;//enable WG
        WriteSerPattern();            
     }//end if(WriteSecCunt < 100)
     if(WriteSecCunt>7000&&WriteSecCunt<15000)
     {
        SSW_MAINCTRL &= 0x7F;
        SSW_WGOUT_EN &= 0xFE;//disable WG
          
     }//end if(WriteSecCunt >= 100)
     if(WriteSecCunt >15000&&WriteSecCunt<30000)  
     {   

        SSW_MAINCTRL = 0xAF;
        SSW_WGOUT_EN |= 0x01;//enable WG
        WriteSerPattern();
                   
     }//end if(WriteSecCunt < 100)
     if(WriteSecCunt>30000)
     {
        SSW_MAINCTRL &= 0x7F;
        SSW_WGOUT_EN &= 0xFE;//disable WG
          
     }
     EnterINT = 1; 
  }//end if(ServoIntStat == 0x4000)     
}//end of IRQ handler

void       OS_CPU_FIQ_ISR_Handler(void)
{
}
void       OS_CPU_RESERVED_Handler(void)
{
}
void       OS_CPU_DATAABORTHandler(void)
{
}
void       OS_CPU_PREFETCHABORTHandler(void)
{}
void       OS_CPU_SWIHandler(void)
{
}
void       OS_CPU_UNDEFINEDHandler(void)
{}


///////////////////////////


INT32U       OS_CPU_GetIntNumber(void)
{
/*  __asm
  {
     MSR     CPSR_c,#0xc0|0x13
     MRS     R0,CPSR
     ORR     R0,R0,0x20
     MSR     CPSR_c,R0   
  
  }
*/ 
  
 return( ( *(volatile unsigned *)INTPND)&0x0000ffff);
}

void OSTickISR(void)
{
  if((OS_CPU_GetIntNumber() & 0x10) !=0 ) //Timer0 interrupt
  {
    OSTimeTick();
    *(volatile unsigned *)INTPND |=0x10;//clear interrupt
  }
  if((OS_CPU_GetIntNumber() & 0x20) !=0 )
  {
  }
  if((OS_CPU_GetIntNumber() & 0x40) !=0 )
  {
  }
  if((OS_CPU_GetIntNumber() & 0x800) !=0 )
  {
  }
  if((OS_CPU_GetIntNumber() & 0x1000) !=0 )
  {
  }
}

⌨️ 快捷键说明

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