Esempio n. 1
0
int libx52_set_led_state(libx52_device *x52, libx52_led_id led, libx52_led_state state)
{
    if (!x52) {
        return -EINVAL;
    }

    switch (led) {
    case LIBX52_LED_FIRE:
    case LIBX52_LED_THROTTLE:
        if (state == LIBX52_LED_STATE_OFF) {
            clr_bit(&x52->led_mask, led);
            set_bit(&x52->update_mask, led);
        } else if (state == LIBX52_LED_STATE_ON) {
            set_bit(&x52->led_mask, led);
            set_bit(&x52->update_mask, led);
        } else {
            /* Colors not supported */
            return -ENOTSUP;
        }
        break;

    default:
        /* All other LEDs support OFF, RED, AMBER and GREEN states
         * However, they are composed of individual RED and GREEN LEDs which
         * must be turned on or off individually.
         */
        switch (state) {
        case LIBX52_LED_STATE_OFF:
            clr_bit(&x52->led_mask, led + 0); // Red
            clr_bit(&x52->led_mask, led + 1); // Green
            break;

        case LIBX52_LED_STATE_RED:
            set_bit(&x52->led_mask, led + 0); // Red
            clr_bit(&x52->led_mask, led + 1); // Green
            break;

        case LIBX52_LED_STATE_AMBER:
            set_bit(&x52->led_mask, led + 0); // Red
            set_bit(&x52->led_mask, led + 1); // Green
            break;

        case LIBX52_LED_STATE_GREEN:
            clr_bit(&x52->led_mask, led + 0); // Red
            set_bit(&x52->led_mask, led + 1); // Green
            break;

        default:
            /* Cannot set the LED to "ON" */
            return -ENOTSUP;
        }

        /* Set the update mask bits */
        set_bit(&x52->update_mask, led + 0); // Red
        set_bit(&x52->update_mask, led + 1); // Green
        break;
    }

    return 0;
}
Esempio n. 2
0
void go_forward(void)
{
    int16 obstaculo = 0;

#ifdef sensorir    
    obstaculo = verificaObstaculo();
    if (obstaculo == 0) {
#endif        
        TIMER0_CLOCK_PRESCALER_64(); //frequencia de oscilacao de 1KHz
        TIMER0_COMPARE_A_CONFIGURE(255); //duty cycle 100%
        TIMER0_COMPARE_B_CONFIGURE(245); //duty cycle 100%
        clr_bit(MOTOR_SHIELD_DDR, MOTOR_INA); //seta a direcao como entrada INA
        clr_bit(MOTOR_SHIELD_DDR, MOTOR_INB); //seta a direcao como entrada INB
        set_bit(MOTOR_SHIELD_PORT, MOTOR_INA); //set_bit : sentido horario, clr_bit: sentido anti-horario
        set_bit(MOTOR_SHIELD_PORT, MOTOR_INB);
#ifdef DEBUG        
        printf("driving forward...\n");
#endif

#ifdef sensorir    

    } else if (obstaculo == 1) {
        go_idle();
        obstaculo = 0;
#ifdef DEBUG
        printf("obstacle, going idle to not crash...\n");
#endif
    }
#endif    
}
Esempio n. 3
0
int main() {
	spi_init_slave();

	//Ativa os dois sensores
	clr_bit(DDRD, SENSOR1);
	clr_bit(DDRD, SENSOR2);

	EICRA = (1 << ISC01) |(1 << ISC11); //interrupcoes no INT0 na borda de descida
	EIMSK = (1 << INT0); //habilita a interrupcao INT0
	TIMSK1 |= 1<<OCIE1A;
	TCCR1B |= (1 << WGM12) | (1 << CS12) | (1 << CS10);

	/*cada um segundo 7812
	 * 1000ms  7812
	 *   1 ms    x   = 8
	 */
	OCR1A= 8;

#if DEBUG
	uart_init();
	uart_sendSTR("Iniciou agente RPM\n");
#endif
	sei();
	while (1);
}
void BACKWARD()
{
	STOP();	
	set_bit(PORTC, IN1);
	clr_bit(PORTC, IN2);
	set_bit(PORTC, IN3);
	clr_bit(PORTC, IN4);
}
Esempio n. 5
0
void init_IO() {
	clr_bit(DDRC,PC0);
	clr_bit(PORTC,PC0);
	clr_bit(DDRC,PC1);
	clr_bit(PORTC,PC1);
	spi_init_slave();
	adc_init();
}
Esempio n. 6
0
void go_back(void)
{
    TIMER0_CLOCK_PRESCALER_64(); //frequencia de oscilacao de 1KHz
    TIMER0_COMPARE_A_CONFIGURE(255); //duty cycle 100%
    TIMER0_COMPARE_B_CONFIGURE(255); //duty cycle 100%
    set_bit(MOTOR_SHIELD_DDR, MOTOR_INA);
    set_bit(MOTOR_SHIELD_DDR, MOTOR_INB);
    clr_bit(MOTOR_SHIELD_PORT, MOTOR_INA); //inversao de sentido nas duas rodas
    clr_bit(MOTOR_SHIELD_PORT, MOTOR_INB);
#ifdef DEBUG
    printf("driving back...\n");
#endif
}
Esempio n. 7
0
int main() {

    bs_ptr bsptr;
   
    if (!(bsptr = bs_alloc(75))) {
       printf("Failed to create bitvector\n");
    }
   
    printf("Setting bits 0, 10, 21, 33, 50, 74\n");

    set_bit(bsptr, 0);
    set_bit(bsptr, 10);
    set_bit(bsptr, 21);
    set_bit(bsptr, 33);
    set_bit(bsptr, 50);
    set_bit(bsptr, 74);

    printf("Checking Values of bits 0, 10, 21, 33, 50, 74\n");

    printf("Value of bit 0: %d\n", get_bit(bsptr, 0));
    printf("Value of bit 10: %d\n", get_bit(bsptr, 10));
    printf("Value of bit 21: %d\n", get_bit(bsptr, 21));
    printf("Value of bit 33: %d\n", get_bit(bsptr, 33));
    printf("Value of bit 50: %d\n", get_bit(bsptr, 50));
    printf("Value of bit 74: %d\n", get_bit(bsptr, 74));

    printf("Checking Values of bits 1, 11, 22, 34, 51, 73\n");

    printf("Value of bit 1: %d\n", get_bit(bsptr, 1));
    printf("Value of bit 11: %d\n", get_bit(bsptr, 11));
    printf("Value of bit 22: %d\n", get_bit(bsptr, 22));
    printf("Value of bit 34: %d\n", get_bit(bsptr, 34));
    printf("Value of bit 51: %d\n", get_bit(bsptr, 51));
    printf("Value of bit 73: %d\n", get_bit(bsptr, 73));

    printf("Clearing bits 0, 21, 50\n");

    clr_bit(bsptr, 0);
    clr_bit(bsptr, 21);
    clr_bit(bsptr, 50);

    printf("Checking Values of bits 0, 10, 21, 33, 50, 74\n");

    printf("Value of bit 0: %d\n", get_bit(bsptr, 0));
    printf("Value of bit 10: %d\n", get_bit(bsptr, 10));
    printf("Value of bit 21: %d\n", get_bit(bsptr, 21));
    printf("Value of bit 33: %d\n", get_bit(bsptr, 33));
    printf("Value of bit 50: %d\n", get_bit(bsptr, 50));
    printf("Value of bit 74: %d\n", get_bit(bsptr, 74));
}
Esempio n. 8
0
void turn_right(void)
{
    TIMER0_CLOCK_PRESCALER_64(); //frequencia de oscilacao de 1KHz
    TIMER0_COMPARE_A_CONFIGURE(255); //duty cycle 100% 
    TIMER0_COMPARE_B_CONFIGURE(0); //duty cycle 25%        //volta mais rapida //era 25% = 64 ou 0 para ficar parado  //teste com 255, era 0 21/julho
    clr_bit(MOTOR_SHIELD_DDR, MOTOR_INA);
    clr_bit(MOTOR_SHIELD_DDR, MOTOR_INB);

    set_bit(MOTOR_SHIELD_PORT, MOTOR_INA); //roda de esquerda em sentido horario
    clr_bit(MOTOR_SHIELD_PORT, MOTOR_INB); //roda da direita no sentido anti-horario
#ifdef DEBUG
    printf("turning right...\n");
#endif
}
Esempio n. 9
0
void turn_left(void)
{
    TIMER0_CLOCK_PRESCALER_64(); //frequencia de oscilacao de 1KHz
    TIMER0_COMPARE_A_CONFIGURE(0); //duty cycle 25% //era 25% = 64 ou 0 para parar totalmente o motor  //teste com 255, era 0 21/julho
    TIMER0_COMPARE_B_CONFIGURE(255); //duty cycle 100% 
    clr_bit(MOTOR_SHIELD_DDR, MOTOR_INA);
    clr_bit(MOTOR_SHIELD_DDR, MOTOR_INB);

    clr_bit(MOTOR_SHIELD_PORT, MOTOR_INA); //roda de esquerda em sentido anti-horario
    set_bit(MOTOR_SHIELD_PORT, MOTOR_INB); //roda da direita no sentido horario
#ifdef DEBUG
    printf("turning left...\n");
#endif
}
Esempio n. 10
0
PUBLIC uint8_t i2c0_burst_read(uint8_t slaveAddr, uint8_t memAddr, uint16_t byteCount, uint8_t* data)
{
    i2c_start();
    i2cWriteByte(clr_bit(slaveAddr,0));
    
    
}
Esempio n. 11
0
BOOL CNameHttpCMD::OnExecuted()
{
    if (FALSE == m_bError)
    {
        return FALSE;
    }

    Json::Value root;
    Json::Reader reader;
    if( !reader.parse( m_strResult, root ) )
    {
        SYS_CRITICAL( _SDT( "json parse error, result:%s" ), m_strResult.c_str() );
        return FALSE;
    }

    //检测数据个数,如果为零刚为出错,防止崩溃
    if (!root.isObject())
    {
        SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
        return FALSE;
    }

    //解析返回的状态码
    INT32 nErrCode = 0;
    if (!root["errcode"].isInt())
    {
        SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
        return FALSE;
    }
	nErrCode = root["errcode"].asInt();
	if (0 != nErrCode)
	{
		SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
		return FALSE;
	}

    CPlayer *poPlayer = CPlayerMgr::Instance()->FindPlayer(stNameInfo.dwPlayerID);
    if(NULL == poPlayer)
    {
        SYS_CRITICAL(_SDT("[%s: %d]: player[playerid = %u] try to reg dispname[%s] fail!"), MSG_MARK, stNameInfo.dwPlayerID, stNameInfo.strName.c_str());
        return FALSE;
    }

    // 检测玩家是否是因为合区导致的昵称冲突而重新注册的,是的话要记录日志
    BOOL bNeedReRegDspName = (get_bit(poPlayer->GetExtData(), em_EDIT_NAME));
    if(bNeedReRegDspName)
    {
        //修改标志位
        clr_bit(poPlayer->GetExtData(), em_EDIT_NAME);

        CHAR szComment[256] = {0};
        SDSnprintf(szComment, sizeof(szComment) - 1, "[%s] - [%s]", stNameInfo.strOldName.c_str(), stNameInfo.strName.c_str());

        CRecordMgr::Instance()->RecordInfo(stNameInfo.dwPlayerID, ERM_PLAYER_OPERATE, CRecordMgr::EPO_RE_REG_NICK_NAME, 1, 1, 
            poPlayer->GetLevel(), poPlayer->GetDT_PLAYER_BASE_DATA().byVipLevel, 0, 0, 0, 0, szComment);
    }    

	return TRUE;
}
Esempio n. 12
0
static void rt_isr_event_entry(void* parameter)
{
	rt_err_t err;
	rt_uint32_t e;

	printf_syn("rt_isr_event_entry()\n");
	say_thread_start();

	while (1) {
		err = rt_event_recv(&isr_event_set
				, EVENT_BIT_NEED_RUN_TIM2_IRQ | EVENT_BIT_NEED_RUN_TIM4_IRQ | EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ
				, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e);

		if (RT_EOK != err) {
			printf_syn("recv isr event error(%d)", err);
		} else {
#if RT_USING_SI4432_MAC
			if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ)) {
				clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ);
				si4432_mac_exti_isr();
			}
#endif
#if RT_USING_ADE7880
			if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM4_IRQ)) {
				clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM4_IRQ);
#if 0 == ADE7880_USE_I2C_HSDC
 				tim4_isr();
#endif
			}
#endif
#if RT_USING_SI4432_MAC
			if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ)) {
				clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ);
				si4432_mac_exti_isr();
			}

			if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM2_IRQ)) {
				clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM2_IRQ);
				tim2_isr();
			}
#endif
		}
	}

	return;
}
Esempio n. 13
0
void light_func(uint8_t new_light) //latches Federal Signal circuit
{  //toggles based on state
   static uint8_t old_light;         
   if((new_light == 0) && (old_light !=0)){set_bit(PORTD, old_light); old_light = 0;} //turn light off
   else{
    if(old_light != new_light){set_bit(PORTD, old_light); clr_bit(PORTD, new_light); old_light = new_light;} //record which light is on
   } 
}
Esempio n. 14
0
/* ------------------------------------------------------------------------- */
void nrf24_setupPins()
{
    set_bit(RF_DDR,CE); // CE output
    set_bit(RF_DDR,CSN); // CSN output
    set_bit(RF_DDR,SCK); // SCK output
    set_bit(RF_DDR,MOSI); // MOSI output
    clr_bit(RF_DDR,MISO); // MISO input
}
/* ------------------------------------------------------------------------- */
void nrf24_setupPins()
{
    set_bit(DDRC,4); // CE output
    set_bit(DDRC,3); // CSN output

    set_bit(DDRC,2); // SCK output
    set_bit(DDRC,1); // MOSI output
    clr_bit(DDRC,0); // MISO input
}
Esempio n. 16
0
void GPIO_pin_outputBit(regPin *pin, uint8 flag)
{
    if(flag)
    {
        set_bit(*pin->out, pin->pin);
    }
    else
    {
        clr_bit(*pin->out, pin->pin);
    }
}
Esempio n. 17
0
void GPIO_outputBit(volatile uint8 *port, uint8 pino, uint8 UI8_flag)
{
    if(UI8_flag)
    {
        set_bit(*port, pino);
    }
    else
    {
        clr_bit(*port, pino);
    }
}
Esempio n. 18
0
/* ------------------------------------------------------------------------- */
void nrf24_csn_digitalWrite(uint8_t state)
{
	if(state)
	{
		set_bit(PORTB,0);
	}
	else
	{
		clr_bit(PORTB,0);
	}
}
Esempio n. 19
0
/* ------------------------------------------------------------------------- */
void nrf24_ce_digitalWrite(uint8_t state)
{
	if(state)
	{
		set_bit(PORTD,7);
	}
	else
	{
		clr_bit(PORTD,7);
	}
}
Esempio n. 20
0
/* ------------------------------------------------------------------------- */
void nrf24_csn_digitalWrite(uint8_t state)
{
    if(state)
    {
        set_bit(RF_PORT,CSN);
    }
    else
    {
        clr_bit(RF_PORT,CSN);
    }
}
Esempio n. 21
0
/* ------------------------------------------------------------------------- */
void nrf24_sck_digitalWrite(uint8_t state)
{
    if(state)
    {
        set_bit(RF_PORT, SCK);
    }
    else
    {
        clr_bit(RF_PORT,SCK);
    }
}
Esempio n. 22
0
/* ------------------------------------------------------------------------- */
void nrf24_mosi_digitalWrite(uint8_t state)
{
    if(state)
    {
        set_bit(RF_PORT,MOSI);
    }
    else
    {
        clr_bit(RF_PORT,MOSI);
    }
}
/* ------------------------------------------------------------------------- */
void nrf24_sck_digitalWrite(uint8_t state)
{
    if(state)
    {
        set_bit(PORTC,2);
    }
    else
    {
        clr_bit(PORTC,2);
    }
}
/* ------------------------------------------------------------------------- */
void nrf24_mosi_digitalWrite(uint8_t state)
{
    if(state)
    {
        set_bit(PORTC,1);
    }
    else
    {
        clr_bit(PORTC,1);
    }
}
Esempio n. 25
0
void GPIO_confDir(regGPIO *pin, PIN_DIR IODirection)
{
    if(IODirection)
    {
       //input
       set_bit(*pin->tris, pin->numPin);
    }
    else
    {
       //output
       clr_bit(*pin->tris, pin->numPin);
    }
}
Esempio n. 26
0
int bdealloc(int devId, int bno) {
	int  i;
	char buf[BLKSIZE];

	// read block_bitmap block
	get_block(devId, getBMap(devId), buf);
			 
	clr_bit(buf, bno - 1); //Account for indexing starting at 1
	updateFreeBlocks(devId, 1);

	put_block(devId, getBMap(devId), buf);
	
	return 0;
}
Esempio n. 27
0
int idealloc(int devId, int ino) {
	int  i;
	char buf[BLKSIZE];

	// read inode_bitmap block
	get_block(devId, getIMap(devId), buf);
			 
	clr_bit(buf,ino - 1);
	updateFreeInodes(devId, 1);

	put_block(devId, getIMap(devId), buf);

	return 0;
}
Esempio n. 28
0
int libx52_set_blink(libx52_device *x52, uint8_t state)
{
    if (!x52) {
        return -EINVAL;
    }

    if (state) {
        set_bit(&x52->led_mask, X52_BIT_POV_BLINK);
    } else {
        clr_bit(&x52->led_mask, X52_BIT_POV_BLINK);
    }

    set_bit(&x52->update_mask, X52_BIT_POV_BLINK);
    return 0;
}
Esempio n. 29
0
int libx52_set_shift(libx52_device *x52, uint8_t state)
{
    if (!x52) {
        return -EINVAL;
    }

    if (state) {
        set_bit(&x52->led_mask, X52_BIT_SHIFT);
    } else {
        clr_bit(&x52->led_mask, X52_BIT_SHIFT);
    }

    set_bit(&x52->update_mask, X52_BIT_SHIFT);
    return 0;
}
Esempio n. 30
0
/**
 * The UART 3 receive complete interrupt handler.
 * For efficiency, implement it in here instead of the default
 * generic handlers in uart.c to avoid losing time.
 */
ISR(USART3_RX_vect, ISR_BLOCK) {
    /* Display UART status on PORTH.
     * PH3: data overrun*/
    PORTH |= UCSR3A;

    if (rb_free_slots() < CTS_HIGH) {
        set_bit(PORTJ, CTS);
    }

    _rb_put(UDR3);

    if (_processing) {
        return;
    }

    _processing = true;

    /* Critical section done, reenable other interrupts.
     * If more speed is needed think about moving this further up still. */
    sei();

    uint8_t byte;
    uint8_t size;

    /* Disable interrupts while accessing ring buffer. */
    cli();
    while ((size = _rb_data_slots()) != 0) {
        _rb_get(&byte);
        sei();
        /* Putting the CTS code outside the critical section *should*
         * be ok since only one "thread" is in this section at a time and
         * if the flow control is set to off, we shouldn't be getting any
         * new data. If any bugs pop up though, let's keep this in mind. */
        if (size == CTS_LOW) {
            clr_bit(PORTJ, CTS);
        }
        _recv_callback(byte);
    }

    /* Disable interrupts while setting _processing flag.
     * Don't call sei() because that happens automatically when
     * returning from this. */
    cli();
    _processing = false;
}