int hle::kd::Semaphore::Wait(int count, SceUInt * timeout, bool check_callbacks, int intr)
{
    return SCE_KERNEL_ERROR_OK;

#if 0
    unsigned int result;

    if (intr == 0 || g_scheduler->m_dispatch_thread_suspended != 0)
    {
        return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
    }

    if (count > this->m_maximum_count)
    {
        return SCE_KERNEL_ERROR_ILLEGAL_COUNT;
    }

    SceKernelSysClock sysclock(theSysClock->Get());

    if (timeout)
    {
        sysclock += u64(*timeout);
    }

    bool is_waiting = false;

    do
    {
        auto * current_thread = g_scheduler->GetCurrentThread();

        if (check_callbacks && current_thread->m_callback_notify)
        {
            current_thread->DispatchCallbacks(intr);
        }

        bool is_fifo = !(this->m_attributes & WAITQUEUE_PRIORITY);

        if ((this->m_waiters_count <= 0) || is_fifo || (current_thread->m_current_priority < this->m_waiters_queue.First()->m_current_priority))
        {
            if (is_fifo)
            {
                is_waiting = true;
            }

            if (is_waiting || (this->m_current_count < count))
            {
                current_thread->m_cb_arg1 = count;
            }
            else
            {
                result = 0;

                this->m_current_count -= count;

                break;
            }
        }
        else
        {
            is_waiting = true;

            current_thread->m_cb_arg1 = count;
        }

        current_thread->m_check_callbacks = check_callbacks;

        result = WaitQueue::AddWaitingThread(current_thread, WAITTYPE_SEMA, sysclock, timeout);
    }
    while (check_callbacks && (result == SCE_KERNEL_ERROR_NOTIFY_CALLBACK));

    return result;
#endif
}
Beispiel #2
0
void init(void)
{
  //disable interrupts
  DISABLE_IRQ();

  //init BOD 
  LPC_SYSCON->BODCTRL = (2<<0)|(1<<4); //2.35V - 2.43V

  //set power down config
  LPC_SYSCON->PDRUNCFG &= ~(1<<4); //enable ADC

  //init system AHB
  LPC_SYSCON->SYSAHBCLKDIV = 0x00000001; //clock divider
  #define AHB_WDT    (1<<15)
  #define AHB_CT16B0 (1<< 7)
  #define AHB_CT16B1 (1<< 8)
  #define AHB_CT32B0 (1<< 9)
  #define AHB_CT32B1 (1<<10)
  #define AHB_GPIO   (1<< 6)
  #define AHB_IOCON  (1<<16)
  #define AHB_SSP0   (1<<11)
  #define AHB_SSP1   (1<<18)
  #define AHB_I2C    (1<< 5)
  #define AHB_UART   (1<<12)
  #define AHB_ADC    (1<<13)
  LPC_SYSCON->SYSAHBCLKCTRL = 0x1F | AHB_CT16B1 | AHB_GPIO | AHB_IOCON | AHB_ADC; //CT16 = PWM for backlight

  //init pins
  GPIO_PORT(SS_PORT)->DIR &= (1<<SS_PIN);
  IOCON_SETPIN(SS_PORT, SS_PIN, IOCON_PULLUP);
  IOCON_SETPIN(UART_PORT, RX_PIN, IOCON_PULLUP);
  IOCON_SETPIN(SPI_PORT, MOSI_PIN, IOCON_PULLUP);
  GPIO_PORT(IO_PORT)->DIR &= (1<<IO_PIN);
  IOCON_SETPIN(IO_PORT, IO_PIN, IOCON_PULLUP);
  GPIO_PORT(LED_PORT)->DIR |= (1<<LED_PIN);
  GPIO_CLRPIN(LED_PORT, LED_PIN);
  GPIO_PORT(PWM_PORT)->DIR |= (1<<PWM_PIN);
  GPIO_CLRPIN(PWM_PORT, PWM_PIN);

  //init PWM for backlight
  // LPC_IOCON->PIO1_9 = (0x1<<0); //PIO1_9/CT16B1MAT0 -> PWM (set in set_pwm())
  LPC_TMR16B1->TC   = 0;
  LPC_TMR16B1->PR   = 0; //no prescale
  LPC_TMR16B1->PC   = 0;
  LPC_TMR16B1->CTCR = 0;
  LPC_TMR16B1->MCR  = 0;
  LPC_TMR16B1->MR0  = ~((0xFFFF*0)/100); //0%
  LPC_TMR16B1->PWMC = (1<<0); //PWM chn 0 on
  LPC_TMR16B1->EMR  = (1<<0)|(2<<4); //enable PIO1_9/CT16B1MAT0
  LPC_TMR16B1->TCR  = (1<<0); //enable timer

  //init adc
  LPC_ADC->CR = (((sysclock(0)/4000000UL)-1)<< 8) | //4MHz
                                          (0<<16) | //burst off
                                        (0x0<<17) | //10bit
                                        (0x0<<24);  //stop

  //init systick timer
  ms_ticks = 0;
  SysTick_Config(sysclock(0) / 1000); //1000 Hz

  //enable interrupts
  ENABLE_IRQ();

  return;
}