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@205 | 29 | /* Map the I/O region to the task. */ |
paul@205 | 30 | |
paul@205 | 31 | init_page_table(STAGE2_PAGE_TABLE, |
paul@205 | 32 | TASK_GPIO_BASE, |
paul@205 | 33 | GPIO_BASE, |
paul@205 | 34 | page_size(GPIO_REGION_SIZE), TLB_WRITE, task); |
paul@205 | 35 | } |
paul@205 | 36 | |
paul@205 | 37 | inline void task_gpio_set_pin(unsigned short pin) |
paul@205 | 38 | { |
paul@208 | 39 | TASK_REG_GPIO_PXDATS(pin / 32) |= (1 << (pin % 32)); |
paul@205 | 40 | } |
paul@205 | 41 | |
paul@205 | 42 | inline void task_gpio_clear_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 int task_gpio_get_pin(unsigned short pin) |
paul@205 | 48 | { |
paul@205 | 49 | return TASK_REG_GPIO_PXPIN(pin / 32) & (1 << (pin % 32)); |
paul@205 | 50 | } |