paul@68 | 1 | /* |
paul@68 | 2 | * Interrupt handling. |
paul@68 | 3 | * |
paul@121 | 4 | * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@68 | 5 | * |
paul@68 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@68 | 7 | * it under the terms of the GNU General Public License as published by |
paul@68 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@68 | 9 | * (at your option) any later version. |
paul@68 | 10 | * |
paul@68 | 11 | * This program is distributed in the hope that it will be useful, |
paul@68 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@68 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@68 | 14 | * GNU General Public License for more details. |
paul@68 | 15 | * |
paul@68 | 16 | * You should have received a copy of the GNU General Public License |
paul@68 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@68 | 18 | */ |
paul@68 | 19 | |
paul@108 | 20 | #ifdef CONFIG_CPU_JZ4730_MINIPC |
paul@108 | 21 | #include "minipc.h" |
paul@108 | 22 | #else |
paul@108 | 23 | #include "nanonote.h" |
paul@108 | 24 | #endif |
paul@108 | 25 | |
paul@68 | 26 | #include "board-specific.h" |
paul@68 | 27 | #include "board.h" |
paul@68 | 28 | #include "lcd.h" |
paul@68 | 29 | #include "jzlcd.h" |
paul@68 | 30 | #include "cpu.h" |
paul@151 | 31 | #include "paging.h" |
paul@121 | 32 | #include "irq.h" |
paul@68 | 33 | |
paul@68 | 34 | extern vidinfo_t panel_info; |
paul@68 | 35 | |
paul@121 | 36 | void next_pixel(unsigned short *x, unsigned short *y) |
paul@68 | 37 | { |
paul@121 | 38 | (*x)++; |
paul@121 | 39 | if (*x >= panel_info.vl_col) { |
paul@121 | 40 | *x = 0; |
paul@121 | 41 | (*y)++; |
paul@121 | 42 | if (*y >= panel_info.vl_row) |
paul@121 | 43 | *y = 0; |
paul@68 | 44 | } |
paul@68 | 45 | } |
paul@68 | 46 | |
paul@132 | 47 | /* Task management. */ |
paul@132 | 48 | |
paul@133 | 49 | enum { max_tasks = 3 }; |
paul@133 | 50 | static u32 stack_pointers[max_tasks]; |
paul@145 | 51 | static u32 registers[max_tasks][32]; |
paul@145 | 52 | |
paul@145 | 53 | u8 current_task; |
paul@145 | 54 | u32 *current_stack_pointer; |
paul@145 | 55 | u32 *current_registers; |
paul@145 | 56 | |
paul@133 | 57 | extern u32 _got_copy_start; |
paul@133 | 58 | |
paul@149 | 59 | const u32 stack_start = 0x00080000; |
paul@132 | 60 | const u32 stack_size = 0x00002000; |
paul@132 | 61 | const u32 pagesize = 4 * 1024; |
paul@132 | 62 | |
paul@68 | 63 | /* Tasks. */ |
paul@68 | 64 | |
paul@121 | 65 | void plot_pattern(unsigned short pixel_type, unsigned short x, unsigned short y) |
paul@68 | 66 | { |
paul@68 | 67 | while (1) { |
paul@68 | 68 | if (pixel_type) |
paul@138 | 69 | test_pixel(x, y, pixel_type); |
paul@68 | 70 | else |
paul@68 | 71 | clear_pixel(x, y); |
paul@121 | 72 | next_pixel(&x, &y); |
paul@68 | 73 | udelay(100); |
paul@68 | 74 | } |
paul@68 | 75 | } |
paul@68 | 76 | |
paul@68 | 77 | /* Initialisation and handling. */ |
paul@68 | 78 | |
paul@68 | 79 | void irq_init() |
paul@68 | 80 | { |
paul@136 | 81 | handle_error_level(); |
paul@68 | 82 | timer_init_irq(); |
paul@84 | 83 | init_interrupts(); |
paul@68 | 84 | } |
paul@68 | 85 | |
paul@68 | 86 | void irq_handle() |
paul@68 | 87 | { |
paul@68 | 88 | unsigned short i; |
paul@68 | 89 | |
paul@68 | 90 | /* Check interrupt identity. */ |
paul@68 | 91 | |
paul@68 | 92 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 93 | |
paul@133 | 94 | /* Switch task. */ |
paul@68 | 95 | |
paul@143 | 96 | switch_task(); |
paul@68 | 97 | |
paul@68 | 98 | /* Clear interrupt status. */ |
paul@68 | 99 | |
paul@68 | 100 | __intc_ack_irq(TIMER_CHAN_IRQ); |
paul@68 | 101 | __tcu_clear_full_match_flag(TIMER_CHAN); |
paul@68 | 102 | |
paul@68 | 103 | /* Handle other interrupts, anyway. */ |
paul@68 | 104 | |
paul@68 | 105 | } else { |
paul@68 | 106 | for (i = 0; i < 32; i++) { |
paul@68 | 107 | if (REG_INTC_IPR & (1 << i)) |
paul@68 | 108 | __intc_ack_irq(i); |
paul@68 | 109 | } |
paul@68 | 110 | } |
paul@68 | 111 | } |
paul@68 | 112 | |
paul@145 | 113 | void init_tasks() |
paul@145 | 114 | { |
paul@145 | 115 | current_task = 0; |
paul@145 | 116 | current_stack_pointer = &stack_pointers[current_task]; |
paul@145 | 117 | current_registers = registers[current_task]; |
paul@145 | 118 | } |
paul@145 | 119 | |
paul@133 | 120 | void start_task(unsigned short task) |
paul@133 | 121 | { |
paul@138 | 122 | u32 args[] = {task, 0, (task - 1) * 60}; |
paul@136 | 123 | u32 virtual, physical; |
paul@133 | 124 | |
paul@133 | 125 | /* |
paul@133 | 126 | Each task employs a stack at a multiple of the given start address in |
paul@133 | 127 | physical memory, but at the same address in virtual memory. |
paul@133 | 128 | */ |
paul@133 | 129 | |
paul@150 | 130 | virtual = stack_start; |
paul@145 | 131 | physical = stack_start - stack_size * task; |
paul@136 | 132 | |
paul@142 | 133 | init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, 0x1e, task); |
paul@136 | 134 | |
paul@149 | 135 | stack_pointers[task] = virtual - 12; |
paul@145 | 136 | |
paul@133 | 137 | /* |
paul@145 | 138 | Set the registers for the new task, initialising the global pointer and |
paul@133 | 139 | return address. |
paul@133 | 140 | */ |
paul@133 | 141 | |
paul@145 | 142 | init_registers(registers[task], _got_copy_start, (void (*)()) plot_pattern, args, 3); |
paul@131 | 143 | } |
paul@133 | 144 | |
paul@133 | 145 | void switch_task() |
paul@133 | 146 | { |
paul@133 | 147 | /* Switch the current task. */ |
paul@133 | 148 | |
paul@133 | 149 | current_task++; |
paul@152 | 150 | if (current_task == max_tasks) current_task = 0; |
paul@133 | 151 | |
paul@145 | 152 | /* Indicate the current stack pointer and task registers. */ |
paul@134 | 153 | |
paul@145 | 154 | current_stack_pointer = &stack_pointers[current_task]; |
paul@145 | 155 | current_registers = registers[current_task]; |
paul@134 | 156 | } |