Ejemplo n.º 1
0
//!  Checks Target Vdd  - Updates Target Vdd LED & status
//!
//!  Updates \ref cable_status
//!
uint8_t bdm_checkTargetVdd(void) {
#if (HW_CAPABILITY&CAP_VDDSENSE)
   if (bdm_targetVddMeasure() > VDD_2v) {
      RED_LED_ON();
      if (bdm_option.targetVdd == BDM_TARGET_VDD_OFF)
         cable_status.power = BDM_TARGET_VDD_EXT;
      else
         cable_status.power = BDM_TARGET_VDD_INT;
   }
   else {
      RED_LED_OFF();
      if (bdm_option.targetVdd == BDM_TARGET_VDD_OFF)
         cable_status.power = BDM_TARGET_VDD_NONE;
      else {
    	 // Possible overload
         cable_status.power = BDM_TARGET_VDD_ERR;
         VDD_OFF();
      }
   }
#else
   // No target Vdd sensing - assume external Vdd is present
   cable_status.power = BDM_TARGET_VDD_EXT;
#endif // CAP_VDDSENSE
   if ((cable_status.power == BDM_TARGET_VDD_NONE) ||
       (cable_status.power == BDM_TARGET_VDD_ERR))
      return BDM_RC_VDD_NOT_PRESENT;
   return BDM_RC_OK;
}
Ejemplo n.º 2
0
int main(void)
{
	int8_t i;
	
	rc_init();
	rfm70_init(RFM70_MODE_PTX, rfm70_addr);
	RED_LED_OUT();
	RED_LED_OFF();
	sei();
	
	while(1) {
		rc_get_code(&code);
		//RED_LED_TOGGLE();
		
		tx_buf[0] = code.addr;
		tx_buf[1] = code.data;
#if 0		
		for(i = 7; i >= 0; i--)
		{
			if(code.data & (1 << i)) {
				RED_LED_ON();
				_delay_ms(50);
				RED_LED_OFF();
				_delay_ms(50);
			}
			RED_LED_ON();
			_delay_ms(50);
			RED_LED_OFF();
			_delay_ms(50);
				
			_delay_ms(500);
		}
#endif
	
		if(0 == rfm70_transmit_packet(tx_buf,sizeof(tx_buf))) {
			RED_LED_TOGGLE();
		}	

	
		_delay_ms(70);
	
	}
}
Ejemplo n.º 3
0
void core1_main(void)
{
    //asm volatile ("mov sp,%0" : :"r" (ram1));
    
    while(1)
    {
        for(j=0; j < 300000; j++); //wait for some time
        RED_LED_ON();
        for(j=0; j < 300000; j++); //wait for some time
        RED_LED_OFF();
    }
}
Ejemplo n.º 4
0
void Receive_Packet(void)
{
	UINT8 i, len, chksum = 0; 
	
	RFM73_Receive_Packet(rx_buf, &len);
	
	for(i=0;i<16;i++)
	{
		chksum +=rx_buf[i]; 
	}
	if(chksum==rx_buf[16]&&rx_buf[0]==0x30)
	{
		/* Packet received correctly */
		RED_LED_ON();
		_delay_ms(50);
		RED_LED_OFF();
	}
}
Ejemplo n.º 5
0
usbMsgLen_t	usbFunctionWrite(uint8_t *data, uint8_t len)
{
	if(ledState == data[0]) { /* same value as present */
		return 1; 
	}
	else {
		ledState = data[0];
	}
	/* LED for Capslock */
	if(ledState & 0x2) {
		RED_LED_ON();
	} 
	else {
		RED_LED_OFF();
	}
	
	return 1;
}
Ejemplo n.º 6
0
int main(void)
{
	power_on_delay();  
 	timer0_init();
	RED_LED_OUT();
	RED_LED_OFF();

	if(rfm70_init(RFM70_MODE_PRX, addr) != 0) {
		RED_LED_ON();
	}

	sei();   // enable interrupts globally
	rfm70_set_ack_payload(RFM70_PIPE0, ack_pld, sizeof(ack_pld));
	while(1)
	{
		Receive_Packet();
	}
}
Ejemplo n.º 7
0
void Receive_Packet(void)
{
	uint8_t i, len, chksum = 0; 
	
	rfm70_receive_packet(rx_buf, &len);
	if(len == 0) { /* No packet received */
		return;
	}
		
	for(i=0;i<16;i++)
	{
		chksum +=rx_buf[i]; 
	}
	if(chksum==rx_buf[16]&&rx_buf[0]==0x30)
	{	
		/* set ack payload */
		rfm70_set_ack_payload(RFM70_PIPE0, ack_pld, sizeof(ack_pld));
		
		/* Packet received correctly */
		RED_LED_ON();
		_delay_ms(50);
		RED_LED_OFF();
	}
}
Ejemplo n.º 8
0
void StackEventHandler(uint32 event,void *eventParam)
{
    
    switch(event)
	{
        
		case CYBLE_EVT_STACK_ON:
            //Starting Advertisement as soon as Stack is ON
             apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            if (apiResult == CYBLE_ERROR_OK)
            {
                printf ("Starting Advertisement\r\n");
            }
            else
            {
                printf ("Error Start Adv %d\r\n",apiResult);
            }
            break;
            
        case CYBLE_EVT_TIMEOUT:
         if( CYBLE_GAP_ADV_MODE_TO ==*(uint16*) eventParam)
            {
                printf ("Advertisement TimedOut\r\n");
                apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
                if (apiResult != CYBLE_ERROR_OK)
                {
                    printf ("\nRestarting  Advertisement\r\n");
                }
            }
		
		case CYBLE_EVT_GATT_DISCONNECT_IND:
			/* Red LED Glows when device is disconnected */
            RED_LED_ON ();
            break;
            
        case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
            printf ("Disconnected \r\n");
            // Starting Advertisent again when there is disconnection
            apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            if (apiResult != CYBLE_ERROR_OK)
            {
                printf ("\nRestarting  Advertisement\r\n");
            }
            break;
            
			
		case CYBLE_EVT_GAP_DEVICE_CONNECTED:
            printf ("\n\r Connection Established \r\n");
            //Blue LED glows when device is connected
            BLUE_LED_ON ();
            break;

		
		case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
         // This Event is received when advertisement is started or stopped.
            if (CyBle_GetState() == CYBLE_STATE_ADVERTISING)
            {
                printf("Advertising...\r\n");
                //Green LED Indicates that Advertisement is going on.
                GREEN_LED_ON();
            }
            else
            {
                RED_LED_ON();
                printf ("Advertisement Stopped \r\n");
                if (AddRequest == 1)
                {
                    AddRequest = 0;
                    // Adding the Device to whitelist
                    apiResult = CyBle_GapAddDeviceToWhiteList(&whitelistdeviceaddress); 
                                
                    if(apiResult == CYBLE_ERROR_INVALID_PARAMETER)
					{
						printf ("Adding to Whitelist Failed. Invalid parameter \r\n");
                    }
                    else if   (apiResult ==CYBLE_ERROR_INVALID_OPERATION)
                    {
                        printf ("Invalid Operation \r\n");
                    }
                    else if (apiResult ==CYBLE_ERROR_INSUFFICIENT_RESOURCES)
                    {
                      printf ("Adding to Whitelist Failed. List already full \r\n");
                    }
                    else if (apiResult ==CYBLE_ERROR_DEVICE_ALREADY_EXISTS)
                    {
                        printf ("Device Already exists \r\n");
                    }
                    else if (apiResult == CYBLE_ERROR_OK)
                    {
                        //Copying the address to the BackUp Array
                        whitelistdeviceaddressBackup[Index] = whitelistdeviceaddress; 
                        Index++;
                        printf ("Device Added to WhiteList\r\n");
                        printf ("Press A to Add or R to remove a from Whitelist \r\n");
                    }
                    
                    // Restarting the advertisement
                    apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        printf ("Restarting Advertisement \r\n");
                        GREEN_LED_ON ();
                    }
                    else
                    {
                        printf ("Error Start Adv %d \r\n",apiResult);
                    }
                }
                if (DelRequest == 1)
                {
                    DelRequest = 0;
                    //Removing the Device from Whitelist
                    apiResult = CyBle_GapRemoveDeviceFromWhiteList 
                    (&whitelistdeviceaddressBackup[RemoveIndex]);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        
                        uint8 j;
                        for (j = RemoveIndex; j<Index - 1; j++)
                        {
                            whitelistdeviceaddressBackup[j] = 
                            whitelistdeviceaddressBackup[j+1];
                        }
                        Index--;
                                                                                                                      
                        printf ("Device %d Removed from Whitelist\r\n",RemoveIndex + 1);
                        printf ("Press A to Add a Device or R to remove a device\r\n");
                    }
                    else if (apiResult == CYBLE_ERROR_NO_DEVICE_ENTITY)
                    {
                        printf ("No Such Device Exists. Press A to Add a Device or R to remove\r\n");
                    }
                    else 
                    {
                        printf ("Error: Operation cannot be performed");
                        printf ("Press A to Add a Device or R to remove\r\n");
                    }
                    //re-starting Advertisement
                    apiResult = CyBle_GappStartAdvertisement (CYBLE_ADVERTISING_FAST);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        printf ("Restarting Advertisement\r\n");
                    }
                    else
                    {
                        printf ("Restarting Advertisement Failed\r\n");
                    }
                }
            }
            
		default:
			break;
	}
}
Ejemplo n.º 9
0
int main()
{
  
    /* Initializing all the Flags and Indexes to 0 */
    ALL_LED_OFF ();
    Count = 0;
    Index = 0;
    AddRequest = 0;
    DelRequest = 0;

    CyGlobalIntEnable;  /* Comment this line to disable global interrupts. */
    
    /* Start BLE component and register Event handler function */	
    CyBle_Start(StackEventHandler);
	

    /* Start UART Component which is used for receiving inputs and Debugging */
    UART_Start();

	printf("BLE WhiteList Example \r\n");
    printf("Press A to add a Device to WhiteList. R to remove the Device from Whitelist \r\n");

    /* Continuous loop scans for inputs from UART Terminal and accordingly 
    handles Addition to and Removal from Whitelist. Also processes
    BLE events */
    
    for(;;)
    {
        //Checks the internal task queue in the BLE Stack
        CyBle_ProcessEvents();
        
        if(UART_SpiUartGetRxBufferSize())
		{
		   	UartRxDataSim = UART_UartGetChar();
            if (UartRxDataSim == 'A' || UartRxDataSim == 'a')  // The user has to Enter D for disconnection 
            {
                printf ("Enter the Address of the Device. Press Z to Go Back \r\n");
                for (;;)
                {
                    if (Count ==12)
                    {
                        //If the user had entered the full address, stop advertisement
                        //for addition process
                        CyBle_GappStopAdvertisement ();
                        /*Once We stop advertisement, the 
                        CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked.
                         After this, the API for adding the device to whitelist is invoked
                        in the StackEventHandler*/
                        RED_LED_ON ();
                        AddRequest = 1;
                        printf ("\r\n");
                        printf ("Address is 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",
                                whitelistdeviceaddress.bdAddr[5],
                                whitelistdeviceaddress.bdAddr[4],
                                whitelistdeviceaddress.bdAddr[3],
                                whitelistdeviceaddress.bdAddr[2],
                                whitelistdeviceaddress.bdAddr[1],
                                whitelistdeviceaddress.bdAddr[0]);
                        printf ("Attempting to Add to whitelist \r \n");
                        Count = 0; 
                        break;
                    }
                    
                    if(UART_SpiUartGetRxBufferSize())
                    {
                        UartRxDataSim = UART_UartGetChar();
                        if (UartRxDataSim == 'Z' || UartRxDataSim == 'z')  
                        {
                            Count = 0;
                            printf("Press A to add a Device to WhiteList \r\n");
                            break;
                        }
                       
                        else
                        {
                            if ((UartRxDataSim >= '0') && (UartRxDataSim <= '9' ))
                            {
                                AddrNibble = UartRxDataSim - '0';
                                UART_UartPutChar (UartRxDataSim);
                            }
                            else if ((UartRxDataSim >= 'A') && (UartRxDataSim <= 'F' ))
                            {
                                AddrNibble = UartRxDataSim - 'A' + 0xA;
                                UART_UartPutChar (UartRxDataSim);
                            }
                             else if ((UartRxDataSim >= 'a') && (UartRxDataSim <= 'f' ))
                            {
                                AddrNibble = UartRxDataSim - 'a' + 0xA;
                                UART_UartPutChar (UartRxDataSim);
                            }
                            else 
                            {
                                printf ("\nplease Enter a Valid Address. Press A to Enter a New Address. R ro remove the Device\r\n");
                                Count = 0;
                                break;
                            }
                            
                            //Receiving the addresss Nibble by Nibble
                            whitelistdeviceaddress.bdAddr[5 - (Count/2)] =
                            (whitelistdeviceaddress.bdAddr[5 - (Count/2)]<<4)|AddrNibble;
                            Count ++;
                        }
                    }
                }
            }
            
            else if (UartRxDataSim == 'R' || UartRxDataSim == 'r')
            {
                if (Index == 0)
                {
                    printf ("No Devices in WhiteList. press A to Add \r\n");
                   
                }
                else
                {
                    printf (" The List of Devices are given below \4\n");
                    uint8 i = 0;
                    // Retrieving the list of added devices for user to choose
                    for (i = 0; i< Index; i++)
                    {
                        printf ("Device %d 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",i + 1,
                            whitelistdeviceaddressBackup[i].bdAddr[5],
                            whitelistdeviceaddressBackup[i].bdAddr[4],
                            whitelistdeviceaddressBackup[i].bdAddr[3],
                            whitelistdeviceaddressBackup[i].bdAddr[2],
                            whitelistdeviceaddressBackup[i].bdAddr[1],
                            whitelistdeviceaddressBackup[i].bdAddr[0]);
                    }
                    printf ("Enter the Index of the device to be removed. Press Z to go back \r\n");
                    
                    for (;;)
                    {
                        if(UART_SpiUartGetRxBufferSize())
                        {
                            UartRxDataSim = UART_UartGetChar();
                            if (UartRxDataSim == 'Z' || UartRxDataSim == 'z')  
                            {
                                printf("Press A to add a Device to WhiteList. R to remove \r\n");
                                break;
                            }
                            else if (UartRxDataSim >= '1' || UartRxDataSim <= '0' + Index)
                            {
                                RemoveIndex = UartRxDataSim - '1';
                                if(RemoveIndex < Index)
                                {
                                    CyBle_GappStopAdvertisement ();
                                /*Once We stop advertisement, the 
                                CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked.
                                After this, the API for removing the device from whitelist 
                                is invoked in the StackEventHandler*/
                                    DelRequest = 1;
                                    break;
                                }
                                else
                                {
                                    printf("There is no device with that number.\r\n");
                                }
                            }
                            else 
                            {
                                printf ("Invaid Index. Press A to Add and R to remove a Device");
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}