Beispiel #1
0
void blinkLEDs(void)
{
   if (blink_mode == 0)
   {
      led1Toggle();
      led2Toggle();
      led3Toggle();
   }
   else if (blink_mode == 1)
   {
      switch(blink_state)
      {
         case 0:
            blink_state = 1;
            led1On(); led2Off(); led3On();
            break;
         case 1:
            blink_state = 0;
            led1Off(); led2On(); led3Off();
            break;
      }
   }
   else if (blink_mode == 2)
   {
      switch(blink_state)
      {
         case 0:
            blink_state = 1;
            led1Off(); led2Off(); led3Off();
            break;
         case 1:
            blink_state = 2;
            led1On(); led2Off(); led3Off();
            break;
         case 2:
            blink_state = 3;
            led1On(); led2On(); led3Off();
            break;
         case 3:
            blink_state = 0;
            led1On(); led2On(); led3On();
            break;
      }
   }
   
   IFS0bits.T1IF = 0;
}
Beispiel #2
0
void bounceThread2_start(void *arg) {
  message_t msg2;

  for(;;) {
    while (amRadioSend(AM_BROADCAST_ADDR, &msg2, 0, 22) == EBUSY) {}
    led2Off();

    if(amRadioReceive(&msg2, 5000, 22) == SUCCESS) {
      led2On();
    }

    tosthread_sleep(500);
  }
}
Beispiel #3
0
/********************************************************************
* Function: 	main()
********************************************************************/
INT main(void)
{
   DWORD count1 = 0;
   BYTE timer_ro = 1;

   // switch to FRC w/PLL to keep up at higher baud rates (120MHz!
   PLLFBD=63;
   CLKDIVbits.PLLPOST = 0;
   CLKDIVbits.PLLPRE = 0;

    __builtin_write_OSCCONH(0x01);
   __builtin_write_OSCCONL(OSCCON | 0x01);

   while (OSCCONbits.COSC != 0b001);
   while (OSCCONbits.LOCK != 1);

   // Initialize I/O, UART and timer (interrupt)
   initIO();

   led1Off();
   led2Off();
   led3Off();

   printString("BL:V1.00:");
   
   if (ValidAppPresent())
   {
      while(count1<20)
      {
         if ((SWITCH1 == 0) || (SWITCH2 == 0))  // if either switch gets released, start app
            JumpToApp();

         // Blink LEDs
         if (timer_ro)
         {
            if (TMR1 > 7000)
            {
               blinkLEDs();
               count1++;
               timer_ro = 0;
            }
         }
         else if (TMR1 < 7000)
            timer_ro = 1;
      }
      printString("PB:");
   }
   else
   {
      printString("NA:");                    // No app present, enter bootloader regardless
   }

   T1CONbits.TON = 0;
   PR1 = 50000;                              // slow down blinking
   T1CONbits.TON = 1;

   blink_mode = 1;

   // Be in loop till framework recieves "run application" command from PC
   while(!ExitFirmwareUpgradeMode()) 
   {
      uartTask();          // Run Transport layer tasks
      if(FrameWorkTask())  // Run frame work related tasks (Handling Rx frame, process frame and so on)
      {
         blink_mode = 2;   // If we've communicated with the PC, use progress flashing
      }

      // Blink LEDs
      if (timer_ro)
      {
         if (TMR1 > 25000)
         {
            if (SWITCH1 && (SWITCH2 == 0))   // reset the device on SWITCH1 press
               reset();
            
            blinkLEDs();
            timer_ro = 0;
         }
      }
      else if (TMR1 < 25000)
         timer_ro = 1;
   }
   
	JumpToApp();
	return 0;
}