Beispiel #1
0
uchar ispFlushPage(unsigned long address, uchar pollvalue) 
{
  ISP_transmit(0x4C);
  ISP_transmit(address >> 9);
  ISP_transmit(address >> 1);
  ISP_transmit(0);


  if (pollvalue == 0xFF) {
    TIMER_delay(5);
    return 0;
  } else {

    // polling flash 
    uchar retries = 30;
	TIMER_start(1);


    while (retries != 0) {
      if (ispReadFlash(address) != 0xFF) {
	return 0;
      };

      if (TIMER_timeout == 0) 
	    {
   	      TIMER_start(1);
	      retries --;
        }
    }

    return 1; // error 
  }
}
Beispiel #2
0
uchar ispWriteFlash(unsigned long address, uchar data, uchar pollmode) 
{
  ISP_transmit(0x40 | ((address & 1) << 3));
  ISP_transmit(address >> 9);
  ISP_transmit(address >> 1);
  ISP_transmit(data);

  if (pollmode == 0)
    return 0;

  if (data == 0x7F) {
    TIMER_delay(5); // wait 4,8 ms 
    return 0;
  } else {

    // polling flash 
    uchar retries = 30;
	TIMER_start(1);
    while (retries != 0) {
      if (ispReadFlash(address) != 0x7F) {
	return 0;
      };
      
      if (TIMER_timeout == 0) 
	    {
   	      TIMER_start(1);
	      retries --;
        }

    }
    return 1; // error 
  }
}
Beispiel #3
0
int main(void)
{
    extern uchar usbNewDeviceAddr;
    uint8_t i;
//Reconnect USB
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i)
        _delay_ms(2);
    usbDeviceConnect();
    usbInit();
    sei();

    leds[LED_RED].frequency = LED_ON;
    LED_init();
    for (i=0; i<3; i++)
        TIMER_delay(250);
    leds[LED_RED].frequency = LED_OFF;
    leds[LED_GREEN].frequency = 1;


    while(1)
    {
        if (TIMER_timeout == 0)
        {
            if(usbNewDeviceAddr)
                leds[LED_BLUE].frequency = LED_ON;
            PORTD ^= (1<<PD7);
            TIMER_start(1);
            usbPoll();
            LED_poll();
        }
    }
}
//每一分钟超时处理函数
static void cup_timer_timeout_handler( void* inContext )
{
    cup_obj *pCpuTimeObj;
    pCpuTimeObj = (cup_obj *)inContext;

    pCpuTimeObj->unitTimes ++;
    if (pCpuTimeObj->unitTimes == pCpuTimeObj->drinkTime)
    {
        printf("go to drink++++++++++++++\r\n");
        mico_rtos_set_semaphore(&pCpuTimeObj->playMp3_sem);  //通知播放音乐
        mico_rtos_set_semaphore(&pCpuTimeObj->playLed_sem);  //通知亮LED灯
        TIMER_start();
    }
}
Beispiel #5
0
int main(void)
{
  extern uchar usbNewDeviceAddr;
  PORTC |= (1<<PC2);
  uint8_t i;
//Reconnect USB
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 0;
  while(--i)
     _delay_ms(2);
  usbDeviceConnect();
  usbInit();
  sei();


  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;

  CHANNELDDR1 &= ~((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELPORT1 |= ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELDDR2 &= ~((1 << CHANNEL_5) | (1 << CHANNEL_6));
  CHANNELPORT2 |= ((1 << CHANNEL_5) | (1 << CHANNEL_6));

  uint8_t tmp1,tmp1_old; 
  uint8_t tmp2,tmp2_old;
  while(1)
    {
      if (TIMER_timeout == 0)
        {
          if(usbNewDeviceAddr)
            leds[LED_BLUE].frequency = LED_ON;
          TIMER_start(49);
          usbPoll();
          LED_poll();
        }
      tmp1 = CHANNELPIN1; 
      tmp2 = CHANNELPIN2;
	  if ((tmp1 != tmp1_old) || (tmp2 != tmp2_old))
//      if (((channel1trigger & tmp1) == channel1trigger) || ((channel2trigger & tmp2) == channel2trigger))
        {
		  buffer[buffer_put++] = (tmp1 & ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4)))
		                        +(tmp2 & ((1 << CHANNEL_5) | (1 << CHANNEL_6))); 
	    }
      tmp1_old = tmp1; 
      tmp2_old = tmp2; 
	}
}
/* user main function, called by AppFramework after system init done && wifi
 * station on in user_main thread.
 */
OSStatus user_main( app_context_t * const app_context )
{
    OSStatus err = kNoErr;
    int time_sencond = 50*1000;  /* 60s */


    require(app_context, exit);
    net_init(app_context);

    /* Create a new thread */

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "RGB_LED", LED_handleThread, 1024, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the RGB LED thread ." );

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MP3_PLAY", MP3_handleThread, 1024, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the MP3 PLAY thread" );

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "BAT_DETECT", BAT_handleThread, 500, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the BAT DETECT thread ." );

    KEY_Init(KEY_irq_handler); //按键初始化

    mico_rtos_init_semaphore(&cupTimeObj.playMp3_sem, 1);  //信号量初始化
    mico_rtos_init_semaphore(&cupTimeObj.playLed_sem, 1);
    mico_rtos_init_semaphore(&cupTimeObj.stopLed_sem, 1);

    err = mico_init_timer(&cupTimeObj.cup_timer, time_sencond, cup_timer_timeout_handler, (void *)&cupTimeObj);
    cupTimeObj.drinkTime = 1;
    cupTimeObj.playMode = PLAY_MP3_LED;
    if (KEY_getValue() == KEY_DOWN)
    {
        TIMER_start(); //启动定时喝水
    }

    while(1)
    {
        // printf("this is main thread.\r\n");
        //net_test(app_context);
        mico_thread_sleep(10);
    }

exit:
    if(kNoErr != err) {
        printf("ERROR: user_main thread exit with err=%d", err);
    }
    mico_rtos_delete_thread(NULL);
    return kNoErr;
}
//提杯和放杯处理函数
static void  KEY_irq_handler( void* arg )
{
    (void)(arg);

    if ( KEY_getValue() == KEY_UP)
    {
        printf("key up!\r\n");
        TIMER_stop();
    }
    else
    {
        TIMER_start();
        printf("key down!\r\n");
    }

}
int main(void)
{
  extern uchar usbNewDeviceAddr;
  uint8_t i,j;
  PORTC |= (1<<PC2);
  /* activate pull-ups except on USB lines */
  USB_CFG_IOPORT   = (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));
  /* all pins input except USB (-> USB reset) */
#ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
  USBDDR    = 0;    /* we do RESET by deactivating pullup */
  usbDeviceDisconnect();
#else
  USBDDR    = (1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT);
#endif
  j = 0;
  while(--j){          /* USB Reset by device only required on Watchdog Reset */
      i = 0;
      while(--i);      /* delay >10ms for USB reset */
  }
#ifdef USB_CFG_PULLUP_IOPORT
  usbDeviceConnect();
#else
  USBDDR    = 0;      /*  remove USB reset condition */
#endif
  usbInit();
  sei();

  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;

  while(1)
    {
      if (TIMER_timeout == 0)
        {
          if(usbNewDeviceAddr)
            leds[LED_BLUE].frequency = LED_ON;
          TIMER_start(10);
          usbPoll();
          LED_poll();
		  KEY_pol();
        }
	}
}
Beispiel #9
0
int main(void)
{
  extern uchar usbNewDeviceAddr;
  uint8_t i;
//Reconnect USB
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 0;
  while(--i)
     _delay_ms(2);
  usbDeviceConnect();
  usbInit();
  sei();


  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;
  leds[LED_GREEN].frequency = LED_ON;

  //Input with pullups
  CHANNELDDR1 &= ~((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELPORT1 |= ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELDDR2 &= ~((1 << CHANNEL_5) | (1 << CHANNEL_6));
  CHANNELPORT2 |= ((1 << CHANNEL_5) | (1 << CHANNEL_6));
  
  //Preset data with actual pin states
  DATA = 0;
  if (CHANNELPIN1 & (1<<CHANNEL_1))
    DATA = 1;
  if (CHANNELPIN1 & (1<<CHANNEL_2))
    DATA = 2;
  if (CHANNELPIN1 & (1<<CHANNEL_3))
    DATA = 4;
  if (CHANNELPIN1 & (1<<CHANNEL_4))
    DATA = 8;
  if (CHANNELPIN2 & (1<<CHANNEL_5))
    DATA = 16;
  if (CHANNELPIN2 & (1<<CHANNEL_6))
    DATA = 32;
  
  //Set actual Pinstates as Output
  CHANNELPORT1 = CHANNELPIN1;
  CHANNELPORT2 = CHANNELPIN2;
  CHANNELDDR1 |= ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELDDR2 |= ((1 << CHANNEL_5) | (1 << CHANNEL_6));
  

  while(1)
    {
      if (TIMER_timeout == 0)
        {
          if(usbNewDeviceAddr)
            leds[LED_BLUE].frequency = LED_ON;
          TIMER_start(10);
          usbPoll();
          LED_poll();
        }
	}
}