Пример #1
0
static void CheckButton(void) {
	uint32_t val;

  val = GPIO_DRV_ReadPinInput(BUTTON_SW2);
  if (val==0) { /* SW2 pressed! */
	  nofButtonPresses++;
	  whichLED <<= 1;
	  if (whichLED>LED_COLOR_BLUE) {
		  whichLED = LED_COLOR_RED; /* back to red */
	  }
	  while(GPIO_DRV_ReadPinInput(BUTTON_SW2)==0) {
		  /* wait until button is released */
	  }
  }
  val = GPIO_DRV_ReadPinInput(BUTTON_SW3);
  if (val==0) { /* SW3 pressed! */
	  nofButtonPresses++;
	  whichLED >>= 1;
	  if (whichLED==0) {
		  whichLED = LED_COLOR_BLUE;
	  }
	  while(GPIO_DRV_ReadPinInput(BUTTON_SW3)==0) {
		  /* wait until button is released */
	  }
  }
Пример #2
0
// Connect green led to gsm netlight pin
uint16_t get_green_signal(uint32_t charging_state)
{
	if(charging_state)
	{
		return GPIO_DRV_ReadPinInput(SIM808_NETLIGHT)*GREEN_LED_BATTERY_DUTY;
	}
	else
	{
		return GPIO_DRV_ReadPinInput(SIM808_NETLIGHT)*GREEN_LED_CHARGING_DUTY;
	}
}
Пример #3
0
void led_main_task(void *param)
{
	xSemaphore_lp_state_indicator = xSemaphoreCreateMutex();
	if(xSemaphoreTake(xSemaphore_lp_state_indicator, 0))
	{
		lp_state_red_indicator = MODULE_POWERED_OFF;
		xSemaphoreGive( xSemaphore_lp_state_indicator );
	}

	while(true)
	{
		TPM1_C0V = get_red_signal(GPIO_DRV_ReadPinInput(LTC4065_CHRG));
		TPM1_C1V = get_green_signal(GPIO_DRV_ReadPinInput(LTC4065_CHRG));

		vTaskDelay(MS_DELAY/portTICK_RATE_MS); /* wait for 250 ms */
	}
}
Пример #4
0
static void AppTaskStart (void *p_arg)
{
  OS_ERR err;
  CPU_ERR cpu_err;
  uint32_t value;
  static uint32_t pulse_flag = 0;
  CPU_TS64 before, after;
  char tmp[80];
    
  (void)p_arg;

  CPU_Init();
  Mem_Init();
  Math_Init();

  BSP_Ser_Init(115200u);

    while (DEF_ON) {
        GPIO_DRV_TogglePinOutput( outPTB23 );
        value = GPIO_DRV_ReadPinInput( inPTB9 );
        if( value ){
            if(pulse_flag == 0)
                before = CPU_TS_Get64();    // in cpu_cfg.h must set: #define  CPU_CFG_TS_64_EN DEF_ENABLED
            pulse_flag = 1;
            GPIO_DRV_ClearPinOutput( BOARD_GPIO_LED_BLUE );
        }
        else{
            GPIO_DRV_SetPinOutput( BOARD_GPIO_LED_BLUE );
            if(pulse_flag == 1)
            {
                after = CPU_TS_Get64();     // see comment above
                sprintf( tmp, "Elapsed time in Task R = %f s\n\r", (float)((1.0*(after-before))/CPU_TS_TmrFreqGet( &cpu_err )) );
                APP_TRACE_DBG(( tmp ));
            }
            pulse_flag = 0;
        }
        OSTimeDlyHMSM(0u, 0u, 0u, 200u, OS_OPT_TIME_HMSM_STRICT, &err);
        
    }
}
Пример #5
0
void PORTA_IRQHandler(void)
{
    /* Clear interrupt flag.*/
    PORT_HAL_ClearPortIntFlag(PORTA_BASE_PTR);

    if (GPIO_DRV_ReadPinInput(g_switch1.pinName)) {
        TPM_DRV_PwmStop(0, &param, 3);
        PIT_DRV_StopTimer(0, 0);
    } else {
        position = 0;
        PIT_DRV_StartTimer(0, 0);
    }

    if (GPIO_DRV_ReadPinInput(g_switch2.pinName)) {
        LPUART_DRV_AbortSendingData(1);
        laser_on = 0;
    } else {
        laser_on = 1;
    }

    if (!GPIO_DRV_ReadPinInput(g_switchUp.pinName)) {
        txBuff[0] = 'R';
    }
    if (!GPIO_DRV_ReadPinInput(g_switchLeft.pinName)) {
        txBuff[0] = 'G';
    }
    if (!GPIO_DRV_ReadPinInput(g_switchRight.pinName)) {
        txBuff[0] = 'B';
    }
    if (!GPIO_DRV_ReadPinInput(g_switchDown.pinName)) {
        txBuff[0] = 'T';
    }
    if (!GPIO_DRV_ReadPinInput(g_switchSelect.pinName)) {
        cue_next_image = 1;
    }
}
Пример #6
0
/*TASK*-----------------------------------------------------
* 
* Task Name    : sdcard_task
* Comments     : Open device and install MFS on device
*    
*
*END*-----------------------------------------------------*/
void sdcard_task(void)
{ /* Body */
   int                          dev_fd = -1, a_fd = -1;
   bool                         inserted = FALSE, last = FALSE;
   int32_t                      error_code;
   uint32_t                     isFormatted = 0;
   int                          esdhc_handle = -1;
   char                         partman_name[] = "pm:";
   char                         partition_name[] = "pm:1";
   int                          partition_handle;
   SDCARD_INIT_STRUCT           sdcard_init_data;
   LWSEM_STRUCT                 lwsem;

   /* Create and post card detection semaphore */
   if( _lwsem_create(&lwsem, 0) != MQX_OK ){
       printf("\nlwsem create failed!");
       _task_block();
   }
   if( _lwsem_post(&lwsem) != MQX_OK ){
       printf("\nlwsem post failed!");
       _task_block();
   }

#ifdef BOARD_SDHC_GPIO_INSTANCE
   configure_gpio_pins(GPIO_EXTRACT_PORT(BOARD_SDHC_GPIO_INSTANCE));
#endif

   /* initialize SDHC pins */
   configure_sdhc_pins(BOARD_SDHC_INSTANCE);

   /* install SDHC low-level driver */
   _nio_dev_install("esdhc:", &nio_esdhc_dev_fn, (void*)&_bsp_esdhc_init, NULL);

   /* get an instance of the SDHC driver */
   esdhc_handle = open("esdhc:", 0);

   if(esdhc_handle < 0)
   {
      printf("\nCould not open esdhc!");
      _task_block();
   }

   /* prepare init data structure */
   sdcard_init_data.com_dev = esdhc_handle;
   sdcard_init_data.const_data = (SDCARD_CONST_INIT_STRUCT_PTR)&sdcard_esdhc_init_data;

   /* install device */
   if (_nio_dev_install("sdcard:", &nio_sdcard_dev_fn, (void*)&sdcard_init_data, NULL) == NULL)
   {
   /* Number of sectors is returned by ioctl IO_IOCTL_GET_NUM_SECTORS function */
   /* If another disc structure is desired, use MFS_FORMAT_DATA structure to   */
   /* define it and call standart format function instead default_format       */   
      printf("\nError installing memory device");
      _task_block();
   } /* Endif */

   /* install isr for card detection handling and initialize gpio pin */
   _int_install_isr(g_portIrqId[GPIO_EXTRACT_PORT(CDET_PIN->pinName)], card_detect_isr, &lwsem);   
   GPIO_DRV_InputPinInit(CDET_PIN);

   for(;;){

     /* Wait for card insertion or removal */
     if( _lwsem_wait(&lwsem) != MQX_OK ){
       printf("\nlwsem_wait failed!");
       _task_block();
     }

     /* Check if card is present */
     if(CDET_PIN->config.pullSelect == kPortPullDown)
         inserted = GPIO_DRV_ReadPinInput(CDET_PIN->pinName);
     else
         inserted = !GPIO_DRV_ReadPinInput(CDET_PIN->pinName);

     if(last != inserted){
       last = inserted;

       /* Card detection switch debounce delay */
       _time_delay(100);

       if(inserted)
       {
         /* Open the device which MFS will be installed on */
         dev_fd = open("sdcard:", O_RDWR);
         if ( dev_fd <= 0 ) {
              printf("\nUnable to open SDCARD device");
              _task_block();
         } /* Endif */

         /* Install partition manager over SD card driver */
         error_code = _io_part_mgr_install(dev_fd, partman_name, 0);
         if (error_code != MFS_NO_ERROR)
         {
             printf("Error installing partition manager: %s\n", MFS_Error_text((uint32_t)error_code));
             _task_block();
         }

         /* Open partition */
         partition_handle = open(partition_name, O_RDWR);
         if (partition_handle >= 0)
         {
             printf("Installing MFS over partition...\n");
        
             /* Validate partition */
             error_code = ioctl(partition_handle, IO_IOCTL_VAL_PART, NULL);
             if (error_code != MFS_NO_ERROR)
             {
                 printf("Error validating partition: %s\n", MFS_Error_text((uint32_t)error_code));
                 printf("Not installing MFS.\n");
                 _task_block();
             }

             /* Install MFS over partition */
             error_code = _io_mfs_install(partition_handle, "a:", 0);
             if (error_code != MFS_NO_ERROR)
             {
                 printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint32_t)error_code));
             }

         } else
         {
           printf("Installing MFS over SD card driver...\n");
            
           /* Install MFS over SD card driver */
           error_code = _io_mfs_install(dev_fd, "a:", (_file_size)0);
           if (error_code != MFS_NO_ERROR)
           {
               printf("Error initializing MFS: %s\n", MFS_Error_text((uint32_t)error_code));
           }
         }

         /* Open the filesystem and format detect, if format is required */
         a_fd = open("a:", O_RDWR);
         if (0 >= a_fd) {
             printf("\nError while opening a:\\ (%s)", MFS_Error_text((uint32_t)errno));
             _task_block();
         }

         _io_register_file_system(a_fd, "a:");

         /* We check if the device is formatted with the ioctl command. */
         error_code = ioctl(a_fd, IO_IOCTL_CHECK_FORMATTED, &isFormatted);
         if (0 > error_code) {
             printf("\nError while accessing a:\\ (%s)", MFS_Error_text((uint32_t)error_code));
             _task_block();
         }
         else{
           if(!isFormatted){
               printf("\nNOT A DOS DISK! You must format to continue.");
           }
         }
       }
       else
       {
         /* Close the filesystem */
         if ((a_fd >= 0) && (MQX_OK != close(a_fd)))
         {
             printf("Error closing filesystem.\n");
         }
         a_fd = -1;

         /* Force uninstall filesystem */
         error_code = _nio_dev_uninstall_force("a:", NULL);
         if (error_code < 0)
         {
             printf("Error uninstalling filesystem.\n");
         }

         /* Close partition */
         if ((partition_handle >= 0) && (MQX_OK != close(partition_handle)))
         {
             printf("Error closing partition.\n");
         }
         partition_handle = -1;

         /* Uninstall partition manager */
         error_code = _nio_dev_uninstall_force(partman_name, NULL);
         if (error_code < 0)
         {
             printf("Error uninstalling partition manager.\n");
         }

         /* Close the SD card device */
         if ((dev_fd >= 0) && (MQX_OK != close(dev_fd)))
         {
             printf("Error closing SD card device.\n");
         }

         dev_fd = -1;

         printf ("SD card uninstalled.\n");
       }
     }
   }
} /* Endbody */ 
/*FUNCTION**********************************************************************
 *
 * Function Name : SMARTCARD_DRV_NCN8025Control
 * Description   : This function is used to differnet control interface/slot specific parameters
 *
 *END**************************************************************************/
void SMARTCARD_DRV_NCN8025Control(uint32_t instance, void *interfaceControl, void *param)
{
    assert(instance < HW_SMARTCARD_INSTANCE_COUNT);
    assert(interfaceControl);
    assert(param);
    
    smartcard_interface_control_t *interfaceControlPtr = (smartcard_interface_control_t *)interfaceControl;
    smartcard_state_t * smartcardStatePtr = (smartcard_state_t *)g_smartcardStatePtr[instance];
    smartcard_interface_slot_t * interfaceSlotParams = (smartcard_interface_slot_t *)(smartcardStatePtr->interfaceState->slot[smartcardStatePtr->interfaceConfig.cardSoltNo]);
    smartcard_card_voltage_class_t *vcc;
    uint32_t *clockToResetDelay;
    smartcard_interface_slot_t *statusParams;
#if defined(EMVSIM_INSTANCE_COUNT)
    EMVSIM_Type * base = g_emvsimBase[smartcardStatePtr->interfaceConfig.clockModuleInstance];
#endif
    
    switch(*interfaceControlPtr)
    {
    case kSmartcardInterfaceSetVcc:
        /* Set card parameter to VCC level set by caller */
        vcc = (smartcard_card_voltage_class_t *)param;
        smartcardStatePtr->cardParams.vcc = *vcc;
        interfaceSlotParams->vcc = *vcc;
        break;
    case kSmartcardInterfaceSetClockToResetDelay:
        /* Set interface clock to Reset delay set by caller */
        clockToResetDelay = (uint32_t *)param;
        interfaceSlotParams->clockToResetDelay = *clockToResetDelay;
        break;
    case kSmartcardInterfaceReadStatus:
        /* Read interface/card status */
        statusParams = (smartcard_interface_slot_t *)param;

#if defined(EMVSIM_INSTANCE_COUNT)
        /* Expecting active low present detect */
        statusParams->present = (EMVSIM_HAL_GetCardPresenceDetectPinStatus(base) == kEmvsimPDPinIsLow);
#else		
        if(GPIO_DRV_ReadPinInput(GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.controlPort, (uint32_t)smartcardStatePtr->interfaceConfig.controlPin)))
        {
            if(GPIO_DRV_ReadPinInput(GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.irqPort, (uint32_t)smartcardStatePtr->interfaceConfig.irqPin)))
            {
                /* CMDVCC is high => session is inactive and INT is high => card is present */
                statusParams->present = true;
                statusParams->active = false;
                statusParams->faulty = false;
                statusParams->status = MASK_NCN8025_STATUS_PRES;
            }
            else
            {
                /* CMDVCC is high => session is inactive and INT is low => card is absent */
                statusParams->present = false;
                statusParams->active = false;
                statusParams->faulty = false;
                statusParams->status = 0;
            }
        }
        else
        {
            if(GPIO_DRV_ReadPinInput(GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.irqPort, (uint32_t)smartcardStatePtr->interfaceConfig.irqPin)))
            {
                /* CMDVCC is low => session is active and INT is high => card is present */
                statusParams->present = true;
                statusParams->active = true;
                statusParams->faulty = false;
                statusParams->status = MASK_NCN8025_STATUS_PRES | MASK_NCN8025_STATUS_ACTIVE ;
            }
            else
            {
                /* CMDVCC is low => session is active and INT is low => card is absent/deactivated due to some fault */
                /* A fault has been detected (card has been deactivated) but The cause of the deactivation is not yet known.
                 * Lets determine the cause of fault by pulling CMD high 
                 */
                GPIO_DRV_SetPinOutput(GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.controlPort, (uint32_t)smartcardStatePtr->interfaceConfig.controlPin));
                
                if(GPIO_DRV_ReadPinInput(GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.irqPort, (uint32_t)smartcardStatePtr->interfaceConfig.irqPin)))
                {
                    /* The fault detected was not a card removal (card is still present) */
                    /* If INT follows CMDVCCN, the fault is due to a supply voltage drop, a VCC over-current detection or overheating. */
                    statusParams->present = true;
                    statusParams->active = false;
                    statusParams->faulty = true;
                    statusParams->status = MASK_NCN8025_STATUS_PRES | MASK_NCN8025_STATUS_FAULTY | MASK_NCN8025_STATUS_CARD_DEACTIVATED ;
                }
                else
                {
                    /* The fault detected was the card removal
                     * Setting CMDVCCN allows checking if the deactivation is due to card removal.
                     * In this case the INT pin will stay low after CMDVCCN is high.
                     */
                    statusParams->present = false;
                    statusParams->active = false;
                    statusParams->faulty = false;
                    statusParams->status = MASK_NCN8025_STATUS_CARD_REMOVED | MASK_NCN8025_STATUS_CARD_DEACTIVATED ;
                }
            }
        }
#endif

        /* Copying results back to caller buffer structure */
        interfaceSlotParams->present = statusParams->present;
        interfaceSlotParams->active = statusParams->active;
        interfaceSlotParams->faulty = statusParams->faulty;
        interfaceSlotParams->status = statusParams->status;
        break;
    default:
        break;
    }    
}
Пример #8
0
/*!
 * @brief Check if button is pressed.
 *
 * This function gets the state of button.
 *
 * @return 0 if botton is not pressed.
 *         1 if botton is pressed
 */
static uint32_t is_key_pressed(void)
{
    return (!GPIO_DRV_ReadPinInput(kGpioSW1));
}