Example #1
0
void BlinkUSBStatus(void) {
  static WORD led_count = 0;

  if (led_count == 0)
    led_count = 10000U;
  led_count--;

#define mLED_Both_Off() \
  {                     \
    mLED_1_Off();       \
    mLED_2_Off();       \
  }
#define mLED_Both_On() \
  {                    \
    mLED_1_On();       \
    mLED_2_On();       \
  }
#define mLED_Only_1_On() \
  {                      \
    mLED_1_On();         \
    mLED_2_Off();        \
  }
#define mLED_Only_2_On() \
  {                      \
    mLED_1_Off();        \
    mLED_2_On();         \
  }

  if (USBSuspendControl == 1) {
    if (led_count == 0) {
      mLED_1_Toggle();
      if (mGetLED_1()) {
        mLED_2_On();
      } else {
        mLED_2_Off();
      }
    }
  } else {
    if (USBDeviceState == DETACHED_STATE) {
      mLED_Both_Off();
    } else if (USBDeviceState == ATTACHED_STATE) {
      mLED_Both_On();
    } else if (USBDeviceState == POWERED_STATE) {
      mLED_Only_1_On();
    } else if (USBDeviceState == DEFAULT_STATE) {
      mLED_Only_2_On();
    } else if (USBDeviceState == ADDRESS_STATE) {
      if (led_count == 0) {
        mLED_1_Toggle();
        mLED_2_Off();
      }
    } else if (USBDeviceState == CONFIGURED_STATE) {
      if (led_count < 100) {
        mLED_Both_On();
      } else {
        mLED_Both_Off();
      }
    }
  }
}
Example #2
0
void
nrf_send_frame (uint8_t * frame, int send_mode)
{
  int ret;
  if (mode != MODE_NOMODE)
    return;

  UART2PutStr ("sf\n\r");

  nrf_write_reg (R_CONFIG, R_CONFIG_PWR_UP | R_CONFIG_EN_CRC);

  NRF_CS_LOW ();
  mLED_2_On ();
  SPI2_xmit (C_W_TX_PAYLOAD);
  SPI2_transmit (frame, 32);
  mLED_2_Off ();
  NRF_CS_HIGH ();

  NRF_CE_HIGH ();
  while (1)
    {
      ret = nrf_read_reg (R_FIFO_STATUS);
      if (send_mode)
	{
	  if ((ret & R_FIFO_STATUS_TX_EMPTY) == R_FIFO_STATUS_TX_EMPTY)
	    break;
	}
      else
	{
	  if ((ret & R_FIFO_STATUS_TX_FULL) == 0)
	    break;
	}
    }
  NRF_CE_LOW ();
}
Example #3
0
/********************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs 
 *                  corresponding to the USB device state.
 *
 * Note:            mLED macros can be found in HardwareProfile.h
 *                  USBDeviceState is declared and updated in
 *                  usb_device.c.
 *******************************************************************/
void BlinkUSBStatus(void)
{
    static WORD led_count=0;
    
    if(led_count == 0)led_count = 10000U;
    led_count--;

    #define mLED_Both_Off()         {mLED_1_Off();mLED_2_Off();}
    #define mLED_Both_On()          {mLED_1_On();mLED_2_On();}
    #define mLED_Only_1_On()        {mLED_1_On();mLED_2_Off();}
    #define mLED_Only_2_On()        {mLED_1_Off();mLED_2_On();}

    if(USBSuspendControl == 1)
    {
        if(led_count==0)
        {
            mLED_1_Toggle();
            mLED_2 = mLED_1;        // Both blink at the same time
        }//end if
    }
    else
    {
        if(USBDeviceState == DETACHED_STATE)
        {
            mLED_Both_Off();
        }
        else if(USBDeviceState == ATTACHED_STATE)
        {
            mLED_Both_On();
        }
        else if(USBDeviceState == POWERED_STATE)
        {
            mLED_Only_1_On();
        }
        else if(USBDeviceState == DEFAULT_STATE)
        {
            mLED_Only_2_On();
        }
        else if(USBDeviceState == ADDRESS_STATE)
        {
            if(led_count == 0)
            {
                mLED_1_Toggle();
                mLED_2_Off();
            }//end if
        }
        else if(USBDeviceState == CONFIGURED_STATE)
        {
            if(led_count==0)
            {
                mLED_1_Toggle();
                mLED_2 = !mLED_1;       // Alternate blink                
            }//end if
        }//end if(...)
    }//end if(UCONbits.SUSPND...)

}//end BlinkUSBStatus
Example #4
0
void usb_tty_status(void) {

    static WORD led_count = 0;

    if (led_count == 0)led_count = 4U;
    led_count--;

    // verifica UCONbits.SUSPND
    if (USBSuspendControl == 1) {
        if (led_count == 0) {
                mLED_1_Toggle();
            if (mGetLED_1()) {
                mLED_2_On();
            } else {
                mLED_2_Off();
            }
        }
    } else {
            if (USBDeviceState == DETACHED_STATE) {
                mLED_Both_Off();
            } else if (USBDeviceState == ATTACHED_STATE) {
                mLED_Both_On();
            } else if (USBDeviceState == POWERED_STATE) {
                mLED_Only_1_On();
            } else if (USBDeviceState == DEFAULT_STATE) {
                mLED_Only_2_On();
            } else if (USBDeviceState == ADDRESS_STATE) {
                if (led_count == 0) {
                    mLED_1_Toggle();
                    mLED_2_Off();
                }
            } else if (USBDeviceState == CONFIGURED_STATE) {
            if (led_count == 0) {
                mLED_1_Toggle();
                if (mGetLED_1()) {
                    mLED_2_Off();
                } else {
                    mLED_2_On();
                }
            }
        }
    }
}
Example #5
0
void USB_blinkStatus(void) {
    static WORD led_count = 0;

    if (led_count == 0)led_count = 2000U; // Ajustado para USB low speed
    led_count--;

    if (USBSuspendControl == 1) {
        if (led_count == 0) {
            mLED_1_Toggle();
            if (mGetLED_1()) {
                mLED_2_On();
            } else {
                mLED_2_Off();
            }
        }//end if
    } else {
        if (USBDeviceState == DETACHED_STATE) {
            mLED_Both_Off();
        } else if (USBDeviceState == ATTACHED_STATE) {
            mLED_Both_On();
        } else if (USBDeviceState == POWERED_STATE) {
            mLED_Only_1_On();
        } else if (USBDeviceState == DEFAULT_STATE) {
            mLED_Only_2_On();
        } else if (USBDeviceState == ADDRESS_STATE) {
            if (led_count == 0) {
                mLED_1_Toggle();
                mLED_2_Off();
            }//end if
        } else if (USBDeviceState == CONFIGURED_STATE) {
            if (led_count == 0) {
                mLED_1_Toggle();
                if (mGetLED_1()) {
                    mLED_2_Off();
                } else {
                    mLED_2_On();
                }
            }//end if
        }//end if(...)
    }//end if(UCONbits.SUSPND...)

}//end BlinkUSBStatus
Example #6
0
/******************************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs corresponding to
 *                  the USB device state.
 *
 * Note:            mLED macros can be found in io_cfg.h
 *                  usb_device_state is declared in usbmmap.c and is modified
 *                  in usbdrv.c, usbctrltrf.c, and usb9.c
 *****************************************************************************/
void BlinkUSBStatus(void)
{
	static word led_count=0;
	static char startup_state=0xFF;
	
	if(led_count == 0)led_count = 10000U;
		led_count--;
	
	if(UCONbits.SUSPND == 1)
	{
		//USBWakeFromSuspend();
		if(led_count==0)
		{
			mLED_1_Off();
			mLED_2_Off();
			mLED_3_Toggle();
		}//end if
	}
	else
	{
		if(usb_device_state == DETACHED_STATE)
		{
			setLeds(1);
		}
		else if(usb_device_state == ATTACHED_STATE)
		{
			setLeds(2);
		}
		else if(usb_device_state == POWERED_STATE)
		{
			setLeds(4);
		}
		else if(usb_device_state == DEFAULT_STATE)
		{
			setLeds(2);
		}
		else if(usb_device_state == ADDRESS_STATE)
		{
			setLeds(LEDS_ON);
		}
		else if(usb_device_state == CONFIGURED_STATE)
		{
			startup_state=0;
		}
	}
}
Example #7
0
BOOL USER_USB_CALLBACK_EVENT_HANDLER(int event, void* pdata, WORD size) {
  switch (event) {
    case EVENT_TRANSFER:
      // Add application specific callback task or callback function here if
      // desired.
      break;
    case EVENT_SOF:
      break;
    case EVENT_SUSPEND:
      USBCBSuspend();
      break;
    case EVENT_RESUME:
      USBCBWakeFromSuspend();
      break;
    case EVENT_CONFIGURED:
      USBCBInitEP();
      break;
    case EVENT_SET_DESCRIPTOR:
      break;
    case EVENT_EP0_REQUEST:
      USBCBCheckOtherReq();
      break;
    case EVENT_BUS_ERROR:
      mLED_1_On();
      mLED_2_Off();
      break;
    case EVENT_TRANSFER_TERMINATED:
      // Add application specific callback task or callback function here if
      // desired.
      // The EVENT_TRANSFER_TERMINATED event occurs when the host performs a
      // CLEAR
      // FEATURE (endpoint halt) request on an application endpoint which was
      // previously armed (UOWN was = 1).  Here would be a good place to:
      // 1.  Determine which endpoint the transaction that just got terminated
      // was
      //    on, by checking the handle value in the *pdata.
      // 2.  Re-arm the endpoint if desired (typically would be the case for OUT
      //    endpoints).
      break;
    default:
      break;
  }
  return TRUE;
}
Example #8
0
//left (clear) shift FIFO
char emptyShiftInputCommandBuffer(void){
	char iterator = 0;
	char *dataMoveInputPointer  = headInputPointer;
	char shiftAmount = (char)(headInputPointer - commandInBuffer);
	char bytesToShift = (char)(tailInputPointer - headInputPointer);
	
	if (headInputPointer == tailInputPointer){
		flushInputCommandBuffer();	
		return fifoBufferStatusEmpty;
	}	 
	
	if (headInputPointer == commandInBuffer){	
		return fifoBufferStatusGood;
	}	 

	if (shiftAmount == 0) return fifoBufferStatusGood;
	
	//iffy statement
	headInputPointer = headInputPointer - bytesToShift;
	tailInputPointer = tailInputPointer - bytesToShift;
	
	for (iterator = 0; iterator < bytesToShift; iterator++){
		*(dataMoveInputPointer - shiftAmount) = *(dataMoveInputPointer);
		dataMoveInputPointer++;	
		
				if(iterator > 5){
						while (1){
						mLED_1_On();
						mLED_2_Off();
						Delay10KTCYx(1);
						mLED_2_On();
						mLED_1_Off();
						Delay10KTCYx(1);
						mLED_2_On();
						mLED_2_On();
						Delay10KTCYx(1);
						}
					}	
	}	
	
	return fifoBufferStatusGood;
}
Example #9
0
// Secondary callback function that gets called when the above
// control transfer completes for the USBHIDCBSetReportHandler()
void USBHIDCBSetReportComplete(void) {
  // 1 byte of LED state data should now be in the CtrlTrfData buffer.

  // Num Lock LED state is in Bit0.
  if (CtrlTrfData[0] & 0x01)  // Make LED1 and LED2 match Num Lock state.
  {
    mLED_1_On();
    mLED_2_On();
  } else {
    mLED_1_Off();
    mLED_2_Off();
  }

  // Stop toggling the LEDs, so you can temporily see the Num lock LED state
  // instead.
  // Once the g_usb_led_timer reaches 0, the LEDs will go back to showing USB
  // state instead.
  g_blink_status_valid = FALSE;
  g_usb_led_timer = 140000;
}
Example #10
0
// ****************************************************************************
// ************** USB Callback Functions **************************************
// ****************************************************************************
void USBCBSuspend(void) {
  // Example power saving code.  Insert appropriate code here for the desired
  // application behavior.  If the microcontroller will be put to sleep, a
  // process similar to that shown below may be used:

  // ConfigureIOPinsForLowPower();
  // SaveStateOfAllInterruptEnableBits();
  // DisableAllInterruptEnableBits();
  // EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMicro();  //should enable at
  // least USBActivityIF as a wake source
  // Sleep();
  // RestoreStateOfAllPreviouslySavedInterruptEnableBits();  //Preferrably, this
  // should be done in the USBCBWakeFromSuspend() function instead.
  // RestoreIOPinsToNormal();                  //Preferrably, this should be
  // done in the USBCBWakeFromSuspend() function instead.

  // Alternatively, the microcontorller may use clock switching to reduce
  // current consumption.
  // Configure device for low power consumption
  mLED_1_Off();
  mLED_2_Off();
  // Should also configure all other I/O pins for lowest power consumption.
  // Typically this is done by driving unused I/O pins as outputs and driving
  // them high or low.
  // In this example, this is not done however, in case the user is expecting
  // the I/O pins
  // to remain tri-state and has hooked something up to them.
  // Leaving the I/O pins floating will waste power and should not be done in a
  // real application.

  // Note: The clock switching code needed is processor specific, as the
  // clock trees and registers aren't identical accross all PIC18 USB device
  // families.
  // Sleep on sleep, 125kHz selected as microcontroller clock source
  OSCCON = 0x13;
  // IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here.  This bit
  // is
  // cleared inside the usb_device.c file.  Clearing USBActivityIF here will
  // cause
  // things to not work as intended.
}
Example #11
0
int
nrf_receive_poll (uint8_t * frame)
{
  uint8_t len;
  uint8_t status = 0;

  if (mode != MODE_RECEIVE_POLL)
    return (-1);

  status = nrf_cmd_status (C_NOP);

  if ((status & R_STATUS_RX_P_NO) == R_STATUS_RX_FIFO_EMPTY)
    {
      if ((status & R_STATUS_RX_DR) == R_STATUS_RX_DR)
	{
	  nrf_write_reg (R_STATUS, R_STATUS_RX_DR);
	};
      return 0;
    }

  nrf_read_long (C_R_RX_PL_WID, 1, &len);
  nrf_write_reg (R_STATUS, R_STATUS_RX_DR);

  if (len > 32)
    return -2;

  if (len < 1)
    return -1;

/*
  UART2PutHex (status);
  UART2PutStr ("  ");
 UART2PutHex (len);
   UART2PutStr ("\r\n");
*/
  mLED_2_On ();
  nrf_read_pkt (32, frame);
  mLED_2_Off ();
  return len;
}
Example #12
0
/********************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs 
 *                  corresponding to the USB device state.
 *
 * Note:            mLED macros can be found in HardwareProfile.h
 *                  USBDeviceState is declared and updated in
 *                  usb_device.c.
 *******************************************************************/
void led_off(void) {mLED_1_Off();mLED_2_Off();}
Example #13
0
/********************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs
 *                  corresponding to the USB device state.
 *
 * Note:            mLED macros can be found in HardwareProfile.h
 *                  USBDeviceState is declared and updated in
 *                  usb_device.c.
 *******************************************************************/
void BlinkUSBStatus(void)
{
    static WORD led_count=0;
    char a=0;

    if(led_count == 0)led_count = 10000U;
    led_count--;

#define mLED_Both_Off()         {mLED_1_Off();mLED_2_Off();}
#define mLED_Both_On()          {mLED_1_On();mLED_2_On();}
#define mLED_Only_1_On()        {mLED_1_On();mLED_2_Off();}
#define mLED_Only_2_On()        {mLED_1_Off();mLED_2_On();}
    a = is_clear();
    if(a=1)
    {
        mLED_3_On();
    } else {
        mLED_3_Off();
    }
    if(USBSuspendControl == 1)
    {
        if(led_count==0)
        {
            mLED_1_Toggle();
            if(mGetLED_1())
            {
                mLED_2_On();
            }
            else
            {
                mLED_2_Off();
            }
        }//end if
    }
    else
    {
        if(USBDeviceState == DETACHED_STATE)
        {
            mLED_Both_Off();
        }
        else if(USBDeviceState == ATTACHED_STATE)
        {
            mLED_Both_On();
        }
        else if(USBDeviceState == POWERED_STATE)
        {
            mLED_Only_1_On();
        }
        else if(USBDeviceState == DEFAULT_STATE)
        {
            mLED_Only_2_On();
        }
        else if(USBDeviceState == ADDRESS_STATE)
        {
            if(led_count == 0)
            {
                mLED_1_Toggle();
                mLED_2_Off();
            }//end if
        }
        else if(USBDeviceState == CONFIGURED_STATE)
        {
            if(led_count==0)
            {
                mLED_1_Toggle();
                if(mGetLED_1())
                {
                    mLED_2_Off();
                }
                else
                {
                    mLED_2_On();
                }
            }//end if
        }//end if(...)
    }//end if(UCONbits.SUSPND...)

}//end BlinkUSBStatus