Beispiel #1
0
   /* has been taken.                                                   */
int HCILL_ActionTaken(HCILL_Action_Request_t Action)
{
   int ret_val = 0;
   int Flags;

   /* Determine the next state based on the requested action that was   */
   /* just completed.                                                   */
   switch(Action)
   {
      case haSendSleepAck:
         /* Enter a critical section to modify the HCILL State.         */
         CriticalEnter(&Flags);

         /* We should only have sent a Sleep Ack when we were waiting   */
         /* to send HCILL_GO_TO_SLEEP_ACK right before entering the     */
         /* sleep state.                                                */
         if(HCILL_State == hsWaitSendSleepAck)
         {
            /* We are sleeping.                                         */
            HCILL_State = hsSleep;

            /* Exit the critical region.                                */
            CriticalExit(Flags);

            ret_val     = 1;
         }
         else
         {
            /* Exit the critical region.                                */
            CriticalExit(Flags);
         }
         break;
      case haSendWakeupAck:
         /* Enter a critical section to modify the HCILL State.         */
         CriticalEnter(&Flags);

         /* We should only be sending Wake-Up Acks if we are in         */
         /* Controller initiated wake-up state.                         */
         if(HCILL_State == hsControllerInitWakeup)
         {
            /* We have now been woken up by the controller.             */
            HCILL_State = hsAwake;

            /* Exit the critical region.                                */
            CriticalExit(Flags);

            ret_val     = 1;
         }
         else
         {
            /* Exit the critical region.                                */
            CriticalExit(Flags);
         }
         break;    
   }
   
   return(ret_val);
}
Beispiel #2
0
//note to self:  do try not to rely on this too much.
void __cdecl CrashError(const TCHAR *format, ...)
{
    if(!format) return;

    va_list arglist;

    va_start(arglist, format);

    String strOut = FormattedStringva(format, arglist);

    OpenLogFile();
    LogFile.WriteStr(TEXT("\r\nError: "));
    LogFile.WriteAsUTF8(strOut);
    LogFile.WriteStr(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBoxva(format, arglist);

#if defined(_DEBUG) && defined(_WIN32)
    if(bDebugBreak && OSDebuggerPresent())
        ProgramBreak();
#endif

    CriticalExit();
}
Beispiel #3
0
void STDCALL TraceCrashEnd()
{
    String strStackTrace = TEXT("\r\nException Fault - Stack Trace:");

    for(unsigned int i=0; i<TraceFuncList.Num(); i++)
    {
        if(i) strStackTrace << TEXT(" -> ");
        if(!(i%10)) strStackTrace << TEXT("\r\n    ");
        strStackTrace << TraceFuncList[i];
    }

    if(TraceFuncList.Num() == MAX_STACK_TRACE)
        strStackTrace << TEXT(" -> ...");

    String strOut = FormattedString(TEXT("%s\r\n"), strStackTrace.Array());

    OpenLogFile();
    LogFile.WriteAsUTF8(strOut, strOut.Length());
    LogFile.WriteAsUTF8(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBox(TEXT("Error: Exception fault - More info in the log file.\r\n\r\nMake sure you're using the latest verison, otherwise send your log to [email protected]"));

    TraceFuncList.Clear();
    CriticalExit();
}
Beispiel #4
0
   /* entry into Processor Low Power mode.                              */
void HCILL_Power_Lock(void)
{
   int Flags = 0;
   
   /* Enter a critical section to modify the HCILL Lock Count.          */
   CriticalEnter(&Flags);

   ++HCILL_Lock;

   /* Exit the critical region.                                         */
   CriticalExit(Flags);
}
Beispiel #5
0
   /* times.                                                            */
void HCILL_Decrement_Power_Lock(unsigned int Count)
{
   int Flags = 0;
   
   /* Enter a critical section to modify the HCILL Lock Count.          */
   CriticalEnter(&Flags);

   if(HCILL_Lock >= Count)
      HCILL_Lock -= Count;
   else
      HCILL_Lock = 0;
   
   /* Exit the critical region.                                         */
   CriticalExit(Flags);
}
Beispiel #6
0
   /* should Send HCILL_WAKEUP_IND followed by lowering RTS line.       */
int HCILL_HostInitWakeup(void)
{  
   int Flags   = 0;
   int ret_val = 0;
   
   /* Enter a critical section to modify the HCILL State.               */
   CriticalEnter(&Flags);
   
   /* Only change the state machine state if we are in sleep mode.      */
   if(HCILL_State == hsSleep)
   {
      HCILL_State = hsHostInitWakeup;
      ret_val     = 1;
   }
   
   /* Exit the critical region.                                         */
   CriticalExit(Flags);
   
   return (ret_val);
}
Beispiel #7
0
   /* in are not BT HCI related characters.                             */
HCILL_Action_Request_t HCILL_Process_Characters(unsigned char *Buffer,int Count,unsigned int *Processed)
{
   HCILL_Action_Request_t ret_val = haNone;
   int                    Done    = 0;
   int                    Index;
   int                    Flags;      

   /* Verify that the parameters seem semi-valid before continueing.    */
   if((Buffer) && (Count) && (Processed) && (IsHCILLCharacter(Buffer[0])))
   {
      /* Loop through all characters or until we have processed as many */
      /* characters as possible.                                        */
      for(Index = 0; (Index < Count) && (!Done); Index++)
      {
         switch(Buffer[Index])
         {
            case HCILL_GO_TO_SLEEP_IND:
               /* Enter a critical section to modify the HCILL State.   */
               CriticalEnter(&Flags);

               /* Ignore, this except in the Awake state.               */
               if(HCILL_State == hsAwake)
               {
                  /* Set that we are expecting to go to sleep.          */
                  HCILL_State = hsWaitSendSleepAck;

                  /* Exit the critical region.                          */
                  CriticalExit(Flags);

                  /* We should only receive HCILL_GO_TO_SLEEP_IND when  */
                  /* we awake, however we may have Type 2 collision in  */
                  /* which case this message should be ignored. If we   */
                  /* are in a correct state to receive it the caller    */
                  /* should send a HCILL_GO_TO_SLEEP_ACK.               */
                  ret_val = haSendSleepAck;                                  
               }
               else
               {
                  /* Exit the critical region.                          */
                  CriticalExit(Flags);
               }
               
               ++(*Processed);
               break;
            case HCILL_GO_TO_SLEEP_ACK:
               /* Error, controller should never send us an this        */
               /* because we never send HCILL_GO_TO_SLEEP_IND.          */
               Done = 1;
               break;
            case HCILL_WAKE_UP_IND:
               /* Enter a critical section to modify the HCILL State.   */
               CriticalEnter(&Flags);

               /* Handle Type 1 collisions, where the Host and          */
               /* Controller both trying to wake each other up.         */
               if(HCILL_State == hsHostInitWakeup)
               {
                  /* Return to the Awake state.                         */
                  HCILL_State = hsAwake;       
                                
                  /* Exit the critical region.                          */
                  CriticalExit(Flags);

                  /* We do not need to wait on HCILL_WAKEUP_ACK, thus   */
                  /* there there is nothing to do.                      */
                  ret_val = haNone;
               }
               else
               {
                  /* The only other time we should receive this is when */
                  /* we are in the sleep state and the controller is    */
                  /* attempting to wake us up.                          */   
                  if(HCILL_State == hsControllerInitWakeup)
                  {
                     /* Exit the critical region.                       */
                     CriticalExit(Flags);

                     /* Tell the caller to send a Wakeup                */
                     /* Acknowledgement.                                */
                     ret_val = haSendWakeupAck;
                  }
                  else
                  {
                     /* Exit the critical region.                       */
                     CriticalExit(Flags);
                  }
               }
               
               ++(*Processed);
               break;
            case HCILL_WAKE_UP_ACK:
               /* Enter a critical section to modify the HCILL State.   */
               CriticalEnter(&Flags);

               /* We are now awake.                                     */
               HCILL_State = hsAwake;

               /* Exit the critical region.                             */
               CriticalExit(Flags);

               /* Nothing to do on return, we are done.                 */
               ret_val = haNone;
               
               /* Credit the character as being processed.              */
               ++(*Processed);
               
               Done = 1;
               break;
            default:
               /* If we do not understand the character as an HCILL     */
               /* Command or Acknowledgement then we are done.          */
               Done = 1;
               break;
         }
      }
   }
   
   return(ret_val);
}