Beispiel #1
0
int main(void)
{
    wdt_disable();
    cli();

    DDRB=0xff;
    DDRC=0xff;
    // 36 kHz -- FIXME need normal name for this function.
    timer_load();//it used PORTD -- BIT 6

    // 200-600 us -- FIXME need nomral name for this function.
    frame_timer_load();
    recv_initialize();

   /// CODER (user, gid, gun, CRC)
   //         00111 011  0000 1010
   uint32_t st;
   st=0x3b0a;
   uint8_t msg[8];
   msg[3]=msg[4]=msg[5]=msg[6]=msg[7]=0;
   uint8_t  *code   = (uint8_t*)  &st;

   code2ir_shot(code, msg, 16);
   hitting(1,2,3,4);
   int i;
   /// CODER
    sei();
    do{
      //// Software interrupts
      // check recv buffer...
      i=8;
      while(i--){
        if((recv_mask[0]>>i)&1){
          if(recv[i*2]==0x3b){
            if(recv[i*2+1]==0x0a){
              cli();
                audi+=5;
                recv_mask[0]&=~(1<<i); // drop it bit
              sei();
            }
          }
        }
      }
      ///////////////////////////


      //led_code(0x00);
      cli();
      if(send_is_freely()==0){
        sei();
        led_code(i++);
        _delay_ms(500);
        //audi=3;
        cli();
        send_set_message(msg, 8);
      }
      sei();
    }while(1);
    return 0;
}
Beispiel #2
0
void play_note_delay(note_t *note)
{
	timer_load(TIMER_2, (1193181/note->freq));
	speaker_on();
	delay(note->dur);
	speaker_off();
}
Beispiel #3
0
void music_state_machine() {
	static int noteTime = 0;
	
	switch (state) {
		case OFF:
			break;
		case INIT:
			if (noteIndex >= song->lenght) {
				state = OFF;
				break;
			}
			
			Note *note = &song->notes[noteIndex++];
			noteTime = note->dur;
			timer_load(TIMER_2, TIMER_CLK / notes_frequency[note->freq]);
			speaker_on();
			state = PLAYING;
			break;
		case PLAYING:
			noteTime--;
			if (noteTime <= 0) {
				speaker_off();
				state = PAUSING;
				noteTime = song->pause;
			}
			break;
		case PAUSING:
			noteTime--;
			if (noteTime <= 0) {
				state = INIT;
			}				
	}
}
Beispiel #4
0
void play_note(Note *note)
{

timer_init(2,LCOM_MODE);
timer_load(2,musicDiv(note->freq));

speaker_on();
mili_sleep(note->dur);
speaker_off();

}
Beispiel #5
0
void platform_test_tick_cycles()
{
	/* Initialize the timer */
	const int load_value = 1000;
	int mhz_top, mhz_bot, temp;
	unsigned long timer_base =
		timer_secondary_base(PLATFORM_TIMER0_VBASE);
	int cyccnt;

	/* Make sure timer is disabled */
	timer_stop(timer_base);

	/* Load the timer with ticks value */
	timer_load(load_value, timer_base);

	/* One shot, 32 bits, no irqs */
	timer_init_oneshot(timer_base);

	/* Start the timer */
	timer_start(timer_base);

	/* Start counter */
	perfmon_reset_start_cyccnt();

	/* Wait until 0 */
	while (timer_read(timer_base) != 0)
		;

	cyccnt = perfmon_read_cyccnt();

	/* Fixed-point accuracy on bottom digit */
	temp = cyccnt * 64 * 10 / load_value;
	mhz_top = temp / 10;
	mhz_bot = temp - mhz_top * 10;

	//printk("Perfmon: %u cycles/%dMhz\n",
	//       cyccnt * 64, timer_load);
	printk("%s: %d.%d MHz CPU speed measured by timer REFCLK at 1MHz\n",
	       __KERNELNAME__, mhz_top, mhz_bot);
}