예제 #1
0
/* ===================================================================*/
void GPIO2_SetFieldValue(LDD_TDeviceData *DeviceDataPtr, LDD_GPIO_TBitField Field, GPIO2_TFieldValue Value)
{
  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  switch (Field) {                     /* no break */
    case I2C_DAT: {                    /* bit field #0 */
      GPIO_PDD_SetPortDataOutput(GPIO2_MODULE_BASE_ADDRESS,
        (
          GPIO_PDD_GetPortDataOutput(GPIO2_MODULE_BASE_ADDRESS)
          & ((GPIO2_TPortValue)(~((GPIO2_TPortValue)GPIO2_I2C_DAT_MASK)))
        )
        | (
          ((GPIO2_TPortValue)(Value << GPIO2_I2C_DAT_START_BIT))
          & ((GPIO2_TPortValue)GPIO2_I2C_DAT_MASK)
        )
      );
      break;
    }
    case I2C_CLK: {                    /* bit field #1 */
      GPIO_PDD_SetPortDataOutput(GPIO2_MODULE_BASE_ADDRESS,
        (
          GPIO_PDD_GetPortDataOutput(GPIO2_MODULE_BASE_ADDRESS)
          & ((GPIO2_TPortValue)(~((GPIO2_TPortValue)GPIO2_I2C_CLK_MASK)))
        )
        | (
          ((GPIO2_TPortValue)(Value << GPIO2_I2C_CLK_START_BIT))
          & ((GPIO2_TPortValue)GPIO2_I2C_CLK_MASK)
        )
      );
      break;
    }
    default:
      break;                           /* Invalid Field is not treated, result is undefined */
  } /* switch (Field) */
}
예제 #2
0
/*
** ===================================================================
**     Method      :  BitsIoLdd2_GetBit (component BitsIO_LDD)
**
**     Description :
**         Returns the value of the specified bit/pin of the
**         Input/Output component. If the direction is [input] then it
**         reads the input value of the pin and returns it. If the
**         direction is [output] then it returns the last written value
**         (see <Safe mode> property for limitations).
**     Parameters  :
**         NAME            - DESCRIPTION
**       * DeviceDataPtr   - Device data structure
**                           pointer returned by <Init> method.
**         Bit             - Bit/pin number to read
**       * BitVal          - The returned value: 
**                           <false> - logical "0" (Low level)
**                           <true> - logical "1" (High level)
**     Returns     :
**         ---             - Error code, possible values:
**                           ERR_OK - OK
**                           ERR_PARAM_MASK - Invalid pin index
**                           ERR_VALUE - Invalid output parameter
** ===================================================================
*/
LDD_TError BitsIoLdd2_GetBit(LDD_TDeviceData *DeviceDataPtr, byte Bit, bool *BitVal)
{
  uint32_t mask = 0;

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */

  /* Bit number value - this test can be disabled by setting the "Ignore range checking"
     property to the "yes" value in the "Configuration inspector" */
  if (Bit > 3U) {
    return ERR_PARAM_MASK;
  }

  /* Bit value returned - this test can be disabled by setting the "Ignore range checking"
     property to the "yes" value in the "Configuration inspector" */
  if (NULL == BitVal) {
    return ERR_VALUE;
  }

  mask = BitsIoLdd2_PIN_MASK_MAP[Bit];

  if ((GPIO_PDD_GetPortDataOutput(BitsIoLdd2_MODULE_BASE_ADDRESS) & mask) != 0U) {
    *BitVal = (bool)TRUE;
  }
  else {
    *BitVal = (bool)FALSE;
  }

  return ERR_OK;
}
예제 #3
0
/* ===================================================================*/
bool BitIoLdd2_GetVal(LDD_TDeviceData *DeviceDataPtr)
{
  uint32_t PortData;                   /* Port data masked according to the bit used */

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  PortData = GPIO_PDD_GetPortDataOutput(BitIoLdd2_MODULE_BASE_ADDRESS) & BitIoLdd2_PORT_MASK;
  return (PortData != 0U) ? (bool)TRUE : (bool)FALSE;
}
예제 #4
0
/*
** ===================================================================
**     Method      :  BitsIoLdd2_GetVal (component BitsIO_LDD)
**
**     Description :
**         Returns the value of the Input/Output component. If the
**         direction is [input] then reads the input value of the pins
**         and returns it. If the direction is [output] then returns
**         the last written value (see <Safe mode> property for
**         limitations).
**     Parameters  :
**         NAME            - DESCRIPTION
**       * DeviceDataPtr   - Device data structure
**                           pointer returned by <Init> method.
**     Returns     :
**         ---             - Input value
** ===================================================================
*/
dword BitsIoLdd2_GetVal(LDD_TDeviceData *DeviceDataPtr)
{
  dword portData;

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */

  portData = GPIO_PDD_GetPortDataOutput(BitsIoLdd2_MODULE_BASE_ADDRESS) & BitsIoLdd2_PORT_MASK;


  return portData >> BitsIoLdd2_PIN_ALLOC_0_INDEX; /* Return port data shifted with the offset of the first allocated pin*/
}
예제 #5
0
/* ===================================================================*/
bool BitIoLdd4_GetVal(LDD_TDeviceData *DeviceDataPtr)
{
  uint32_t PortData;                   /* Port data masked according to the bit used */

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  if ((GPIO_PDD_GetPortDirection(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK) == 0U) {
    /* Port is configured as input */
    PortData = GPIO_PDD_GetPortDataInput(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK;
  } else {
    /* Port is configured as output */
    PortData = GPIO_PDD_GetPortDataOutput(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK;
  }
  return (PortData != 0U) ? (bool)TRUE : (bool)FALSE;
}
예제 #6
0
/*
** ===================================================================
**     Method      :  BitsIoLdd4_PutVal (component BitsIO_LDD)
**
**     Description :
**         Specified value is passed to the Input/Output component. If
**         the direction is [input] saves the value to a memory or a
**         register, this value will be written to the pins after
**         switching to the output mode - using [SetDir(TRUE)] (see
**         <Safe mode> property for limitations). If the direction is
**         [output] it writes the value to the pins. (Method is
**         available only if the Direction = _[output]_ or
**         _[input/output]_).
**     Parameters  :
**         NAME            - DESCRIPTION
**       * DeviceDataPtr   - Device data structure
**                           pointer returned by <Init> method.
**         Val             - Output value
**     Returns     : Nothing
** ===================================================================
*/
void BitsIoLdd4_PutVal(LDD_TDeviceData *DeviceDataPtr, dword Val)
{
  /* Store the raw value of the port, set according to the offset of the first allocated pin */
  dword rawVal;

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */

  /* Calculate the raw data to be set (i.e. shifted to left according to the first allocated pin) */
  rawVal = (Val & BitsIoLdd4_PORT_VALID_VALUE_MASK) << BitsIoLdd4_PIN_ALLOC_0_INDEX; /* Mask and shift output value */

  /* Set port data by toggling the different bits only */
  GPIO_PDD_TogglePortDataOutputMask(BitsIoLdd4_MODULE_BASE_ADDRESS,
      (GPIO_PDD_GetPortDataOutput(BitsIoLdd4_MODULE_BASE_ADDRESS) ^ rawVal) & BitsIoLdd4_PORT_MASK);
}
예제 #7
0
/*
** ===================================================================
**     Method      :  BitsIoLdd4_GetVal (component BitsIO_LDD)
**
**     Description :
**         Returns the value of the Input/Output component. If the
**         direction is [input] then reads the input value of the pins
**         and returns it. If the direction is [output] then returns
**         the last written value (see <Safe mode> property for
**         limitations).
**     Parameters  :
**         NAME            - DESCRIPTION
**       * DeviceDataPtr   - Device data structure
**                           pointer returned by <Init> method.
**     Returns     :
**         ---             - Input value
** ===================================================================
*/
dword BitsIoLdd4_GetVal(LDD_TDeviceData *DeviceDataPtr)
{
  dword portData;

  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */

  if ((GPIO_PDD_GetPortDirection(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK) != 0U) {
    /* port is configured as output */
    portData = GPIO_PDD_GetPortDataOutput(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK;
  } else {
    /* port is configured as input */
    portData = GPIO_PDD_GetPortDataInput(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK;
  }

  return portData >> BitsIoLdd4_PIN_ALLOC_0_INDEX; /* Return port data shifted with the offset of the first allocated pin*/
}
예제 #8
0
/* ===================================================================*/
void LEDRed_SetFieldValue(LDD_TDeviceData *DeviceDataPtr, LDD_GPIO_TBitField Field, LEDRed_TFieldValue Value)
{
  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  switch (Field) {                     /* no break */
    case LED_RED: {                    /* bit field #0 */
      GPIO_PDD_SetPortDataOutput(LEDRed_MODULE_BASE_ADDRESS,
        (
          GPIO_PDD_GetPortDataOutput(LEDRed_MODULE_BASE_ADDRESS)
          & ((LEDRed_TPortValue)(~((LEDRed_TPortValue)LEDRed_LED_RED_MASK)))
        )
        | (
          ((LEDRed_TPortValue)(Value << LEDRed_LED_RED_START_BIT))
          & ((LEDRed_TPortValue)LEDRed_LED_RED_MASK)
        )
      );
      break;
    }
    default:
      break;                           /* Invalid Field is not treated, result is undefined */
  } /* switch (Field) */
}