示例#1
0
static void runTX(char c1, char c2, char c3, char c4)
{
  // Initialize packet buffer of size PKTLEN + 1
  uint8 txBuffer[PKTLEN+1] = {0};

   P2SEL &= ~0x40; // P2SEL bit 6 (GDO0) set to one as default. Set to zero (I/O)
  // connect ISR function to GPIO0, interrupt on falling edge
  trxIsrConnect(GPIO_0, FALLING_EDGE, &radioRxTxISR);

  // enable interrupt from GPIO_0
  trxEnableInt(GPIO_0);

	// create a random packet with PKTLEN + 2 byte packet counter + n x random bytes
	createPacket(txBuffer, c1, c2, c3, c4);

  // write packet to tx fifo
  cc11xLSpiWriteTxFifo(txBuffer,sizeof(txBuffer));

  // strobe TX to send packet
  trxSpiCmdStrobe(CC110L_STX);

	// wait for interrupt that packet has been sent.
	// (Assumes the GPIO connected to the radioRxTxISR function is set
	// to GPIOx_CFG = 0x06)
	while(!packetSemaphore);

	// clear semaphore flag
	packetSemaphore = ISR_IDLE;

  halLedToggle(LED1);
   __delay_cycles(250000);
   halLedToggle(LED1);
}
示例#2
0
/***********************************************************************************
* @fn          halAssertHandler
*
* @brief       Logic to handle an assert.
*
* @param       none
*
* @return      none
***********************************************************************************
*/
void halAssertHandler(void)
{
    // execute code that handles asserts 
    // blink all leds
    while(TRUE){
        halLedToggle(1);
        halLedToggle(2);
        halLedToggle(3);
        halLedToggle(4);
        halMcuWaitMs(50);
    }
}
示例#3
0
文件: Atmega.c 项目: openwsn/node
void led_toggle(char)
{
    switch (Ledno)
    {
    case "LED_RED":
        halLedToggle(1);
    case "LED_YELLOW":
        halLedToggle(2);
    case "LED_GREEN":
        halLedToggle(3);
    }
}
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the RF HID application. It sets
*              distinct short addresses for the nodes, initalises and runs
*              receiver and sender tasks sequentially in an endless loop.
*
* @return      none
*/
void main(void)
{

    // Initialise board peripherals
    halBoardInit();

    // Initialise USB
    usbHidInit();

    // Initialize MRFI
    mrfiLinkInit(DONGLE_ADDRESS,EB_ADDRESS,MRFI_CHANNEL);

    // Indicate that the device is initialised
    halLedSet(1);

    //  Main processing loop
    while (TRUE) {

        // Process USB standard requests
        usbHidProcessEvents();

        // Process incoming radio traffic from HID devices
        if (mrfiLinkDataRdy()) {

            uint8 numBytes;

            // Receive RF packet
            numBytes = mrfiLinkRecv(pRfData);

            // If reception successful, ACK it and send packet to host over USB
            if(numBytes>0) {

                if (pRfData[0]==KEYBOARD_DATA_ID && numBytes==KEYBOARD_DATA_SIZE) {
                    // Process keyboard data
                    usbHidProcessKeyboard(pRfData);
                    halLedToggle(1);
                }

                if (pRfData[0]==MOUSE_DATA_ID && numBytes==MOUSE_DATA_SIZE) {
                    // Process mouse data
                    usbHidProcessMouse(pRfData);
                    halLedToggle(1);
                }

            }

        }

    }

}
示例#5
0
void DrumSet()
{
  Intitialize_Drumset();
  while(1)
  {
    if(P0 & 0x3F)
    {
      tmp_port = P0;
      for(inn=0;inn<6;inn++)
      {
        if((tmp_port>>inn) & 0x01)
           break;
      }
      if(inn<6 && timerID_DR[inn] == TimerId_INVALID)
      {
         timerID_DR[inn] = SetTimerReq(&Drum_ISR,200);
         halLedToggle(1);
         P0IFG &= ~(1<<inn);
         Capture_DR[inn] = 0;
      }
    }

    if(Print_Flag == 1)
    {
      tx1_send(tx1_buf,3);
      Print_Flag = 0;
    }
  }
/***********************************************************************************
* @fn      waitForTouch
*
* @brief  Wait for Touch on Screen
*
* @param   none
*
* @return  none
*/
void waitForTouch(void)
{
	setTouchDrives();
	if((P0 & YP)) {                       // Y+ high?
	P0IFG = 0;                             // Clear interrupt flags
	PICTL |= 1;
	while(P0IFG == 0);  //__bis_SR_register(LPM4_bits + GIE);     // Wait for interrupt
	}
	halLedToggle(1);
	clearDrives();                            // Clear drive wires
}
示例#7
0
/***********************************************************************************
* @fn          appRfSenderTask
*
* @brief       Checks if new bytes have arrived from the UART. If there
*              are enough bytes to fill a maximal sized packet, or if the UART
*              is idle, the  bytes are transmitted on the air.
*
* @param       none
*
* @return      none
*/
static void appRfSenderTask(void)
{
    uint8 nBytes;
    uint8 payloadLength;
    uint8 bytesToRead;

    nBytes = halUartGetNumRxBytes();
    payloadLength= 0;
    bytesToRead= 0;

    if(nBytes >= APP_PAYLOAD_LENGTH || (appUartRxIdle && nBytes>0) ) {
        // Signal PC not to send on UART, while sending on air.
        halUartEnableRxFlow(FALSE);
        // Wait for PC to respond
        halMcuWaitUs(1000);

        bytesToRead = MIN(nBytes, APP_PAYLOAD_LENGTH);
        halUartRead(pTxData,bytesToRead);
        payloadLength+= bytesToRead;

        halLedToggle(3);
        if( (mrfiLinkSend(pTxData, payloadLength,N_RETRIES)) != MRFI_TX_RESULT_SUCCESS) {
            nTxErr++;
            appUpdateDisplay();
        }

        // Signal RX flow on
        halUartEnableRxFlow(TRUE);

        // Restart idle timer
        halTimer32kRestart();
        halTimer32kIntEnable();
        // Reset idle fimer flag
        appUartRxIdle = FALSE;
    }
}