1 /**************************************************************************************************\r
2 * Filename: main.c\r
3 * Description: This file contains the main for the gnu platform.\r
4 *\r
5 *\r
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/\r
7 *\r
8 *\r
9 * Redistribution and use in source and binary forms, with or without\r
10 * modification, are permitted provided that the following conditions\r
11 * are met:\r
12 *\r
13 * Redistributions of source code must retain the above copyright\r
14 * notice, this list of conditions and the following disclaimer.\r
15 *\r
16 * Redistributions in binary form must reproduce the above copyright\r
17 * notice, this list of conditions and the following disclaimer in the\r
18 * documentation and/or other materials provided with the\r
19 * distribution.\r
20 *\r
21 * Neither the name of Texas Instruments Incorporated nor the names of\r
22 * its contributors may be used to endorse or promote products derived\r
23 * from this software without specific prior written permission.\r
24 *\r
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
36 *\r
37 */\r
38 #include <pthread.h>\r
39 #include <stdio.h>\r
40 #include <stdlib.h>\r
41 \r
42 #include "rpc.h"\r
43 #include "stressTest.h"\r
44 \r
45 #include "dbgPrint.h"\r
46 \r
47 void *rpcTask(void *argument)\r
48 {\r
49 while (1)\r
50 {\r
51 rpcProcess();\r
52 }\r
53 \r
54 dbg_print(PRINT_LEVEL_WARNING, "rpcTask exited!\n");\r
55 }\r
56 \r
57 void *appTask(void *argument)\r
58 {\r
59 while (1)\r
60 {\r
61 appProcess(argument);\r
62 }\r
63 }\r
64 \r
65 void *appInMessageTask(void *argument)\r
66 {\r
67 while (1)\r
68 {\r
69 appMsgProcess(NULL);\r
70 }\r
71 }\r
72 \r
73 int main(int argc, char* argv[])\r
74 {\r
75 //int retval = 0;\r
76 char * selected_serial_port;\r
77 pthread_t rpcThread, appThread, inMThread;\r
78 \r
79 dbg_print(PRINT_LEVEL_INFO, "%s -- %s %s\n", argv[0], __DATE__, __TIME__);\r
80 \r
81 // accept only 1\r
82 if (argc < 4)\r
83 {\r
84 dbg_print(PRINT_LEVEL_INFO,\r
85 "usage: %s <UART port> <dev type (coord: c, router:r, enddevice:e)> <channel (11-26)>\n",\r
86 argv[0]);\r
87 return -1;\r
88 }\r
89 else\r
90 {\r
91 selected_serial_port = argv[1];\r
92 }\r
93 \r
94 int serialPortFd = rpcOpen(selected_serial_port, 0);\r
95 if (serialPortFd == -1)\r
96 {\r
97 dbg_print(PRINT_LEVEL_ERROR, "could not open serial port\n");\r
98 exit(-1);\r
99 }\r
100 \r
101 rpcInitMq();\r
102 \r
103 //init the application thread to register the callbacks\r
104 appInit();\r
105 \r
106 //Start the Rx thread\r
107 dbg_print(PRINT_LEVEL_INFO, "creating RPC thread\n");\r
108 pthread_create(&rpcThread, NULL, rpcTask, (void *) &serialPortFd);\r
109 \r
110 //Start the example thread\r
111 dbg_print(PRINT_LEVEL_INFO, "creating example thread\n");\r
112 pthread_create(&appThread, NULL, appTask, (void *) &argv[2]);\r
113 pthread_create(&inMThread, NULL, appInMessageTask, NULL);\r
114 \r
115 while (1)\r
116 ;\r
117 \r
118 }\r