blob: eddb28642a48d1603c8fe077a66ded83e3f679d5 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <pthread.h>
5#include <lynq/lynq-irq.h>
6
7
8#define CMD_SET_WAKE "set_wake"
9#define CMD_GET_WAKE "get_wake\n"
10#define CMD_SET_TYPE "set_type"
11#define CMD_GET_TYPE "get_type\n"
12#define CMD_UNINSTALL "uninstall\n"
13#define CMD_QUIT_TEST "quit\n"
14
15int line;
16
17
18static void printUsage(void)
19{
20 printf("Usage:\n");
21 printf("-set_wake <en>\n");
22 printf("-set_type <en>\n");
23 printf("-get_type\n");
24 printf("-get_wake\n");
25 printf("-uninstall\n");
26 printf("-quit\n");
27 printf("Please input an cmd:");
28}
29
30
31static void irq_test_handler(void)
32{
33 int trig_type;
34 trig_type = lynq_irq_get_type(line);
35 printf("this is irq_test_handler\nthis irq is gpio %d,trig_type is %d\n", line_gpio[line], trig_type);
36// return NULL;
37}
38
39
40int main(int argc, char** argv)
41{
42 int ret;
43 int irq;
44 int trig_type;
45 int en;
46 char cmd[16];
47 char *cmd2;
48 char *cmd1;
49
50 if(argc != 3)
51 {
52 printf("wrong input format, please inout lynq-irq-demo <irq_line> <trig_type/wake_state> \n");
53 return -1;
54 }
55 irq = atoi(argv[1]);
56 trig_type = atoi(argv[2]);
57 ret = lynq_irq_install(irq, irq_test_handler, trig_type);
58 if(ret != 0)
59 {
60 printf("lynq_irq_install fail\n");
61 return 0;
62 }
63 else
64 {
65 printf("lynq_irq_install success\n");
66 line = irq;
67 }
68
69 while(1)
70 {
71 printUsage();
72 memset(cmd,0,sizeof(cmd));
73 fgets(cmd, sizeof(cmd), stdin);
74 printf("cmd:%s\n",cmd);
75 cmd1 = strtok(cmd, " ");
76 cmd2 = strtok(NULL, " ");
77 if(strcmp(cmd1, CMD_SET_WAKE) == 0)
78 {
79 if(cmd2 == NULL)
80 {
81 printf("wake_state is NULL\n");
82 break;
83 }
84 en = atoi(cmd2);
85 ret = lynq_irq_set_wake(irq, en);
86 if(ret < 0)
87 {
88 printf("lynq_irq_set_wake fail\n");
89 printf("ret=%d\n", ret);
90 }
91 else
92 {
93 printf("lynq_irq_set_wake success\n");
94 printf("ret=%d\n", ret);
95 }
96 }
97 else if(strcmp(cmd1, CMD_GET_WAKE) == 0)
98 {
99 ret = lynq_irq_get_wake(irq);
100 printf("lynq_irq_get_wake ret %d\n", ret);
101 }
102 else if(strcmp(cmd1, CMD_SET_TYPE) == 0)
103 {
104 if(cmd2 == NULL)
105 {
106 printf("trig_type is NULL\n");
107 break;
108 }
109 trig_type = atoi(cmd2);
110 ret = lynq_irq_set_type(line, trig_type);
111 if(ret < 0)
112 {
113 printf("lynq_irq_set_type fail\n");
114 }
115 else
116 {
117 printf("lynq_irq_set_type success\n");
118 }
119 }
120 else if(strcmp(cmd1, CMD_GET_TYPE) == 0)
121 {
122 ret = lynq_irq_get_type(irq);
123 printf("lynq_irq_get_type ret %d\n", ret);
124 }
125 else if(strcmp(cmd1, CMD_UNINSTALL) == 0)
126 {
127 ret = lynq_irq_uninstall(irq);
128 if(ret != 0)
129 {
130 printf("lynq_irq_uninstall fail\n");
131 }
132 else
133 {
134 printf("lynq_irq_uninstall success\n");
135 }
136 }
137 else if(strcmp(cmd1, CMD_QUIT_TEST) == 0)
138 {
139 ret = lynq_irq_uninstall(irq);
140 if(ret != 0)
141 {
142 printf("lynq_irq_uninstall fail\n");
143 }
144 else
145 {
146 printf("lynq_irq_uninstall success\n");
147 }
148 break;
149 }
150 else
151 {
152 printf("wrong input format\n");
153 }
154 }
155
156 return 0;
157}
158
159