diff options
Diffstat (limited to 'os/hal/ports/TIVA/LLD')
-rw-r--r-- | os/hal/ports/TIVA/LLD/pal_lld.c | 100 | ||||
-rw-r--r-- | os/hal/ports/TIVA/LLD/pal_lld.h | 54 |
2 files changed, 103 insertions, 51 deletions
diff --git a/os/hal/ports/TIVA/LLD/pal_lld.c b/os/hal/ports/TIVA/LLD/pal_lld.c index 657f982..d39b9b9 100644 --- a/os/hal/ports/TIVA/LLD/pal_lld.c +++ b/os/hal/ports/TIVA/LLD/pal_lld.c @@ -253,57 +253,55 @@ void _pal_lld_setgroupmode(ioportid_t port, ioportmask_t mask, iomode_t mode) { - /* TODO: What does this function exactly do? The pins are already configured - * in board.h and initialized by the pal driver. */ - - (void) port; - (void) mask; - (void) mode; - - /* - switch (mode) { - case PAL_MODE_UNCONNECTED: - case PAL_MODE_INPUT_PULLUP: - port->PUR |= mask; - case PAL_MODE_INPUT: - port->AFSEL &= ~mask; - port->DIR &= ~mask; - port->ODR &= ~mask; - port->DEN |= mask; - break; - - case PAL_MODE_INPUT_PULLDOWN: - port->AFSEL &= ~mask; - port->DIR &= ~mask; - port->ODR &= ~mask; - port->DEN |= mask; - port->PDR |= mask; - break; - - case PAL_MODE_RESET: - case PAL_MODE_INPUT_ANALOG: - port->AFSEL &= ~mask; - port->DIR &= ~mask; - port->ODR &= ~mask; - port->DEN &= ~mask; - port->PUR &= ~mask; - port->PDR &= ~mask; - break; - - case PAL_MODE_OUTPUT_PUSHPULL: - port->AFSEL &= ~mask; - port->DIR |= mask; - port->ODR &= ~mask; - port->DEN |= mask; - break; - - case PAL_MODE_OUTPUT_OPENDRAIN: - port->AFSEL &= ~mask; - port->DIR |= mask; - port->ODR |= mask; - port->DEN |= mask; - break; - }*/ + uint32_t dir = (mode & PAL_TIVA_DIR_MASK) >> 0; + uint32_t afsel = (mode & PAL_TIVA_AFSEL_MASK) >> 1; + uint32_t dr2r = (mode & PAL_TIVA_DR2R_MASK) >> 2; + uint32_t dr4r = (mode & PAL_TIVA_DR4R_MASK) >> 3; + uint32_t dr8r = (mode & PAL_TIVA_DR8R_MASK) >> 4; + uint32_t odr = (mode & PAL_TIVA_ODR_MASK) >> 5; + uint32_t pur = (mode & PAL_TIVA_PUR_MASK) >> 6; + uint32_t pdr = (mode & PAL_TIVA_PDR_MASK) >> 7; + uint32_t slr = (mode & PAL_TIVA_SLR_MASK) >> 8; + uint32_t den = (mode & PAL_TIVA_DEN_MASK) >> 9; + uint32_t amsel = (mode & PAL_TIVA_AMSEL_MASK) >> 10; + uint32_t pctl = (mode & PAL_TIVA_PCTL_MASK) >> 11; + uint32_t bit = 0; + + while(TRUE) { + uint32_t pctl_mask = (7 << (4 * bit)); + if ((mask & 1) != 0) { + port->DIR = (port->DIR & ~mask) | dir; + port->AFSEL = (port->AFSEL & ~mask) | afsel; + port->DR2R = (port->DR2R & ~mask) | dr2r; + port->DR4R = (port->DR4R & ~mask) | dr4r; + port->DR8R = (port->DR8R & ~mask) | dr8r; + port->ODR = (port->ODR & ~mask) | odr; + port->PUR = (port->PUR & ~mask) | pur; + port->PDR = (port->PDR & ~mask) | pdr; + port->SLR = (port->SLR & ~mask) | slr; + port->DEN = (port->DEN & ~mask) | den; + port->AMSEL = (port->AMSEL & ~mask) | amsel; + port->PCTL = (port->PCTL & ~pctl_mask) | pctl; + } + + mask >>= 1; + if (!mask) { + return; + } + dir <<= 1; + afsel <<= 1; + dr2r <<= 1; + dr4r <<= 1; + dr8r <<= 1; + odr <<= 1; + pur <<= 1; + pdr <<= 1; + slr <<= 1; + den <<= 1; + amsel <<= 1; + pctl <<= 4; + bit++; + } } #endif /* HAL_USE_PAL */ diff --git a/os/hal/ports/TIVA/LLD/pal_lld.h b/os/hal/ports/TIVA/LLD/pal_lld.h index a87e5fd..4edbb5d 100644 --- a/os/hal/ports/TIVA/LLD/pal_lld.h +++ b/os/hal/ports/TIVA/LLD/pal_lld.h @@ -31,6 +31,60 @@ /* Unsupported modes and specific modes */ /*===========================================================================*/ +/** + * @name TIVA-specific I/O mode flags + * @{ + */ +#define PAL_TIVA_DIR_MASK (1 << 0) +#define PAL_TIVA_DIR_INPUT (0 << 0) +#define PAL_TIVA_DIR_OUTPUT (1 << 0) + +#define PAL_TIVA_AFSEL_MASK (1 << 1) +#define PAL_TIVA_AFSEL_GPIO (0 << 1) +#define PAL_TIVA_AFSEL_ALTERNATE (1 << 1) + +#define PAL_TIVA_DR2R_MASK (1 << 2) +#define PAL_TIVA_DR2R_DISABLE (0 << 2) +#define PAL_TIVA_DR2R_ENABLE (1 << 2) + +#define PAL_TIVA_DR4R_MASK (1 << 3) +#define PAL_TIVA_DR4R_DISABLE (0 << 3) +#define PAL_TIVA_DR4R_ENABLE (1 << 3) + +#define PAL_TIVA_DR8R_MASK (1 << 4) +#define PAL_TIVA_DR8R_DISABLE (0 << 4) +#define PAL_TIVA_DR8R_ENABLE (1 << 4) + +#define PAL_TIVA_ODR_MASK (1 << 5) +#define PAL_TIVA_ODR_PUSHPULL (0 << 5) +#define PAL_TIVA_ODR_OPENDRAIN (1 << 5) + +#define PAL_TIVA_PUR_MASK (1 << 6) +#define PAL_TIVA_PUR_DISABLE (0 << 6) +#define PAL_TIVA_PUR_ENABLE (1 << 6) + +#define PAL_TIVA_PDR_MASK (1 << 7) +#define PAL_TIVA_PDR_DISABLE (0 << 7) +#define PAL_TIVA_PDR_ENABLE (1 << 7) + +#define PAL_TIVA_SLR_MASK (1 << 8) +#define PAL_TIVA_SLR_DISABLE (0 << 8) +#define PAL_TIVA_SLR_ENABLE (1 << 8) + +#define PAL_TIVA_DEN_MASK (1 << 9) +#define PAL_TIVA_DEN_DISABLE (0 << 9) +#define PAL_TIVA_DEN_ENABLE (1 << 9) + +#define PAL_TIVA_AMSEL_MASK (1 << 10) +#define PAL_TIVA_AMSEL_DISABLE (0 << 10) +#define PAL_TIVA_AMSEL_ENABLE (1 << 10) + +#define PAL_TIVA_PCTL_MASK (7 << 11) +#define PAL_TIVA_PCTL(n) ((n) << 11) +/** + * @} + */ + /*===========================================================================*/ /* I/O Ports Types and constants. */ /*===========================================================================*/ |