paul@205 | 1 | /* |
paul@205 | 2 | * GPIO access for tasks. |
paul@205 | 3 | * |
paul@205 | 4 | * Copyright (C) 2016 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@205 | 27 | void task_gpio_init(unsigned short task) |
paul@205 | 28 | { |
paul@209 | 29 | u32 virtual, physical; |
paul@209 | 30 | |
paul@205 | 31 | /* Map the I/O region to the task. */ |
paul@205 | 32 | |
paul@209 | 33 | for (virtual = TASK_GPIO_BASE, physical = GPIO_BASE; |
paul@209 | 34 | virtual < (u32) TASK_GPIO_BASE + (u32) 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@209 | 38 | page_size(STAGE2_PAGESIZE), TLB_WRITE, task); |
paul@209 | 39 | } |
paul@205 | 40 | } |
paul@205 | 41 | |
paul@205 | 42 | inline void task_gpio_set_pin(unsigned short pin) |
paul@205 | 43 | { |
paul@208 | 44 | TASK_REG_GPIO_PXDATS(pin / 32) |= (1 << (pin % 32)); |
paul@205 | 45 | } |
paul@205 | 46 | |
paul@205 | 47 | inline void task_gpio_clear_pin(unsigned short pin) |
paul@205 | 48 | { |
paul@208 | 49 | TASK_REG_GPIO_PXDATS(pin / 32) &= ~(1 << (pin % 32)); |
paul@205 | 50 | } |
paul@205 | 51 | |
paul@205 | 52 | inline int task_gpio_get_pin(unsigned short pin) |
paul@205 | 53 | { |
paul@205 | 54 | return TASK_REG_GPIO_PXPIN(pin / 32) & (1 << (pin % 32)); |
paul@205 | 55 | } |