Exemplo n.º 1
0
void pwm_init(void)
{
  /* Configure Timer1 in PWM Fast mode */
  TCCR1B =
    (0<<WGM13)|(1<<WGM12)|         /*< Mode: Fast PWM, 8 bit */
    (0<<CS12)|(1<<CS11)|(1<<CS10)| /* Prescaler: 64 */
    (0<< ICNC1)|(0<< ICES1);       /*< No extra flags */
  TCCR1A =
    (0<<WGM11)|(1<<WGM10)|         /*< Mode: Fast PWM, 8 bit */
    (1<<COM1A1)|(0<<COM1A0)|       /*< Compare output mode OC1A: non-inverting */
    (1<<COM1B1)|(0<<COM1B0)|       /*< Compare output mode OC1B: non-inverting */
    (0<<FOC1A)|(0<<FOC1B);         /*< No forced output */
  OCR1A = UINT16_C(0);
  OCR1B = UINT16_C(0);
  TCNT1 = UINT16_C(0);
  DDRD |= ((1U << DDD4)|(1U << DDD5)|(1U << DDD7));

  /* Configure Timer2 in PWM fast mode */
  /* Reset the Timer2 counter */
  TCNT2 = UINT8_C(0);
  /* Timer2 compare register: 1001.73913Hz */
  OCR2 = UINT8_C(0);
  /* Set the control register */
  TCCR2 =
    (1<<WGM21)|(1<<WGM20)| /*< Mode: Fast PWM */
    (1<<COM21)|(0<<COM21)| /*< Compare output mode OC2: non-inverting */
    (1<<CS22)|(0<<CS21)|(0<<CS20); /* Prescaler: 64 */
}
Exemplo n.º 2
0
IRIRef *IRIRef::urify() throw(BadAllocException) {
  if (this->urified) {
    return this;
  }
  const uint8_t *begin = this->utf8str->dptr();
  const uint8_t *end = begin + this->utf8str->size();
  const uint8_t *mark = begin;
  const uint8_t *next = NULL;
  uint32_t codepoint;
  while (mark != end) {
    codepoint = utf8char(mark, &next);
    if (IRIRef::isIPrivate(codepoint) || IRIRef::isUCSChar(codepoint)) {
      break;
    }
    mark = next;
  }
  if (mark == end) {
    this->urified = true;
    return this;
  }
  vector<uint8_t> urivec;
  urivec.reserve(this->utf8str->size() + 2);
  do {
    urivec.insert(urivec.end(), begin, mark);
    for (; mark != next; ++mark) {
      urivec.push_back(to_ascii('%'));
      uint8_t hi4 = (*mark) >> 4;
      uint8_t lo4 = (*mark) & UINT8_C(0x0F);
      urivec.push_back(hi4 <= UINT8_C(9) ? to_ascii('0') + hi4
                                         : to_ascii('A') + (hi4 - 10));
      urivec.push_back(lo4 <= UINT8_C(9) ? to_ascii('0') + lo4
                                         : to_ascii('A') + (lo4 - 10));
    }
    begin = mark;
    while (mark != end) {
      codepoint = utf8char(mark, &next);
      if (IRIRef::isIPrivate(codepoint) || IRIRef::isUCSChar(codepoint)) {
        break;
      }
      mark = next;
    }
  } while(mark != end);
  urivec.insert(urivec.end(), begin, mark);
  MPtr<uint8_t> *uristr;
  try {
    NEW(uristr, MPtr<uint8_t>, urivec.size());
  } RETHROW_BAD_ALLOC
  copy(urivec.begin(), urivec.end(), uristr->dptr());
  this->utf8str->drop();
  this->utf8str = uristr;
  this->urified = true;
  return this; 
}
Exemplo n.º 3
0
EXTERN_C
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
{
  std::uint8_t duty_cycle_reg_value;

  // Calculate the scaled duty cycle.
  duty_cycle_reg_value = static_cast<std::uint8_t>(DutyCycle / UINT8_C(0x80));

  switch(ChannelNumber)
  {
    case PWM_CHANNEL_B_5:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr1al, duty_cycle_reg_value);
      break;

    case PWM_CHANNEL_B_6:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr1bl, duty_cycle_reg_value);
      break;

    case PWM_CHANNEL_B_7:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr0a, duty_cycle_reg_value);
      break;

    case PWM_CHANNEL_C_6:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr3al, duty_cycle_reg_value);
      break;
/*
    case PWM_CHANNEL_C_7:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr4a, LOBYTE(DutyCycle));
      break;

    case PWM_CHANNEL_D_0:
      util::dma<uint8,
                uint8>::reg_set(mcal::reg::ocr0b, LOBYTE(DutyCycle));
      break;
      
    case PWM_SW_CHANNEL:
      // code;
      break;
*/
/*
    case PWM_CHANNEL_D_6:
      // code;
      break;

    case PWM_CHANNEL_D_7:
      // code;
      break;

    default:
     // return error;
      break;
*/
  }
}
Exemplo n.º 4
0
int main(void)
{
  char buf[64];
  int8_t i8;
  uint8_t u8;
  int16_t i16;
  uint16_t u16;
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  int32_t i32;
  uint32_t u32;
#endif
  intmax_t imax;
  uintmax_t umax;
  TEST_PRINT(buf, PRId8, INT8_C(-128), "-128");
  TEST_PRINT(buf, PRIi8, INT8_C(-128), "-128");
  TEST_PRINT(buf, PRIo8, UINT8_C(255), "377");
  TEST_PRINT(buf, PRIu8, UINT8_C(255), "255");
  TEST_PRINT(buf, PRIx8, UINT8_C(255), "ff");
  TEST_PRINT(buf, PRIX8, UINT8_C(255), "FF");
  TEST_PRINT(buf, PRId16, INT16_C(-32767), "-32767");
  TEST_PRINT(buf, PRIi16, INT16_C(-32767), "-32767");
  TEST_PRINT(buf, PRIo16, UINT16_C(65535), "177777");
  TEST_PRINT(buf, PRIu16, UINT16_C(65535), "65535");
  TEST_PRINT(buf, PRIx16, UINT16_C(65535), "ffff");
  TEST_PRINT(buf, PRIX16, UINT16_C(65535), "FFFF");
  TEST_PRINT(buf, PRIdMAX, INTMAX_C(-32767), "-32767");
  TEST_PRINT(buf, PRIuMAX, UINTMAX_C(65535), "65535");
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  TEST_PRINT(buf, PRId32, INT32_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIi32, INT32_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIo32, UINT32_C(4294967295), "37777777777");
  TEST_PRINT(buf, PRIu32, UINT32_C(4294967295), "4294967295");
  TEST_PRINT(buf, PRIx32, UINT32_C(4294967295), "ffffffff");
  TEST_PRINT(buf, PRIX32, UINT32_C(4294967295), "FFFFFFFF");
  TEST_PRINT(buf, PRIdMAX, INTMAX_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIuMAX, UINTMAX_C(4294967295), "4294967295");
#endif
  TEST_SCAN("-128", SCNd8, i8, INT8_C(-128));
  TEST_SCAN("-128", SCNi8, i8, INT8_C(-128));
  TEST_SCAN("377", SCNo8, u8, UINT8_C(255));
  TEST_SCAN("255", SCNu8, u8, UINT8_C(255));
  TEST_SCAN("Ff", SCNx8, u8, UINT8_C(255));
  TEST_SCAN("-32767", SCNd16, i16, INT16_C(-32767));
  TEST_SCAN("-32767", SCNi16, i16, INT16_C(-32767));
  TEST_SCAN("177777", SCNo16, u16, UINT16_C(65535));
  TEST_SCAN("65535", SCNu16, u16, UINT16_C(65535));
  TEST_SCAN("FffF", SCNx16, u16, UINT16_C(65535));
  TEST_SCAN("-32767", SCNdMAX, imax, INTMAX_C(-32767));
  TEST_SCAN("65535", SCNuMAX, umax, UINTMAX_C(65535));
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  TEST_SCAN("-2147483647", SCNd32, i32, INT32_C(-2147483647));
  TEST_SCAN("-2147483647", SCNi32, i32, INT32_C(-2147483647));
  TEST_SCAN("37777777777", SCNo32, u32, UINT32_C(4294967295));
  TEST_SCAN("4294967295", SCNu32, u32, UINT32_C(4294967295));
  TEST_SCAN("ffFFffFF", SCNx32, u32, UINT32_C(4294967295));
  TEST_SCAN("-2147483647", SCNdMAX, imax, INTMAX_C(-2147483647));
  TEST_SCAN("4294967295", SCNuMAX, umax, UINTMAX_C(4294967295));
#endif
  return 0;
}
Exemplo n.º 5
0
void initContext( RenderWindow* window )
{
    //bgfx::glfwSetWindow( window->getHandle() );

    bgfx::init();
    bgfx::reset( window->getWidth(), window->getHeight(), BGFX_RESET_VSYNC );

    // Enable debug text.
    //bgfx::setDebug(debug);

    // Set view 0 clear state.
    bgfx::setViewClear(0
        , UINT8_C(0x01) |UINT8_C(0x08)
        , 0x303030ff
        , 1.0f
        , 0
        );
}
Exemplo n.º 6
0
/**
 * Implements VINF_IOM_MMIO_UNUSED_00.
 *
 * @returns VINF_SUCCESS.
 * @param   pvValue             Where to store the zeros.
 * @param   cbValue             How many bytes to read.
 */
static int iomMMIODoRead00s(void *pvValue, size_t cbValue)
{
    switch (cbValue)
    {
        case 1: *(uint8_t  *)pvValue = UINT8_C(0x00); break;
        case 2: *(uint16_t *)pvValue = UINT16_C(0x0000); break;
        case 4: *(uint32_t *)pvValue = UINT32_C(0x00000000); break;
        case 8: *(uint64_t *)pvValue = UINT64_C(0x0000000000000000); break;
        default:
        {
            uint8_t *pb = (uint8_t *)pvValue;
            while (cbValue--)
                *pb++ = UINT8_C(0x00);
            break;
        }
    }
    return VINF_SUCCESS;
}
Exemplo n.º 7
0
void MsixPciConfigWrite(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev, uint32_t u32Address, uint32_t val, unsigned len)
{
    int32_t iOff = u32Address - pDev->Int.s.u8MsixCapOffset;
    Assert(iOff >= 0 && (pciDevIsMsixCapable(pDev) && iOff < pDev->Int.s.u8MsixCapSize));

    Log2(("MsixPciConfigWrite: %d <- %x (%d)\n", iOff, val, len));

    uint32_t uAddr = u32Address;
    uint8_t u8NewVal;
    bool fJustEnabled = false;

    for (uint32_t i = 0; i < len; i++)
    {
        uint32_t reg = i + iOff;
        uint8_t u8Val = (uint8_t)val;
        switch (reg)
        {
            case 0: /* Capability ID, ro */
            case 1: /* Next pointer,  ro */
                break;
            case VBOX_MSIX_CAP_MESSAGE_CONTROL:
                /* don't change read-only bits: 0-7 */
                break;
            case VBOX_MSIX_CAP_MESSAGE_CONTROL + 1:
            {
                /* don't change read-only bits 8-13 */
                u8NewVal = (u8Val & UINT8_C(~0x3f)) | (pDev->config[uAddr] & UINT8_C(0x3f));
                /* If just enabled globally - check pending vectors */
                fJustEnabled |= msixBitJustCleared(pDev->config[uAddr], u8NewVal, VBOX_PCI_MSIX_FLAGS_ENABLE >> 8);
                fJustEnabled |= msixBitJustCleared(pDev->config[uAddr], u8NewVal, VBOX_PCI_MSIX_FLAGS_FUNCMASK >> 8);
                pDev->config[uAddr] = u8NewVal;
                break;
        }
            default:
                /* other fields read-only too */
                break;
        }
        uAddr++;
        val >>= 8;
    }

    if (fJustEnabled)
        msixCheckPendingVectors(pDevIns, pPciHlp, pDev);
}
Exemplo n.º 8
0
void app::crc::task_init()
{
  // Initialize the test values to 0x31, ..., 0x39.
  std::uint_fast8_t i = UINT8_C(1);

  std::generate_n(app_crc_test_values.begin(),
                  app_crc_test_values.size(),
                  [&i]() -> std::uint_fast8_t
                  {
                    const std::uint_fast8_t value = UINT8_C(0x30) + i;

                    ++i;

                    return std::uint8_t(value);
                  });

  // Set the CRC port measurement pin to output
  app_crc_measurement_port_type::set_direction_output();
}
Exemplo n.º 9
0
static void test_b_out(ctest_ctx *ctx)
{
  const uint8_t SENTINEL = UINT8_C(0xFD);
  uint8_t image[3];
  const uint8_t TAG = UINT8_C(0xa5);
  const uint8_t b = TAG;
  uint8_t *p = image+1;

  image[0] = SENTINEL;
  image[1] = SENTINEL;
  image[2] = SENTINEL;

  b_out(b,&p);

  CTEST(ctx,image[1]==TAG);
  CTEST(ctx,image[0]==SENTINEL);
  CTEST(ctx,image[2]==SENTINEL);
  CTEST(ctx,p==image+2);
}
void do_something()
{
  // Set portb to 0.
  reg_map_dynamic<std::uintptr_t,
                  std::uint8_t,
                  bit8_type>::value(address) = UINT8_C(0);

  // Set portb.5 to 1.
  reg_map_dynamic<std::uintptr_t,
                  std::uint8_t,
                  bit8_type>::bits(address).b5 = 1U;
}
Exemplo n.º 11
0
mcal::pwm::pwm_base& mcal::pwm::mcal_pwm2()
{
  using port2_type = mcal::port::port_pin<std::uint8_t,
                                          std::uint8_t,
                                          mcal::reg::portc,
                                          UINT8_C(5)>;

  using pwm2_type = mcal::pwm::pwm_board<port2_type>;

  static pwm2_type the_pwm2(100U);

  return the_pwm2;
}
Exemplo n.º 12
0
void mcal::gpt::init(const config_type*)
{
  if(gpt_is_initialized() == false)
  {
    // Protection off
    // SYSTEM.PRCR.WORD = 0xA503u;
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::prcr,
                      UINT16_C(0xA503)>::reg_set();

    // Activate timer0/timer1 by clearing bit-5 in the module-stop register.
    mcal::reg::access<std::uint32_t,
                      std::uint32_t,
                      mcal::reg::mstpcra,
                      UINT8_C(5)>::bit_clr();

    // Protection on
    // SYSTEM.PRCR.WORD = 0xA500u;
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::prcr,
                      UINT16_C(0xA500)>::reg_set();

    // Set timer0 to have an interrupt on overflow.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::tmr0_tcr,
                      UINT8_C(0x20)>::reg_set();

    // Enable the timer0 overflow interrupt at ier15.4.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::icu_ier15,
                      UINT8_C(0x04)>::bit_set();

    // Set the timer0 overflow interrupt priority to 7.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::icu_ipr170,
                      UINT8_C(0x07)>::reg_set();

    // Select the internal clock (not external) with the value 8.
    // Also select a prescaler of 32 with the value 3.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::tmr0_tccr,
                      static_cast<std::uint8_t>(UINT8_C(0x08) | UINT8_C(0x03))>::reg_set();

    // Start timer0 counting up.
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::cmt_cmstr0,
                      UINT16_C(0x01)>::reg_set();

    gpt_is_initialized() = true;
  }
}
Exemplo n.º 13
0
static void test_w_out(ctest_ctx *ctx)
{
  const uint8_t SENTINEL = UINT8_C(0xFD);
  const uint8_t TAG_HI = UINT8_C(0xA5);
  const uint8_t TAG_LO = UINT8_C(0x5A);
  const uint16_t TAG = UINT16_C(0xA55A);
  const uint16_t w = TAG;
  uint8_t image[4];
  uint8_t *p = image+1;

  image[0] = SENTINEL;
  image[1] = SENTINEL;
  image[2] = SENTINEL;
  image[3] = SENTINEL;

  w_out(w,&p);

  CTEST(ctx,image[1]==TAG_LO);
  CTEST(ctx,image[2]==TAG_HI);
  CTEST(ctx,image[0]==SENTINEL);
  CTEST(ctx,image[3]==SENTINEL);
  CTEST(ctx,p==image+3);
}
Exemplo n.º 14
0
void app::led::task_func()
{
  if(app_led_monochrome_timer.timeout())
  {
    // Toggle the monochrome user LED at 1/2 Hz.
    mcal::led::led_monochrome0().toggle();

    // Start the next timer interval for the monochrome user LED.
    app_led_monochrome_timer.start_interval(app_led_monochrome_timer_type::seconds(1U));
  }

  if(app_led_rgb_timer.timeout())
  {
    // Animate the RGB LED with the colors of the spectrum at 50 Hz.

    // Define the color transition states.
    typedef enum color_transition_enum
    {
      red_to_yellow,
      yellow_to_green,
      green_to_cyan,
      cyan_to_blue,
      blue_to_magenta,
      magenta_to_red
    }
    color_transition_type;

    // Initialize the color transition state.
    static color_transition_type color_transition_state = red_to_yellow;

    // Make a smooth color transition and
    // increment the color transition state
    // if necessary.
    switch(color_transition_state)
    {
      case red_to_yellow:   { if(++app_led_hue_g == UINT8_C(255)) { color_transition_state = yellow_to_green; } } break;
      case yellow_to_green: { if(--app_led_hue_r == UINT8_C(  0)) { color_transition_state = green_to_cyan;   } } break;
      case green_to_cyan:   { if(++app_led_hue_b == UINT8_C(255)) { color_transition_state = cyan_to_blue;    } } break;
      case cyan_to_blue:    { if(--app_led_hue_g == UINT8_C(  0)) { color_transition_state = blue_to_magenta; } } break;
      case blue_to_magenta: { if(++app_led_hue_r == UINT8_C(255)) { color_transition_state = magenta_to_red;  } } break;
      default:
      case magenta_to_red:  { if(--app_led_hue_b == UINT8_C(  0)) { color_transition_state = red_to_yellow;   } } break;
    }

    // Write the next color to the RGB LED.
    mcal::led::led_rgb0().set_color(app_led_hue_r,
                                    app_led_hue_g,
                                    app_led_hue_b);

    // Start the next timer interval for the RGB LED.
    app_led_rgb_timer.start_interval(app_led_rgb_timer_type::milliseconds(20U));
  }
}
Exemplo n.º 15
0
EXTERN_C
void Pwm_SetPeriodAndDuty(Pwm_ChannelType ChannelNumber, Pwm_PeriodType Period, uint16 DutyCycle)
{
  // first set duty cycle via autosar function.
  Pwm_SetDutyCycle(ChannelNumber, DutyCycle);

  if(Period > static_cast<Pwm_PeriodType>(16384))
  {
    // TBD: Switch to a software PWM here. Requires lots of code.
  }
  else
  {
    std::uint8_t prescaler_register_value;

    if(Period <= static_cast<Pwm_PeriodType>(16))
    {
      prescaler_register_value = UINT8_C(0x01);
    }
    else if(Period <= static_cast<Pwm_PeriodType>(128))
    {
      prescaler_register_value = UINT8_C(0x02);
    }
    else if(Period <= static_cast<Pwm_PeriodType>(1024))
    {
      prescaler_register_value = UINT8_C(0x03);
    }
    else if(Period <= static_cast<Pwm_PeriodType>(4096))
    {
      prescaler_register_value = UINT8_C(0x04);
    }
    else
    {
      prescaler_register_value = UINT8_C(0x05);
    }

//    util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0b, prescaler_register_value);
    util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr1b, prescaler_register_value, UINT8_C(0x07));
    util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr3b, prescaler_register_value, UINT8_C(0x07));
  }
}
Exemplo n.º 16
0
void Crc08_ProcessBytes(const uint8_t*      DataIn,
                        const size_t        DataLength,
                        Crc08_Context_Type* Crc_Context)
{
  size_t LoopCnt;

  /* Loop through the input data stream */
  for(LoopCnt = 0U; LoopCnt < DataLength; ++LoopCnt)
  {
    /* CRC-8/AUTOSAR Table based on 8-bit BYTEs. */

    static const uint8_t Crc08_Table[256U] MCAL_PROGMEM =
    {
      UINT8_C(0x00), UINT8_C(0x2F), UINT8_C(0x5E), UINT8_C(0x71), UINT8_C(0xBC), UINT8_C(0x93), UINT8_C(0xE2), UINT8_C(0xCD),
      UINT8_C(0x57), UINT8_C(0x78), UINT8_C(0x09), UINT8_C(0x26), UINT8_C(0xEB), UINT8_C(0xC4), UINT8_C(0xB5), UINT8_C(0x9A),
      UINT8_C(0xAE), UINT8_C(0x81), UINT8_C(0xF0), UINT8_C(0xDF), UINT8_C(0x12), UINT8_C(0x3D), UINT8_C(0x4C), UINT8_C(0x63),
      UINT8_C(0xF9), UINT8_C(0xD6), UINT8_C(0xA7), UINT8_C(0x88), UINT8_C(0x45), UINT8_C(0x6A), UINT8_C(0x1B), UINT8_C(0x34),
      UINT8_C(0x73), UINT8_C(0x5C), UINT8_C(0x2D), UINT8_C(0x02), UINT8_C(0xCF), UINT8_C(0xE0), UINT8_C(0x91), UINT8_C(0xBE),
      UINT8_C(0x24), UINT8_C(0x0B), UINT8_C(0x7A), UINT8_C(0x55), UINT8_C(0x98), UINT8_C(0xB7), UINT8_C(0xC6), UINT8_C(0xE9),
      UINT8_C(0xDD), UINT8_C(0xF2), UINT8_C(0x83), UINT8_C(0xAC), UINT8_C(0x61), UINT8_C(0x4E), UINT8_C(0x3F), UINT8_C(0x10),
      UINT8_C(0x8A), UINT8_C(0xA5), UINT8_C(0xD4), UINT8_C(0xFB), UINT8_C(0x36), UINT8_C(0x19), UINT8_C(0x68), UINT8_C(0x47),
      UINT8_C(0xE6), UINT8_C(0xC9), UINT8_C(0xB8), UINT8_C(0x97), UINT8_C(0x5A), UINT8_C(0x75), UINT8_C(0x04), UINT8_C(0x2B),
      UINT8_C(0xB1), UINT8_C(0x9E), UINT8_C(0xEF), UINT8_C(0xC0), UINT8_C(0x0D), UINT8_C(0x22), UINT8_C(0x53), UINT8_C(0x7C),
      UINT8_C(0x48), UINT8_C(0x67), UINT8_C(0x16), UINT8_C(0x39), UINT8_C(0xF4), UINT8_C(0xDB), UINT8_C(0xAA), UINT8_C(0x85),
      UINT8_C(0x1F), UINT8_C(0x30), UINT8_C(0x41), UINT8_C(0x6E), UINT8_C(0xA3), UINT8_C(0x8C), UINT8_C(0xFD), UINT8_C(0xD2),
      UINT8_C(0x95), UINT8_C(0xBA), UINT8_C(0xCB), UINT8_C(0xE4), UINT8_C(0x29), UINT8_C(0x06), UINT8_C(0x77), UINT8_C(0x58),
      UINT8_C(0xC2), UINT8_C(0xED), UINT8_C(0x9C), UINT8_C(0xB3), UINT8_C(0x7E), UINT8_C(0x51), UINT8_C(0x20), UINT8_C(0x0F),
      UINT8_C(0x3B), UINT8_C(0x14), UINT8_C(0x65), UINT8_C(0x4A), UINT8_C(0x87), UINT8_C(0xA8), UINT8_C(0xD9), UINT8_C(0xF6),
      UINT8_C(0x6C), UINT8_C(0x43), UINT8_C(0x32), UINT8_C(0x1D), UINT8_C(0xD0), UINT8_C(0xFF), UINT8_C(0x8E), UINT8_C(0xA1),
      UINT8_C(0xE3), UINT8_C(0xCC), UINT8_C(0xBD), UINT8_C(0x92), UINT8_C(0x5F), UINT8_C(0x70), UINT8_C(0x01), UINT8_C(0x2E),
      UINT8_C(0xB4), UINT8_C(0x9B), UINT8_C(0xEA), UINT8_C(0xC5), UINT8_C(0x08), UINT8_C(0x27), UINT8_C(0x56), UINT8_C(0x79),
      UINT8_C(0x4D), UINT8_C(0x62), UINT8_C(0x13), UINT8_C(0x3C), UINT8_C(0xF1), UINT8_C(0xDE), UINT8_C(0xAF), UINT8_C(0x80),
      UINT8_C(0x1A), UINT8_C(0x35), UINT8_C(0x44), UINT8_C(0x6B), UINT8_C(0xA6), UINT8_C(0x89), UINT8_C(0xF8), UINT8_C(0xD7),
      UINT8_C(0x90), UINT8_C(0xBF), UINT8_C(0xCE), UINT8_C(0xE1), UINT8_C(0x2C), UINT8_C(0x03), UINT8_C(0x72), UINT8_C(0x5D),
      UINT8_C(0xC7), UINT8_C(0xE8), UINT8_C(0x99), UINT8_C(0xB6), UINT8_C(0x7B), UINT8_C(0x54), UINT8_C(0x25), UINT8_C(0x0A),
      UINT8_C(0x3E), UINT8_C(0x11), UINT8_C(0x60), UINT8_C(0x4F), UINT8_C(0x82), UINT8_C(0xAD), UINT8_C(0xDC), UINT8_C(0xF3),
      UINT8_C(0x69), UINT8_C(0x46), UINT8_C(0x37), UINT8_C(0x18), UINT8_C(0xD5), UINT8_C(0xFA), UINT8_C(0x8B), UINT8_C(0xA4),
      UINT8_C(0x05), UINT8_C(0x2A), UINT8_C(0x5B), UINT8_C(0x74), UINT8_C(0xB9), UINT8_C(0x96), UINT8_C(0xE7), UINT8_C(0xC8),
      UINT8_C(0x52), UINT8_C(0x7D), UINT8_C(0x0C), UINT8_C(0x23), UINT8_C(0xEE), UINT8_C(0xC1), UINT8_C(0xB0), UINT8_C(0x9F),
      UINT8_C(0xAB), UINT8_C(0x84), UINT8_C(0xF5), UINT8_C(0xDA), UINT8_C(0x17), UINT8_C(0x38), UINT8_C(0x49), UINT8_C(0x66),
      UINT8_C(0xFC), UINT8_C(0xD3), UINT8_C(0xA2), UINT8_C(0x8D), UINT8_C(0x40), UINT8_C(0x6F), UINT8_C(0x1E), UINT8_C(0x31),
      UINT8_C(0x76), UINT8_C(0x59), UINT8_C(0x28), UINT8_C(0x07), UINT8_C(0xCA), UINT8_C(0xE5), UINT8_C(0x94), UINT8_C(0xBB),
      UINT8_C(0x21), UINT8_C(0x0E), UINT8_C(0x7F), UINT8_C(0x50), UINT8_C(0x9D), UINT8_C(0xB2), UINT8_C(0xC3), UINT8_C(0xEC),
      UINT8_C(0xD8), UINT8_C(0xF7), UINT8_C(0x86), UINT8_C(0xA9), UINT8_C(0x64), UINT8_C(0x4B), UINT8_C(0x3A), UINT8_C(0x15),
      UINT8_C(0x8F), UINT8_C(0xA0), UINT8_C(0xD1), UINT8_C(0xFE), UINT8_C(0x33), UINT8_C(0x1C), UINT8_C(0x6D), UINT8_C(0x42),
    };

    /* Perform the CRC-8/AUTOSAR algorithm. */

    const uint_fast8_t DataIndex =
      (uint_fast8_t) (  Crc_Context->Crc08_Value
                      ^ DataIn[LoopCnt]);

    const uint8_t TableValue =
      mcal_cpu_read_program_memory_byte((const uint8_t*) &Crc08_Table[(uint8_t) DataIndex]);

    Crc_Context->Crc08_Value = TableValue;
  }
}
Exemplo n.º 17
0
EXTERN_C
void Pwm_Init(const Pwm_ConfigType* ConfigPtr)
{
  static_cast<void>(ConfigPtr);

  for(uint8_least i = 0U; i < countof(Pwm_ConfigSet.PwmChannelConfigSet); ++i)
  {
    // Configuration for Pwm Mode.
    switch(ConfigPtr->PwmChannelConfigSet[i].Mode)
    {

      case PWM_MODE_FAST_INVERTED:
//        if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_C_7)
        {
         /*
          Missing UINT8_C Value x
          util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
          util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
          */
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_7)
        {
         /*
          Missing UINT8_C Value x
          util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
          util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
          */
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_D_0)
        {
         /*
          Missing UINT8_C Value x
          util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
          util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
          */
        }
//        else
        {
          //Code for other Channels
        }
        break;

      case PWM_MODE_FAST_NONINVERTED:
//        if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_5)
        {
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr1a, UINT8_C(0xC1), UINT8_C(0xC1));
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr1b, UINT8_C(0x08), UINT8_C(0x08));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_6)
        {
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr1a, UINT8_C(0x31), UINT8_C(0x31));
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr1b, UINT8_C(0x08), UINT8_C(0x08));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_7)
        {
          //util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(0xC3));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_C_6)
        {
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr3a, UINT8_C(0xC1), UINT8_C(0xC1));
          util::dma<uint8, uint8>::reg_msk(mcal::reg::tccr3b, UINT8_C(0x08), UINT8_C(0x08));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_C_7)
        {
          //util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(0xC3));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_D_0)
        {
          //util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(0xC3));
        }
//        else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_SW_CHANNEL_D_5)
        {

        }
//        else
        {
          //Code for other Channels
        }
        break;

      case PWM_MODE_PHASECORRECT_INVERTED:
//          if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_C_7)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//          else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_7)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//          else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_D_0)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//        else
        {
            //Code for other Channels
        }
        break;

      case PWM_MODE_PHASECORRECT_NONINVERTED:
//          if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_C_7)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//          else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_B_7)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//          else if(ConfigPtr->PwmChannelConfigSet[i].PwmChannelId == PWM_CHANNEL_D_0)
        {
           /*
            Missing UINT8_C Value x
            util::dma<uint8, uint8>::reg_set(mcal::reg::tccr0a, UINT8_C(x));
            util::dma<uint8, uint8>::reg_set(mcal::reg::timsk0, UINT8_C(x));
            */
        }
//        else
        {
            //Code for other Channels
        }
        break;

      default:
          //Code for unused Channels

        break;
    }
  }
}
Exemplo n.º 18
0
int32_t a3[3] = { INT32_C (17), INT32_MIN, INT32_MAX };
verify (TYPE_MINIMUM (int32_t) == INT32_MIN);
verify (TYPE_MAXIMUM (int32_t) == INT32_MAX);
verify_same_types (INT32_MIN, (int32_t) 0 + 0);
verify_same_types (INT32_MAX, (int32_t) 0 + 0);

#ifdef INT64_MAX
int64_t a4[3] = { INT64_C (17), INT64_MIN, INT64_MAX };
verify (TYPE_MINIMUM (int64_t) == INT64_MIN);
verify (TYPE_MAXIMUM (int64_t) == INT64_MAX);
verify_same_types (INT64_MIN, (int64_t) 0 + 0);
verify_same_types (INT64_MAX, (int64_t) 0 + 0);
#endif

uint8_t b1[2] = { UINT8_C (17), UINT8_MAX };
verify (TYPE_MAXIMUM (uint8_t) == UINT8_MAX);
verify_same_types (UINT8_MAX, (uint8_t) 0 + 0);

uint16_t b2[2] = { UINT16_C (17), UINT16_MAX };
verify (TYPE_MAXIMUM (uint16_t) == UINT16_MAX);
verify_same_types (UINT16_MAX, (uint16_t) 0 + 0);

uint32_t b3[2] = { UINT32_C (17), UINT32_MAX };
verify (TYPE_MAXIMUM (uint32_t) == UINT32_MAX);
verify_same_types (UINT32_MAX, (uint32_t) 0 + 0);

#ifdef UINT64_MAX
uint64_t b4[2] = { UINT64_C (17), UINT64_MAX };
verify (TYPE_MAXIMUM (uint64_t) == UINT64_MAX);
verify_same_types (UINT64_MAX, (uint64_t) 0 + 0);
Exemplo n.º 19
0
// Load data from constant file and check for exact match.
TEST(bits, reverseBytes)
{
	{
		uint8_t val = 0x88, val_r;
		const uint8_t val_r_ok = 0x88;

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		int8_t val = 0x66, val_r;
		const int8_t val_r_ok = 0x66;

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		uint16_t val = 0x1122, val_r;
		const uint16_t val_r_ok = 0x2211;

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		int16_t val = 0x1122, val_r;
		const int16_t val_r_ok = 0x2211;

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		uint32_t val = UINT32_C(0x11223344), val_r;
		const uint32_t val_r_ok = UINT32_C(0x44332211);

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		int32_t val = INT32_C(0x11223344), val_r;
		const int32_t val_r_ok = INT32_C(0x44332211);

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		uint64_t val = UINT64_C(0x1122334455667788), val_r;
		const uint64_t val_r_ok = UINT64_C(0x8877665544332211);

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		int64_t val = INT64_C(0x1122334455667766), val_r;
		const int64_t val_r_ok = INT64_C(0x6677665544332211);

		mrpt::reverseBytes(val, val_r);
		EXPECT_EQ(val_r, val_r_ok);
		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, val_r_ok);
	}
	{
		bool valTrue  = true;
		bool valFalse = false;
		mrpt::reverseBytesInPlace(valTrue);
		mrpt::reverseBytesInPlace(valFalse);
		EXPECT_TRUE(valTrue);
		EXPECT_FALSE(valFalse);
	}
	{
		uint8_t val = UINT8_C(0xc1);

		mrpt::reverseBytesInPlace(val);
		EXPECT_EQ(val, 0xc1);
	}
	{
		//1.0 == 0x3F800000
		float val = 1;
		const uint32_t val_r_ok = UINT32_C(0x803f);

		mrpt::reverseBytesInPlace(val);
		uint32_t val_check = *reinterpret_cast<uint32_t*>(&val);
		EXPECT_EQ(val_check, val_r_ok);
	}
	{
		//1.0 == 0x3ff0000000000000
		double val = 1;
		const uint64_t val_r_ok = UINT32_C(0xf03f);

		mrpt::reverseBytesInPlace(val);
		uint32_t val_check = *reinterpret_cast<uint32_t*>(&val);
		EXPECT_EQ(val_check, val_r_ok);
	}
}
Exemplo n.º 20
0
void     MsiPciConfigWrite(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev,
                           uint32_t u32Address, uint32_t val, unsigned len)
{
    int32_t iOff = u32Address - pDev->Int.s.u8MsiCapOffset;
    Assert(iOff >= 0 && (pciDevIsMsiCapable(pDev) && iOff < pDev->Int.s.u8MsiCapSize));

    Log2(("MsiPciConfigWrite: %d <- %x (%d)\n", iOff, val, len));

    uint32_t uAddr = u32Address;
    bool f64Bit = msiIs64Bit(pDev);

    for (uint32_t i = 0; i < len; i++)
    {
        uint32_t reg = i + iOff;
        uint8_t u8Val = (uint8_t)val;
        switch (reg)
        {
            case 0: /* Capability ID, ro */
            case 1: /* Next pointer,  ro */
                break;
            case VBOX_MSI_CAP_MESSAGE_CONTROL:
                /* don't change read-only bits: 1-3,7 */
                u8Val &= UINT8_C(~0x8e);
                pDev->config[uAddr] = u8Val | (pDev->config[uAddr] & UINT8_C(0x8e));
                break;
            case VBOX_MSI_CAP_MESSAGE_CONTROL + 1:
                /* don't change read-only bit 8, and reserved 9-15 */
                break;
            default:
                if (pDev->config[uAddr] != u8Val)
                {
                    int32_t maskUpdated = -1;

                    /* If we're enabling masked vector, and have pending messages
                       for this vector, we have to send this message now */
                    if (    !f64Bit
                         && (reg >= VBOX_MSI_CAP_MASK_BITS_32)
                         && (reg < VBOX_MSI_CAP_MASK_BITS_32 + 4)
                        )
                    {
                        maskUpdated = reg - VBOX_MSI_CAP_MASK_BITS_32;
                    }
                    if (    f64Bit
                         && (reg >= VBOX_MSI_CAP_MASK_BITS_64)
                         && (reg < VBOX_MSI_CAP_MASK_BITS_64 + 4)
                       )
                    {
                        maskUpdated = reg - VBOX_MSI_CAP_MASK_BITS_64;
                    }

                    if (maskUpdated != -1 && msiIsEnabled(pDev))
                    {
                        uint32_t*  puPending = msiGetPendingBits(pDev);
                        for (int iBitNum = 0; iBitNum < 8; iBitNum++)
                        {
                            int32_t iBit = 1 << iBitNum;
                            uint32_t uVector = maskUpdated*8 + iBitNum;

                            if (msiBitJustCleared(pDev->config[uAddr], u8Val, iBit))
                            {
                                Log(("msi: mask updated bit %d@%x (%d)\n", iBitNum, uAddr, maskUpdated));

                                /* To ensure that we're no longer masked */
                                pDev->config[uAddr] &= ~iBit;
                                if ((*puPending & (1 << uVector)) != 0)
                                {
                                    Log(("msi: notify earlier masked pending vector: %d\n", uVector));
                                    MsiNotify(pDevIns, pPciHlp, pDev, uVector, PDM_IRQ_LEVEL_HIGH, 0 /*uTagSrc*/);
                                }
                            }
                            if (msiBitJustSet(pDev->config[uAddr], u8Val, iBit))
                            {
                                Log(("msi: mask vector: %d\n", uVector));
                            }
                        }
                    }

                    pDev->config[uAddr] = u8Val;
                }
        }
        uAddr++;
        val >>= 8;
    }
}
Exemplo n.º 21
0
int main()
{
   boost::int8_t i8 = INT8_C(0);
   (void)i8;
   boost::uint8_t ui8 = UINT8_C(0);
   (void)ui8;
   boost::int16_t i16 = INT16_C(0);
   (void)i16;
   boost::uint16_t ui16 = UINT16_C(0);
   (void)ui16;
   boost::int32_t i32 = INT32_C(0);
   (void)i32;
   boost::uint32_t ui32 = UINT32_C(0);
   (void)ui32;
#ifndef BOOST_NO_INT64_T
   boost::int64_t i64 = 0;
   (void)i64;
   boost::uint64_t ui64 = 0;
   (void)ui64;
#endif
   boost::int_least8_t i8least = INT8_C(0);
   (void)i8least;
   boost::uint_least8_t ui8least = UINT8_C(0);
   (void)ui8least;
   boost::int_least16_t i16least = INT16_C(0);
   (void)i16least;
   boost::uint_least16_t ui16least = UINT16_C(0);
   (void)ui16least;
   boost::int_least32_t i32least = INT32_C(0);
   (void)i32least;
   boost::uint_least32_t ui32least = UINT32_C(0);
   (void)ui32least;
#ifndef BOOST_NO_INT64_T
   boost::int_least64_t i64least = 0;
   (void)i64least;
   boost::uint_least64_t ui64least = 0;
   (void)ui64least;
#endif
   boost::int_fast8_t i8fast = INT8_C(0);
   (void)i8fast;
   boost::uint_fast8_t ui8fast = UINT8_C(0);
   (void)ui8fast;
   boost::int_fast16_t i16fast = INT16_C(0);
   (void)i16fast;
   boost::uint_fast16_t ui16fast = UINT16_C(0);
   (void)ui16fast;
   boost::int_fast32_t i32fast = INT32_C(0);
   (void)i32fast;
   boost::uint_fast32_t ui32fast = UINT32_C(0);
   (void)ui32fast;
#ifndef BOOST_NO_INT64_T
   boost::int_fast64_t i64fast = 0;
   (void)i64fast;
   boost::uint_fast64_t ui64fast = 0;
   (void)ui64fast;
#endif
   boost::intmax_t im = 0;
   (void)im;
   boost::uintmax_t uim = 0;
   (void)uim;
}
Exemplo n.º 22
0
IRIRef *IRIRef::normalize() THROWS(BadAllocException, TraceableException) {
  if (this->normalized && !this->urified) {
    return this;
  }

  uint8_t *normed = NULL;
  DPtr<uint8_t> *normal = NULL;

  if (this->utf8str->standable()) {
    this->utf8str = this->utf8str->stand();
    normal = this->utf8str;
    normal->hold();
  } else {
    NEW(normal, MPtr<uint8_t>, this->utf8str->size());
  }
  normed = normal->dptr();

  // Percent encoding; decode if IUnreserved
  uint8_t bits = UINT8_C(0);
  uint8_t *begin = this->utf8str->dptr();
  uint8_t *end = begin + this->utf8str->size();
  uint8_t *marki = begin;
  uint8_t *markj = begin;
  uint8_t *markk = normed;
  for (; marki != end; marki = markj) {
    for (markj = marki; markj != end && *markj != to_ascii('%'); ++markj) {
      // loop does the work
    }
    size_t sz = markj - marki;
    memmove(markk, marki, sz * sizeof(uint8_t));
    markk += sz;
    if (markj == end) {
      break;
    }

    uint8_t enc[4] = { UINT8_C(0xFF), UINT8_C(0xFF),
                       UINT8_C(0xFF), UINT8_C(0xFF) };
    enc[0] = (((uint8_t) IRI_HEX_VALUE(markj[1])) << 4)
             | (uint8_t) IRI_HEX_VALUE(markj[2]);
    if (enc[0] <= UINT8_C(0x7F)) {
      if (IRIRef::isIUnreserved(enc[0])) {
        *markk = enc[0];
        ++markk;
      } else {
        markk[0] = markj[0];
        markk[1] = to_upper(markj[1]);
        markk[2] = to_upper(markj[2]);
        markk += 3;
      }
      markj += 3;
      continue;
    }

    uint8_t *markl = markj + 3;
    int i = 1;
    uint8_t bits;
    for (bits = enc[0] << 1; markl != end && *markl == to_ascii('%') &&
                             bits > UINT8_C(0x7F) && i < 4; bits <<= 1) {
      enc[i] = (((uint8_t) IRI_HEX_VALUE(markl[1])) << 4)
               | (uint8_t) IRI_HEX_VALUE(markl[2]);
      markl += 3;
      ++i;
    }
    try {
      const uint8_t *endenc;
      uint32_t codepoint = utf8char(enc, &endenc);
      if (IRIRef::isIUnreserved(codepoint)) {
        i = endenc - enc; // should already be equal, but just in case
        memmove(markk, enc, i * sizeof(uint8_t));
        markk += i;
        markj = markl;
        this->urified = false;
      } else {
        for (; markj != markl; markj += 3) {
          markk[0] = markj[0];
          markk[1] = to_upper(markj[1]);
          markk[2] = to_upper(markj[2]);
          markk += 3;
        }
      }
    } catch (InvalidEncodingException &e) {
      markk[0] = markj[0];
      markk[1] = to_upper(markj[1]);
      markk[2] = to_upper(markj[2]);
      markk += 3;
      markj += 3;
    }
  }
  if (markk != end) {
    DPtr<uint8_t> *temp = normal->sub(0, markk - normed);
    normal->drop();
    normal = temp;
  }

  if (this->normalized) {
    this->utf8str->drop();
    this->utf8str = normal;
    return this;
  }

  // Character normalization; NFC
  DPtr<uint32_t> *codepoints = utf8dec(normal);
  normal->drop();
  DPtr<uint32_t> *codepoints2 = nfc_opt(codepoints);
  codepoints->drop();
  normal = utf8enc(codepoints2);
  codepoints2->drop();
  this->utf8str->drop();
  this->utf8str = normal;

  // Path normalization
  this->resolve(NULL);

  // Case normalization; scheme and host
  DPtr<uint8_t> *part = this->getPart(SCHEME);
  if (part != NULL) {
    begin = part->dptr();
    end = begin + part->size();
    for (; begin != end; ++begin) {
      *begin = to_lower(*begin);
    }
    part->drop();
  }
  part = this->getPart(HOST);
  if (part != NULL) {
    begin = part->dptr();
    end = begin + part->size();
    for (; begin != end; ++begin) {
      *begin = to_lower(*begin);
    }
    part->drop();
  }

  this->normalized = true;
  return this;
}
Exemplo n.º 23
0
int _main_(int _argc, char** _argv)
{
	Args args(_argc, _argv);

	uint32_t width = 1280;
	uint32_t height = 720;
	uint32_t debug = BGFX_DEBUG_TEXT;
	uint32_t reset  = 0
		| BGFX_RESET_VSYNC
		| BGFX_RESET_MSAA_X16
		;

	bgfx::init(args.m_type, args.m_pciId);
	bgfx::reset(width, height, reset);

	// Enable debug text.
	bgfx::setDebug(debug);

	// Set views  clear state.
	bgfx::setViewClear(0
		, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
		, 0x303030ff
		, 1.0f
		, 0
		);

	// Imgui.
	imguiCreate();

	// Uniforms.
	Uniforms uniforms;
	uniforms.init();

	// Vertex declarations.
	PosColorTexCoord0Vertex::init();

	LightProbe lightProbes[LightProbe::Count];
	lightProbes[LightProbe::Bolonga].load("bolonga");
	lightProbes[LightProbe::Kyoto  ].load("kyoto");
	LightProbe::Enum currentLightProbe = LightProbe::Bolonga;

	bgfx::UniformHandle u_mtx        = bgfx::createUniform("u_mtx",        bgfx::UniformType::Mat4);
	bgfx::UniformHandle u_params     = bgfx::createUniform("u_params",     bgfx::UniformType::Vec4);
	bgfx::UniformHandle u_flags      = bgfx::createUniform("u_flags",      bgfx::UniformType::Vec4);
	bgfx::UniformHandle u_camPos     = bgfx::createUniform("u_camPos",     bgfx::UniformType::Vec4);
	bgfx::UniformHandle s_texCube    = bgfx::createUniform("s_texCube",    bgfx::UniformType::Int1);
	bgfx::UniformHandle s_texCubeIrr = bgfx::createUniform("s_texCubeIrr", bgfx::UniformType::Int1);

	bgfx::ProgramHandle programMesh  = loadProgram("vs_ibl_mesh",   "fs_ibl_mesh");
	bgfx::ProgramHandle programSky   = loadProgram("vs_ibl_skybox", "fs_ibl_skybox");

	Mesh* meshBunny;
	meshBunny = meshLoad("meshes/bunny.bin");

	Mesh* meshOrb;
	meshOrb = meshLoad("meshes/orb.bin");

	Camera camera;
	Mouse mouse;

	struct Settings
	{
		Settings()
		{
			m_envRotCurr = 0.0f;
			m_envRotDest = 0.0f;
			m_lightDir[0] = -0.8f;
			m_lightDir[1] = 0.2f;
			m_lightDir[2] = -0.5f;
			m_lightCol[0] = 1.0f;
			m_lightCol[1] = 1.0f;
			m_lightCol[2] = 1.0f;
			m_glossiness = 0.7f;
			m_exposure = 0.0f;
			m_bgType = 3.0f;
			m_radianceSlider = 2.0f;
			m_reflectivity = 0.85f;
			m_rgbDiff[0] = 1.0f;
			m_rgbDiff[1] = 1.0f;
			m_rgbDiff[2] = 1.0f;
			m_rgbSpec[0] = 1.0f;
			m_rgbSpec[1] = 1.0f;
			m_rgbSpec[2] = 1.0f;
			m_lod = 0.0f;
			m_doDiffuse = false;
			m_doSpecular = false;
			m_doDiffuseIbl = true;
			m_doSpecularIbl = true;
			m_showLightColorWheel = true;
			m_showDiffColorWheel = true;
			m_showSpecColorWheel = true;
			m_metalOrSpec = 0;
			m_meshSelection = 0;
			m_crossCubemapPreview = ImguiCubemap::Latlong;
		}

		float m_envRotCurr;
		float m_envRotDest;
		float m_lightDir[3];
		float m_lightCol[3];
		float m_glossiness;
		float m_exposure;
		float m_radianceSlider;
		float m_bgType;
		float m_reflectivity;
		float m_rgbDiff[3];
		float m_rgbSpec[3];
		float m_lod;
		bool m_doDiffuse;
		bool m_doSpecular;
		bool m_doDiffuseIbl;
		bool m_doSpecularIbl;
		bool m_showLightColorWheel;
		bool m_showDiffColorWheel;
		bool m_showSpecColorWheel;
		uint8_t m_metalOrSpec;
		uint8_t m_meshSelection;
		ImguiCubemap::Enum m_crossCubemapPreview;
	};

	Settings settings;

	int32_t leftScrollArea = 0;

	entry::MouseState mouseState;
	while (!entry::processEvents(width, height, debug, reset, &mouseState) )
	{
		imguiBeginFrame(mouseState.m_mx
			, mouseState.m_my
			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT   : 0)
			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT  : 0)
			| (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
			, mouseState.m_mz
			, uint16_t(width)
			, uint16_t(height)
			);

		static int32_t rightScrollArea = 0;
		imguiBeginScrollArea("", width - 256 - 10, 10, 256, 700, &rightScrollArea);

		imguiLabel("Environment light:");
		imguiIndent();
		imguiBool("IBL Diffuse",  settings.m_doDiffuseIbl);
		imguiBool("IBL Specular", settings.m_doSpecularIbl);
		currentLightProbe = LightProbe::Enum(imguiTabs(
								  uint8_t(currentLightProbe)
								, true
								, ImguiAlign::LeftIndented
								, 16
								, 2
								, 2
								, "Bolonga"
								, "Kyoto"
								) );
		if (imguiCube(lightProbes[currentLightProbe].m_tex, settings.m_lod, settings.m_crossCubemapPreview, true) )
		{
			settings.m_crossCubemapPreview = ImguiCubemap::Enum( (settings.m_crossCubemapPreview+1) % ImguiCubemap::Count);
		}
		imguiSlider("Texture LOD", settings.m_lod, 0.0f, 10.1f, 0.1f);
		imguiUnindent();

		imguiSeparator(8);
		imguiLabel("Directional light:");
		imguiIndent();
		imguiBool("Diffuse",  settings.m_doDiffuse);
		imguiBool("Specular", settings.m_doSpecular);
		const bool doDirectLighting = settings.m_doDiffuse || settings.m_doSpecular;
		imguiSlider("Light direction X", settings.m_lightDir[0], -1.0f, 1.0f, 0.1f, doDirectLighting);
		imguiSlider("Light direction Y", settings.m_lightDir[1], -1.0f, 1.0f, 0.1f, doDirectLighting);
		imguiSlider("Light direction Z", settings.m_lightDir[2], -1.0f, 1.0f, 0.1f, doDirectLighting);
		imguiColorWheel("Color:", settings.m_lightCol, settings.m_showLightColorWheel, 0.6f, doDirectLighting);
		imguiUnindent();

		imguiSeparator(8);
		imguiLabel("Background:");
		imguiIndent();
		{
			int32_t selection;
			if      (0.0f == settings.m_bgType) { selection = UINT8_C(0); }
			else if (7.0f == settings.m_bgType) { selection = UINT8_C(2); }
			else                                { selection = UINT8_C(1); }

			selection = imguiTabs(
							  uint8_t(selection)
							, true
							, ImguiAlign::LeftIndented
							, 16
							, 2
							, 3
							, "Skybox"
							, "Radiance"
							, "Irradiance"
							);
			if      (0 == selection) { settings.m_bgType = 0.0f; }
			else if (2 == selection) { settings.m_bgType = 7.0f; }
			else                     { settings.m_bgType = settings.m_radianceSlider; }
			const bool isRadiance = (selection == 1);
			imguiSlider("Mip level", settings.m_radianceSlider, 1.0f, 6.0f, 0.1f, isRadiance);
		}
		imguiUnindent();

		imguiSeparator(8);
		imguiLabel("Post processing:");
		imguiIndent();
		imguiSlider("Exposure", settings.m_exposure, -4.0f, 4.0f, 0.1f);
		imguiUnindent();

		imguiSeparator();

		imguiEndScrollArea();

		imguiBeginScrollArea("", 10, 70, 256, 636, &leftScrollArea);

		imguiLabel("Mesh:");
		imguiIndent();
		settings.m_meshSelection = uint8_t(imguiChoose(settings.m_meshSelection, "Bunny", "Orbs") );
		imguiUnindent();

		const bool isBunny = (0 == settings.m_meshSelection);
		if (!isBunny)
		{
			settings.m_metalOrSpec = 0;
		}

		imguiSeparator(4);
		imguiLabel("Workflow:");
		imguiIndent();
		if (imguiCheck("Metalness", 0 == settings.m_metalOrSpec, isBunny) ) { settings.m_metalOrSpec = 0; }
		if (imguiCheck("Specular",  1 == settings.m_metalOrSpec, isBunny) ) { settings.m_metalOrSpec = 1; }
		imguiUnindent();

		imguiSeparator(4);
		imguiLabel("Material:");
		imguiIndent();
		imguiSlider("Glossiness", settings.m_glossiness, 0.0f, 1.0f, 0.01f, isBunny);
		imguiSlider(0 == settings.m_metalOrSpec ? "Metalness" : "Diffuse - Specular", settings.m_reflectivity, 0.0f, 1.0f, 0.01f, isBunny);
		imguiUnindent();

		imguiColorWheel("Diffuse:", &settings.m_rgbDiff[0], settings.m_showDiffColorWheel, 0.7f);
		imguiSeparator();
		imguiColorWheel("Specular:", &settings.m_rgbSpec[0], settings.m_showSpecColorWheel, 0.7f, (1 == settings.m_metalOrSpec) && isBunny);

		imguiEndScrollArea();

		imguiEndFrame();

		uniforms.m_glossiness   = settings.m_glossiness;
		uniforms.m_reflectivity = settings.m_reflectivity;
		uniforms.m_exposure     = settings.m_exposure;
		uniforms.m_bgType       = settings.m_bgType;
		uniforms.m_metalOrSpec   = float(settings.m_metalOrSpec);
		uniforms.m_doDiffuse     = float(settings.m_doDiffuse);
		uniforms.m_doSpecular    = float(settings.m_doSpecular);
		uniforms.m_doDiffuseIbl  = float(settings.m_doDiffuseIbl);
		uniforms.m_doSpecularIbl = float(settings.m_doSpecularIbl);
		bx::memCopy(uniforms.m_rgbDiff,  settings.m_rgbDiff,  3*sizeof(float) );
		bx::memCopy(uniforms.m_rgbSpec,  settings.m_rgbSpec,  3*sizeof(float) );
		bx::memCopy(uniforms.m_lightDir, settings.m_lightDir, 3*sizeof(float) );
		bx::memCopy(uniforms.m_lightCol, settings.m_lightCol, 3*sizeof(float) );

		int64_t now = bx::getHPCounter();
		static int64_t last = now;
		const int64_t frameTime = now - last;
		last = now;
		const double freq = double(bx::getHPFrequency() );
		const double toMs = 1000.0/freq;
		const float deltaTimeSec = float(double(frameTime)/freq);

		// Use debug font to print information about this example.
		bgfx::dbgTextClear();
		bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/18-ibl");
		bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Image-based lighting.");
		bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);

		// Camera.
		const bool mouseOverGui = imguiMouseOverArea();
		mouse.update(float(mouseState.m_mx), float(mouseState.m_my), mouseState.m_mz, width, height);
		if (!mouseOverGui)
		{
			if (mouseState.m_buttons[entry::MouseButton::Left])
			{
				camera.orbit(mouse.m_dx, mouse.m_dy);
			}
			else if (mouseState.m_buttons[entry::MouseButton::Right])
			{
				camera.dolly(mouse.m_dx + mouse.m_dy);
			}
			else if (mouseState.m_buttons[entry::MouseButton::Middle])
			{
				settings.m_envRotDest += mouse.m_dx*2.0f;
			}
			else if (0 != mouse.m_scroll)
			{
				camera.dolly(float(mouse.m_scroll)*0.05f);
			}
		}
		camera.update(deltaTimeSec);
		bx::memCopy(uniforms.m_cameraPos, camera.m_pos.curr, 3*sizeof(float) );

		// View Transform 0.
		float view[16];
		float proj[16];
		bx::mtxIdentity(view);
		bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f);
		bgfx::setViewTransform(0, view, proj);

		// View Transform 1.
		camera.mtxLookAt(view);
		bx::mtxProj(proj, 45.0f, float(width)/float(height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
		bgfx::setViewTransform(1, view, proj);

		// View rect.
		bgfx::setViewRect(0, 0, 0, uint16_t(width), uint16_t(height) );
		bgfx::setViewRect(1, 0, 0, uint16_t(width), uint16_t(height) );

		// Env rotation.
		const float amount = bx::fmin(deltaTimeSec/0.12f, 1.0f);
		settings.m_envRotCurr = bx::flerp(settings.m_envRotCurr, settings.m_envRotDest, amount);

		// Env mtx.
		float mtxEnvView[16];
		camera.envViewMtx(mtxEnvView);
		float mtxEnvRot[16];
		bx::mtxRotateY(mtxEnvRot, settings.m_envRotCurr);
		bx::mtxMul(uniforms.m_mtx, mtxEnvView, mtxEnvRot); // Used for Skybox.

		// Submit view 0.
		bgfx::setTexture(0, s_texCube, lightProbes[currentLightProbe].m_tex);
		bgfx::setTexture(1, s_texCubeIrr, lightProbes[currentLightProbe].m_texIrr);
		bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
		screenSpaceQuad( (float)width, (float)height, true);
		uniforms.submit();
		bgfx::submit(0, programSky);

		// Submit view 1.
		bx::memCopy(uniforms.m_mtx, mtxEnvRot, 16*sizeof(float)); // Used for IBL.
		if (0 == settings.m_meshSelection)
		{
			// Submit bunny.
			float mtx[16];
			bx::mtxSRT(mtx, 1.0f, 1.0f, 1.0f, 0.0f, bx::pi, 0.0f, 0.0f, -0.80f, 0.0f);
			bgfx::setTexture(0, s_texCube,    lightProbes[currentLightProbe].m_tex);
			bgfx::setTexture(1, s_texCubeIrr, lightProbes[currentLightProbe].m_texIrr);
			uniforms.submit();
			meshSubmit(meshBunny, 1, programMesh, mtx);
		}
		else
		{
			// Submit orbs.
			for (float yy = 0, yend = 5.0f; yy < yend; yy+=1.0f)
			{
				for (float xx = 0, xend = 5.0f; xx < xend; xx+=1.0f)
				{
					const float scale   =  1.2f;
					const float spacing =  2.2f;
					const float yAdj    = -0.8f;

					float mtx[16];
					bx::mtxSRT(mtx
							, scale/xend
							, scale/xend
							, scale/xend
							, 0.0f
							, 0.0f
							, 0.0f
							, 0.0f      + (xx/xend)*spacing - (1.0f + (scale-1.0f)*0.5f - 1.0f/xend)
							, yAdj/yend + (yy/yend)*spacing - (1.0f + (scale-1.0f)*0.5f - 1.0f/yend)
							, 0.0f
							);

					uniforms.m_glossiness   =        xx*(1.0f/xend);
					uniforms.m_reflectivity = (yend-yy)*(1.0f/yend);
					uniforms.m_metalOrSpec = 0.0f;
					uniforms.submit();

					bgfx::setTexture(0, s_texCube,    lightProbes[currentLightProbe].m_tex);
					bgfx::setTexture(1, s_texCubeIrr, lightProbes[currentLightProbe].m_texIrr);
					meshSubmit(meshOrb, 1, programMesh, mtx);
				}
			}
		}

		// Advance to next frame. Rendering thread will be kicked to
		// process submitted rendering primitives.
		bgfx::frame();
	}

	meshUnload(meshBunny);
	meshUnload(meshOrb);

	// Cleanup.
	bgfx::destroyProgram(programMesh);
	bgfx::destroyProgram(programSky);

	bgfx::destroyUniform(u_camPos);
	bgfx::destroyUniform(u_flags);
	bgfx::destroyUniform(u_params);
	bgfx::destroyUniform(u_mtx);

	bgfx::destroyUniform(s_texCube);
	bgfx::destroyUniform(s_texCubeIrr);

	for (uint8_t ii = 0; ii < LightProbe::Count; ++ii)
	{
		lightProbes[ii].destroy();
	}

	uniforms.destroy();

	imguiDestroy();

	// Shutdown bgfx.
	bgfx::shutdown();

	return 0;
}
Exemplo n.º 24
0
void Crc08_Finalize(Crc08_Context_Type* Crc_Context)
{
  Crc_Context->Crc08_Value ^= UINT8_C(0xFF);
}
Exemplo n.º 25
0
static void parport_poll_pad(struct parport_joypad *pad)
{
   /* RetroArch uses an extended version of the Linux
   * Multisystem 2-button joystick protocol for parallel port
   * joypads:
   *
   * | Function    | Pin | Register | Bit | Active |
   * |-------------|-----|----------|-----|--------|
   * | Up          | 2   | Data     | 0   | Low    |
   * | Down        | 3   | Data     | 1   | Low    |
   * | Left        | 4   | Data     | 2   | Low    |
   * | Right       | 5   | Data     | 3   | Low    |
   * | A           | 6   | Data     | 4   | Low    |
   * | B           | 7   | Data     | 5   | Low    |
   * | Start       | 8   | Data     | 6   | Low    |
   * | Select      | 9   | Data     | 7   | Low    |
   * | Menu toggle | 10  | Status   | 6   | Low    |
   * | X           | 11  | Status   | 7   | Low*   |
   * | Y           | 12  | Status   | 5   | Low    |
   * | L1          | 13  | Status   | 4   | Low    |
   * | R1          | 15  | Status   | 3   | Low    |
   *
   * (*) Pin is hardware inverted, but RetroArch inverts it
   *     back again so the same pullup scheme may be used for
   *     all pins.
   *
   * Pin 1 is set high so it can be used for pullups.
   *
   * RetroArch does not perform debouncing, and so long as
   * the button settling time is less than the frame time
   * no bouncing will be observed. This replicates the latching
   * behavior common in old games consoles. For optimum latency
   * and jitter a high performance debouncing routine should be
   * implemented in the controller hardware.
   */

   int i;
   char data;
   char status;

   ioctl(pad->fd, PPRDATA, &data);
   ioctl(pad->fd, PPRSTATUS, &status);

   for (i = 0; i < 8; i++)
   {
      if (!(data & UINT8_C(1 << i)) && pad->button_enable[i])
         BIT64_SET(pad->buttons, i);
      else
         BIT64_CLEAR(pad->buttons, i);
   }
   for (i = 3; i < 8; i++)
   {
      if (!(status & UINT8_C(1 << i)) && pad->button_enable[i + 5])
         BIT64_SET(pad->buttons, i + 5);
      else
         BIT64_CLEAR(pad->buttons, i + 5);
   }

   if (BIT64_GET(pad->buttons, 12) && pad->button_enable[12])
      BIT64_CLEAR(pad->buttons, 12);
   else
      BIT64_SET(pad->buttons, 12);
}
Exemplo n.º 26
0
void app::crc::task_func()
{
  // Calculate and verify the 8-bit, 16-bit,
  // 32-bit and 64-bit CRC.

  typedef enum app_crc_calculation_state
  {
    app_crc_calculation_state_initialize,
    app_crc_calculation_state_process_bytes,
    app_crc_calculation_state_finalize
  }
  app_crc_calculation_state_type;

  static app_crc_calculation_state_type app_crc_calculation_state =
    app_crc_calculation_state_initialize;

  static std::uint_fast8_t app_crc_process_data_byte_count;

  static std::uint_fast8_t app_crc_object_index;

  // On 8-bit target, take runtime statistics for the
  // state machine (averaged over all 8,16,32,64-bit CRCs,
  // all bytes and all states).
  //   * average 10.3us
  //   * low      3.4us
  //   * high    22  us.

  // Average load for CRC calculation only is:
  //   * 10.3us / 1ms = approx. 1%.
  //   * 36ms (total) needed to cycle through all 4 CRCs.

  // Disable all interrupts before each calculation
  // in order to provide for a clean time measurement.
  mcal::irq::disable_all();

  // Use a port pin to provide a real-time measurement.
  app_crc_measurement_port_type::set_pin_high();

  // Distribute the CRC calculations
  // over multitasking time slices.
  // Process one single byte at a time,

  switch(app_crc_calculation_state)
  {
    case app_crc_calculation_state_initialize:

      // Initialize the CRC object.
      app_crc_checksums[app_crc_object_index]->initialize();

      app_crc_calculation_state = app_crc_calculation_state_process_bytes;

      break;

      case app_crc_calculation_state_process_bytes:

      {
        // Process the next byte.
        const std::uint8_t next_byte =
          *(app_crc_test_values.data() + app_crc_process_data_byte_count);

        app_crc_checksums[app_crc_object_index]->process_bytes(&next_byte, 1U);
      }

      ++app_crc_process_data_byte_count;

      if(app_crc_process_data_byte_count >= app_crc_test_values.size())
      {
        // If all bytes for this CRC have been processed,
        // then reset the byte count to 0 and move to the
        // finalize state for this CRC calculation.
        app_crc_process_data_byte_count = 0U;

        // We are now ready to move to CRC state finalize
        // for this CRC object.
        app_crc_calculation_state = app_crc_calculation_state_finalize;
      }

      break;

    default:
    case app_crc_calculation_state_finalize:

      // Finalize this CRC object.
      app_crc_checksums[app_crc_object_index]->finalize();

      // Increment to othe next CRC object in the list.
      ++app_crc_object_index;

      if(app_crc_object_index >= app_crc_checksums.size())
      {
        // If we have reached the end of the CRC object list,
        // Then reset to the beginning of the list.
        app_crc_object_index = 0U;

        // Verify all CRC results.
        app_crc_results_are_ok =
          (    (app_crc_checksums[0U]->get_result<std::uint8_t> () == UINT8_C (0xDF))
            && (app_crc_checksums[1U]->get_result<std::uint16_t>() == UINT16_C(0x29B1))
            && (app_crc_checksums[2U]->get_result<std::uint32_t>() == UINT32_C(0x1697D06A))
            && (app_crc_checksums[3U]->get_result<std::uint64_t>() == UINT64_C(0x995DC9BBDF1939FA)));
      }

      // Return to CRC state initialization.
      app_crc_calculation_state = app_crc_calculation_state_initialize;

      break;
  }

  app_crc_measurement_port_type::set_pin_low();

  // Remember to enable all interrupts after the calculation.
  mcal::irq::enable_all();

  if(app_crc_results_are_ok == false)
  {
    // The CRC results are not OK.

    for(;;)
    {
      // Crash the system and toggle a port
      // to provide an indication of failure.

      app_crc_measurement_port_type::toggle_pin();

      mcal::cpu::nop();
    }
  }
}
Exemplo n.º 27
0
void Crc08_Initialize(Crc08_Context_Type* Crc_Context)
{
  /* Set the initial value. */
  Crc_Context->Crc08_Value = UINT8_C(0xFF);
}
bool mcal::display::display_console::do_write(const std::uint8_t value_to_write)
{
  static const std::array<std::uint8_t, 16U> character_table =
  {{
    UINT8_C('0'),
    UINT8_C('1'),
    UINT8_C('2'),
    UINT8_C('3'),
    UINT8_C('4'),
    UINT8_C('5'),
    UINT8_C('6'),
    UINT8_C('7'),
    UINT8_C('8'),
    UINT8_C('9'),
    UINT8_C('A'),
    UINT8_C('b'),
    UINT8_C('c'),
    UINT8_C('d'),
    UINT8_C('E'),
    UINT8_C('F')
  }};

  std::uint8_t table_index;
  bool         write_is_ok;

  const bool byte_is_in_range =
    (value_to_write < std::uint8_t(character_table.size()));

  if(byte_is_in_range)
  {
    table_index = value_to_write;

    write_is_ok = true;
  }
  else
  {
    table_index = std::uint8_t(character_table.size() - 1U);

    write_is_ok = false;
  }

  set_data(character_table[table_index]);

  std::cout << "seven_segment display: "
            << char(get_data());

  if(get_dp_is_on())
  {
    std::cout << char('.');
  }

  std::cout << std::endl;

  return write_is_ok;
}
Exemplo n.º 29
0
static bool parport_joypad_init_pad(const char *path, struct parport_joypad *pad)
{
   int i;
   char data;
   struct ppdev_frob_struct frob;
   int datadir          = 1; /* read */
   bool set_control     = false;
   int mode             = IEEE1284_MODE_BYTE;
   settings_t *settings = config_get_ptr();

   if (pad->fd >= 0)
      return false;

   if (access(path, R_OK | W_OK) < 0)
      return false;

   pad->fd     = open(path, O_RDWR | O_NONBLOCK);
   *pad->ident = '\0';

   if (pad->fd >= 0)
   {
      RARCH_LOG("[Joypad]: Found parallel port: %s\n", path);

      /* Parport driver does not log failures with RARCH_ERR because they could be
       * a normal result of connected non-joypad devices. */
      if (ioctl(pad->fd, PPCLAIM) < 0)
      {
         RARCH_WARN("[Joypad]: Failed to claim %s\n", path);
         goto error;
      }
      if (ioctl(pad->fd, PPSETMODE, &mode) < 0)
      {
         RARCH_WARN("[Joypad]: Failed to set byte mode on %s\n", path);
         goto error;
      }
      if (ioctl(pad->fd, PPDATADIR, &datadir) < 0)
      {
         RARCH_WARN("[Joypad]: Failed to set data direction to input on %s\n", path);
         goto error;
      }

      if (ioctl(pad->fd, PPRDATA, &data) < 0)
      {
         RARCH_WARN("[Joypad]: Failed to save original data register on %s\n", path);
         goto error;
      }
      pad->saved_data = data;

      if (ioctl(pad->fd, PPRCONTROL, &data) == 0)
      {
         pad->saved_control = data;
         /* Clear strobe bit to set strobe high for pullup +V */
         /* Clear control bit 4 to disable interrupts */
         frob.mask = PARPORT_CONTROL_STROBE | (UINT8_C(1 << 4));
         frob.val = 0;
         if (ioctl(pad->fd, PPFCONTROL, &frob) == 0)
            set_control = true;
      }
      else
      {
         data = pad->saved_data;
         if (ioctl(pad->fd, PPWDATA, &data) < 0)
            RARCH_WARN("[Joypad]: Failed to restore original data register on %s\n", path);
         RARCH_WARN("[Joypad]: Failed to save original control register on %s\n", path);
         goto error;
      }

      /* Failure to enable strobe can break Linux Multisystem style controllers.
       * Controllers using an alternative power source will still work.
       * Failure to disable interrupts slightly increases CPU usage. */
      if (!set_control)
         RARCH_WARN("[Joypad]: Failed to clear nStrobe and nIRQ bits on %s\n", path);

      strlcpy(pad->ident, path, sizeof(settings->input.device_names[0]));

      for (i = 0; i < PARPORT_NUM_BUTTONS; i++)
         pad->button_enable[i] = true;

      return true;
error:
      close(pad->fd);
      pad->fd = 0;
      return false;
   }

   RARCH_WARN("[Joypad]: Failed to open parallel port %s (error: %s).\n", path, strerror(errno));
   return false;
}
Exemplo n.º 30
0
C(INTMAX_MAX)
C(UINTMAX_MAX)
C(PTRDIFF_MIN)
C(PTRDIFF_MAX)
C(SIG_ATOMIC_MIN)
C(SIG_ATOMIC_MAX)
C(SIZE_MAX)
C(WCHAR_MIN)
C(WCHAR_MAX)
C(WINT_MIN)
C(WINT_MAX)
C(INT8_C(0))
C(INT16_C(0))
C(INT32_C(0))
C(INT64_C(0))
C(UINT8_C(0))
C(UINT16_C(0))
C(UINT32_C(0))
C(UINT64_C(0))
C(INTMAX_C(0))
C(UINTMAX_C(0))
S(PRId8)
S(PRId16)
S(PRId32)
S(PRId64)
S(PRIdLEAST8)
S(PRIdLEAST16)
S(PRIdLEAST32)
S(PRIdLEAST64)
S(PRIdFAST8)
S(PRIdFAST16)