paul@205 | 1 | /* |
paul@205 | 2 | * GPIO access for tasks. |
paul@205 | 3 | * |
paul@217 | 4 | * Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@205 | 5 | * |
paul@205 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@205 | 7 | * it under the terms of the GNU General Public License as published by |
paul@205 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@205 | 9 | * (at your option) any later version. |
paul@205 | 10 | * |
paul@205 | 11 | * This program is distributed in the hope that it will be useful, |
paul@205 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@205 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@205 | 14 | * GNU General Public License for more details. |
paul@205 | 15 | * |
paul@205 | 16 | * You should have received a copy of the GNU General Public License |
paul@205 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@205 | 18 | */ |
paul@205 | 19 | |
paul@205 | 20 | #include "board.h" |
paul@205 | 21 | #include "mips.h" |
paul@205 | 22 | #include "cpu.h" |
paul@205 | 23 | #include "paging.h" |
paul@205 | 24 | #include "memory.h" |
paul@205 | 25 | #include "task_gpio.h" |
paul@205 | 26 | |
paul@217 | 27 | void task_gpio_init(uint8_t task) |
paul@205 | 28 | { |
paul@217 | 29 | uint32_t virtual, physical; |
paul@209 | 30 | |
paul@205 | 31 | /* Map the I/O region to the task. */ |
paul@205 | 32 | |
paul@218 | 33 | for (virtual = TASK_GPIO_BASE, physical = GPIO_BASE_PHYSICAL; |
paul@217 | 34 | virtual < (uint32_t) TASK_GPIO_BASE + (uint32_t) GPIO_REGION_SIZE; |
paul@209 | 35 | virtual += page_size(STAGE2_PAGESIZE), physical += page_size(STAGE2_PAGESIZE)) |
paul@209 | 36 | { |
paul@209 | 37 | init_page_table(STAGE2_PAGE_TABLE_BASE, virtual, physical, |
paul@211 | 38 | page_size(STAGE2_PAGESIZE), TLB_UNCACHED | TLB_DIRTY | TLB_VALID, task); |
paul@209 | 39 | } |
paul@205 | 40 | } |
paul@205 | 41 | |
paul@217 | 42 | void task_gpio_as_input(uint8_t pin) |
paul@211 | 43 | { |
paul@219 | 44 | TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32)); |
paul@219 | 45 | TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32)); |
paul@211 | 46 | TASK_REG_GPIO_PXDIRC(pin / 32) = (1 << (pin % 32)); |
paul@211 | 47 | } |
paul@211 | 48 | |
paul@217 | 49 | void task_gpio_as_output(uint8_t pin) |
paul@211 | 50 | { |
paul@219 | 51 | TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32)); |
paul@219 | 52 | TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32)); |
paul@211 | 53 | TASK_REG_GPIO_PXDIRS(pin / 32) = (1 << (pin % 32)); |
paul@211 | 54 | } |
paul@211 | 55 | |
paul@219 | 56 | void task_gpio_enable_pull(uint8_t pin) |
paul@219 | 57 | { |
paul@219 | 58 | TASK_REG_GPIO_PXPEC(pin / 32) = (1 << (pin % 32)); |
paul@219 | 59 | } |
paul@219 | 60 | |
paul@219 | 61 | void task_gpio_disable_pull(uint8_t pin) |
paul@219 | 62 | { |
paul@219 | 63 | TASK_REG_GPIO_PXPES(pin / 32) = (1 << (pin % 32)); |
paul@219 | 64 | } |
paul@219 | 65 | |
paul@219 | 66 | inline int task_gpio_get_pin(uint8_t pin) |
paul@219 | 67 | { |
paul@219 | 68 | return TASK_REG_GPIO_PXPIN(pin / 32) & (1 << (pin % 32)); |
paul@219 | 69 | } |
paul@219 | 70 | |
paul@217 | 71 | inline void task_gpio_set_pin(uint8_t pin) |
paul@205 | 72 | { |
paul@210 | 73 | TASK_REG_GPIO_PXDATS(pin / 32) = (1 << (pin % 32)); |
paul@205 | 74 | } |
paul@205 | 75 | |
paul@217 | 76 | inline void task_gpio_clear_pin(uint8_t pin) |
paul@205 | 77 | { |
paul@210 | 78 | TASK_REG_GPIO_PXDATC(pin / 32) = (1 << (pin % 32)); |
paul@205 | 79 | } |
paul@205 | 80 | |
paul@219 | 81 | inline void task_gpio_mask_irq(uint8_t pin) |
paul@205 | 82 | { |
paul@219 | 83 | TASK_REG_GPIO_PXIMS(pin / 32) = (1 << (pin % 32)); |
paul@205 | 84 | } |
paul@219 | 85 | |
paul@219 | 86 | inline void task_gpio_unmask_irq(uint8_t pin) |
paul@219 | 87 | { |
paul@219 | 88 | TASK_REG_GPIO_PXIMC(pin / 32) = (1 << (pin % 32)); |
paul@219 | 89 | } |