b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include "lynq-irq.h" |
| 2 | |
| 3 | #include "mbtk_type.h" |
| 4 | #include "mbtk_info_api.h" |
| 5 | |
| 6 | int line; |
| 7 | |
| 8 | static void irq_test_handler(void) |
| 9 | { |
| 10 | int trig_type; |
| 11 | trig_type = lynq_irq_get_type(line); |
| 12 | printf("this is irq_test_handler\nthis irq is gpio %d,trig_type is %d\n", line_gpio[line-117],trig_type); |
| 13 | return NULL; |
| 14 | } |
| 15 | |
| 16 | int main(int argc, char *argv[]) |
| 17 | { |
| 18 | char operator[10]; |
| 19 | int opt; |
| 20 | int irq, trig_type, en; |
| 21 | int ret; |
| 22 | irq_handler handler; |
| 23 | mbtk_log_init("radio", "IRQ_TEST"); |
| 24 | |
| 25 | printf("=========irq main=========\n" |
| 26 | "\t0 exit\n" |
| 27 | "\t1 irq install\n" |
| 28 | "\t2 irq set_type\n" |
| 29 | "\t3 irq get_type\n" |
| 30 | "\t4 irq set_wake\n" |
| 31 | "\t5 irq get_wake\n" |
| 32 | "\t6 irq uninstall\n" |
| 33 | "operator: >> \n"); |
| 34 | |
| 35 | while(1) |
| 36 | { |
| 37 | |
| 38 | fgets(operator, sizeof(operator), stdin); |
| 39 | fflush(stdin); |
| 40 | opt = atoi(operator); |
| 41 | switch (opt) |
| 42 | { |
| 43 | case 0: |
| 44 | printf("main exit\n"); |
| 45 | return 0; |
| 46 | case 1: |
| 47 | { |
| 48 | printf("input>> irq \n"); |
| 49 | memset(operator,0x00, sizeof(operator)); |
| 50 | fgets(operator, sizeof(operator)-1, stdin); |
| 51 | fflush(stdin); |
| 52 | irq = atoi(operator); |
| 53 | printf("input>> trig_type \n"); |
| 54 | memset(operator,0x00, sizeof(operator)); |
| 55 | fgets(operator, sizeof(operator)-1, stdin); |
| 56 | fflush(stdin); |
| 57 | trig_type = atoi(operator); |
| 58 | ret = lynq_irq_install(irq, irq_test_handler, trig_type); |
| 59 | if (ret != 0) |
| 60 | { |
| 61 | printf("lynq_irq_install fail\n"); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | printf("lynq_irq_install success\n"); |
| 66 | line = irq; |
| 67 | } |
| 68 | } |
| 69 | break; |
| 70 | case 2: |
| 71 | { |
| 72 | printf("input>> trig_type \n"); |
| 73 | memset(operator,0x00, sizeof(operator)); |
| 74 | fgets(operator, sizeof(operator)-1, stdin); |
| 75 | fflush(stdin); |
| 76 | trig_type = atoi(operator); |
| 77 | ret = lynq_irq_set_type(line, trig_type); |
| 78 | if (ret != 0) |
| 79 | { |
| 80 | printf("lynq_irq_set_type fail\n"); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | printf("lynq_irq_set_type success\n"); |
| 85 | } |
| 86 | } |
| 87 | break; |
| 88 | case 3: |
| 89 | { |
| 90 | printf("input>> irq \n"); |
| 91 | memset(operator,0x00, sizeof(operator)); |
| 92 | fgets(operator, sizeof(operator)-1, stdin); |
| 93 | fflush(stdin); |
| 94 | irq = atoi(operator); |
| 95 | ret = lynq_irq_get_type(irq); |
| 96 | if (ret < 0) |
| 97 | { |
| 98 | printf("lynq_irq_get_type fail\n"); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | printf("lynq_irq_get_type success trig_type =%d\n",ret); |
| 103 | } |
| 104 | } |
| 105 | break; |
| 106 | case 4: |
| 107 | { |
| 108 | printf("input>> irq \n"); |
| 109 | memset(operator,0x00, sizeof(operator)); |
| 110 | fgets(operator, sizeof(operator)-1, stdin); |
| 111 | fflush(stdin); |
| 112 | irq = atoi(operator); |
| 113 | printf("input>> en \n"); |
| 114 | memset(operator,0x00, sizeof(operator)); |
| 115 | fgets(operator, sizeof(operator)-1, stdin); |
| 116 | fflush(stdin); |
| 117 | en = atoi(operator); |
| 118 | ret = lynq_irq_set_wake(irq, en); |
| 119 | if (ret != 0) |
| 120 | { |
| 121 | printf("lynq_irq_set_wake fail\n"); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | printf("lynq_irq_set_wake success\n"); |
| 126 | } |
| 127 | } |
| 128 | break; |
| 129 | case 5: |
| 130 | { |
| 131 | printf("input>> irq \n"); |
| 132 | memset(operator,0x00, sizeof(operator)); |
| 133 | fgets(operator, sizeof(operator)-1, stdin); |
| 134 | fflush(stdin); |
| 135 | irq = atoi(operator); |
| 136 | ret = lynq_irq_get_wake(irq); |
| 137 | if (ret < 0) |
| 138 | { |
| 139 | printf("lynq_irq_get_wake fail\n"); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | printf("lynq_irq_get_wake success en = %d\n", ret); |
| 144 | } |
| 145 | } |
| 146 | break; |
| 147 | case 6: |
| 148 | { |
| 149 | printf("input>> irq \n"); |
| 150 | memset(operator,0x00, sizeof(operator)); |
| 151 | fgets(operator, sizeof(operator)-1, stdin); |
| 152 | fflush(stdin); |
| 153 | irq = atoi(operator); |
| 154 | ret = lynq_irq_uninstall(irq); |
| 155 | if (ret != 0) |
| 156 | { |
| 157 | printf("lynq_irq_uninstall fail\n"); |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | printf("lynq_irq_uninstall success\n"); |
| 162 | } |
| 163 | } |
| 164 | break; |
| 165 | default: |
| 166 | break; |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | |