void Dynamixel::begin(int baud) { //TxDString("[DXL]start begin\r\n"); afio_remap(AFIO_REMAP_USART1);//USART1 -> DXL afio_cfg_debug_ports(AFIO_DEBUG_FULL_SWJ_NO_NJRST); #ifdef BOARD_CM900 //Engineering version case gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP); gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP); gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable #else gpio_set_mode(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, GPIO_OUTPUT_PP); gpio_write_bit(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, 0 );// RX Enable #endif timer_set_mode(TIMER2, TIMER_CH1, TIMER_OUTPUT_COMPARE); timer_pause(TIMER2); uint16 ovf = timer_get_reload(TIMER2); timer_set_count(TIMER2, min(0, ovf)); timer_set_reload(TIMER2, 30000);//set overflow ovf = timer_get_reload(TIMER2); timer_set_compare(TIMER2, TIMER_CH1, min(1000, ovf)); timer_attach_interrupt(TIMER2, TIMER_CH1, TIM2_IRQHandler); timer_generate_update(TIMER2); timer_resume(TIMER2); dxl_initialize(0, baud); }
/* Transmit the frambuffer with buffersize number of bytes to the LEDs * buffersize = (#LEDs / 16) * 24 */ void neomaple_hard_send(uint8_t *buffer, uint32_t size) { // transmission complete flag, indicate that transmission is taking place WS2812_TC = 0; //WS2812_buffer = buffer; // clear all relevant DMA flags dma_clear_isr_bits(DMA1, DMA_CH2); dma_clear_isr_bits(DMA1, DMA_CH5); dma_clear_isr_bits(DMA1, DMA_CH7); // configure the number of bytes to be transferred by the DMA controller //dma_set_mem_addr(DMA1, DMA_CH5, WS2812_buffer); dma_set_num_transfers(DMA1, DMA_CH2, size); dma_set_num_transfers(DMA1, DMA_CH5, size); dma_set_num_transfers(DMA1, DMA_CH7, size); // clear all TIM2 flags TIMER2->regs.gen->SR = 0; // enable the corresponding DMA channels dma_enable(DMA1, DMA_CH2); dma_enable(DMA1, DMA_CH5); dma_enable(DMA1, DMA_CH7); // IMPORTANT: enable the TIM2 DMA requests AFTER enabling the DMA channels! timer_dma_enable_req(TIMER2, 1); timer_dma_enable_req(TIMER2, 2); timer_dma_enable_req(TIMER2, 0); /* TIM_DMA_Update */ // preload counter with 29 so TIM2 generates UEV directly to start DMA transfer timer_set_count(TIMER2, 29); // start TIM2 timer_resume(TIMER2); }
void speaker_setCount(uint16 val) { uint16 ovf = speaker_getOverflow(); //Selects the minimum of the two uint16 result = ((val)<(ovf)?(val):(ovf)); timer_set_count(SPEAKER_TIMER, result); }
/*------------------------------------------------------------------------- VBL timer callback. Called every screen at y = 240 Input: Timer Pointer to the timer that triggered the callback. Data Data associated with the timer. ---------------------------------------------------------------------------*/ void neogeo_VBL_callback ( TIMER *Timer, Uint32 Data ) { /* Handle NEOGEO_HBL_CTRL_VBLANK_LOAD */ if ( neogeo_HIRQ_control & NEOGEO_HIRQ_CTRL_VBLANK_LOAD ) { timer_set_count ( &neogeo_HIRQ_timer, neogeo_VBL_timer.Count + PIXEL_TO_REF ( neogeo_HIRQ_register + 1 ) ); timer_set_state ( &neogeo_HIRQ_timer, TIMER_ACTIVE ); } /* Set / Clear full throttle mode according to disk activity */ if ( ( ( neogeo_cdrom_irq_mask & 0x500 ) == 0x500 ) && ( neogeo_cdrom_read_in_progress ) && ( !neogeo_cdrom_paused ) && ( neogeo_cdrom_current_track == 1 ) && ( neogeo_fullthrottle_enable ) ) { if ( neogeo_run_mode == NEOGEO_RUN_NORMAL ) neogeo_set_runmode ( NEOGEO_RUN_FULL_THROTTLE ); } else { if ( neogeo_run_mode == NEOGEO_RUN_FULL_THROTTLE ) { /* If full throttle is enabled, flush the sound buffer to avoid a delay in the sound */ if ( neogeo_fullthrottle_enable ) { SDL_mutexP ( audio_buffer_mutex ); audio_buffer_init ( &audio_buffer ); SDL_mutexV ( audio_buffer_mutex ); } neogeo_set_runmode ( NEOGEO_RUN_NORMAL ); neogeo_speed_limiter_setup(); } } /* Set VBL IRQ to run */ neogeo_VBL_irq_pending = 1; neogeo_update_interrupts(); timer_arm_relative ( &neogeo_VBL_timer, PIXEL_TO_REF ( NEOGEO_SCREEN_WIDTH * NEOGEO_SCREEN_HEIGHT ) ); }
void HardwareTimer::setCount(uint16 val) { uint16 ovf = this->getOverflow(); timer_set_count(this->dev, min(val, ovf)); }
static void neogeo_controller1_write_word ( Uint32 Address, Uint32 Data ) { timer_set_count ( &neogeo_watchdog_timer, M68K_TO_REF ( WATCHDOG_TIMER_DELAY ) ); }