예제 #1
0
파일: led.c 프로젝트: Tpimp/elevatorpic32
void LED_CLOSE_BLOCKED_SEQUENCE(void)
{
    static short LED_CURRENT_STATE;
    LED_CURRENT_STATE = 0;
    while(LED_CURRENT_STATE >= 0)
    {
        CLEAR_AND_START_TIMER3();
        if(xSemaphoreTake(TIMER3_RDY, portMAX_DELAY))
        {
            switch(LED_CURRENT_STATE)
            {
            case 0: {
                TURN_ON_LED(2);
                LED_CURRENT_STATE++;
                break;
            }
            case 1: {
                TURN_ON_LED(1);
                LED_CURRENT_STATE++;
                break;
            }
            case 2: {
                TURN_OFF_LED(1);
                LED_CURRENT_STATE++;
                break;
            }
            case 3: {
                TURN_ON_LED(1);
                LED_CURRENT_STATE++;
                break;
            }
            case 4: {
                TURN_OFF_LED(1);
                LED_CURRENT_STATE++;
                break;
            }
            case 5: {
                TURN_OFF_LED(2);
                LED_CURRENT_STATE++;
                break;
            }
            default:
            {
                T3CONbits.ON = 0;
                IFS0bits.T3IF = 0;
                LED_CURRENT_STATE = -1;
                TMR3 = 0;
                break;
            }
            }
        }
    }
    vTaskDelete(NULL);
}
예제 #2
0
파일: led.c 프로젝트: Tpimp/elevatorpic32
void NextIteration(void)
{
    switch(LED_CURRENT_VALUE)
    {
    case 0: {
        TURN_OFF_LED(1);
        LED_CURRENT_VALUE++;
        break;
    }
    case 1: {
        TURN_OFF_LED(0);
        TURN_OFF_LED(2);
        LED_CURRENT_VALUE++;
        break;
    }
    case 2:
    {}
    case 3:
    {}
    case 4:
    {}
    case 5:
    {}
    case 6:
    {}
    case 7:
    {
        LED_CURRENT_VALUE++;
        break;
    }
    case 8: {
        TURN_ON_LED(0);
        TURN_ON_LED(2);
        LED_CURRENT_VALUE++;
        break;
    }
    case 9: {
        TURN_ON_LED(1);
        LED_CURRENT_VALUE++;
        break;
    }
    default:
    {
        T3CONbits.ON = 0;
        LED_CURRENT_VALUE = 0;
        TMR3 = 0;
        break;
    }

    }
}
예제 #3
0
파일: led.c 프로젝트: Tpimp/elevatorpic32
void LED_CLOSE_SEQUENCE(void)
{
    static short LED_CURRENT_STATE;
    LED_CURRENT_STATE = 2;
    while(LED_CURRENT_STATE >= 0)
    {
        CLEAR_AND_START_TIMER3();
        // Sleep until TIMER 3 is ready
        if(xSemaphoreTake(TIMER3_RDY, portMAX_DELAY))
        {
            switch(LED_CURRENT_STATE)
            {
            case 0:
            {}
            case 1:
            {}
            case 2: {
                TURN_ON_LED(LED_CURRENT_STATE);
                LED_CURRENT_STATE--;
                break;
            }
            default:
            {
                LED_CURRENT_STATE = -1;
                break;
            }
            }
        }
    }
    vTaskDelete(NULL);
}
예제 #4
0
INT LED_Blink(PMINI_ADAPTER Adapter, UINT GPIO_Num, UCHAR uiLedIndex, ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate)
{
	int Status = STATUS_SUCCESS;
	BOOLEAN bInfinite = FALSE;

	/*Check if num_of_time is -ve. If yes, blink led in infinite loop*/
	if(num_of_time < 0)
	{
		bInfinite = TRUE;
		num_of_time = 1;
	}
	while(num_of_time)
	{

		if(currdriverstate == Adapter->DriverState)
			TURN_ON_LED(GPIO_Num, uiLedIndex);

		/*Wait for timeout after setting on the LED*/
		Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event, 
					currdriverstate != Adapter->DriverState || kthread_should_stop(),
					msecs_to_jiffies(timeout));

		if(kthread_should_stop())
		{
			BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
			Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
			TURN_OFF_LED(GPIO_Num, uiLedIndex);
			Status=EVENT_SIGNALED;
			break;
		}
		if(Status)
		{
			TURN_OFF_LED(GPIO_Num, uiLedIndex);
			Status=EVENT_SIGNALED;
			break;
		}
		
		TURN_OFF_LED(GPIO_Num, uiLedIndex);
		Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
					currdriverstate!= Adapter->DriverState || kthread_should_stop(),
					msecs_to_jiffies(timeout));
		if(bInfinite == FALSE)
			num_of_time--;
	}
	return Status;
}
예제 #5
0
파일: led.c 프로젝트: Tpimp/elevatorpic32
/*******************************************************************
| led_drive - takes three parameters and performs 1 of
| four commands on an led sensor:
|           1.Read LED current state
|           2&3.SET LED ON or OFF
|           4.TOGGLE the LED state
| Parameters:
|   lednum: a value between 0 and 2 PORTD<2-0>
|   cmd: a value between 0 and 2 indicating which command
|   LED_ON: Default is off (0) for LED_ON value, will be used with
|       SET command (1).
| Return: return_value indicates if the command request was
|       successful and if it wasn't, why not.
*******************************************************************/
short led_drive(int lednum, int cmd, int LED_ON)
{
    short return_value;
    return_value = -1;
    // switch on the current command
    switch(cmd)
    {
    case 0: // READ the value for return
    {
        return_value =  READ_LED_STATE(lednum);
        break;
    }
    case 1: // set the led on or off
    {
        if(LED_ON)
        {
            // SET LED_ON
            TURN_ON_LED(lednum);
        }
        else
        {
            // SET LED_OFF
            TURN_OFF_LED(lednum);
        }
        return_value = 2; // return success
        break;
    }
    case 2: // TOGGLE the bits
    {
        // Toggle LED_ON/LED_OFF
        TOGGLE_LED(lednum);
        return_value = 2; // return success
        break;
    }
    // return invalid cmd
    default : {
        return_value = INVALID_LED_COMMAND;
        break;
    }
    }
    return return_value; // EXIT drive_led with return status
}
예제 #6
0
INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx, 
		UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex, LedEventInfo_t currdriverstate)
{
	/* Initial values of TX and RX packets*/
	ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0; 
	/*values of TX and RX packets after 1 sec*/
	ULONG64 Final_num_of_packts_tx = 0, Final_num_of_packts_rx = 0; 
	/*Rate of transfer of Tx and Rx in 1 sec*/
	ULONG64 rate_of_transfer_tx = 0, rate_of_transfer_rx = 0; 
	int Status = STATUS_SUCCESS;
	INT num_of_time = 0, num_of_time_tx = 0, num_of_time_rx = 0;
	UINT remDelay = 0;
	BOOLEAN bBlinkBothLED = TRUE;
	//UINT GPIO_num = DISABLE_GPIO_NUM;
	ulong timeout = 0;
	
	/*Read initial value of packets sent/received */
	Initial_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount);
	Initial_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount);
	/*Scale the rate of transfer to no of blinks.*/
	num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
	num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx);

	while((Adapter->device_removed == FALSE))
	{
		#if 0
		if(0 == num_of_time_tx && 0 == num_of_time_rx)
		{
			timeout = 1000;
			Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
				currdriverstate!= Adapter->DriverState || kthread_should_stop(), 
				msecs_to_jiffies (timeout));
			if(kthread_should_stop())
			{
				BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
				Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
				return EVENT_SIGNALED;
			}
			if(Status)
				return EVENT_SIGNALED;
			
		}
		#endif
		
		timeout = 50;
		#if 0
		/*Turn on LED if Tx is high bandwidth*/
		if(num_of_time_tx > MAX_NUM_OF_BLINKS)
		{
			TURN_ON_LED(1<<GPIO_Num_tx, uiTxLedIndex);
			num_of_time_tx = 0;
			bBlinkBothLED = FALSE;
			num_of_time = num_of_time_rx;
		}
			/*Turn on LED if Rx is high bandwidth*/
		if(num_of_time_rx > MAX_NUM_OF_BLINKS)
		{
			TURN_ON_LED(1<<GPIO_Num_rx, uiRxLedIndex);
			num_of_time_rx = 0;
			bBlinkBothLED = FALSE;
			num_of_time = num_of_time_tx;
		}
		#endif
		/*Blink Tx and Rx LED when both Tx and Rx is in normal bandwidth*/
		if(bBlinkBothLED)
		{
			/*Assign minimum number of blinks of either Tx or Rx.*/
			if(num_of_time_tx > num_of_time_rx)
				num_of_time = num_of_time_rx;
			else
				num_of_time = num_of_time_tx;
			if(num_of_time > 0)
			{
				/*Blink both Tx and Rx LEDs*/
				if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout, num_of_time,currdriverstate) 
							== EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}
				if(LED_Blink(Adapter, 1<<GPIO_Num_rx, uiRxLedIndex, timeout, num_of_time,currdriverstate) 
							== EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}

			}

			if(num_of_time == num_of_time_tx)
			{
				/*Blink pending rate of Rx*/
				if(LED_Blink(Adapter, (1 << GPIO_Num_rx), uiRxLedIndex, timeout, 
						num_of_time_rx-num_of_time,currdriverstate) == EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}
				num_of_time = num_of_time_rx;
			}
			else
			{
				/*Blink pending rate of Tx*/
				if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout, 
					num_of_time_tx-num_of_time,currdriverstate) == EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}
				num_of_time = num_of_time_tx;
			}
		}
		else
		{
			if(num_of_time == num_of_time_tx)
			{
				/*Blink pending rate of Rx*/
				if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout, num_of_time,currdriverstate) 
							== EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}
			}
			else
			{
				/*Blink pending rate of Tx*/
				if(LED_Blink(Adapter, 1<<GPIO_Num_rx, uiRxLedIndex, timeout, 
						num_of_time,currdriverstate) == EVENT_SIGNALED)
				{
					return EVENT_SIGNALED;
				}
			}
		}
		/* If Tx/Rx rate is less than maximum blinks per second, 
			 * wait till delay completes to 1 second
			 */
		remDelay = MAX_NUM_OF_BLINKS - num_of_time;
		if(remDelay > 0)
		{
			timeout= 100 * remDelay;
			Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
						currdriverstate!= Adapter->DriverState ||kthread_should_stop() , 
						msecs_to_jiffies (timeout));

			if(kthread_should_stop())
			{
				BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
				Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
				return EVENT_SIGNALED;
			}
			if(Status)
				return EVENT_SIGNALED;
		}
		
		/*Turn off both Tx and Rx LEDs before next second*/
		TURN_OFF_LED(1<<GPIO_Num_tx, uiTxLedIndex);
		TURN_OFF_LED(1<<GPIO_Num_rx, uiTxLedIndex);
		
		/* 
 		 * Read the Tx & Rx packets transmission after 1 second and 
 		 * calculate rate of transfer
 		 */
		Final_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount);
		rate_of_transfer_tx = Final_num_of_packts_tx - Initial_num_of_packts_tx;
		Final_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount);
		rate_of_transfer_rx = Final_num_of_packts_rx - Initial_num_of_packts_rx;

		/*Read initial value of packets sent/received */
		Initial_num_of_packts_tx = Final_num_of_packts_tx;
		Initial_num_of_packts_rx = Final_num_of_packts_rx ;

		/*Scale the rate of transfer to no of blinks.*/
		num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
		num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
		
	}
	return Status;
}