2019-08-19 01:26:10 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* arch/arm/src/s32k1xx/s32k1xx_pingpio.c
|
2019-08-19 01:26:10 +02:00
|
|
|
*
|
2021-03-24 09:33:59 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2019-08-19 01:26:10 +02:00
|
|
|
*
|
2021-03-24 09:33:59 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-08-19 01:26:10 +02:00
|
|
|
*
|
2021-03-24 09:33:59 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-08-19 01:26:10 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_arch.h"
|
2019-08-19 01:26:10 +02:00
|
|
|
#include "hardware/s32k1xx_gpio.h"
|
|
|
|
#include "s32k1xx_pin.h"
|
|
|
|
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: s32k1xx_gpiowrite
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write one or zero to the selected GPIO pin
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void s32k1xx_gpiowrite(uint32_t pinset, bool value)
|
|
|
|
{
|
|
|
|
uintptr_t base;
|
|
|
|
unsigned int port;
|
|
|
|
unsigned int pin;
|
|
|
|
|
|
|
|
DEBUGASSERT((pinset & _PIN_MODE_MASK) == _PIN_MODE_GPIO);
|
|
|
|
DEBUGASSERT((pinset & _PIN_IO_MASK) == _PIN_OUTPUT);
|
|
|
|
|
|
|
|
/* Get the port number and pin number */
|
|
|
|
|
|
|
|
port = (pinset & _PIN_PORT_MASK) >> _PIN_PORT_SHIFT;
|
|
|
|
pin = (pinset & _PIN_MASK) >> _PIN_SHIFT;
|
|
|
|
|
|
|
|
DEBUGASSERT(port < S32K1XX_NPORTS);
|
|
|
|
if (port < S32K1XX_NPORTS)
|
|
|
|
{
|
|
|
|
/* Get the base address of GPIO block for this port */
|
|
|
|
|
|
|
|
base = S32K1XX_GPIO_BASE(port);
|
|
|
|
|
|
|
|
/* Set or clear the output */
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
putreg32((1 << pin), base + S32K1XX_GPIO_PSOR_OFFSET);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
putreg32((1 << pin), base + S32K1XX_GPIO_PCOR_OFFSET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: s32k1xx_gpioread
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read one or zero from the selected GPIO pin
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool s32k1xx_gpioread(uint32_t pinset)
|
|
|
|
{
|
|
|
|
uintptr_t base;
|
|
|
|
uint32_t regval;
|
|
|
|
unsigned int port;
|
|
|
|
unsigned int pin;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
DEBUGASSERT((pinset & _PIN_MODE_MASK) == _PIN_MODE_GPIO);
|
|
|
|
DEBUGASSERT((pinset & _PIN_IO_MASK) == _PIN_INPUT);
|
|
|
|
|
|
|
|
/* Get the port number and pin number */
|
|
|
|
|
|
|
|
port = (pinset & _PIN_PORT_MASK) >> _PIN_PORT_SHIFT;
|
|
|
|
pin = (pinset & _PIN_MASK) >> _PIN_SHIFT;
|
|
|
|
|
|
|
|
DEBUGASSERT(port < S32K1XX_NPORTS);
|
|
|
|
if (port < S32K1XX_NPORTS)
|
|
|
|
{
|
|
|
|
/* Get the base address of GPIO block for this port */
|
|
|
|
|
|
|
|
base = S32K1XX_GPIO_BASE(port);
|
|
|
|
|
|
|
|
/* return the state of the pin */
|
|
|
|
|
|
|
|
regval = getreg32(base + S32K1XX_GPIO_PDIR_OFFSET);
|
|
|
|
ret = ((regval & (1 << pin)) != 0);
|
|
|
|
}
|
2021-03-26 17:08:45 +01:00
|
|
|
|
2019-08-19 01:26:10 +02:00
|
|
|
return ret;
|
|
|
|
}
|