Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. RF_Stat RF_flushCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode)
  2. {
  3.     return (abortCmd(h, ch, (mode | 0x2)));
  4. }
  5.  
  6. static RF_Stat abortCmd(RF_Handle h, RF_CmdHandle ch, uint8_t type)
  7. {
  8.       //Assert
  9.     Assert_isTrue((h != NULL), NULL);
  10.  
  11.     // initialize local variables
  12.     RF_Cmd* pCmdPend = Q_peek(&cmdQ.pPend);
  13.     RF_CmdDirImm* pCmdDirImm = &cmdDirImm;
  14.     bool bGraceful = type & 0x1;
  15.     bool bFlushing = false;
  16.     RF_Stat status = RF_StatInvalidParamsError;
  17.  
  18.     // Check if current command
  19.     uint32_t key = Hwi_disable();
  20.     if (ch == RF_CMDHANDLE_FLUSH_ALL)
  21.     {
  22.         ch = cmdQ.nSeqDone + 1;
  23.         pCmdDirImm->flags = 0;
  24.     }
  25.     RF_Cmd* pCmd = &aCmdPool[ch%N_CMD_POOL];
  26.     if (pCmd == cmdQ.pCurrCmd)
  27.     {
  28.         // Clear all pending commands
  29.         if (type & 0x2)
  30.         {
  31.             pCmdPend = cmdQ.pPend;
  32.             cmdQ.pPend = NULL;
  33.         }
  34.  
  35.         // Flag that operation has been aborted.
  36.         pCmd->flags |= (1 << bGraceful);
  37.  
  38.         uint32_t keySwi = Swi_disable();
  39.  
  40.         runDirImmCmd((bGraceful) ? CMDR_DIR_CMD(CMD_STOP) : CMDR_DIR_CMD(CMD_ABORT));
  41.  
  42.         Hwi_restore(key);
  43.  
  44.         // Call callbacks
  45.         if (type & 0x2)
  46.         {
  47.             while (pCmdPend)
  48.             {
  49.                 pCmdPend->flags |= RF_CMD_CANCELLED_FLAG;
  50.                 Q_push(&cmdQ.pDone, Q_pop(&pCmdPend));
  51.             }
  52.         }
  53.  
  54.         Swi_restore(keySwi);
  55.         status = RF_StatSuccess;
  56.     }
  57.     else
  58.     {
  59.         if (pCmdPend == pCmd)
  60.         {
  61.             Clock_stop(Clock_handle(&clkPowerUp));
  62.             if (type & 0x2)
  63.             {
  64.                 cmdQ.pPend = NULL;
  65.             }
  66.             else
  67.             {
  68.                 cmdQ.pPend = cmdQ.pPend->pNext;
  69.             }
  70.             Hwi_restore(key);
  71.  
  72.             do {
  73.                 // Call callbacks
  74.                 pCmdPend->flags |= RF_CMD_CANCELLED_FLAG;
  75.                 Q_push(&cmdQ.pDone, Q_pop(&pCmdPend));
  76.             } while ((pCmdPend) && (type & 0x2));
  77.  
  78.             status = RF_StatSuccess;
  79.         }
  80.         else
  81.         {
  82.             while (pCmdPend)
  83.             {
  84.                 if (pCmdPend->pNext == pCmd)
  85.                 {
  86.                     Clock_stop(Clock_handle(&clkPowerUp));
  87.                     RF_Cmd* pTemp = (RF_Cmd*)pCmdPend->pNext;
  88.                     pCmdPend->pNext = NULL;
  89.                     pCmdPend = pTemp;
  90.                     Hwi_restore(key);
  91.                     if (type & 0x2)
  92.                     {
  93.                         bFlushing = true;
  94.                     }
  95.                     else
  96.                     {
  97.                         pCmdPend->flags |= RF_CMD_CANCELLED_FLAG;
  98.                         Q_push(&cmdQ.pDone, Q_pop(&pCmdPend));
  99.                     }
  100.                     status = RF_StatSuccess;
  101.                 }
  102.                 if (bFlushing)
  103.                 {
  104.                     pCmdPend->flags |= RF_CMD_CANCELLED_FLAG;
  105.                     Q_push(&cmdQ.pDone, Q_pop(&pCmdPend));
  106.                 }
  107.                 else
  108.                 {
  109.                     pCmdPend = (RF_Cmd*)pCmdPend->pNext;
  110.                 }
  111.             }
  112.             if (status != RF_StatSuccess)
  113.             {
  114.                 Hwi_restore(key);
  115.             }
  116.         }
  117.  
  118.         FsmNextState(fsmActiveState);
  119.         Swi_or(Swi_handle(&swiFsm), Fsm_EventLastCommandDone);
  120.  
  121.         if (!bRadioActive)
  122.         {
  123.             FsmNextState(fsmPowerUpState);
  124.         }
  125.     }
  126.  
  127.     return(status);
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement