Skip to content

Commit 00266e3

Browse files
committed
Now auto building resources.
No checkpatch.sh errors, except "Mixed case identifier found"
1 parent b250869 commit 00266e3

File tree

2 files changed

+97
-60
lines changed

2 files changed

+97
-60
lines changed

examples/xedge/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@ MODULE = $(CONFIG_EXAMPLES_XEDGE)
3131

3232
MAINSRC = xedge_main.c BAS/src/BAS.c BAS/src/dlmalloc.c BAS/src/arch/Posix/ThreadLib.c BAS/src/arch/NET/generic/SoDisp.c BAS/src/DiskIo/posix/BaFile.c BAS/examples/xedge/src/xedge.c BAS/examples/xedge/ BAS/examples/xedge/XedgeZip.c
3333

34+
XEDGEZIP = BAS/examples/xedge/XedgeZip.c
35+
36+
$(XEDGEZIP):
37+
. prepare.sh
38+
39+
context:: $(XEDGEZIP)
40+
3441

3542
include $(APPDIR)/Application.mk

examples/xedge/xedge_main.c

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/****************************************************************************
2-
* xedge_main.c
1+
/***************************************************************************
2+
* apps/examples/xedge/xedge_main.c
33
*
44
* Copyright (C) 2025. All rights reserved.
55
* Author: Real Time Logic
@@ -32,7 +32,7 @@
3232
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3333
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
*
35-
****************************************************************************/
35+
***************************************************************************/
3636

3737
/* Xedge NuttX Startup Code (may need adjustments)
3838
*
@@ -44,6 +44,10 @@
4444
* prepare.sh to clone and prepare the build env.
4545
*/
4646

47+
/***************************************************************************
48+
* Included Files
49+
***************************************************************************/
50+
4751
#include <nuttx/config.h>
4852
#include <stdio.h>
4953
#include <stdlib.h>
@@ -56,15 +60,33 @@
5660
#include <BaServerLib.h>
5761
#include "BAS/examples/xedge/src/xedge.h"
5862

59-
extern void barracuda(); /* BAS/examples/xedge/src/xedge.c */
60-
extern void init_dlmalloc(char* heapstart, char* heapend); /* dlmalloc.c */
61-
extern int (*platformInitDiskIo)(DiskIo*); /* xedge.c */
63+
/***************************************************************************
64+
* Private Data
65+
***************************************************************************/
66+
67+
static int running; /* Server running mode */
68+
69+
/* BAS is configured to use dlmalloc for NuttX. This is the pool.
70+
* 2M : recommended minimum
71+
*/
72+
73+
static char poolbuf[2 * 1024 * 1024];
6274

63-
/* The LThreadMgr configured in xedge.c */
64-
extern LThreadMgr ltMgr;
75+
extern LThreadMgr ltMgr; /* The LThreadMgr configured in xedge.c */
6576

66-
/* BAS is configured to use dlmalloc for NuttX. This is the pool. */
67-
static char poolBuf[2 * 1024 * 1024]; /* 2M : recommended minimum */
77+
/***************************************************************************
78+
* External Function Prototypes
79+
***************************************************************************/
80+
81+
/* barracuda(): BAS/examples/xedge/src/xedge.c */
82+
83+
extern void barracuda(void);
84+
extern void init_dlmalloc(char *heapstart, char *heapend); /* dlmalloc.c */
85+
extern int (*platformInitDiskIo)(DiskIo *io); /* xedge.c */
86+
87+
/***************************************************************************
88+
* Private Functions
89+
***************************************************************************/
6890

6991
/* The following two functions are copied from the example:
7092
* https://github.com/RealTimeLogic/BAS/blob/main/examples/xedge/src/led.c
@@ -77,7 +99,8 @@ static char poolBuf[2 * 1024 * 1024]; /* 2M : recommended minimum */
7799
* attempts to find the global Lua function '_XedgeEvent', and if the
78100
* function is found, it will be executed as follows: _XedgeEvent("sntp")
79101
*/
80-
static void executeXedgeEvent(ThreadJob *job, int msgh, LThreadMgr *mgr)
102+
103+
static void execevent(ThreadJob *job, int msgh, LThreadMgr *mgr)
81104
{
82105
lua_State *L = job->Lt;
83106
lua_pushglobaltable(L);
@@ -91,9 +114,10 @@ static void executeXedgeEvent(ThreadJob *job, int msgh, LThreadMgr *mgr)
91114
}
92115

93116
/* Thread started by xedgeOpenAUX() */
117+
94118
static void *checkTimeThread(void *arg)
95119
{
96-
ThreadMutex *soDispMutex = HttpServer_getMutex(ltMgr.server);
120+
ThreadMutex *dm = HttpServer_getMutex(ltMgr.server);
97121
const char *d = __DATE__;
98122
char buf[50];
99123

@@ -102,28 +126,66 @@ static void *checkTimeThread(void *arg)
102126
if (!(basnprintf(buf, sizeof(buf), "Mon, %c%c %c%c%c %s %s",
103127
d[4], d[5], d[0], d[1], d[2], d + 7, __TIME__) < 0))
104128
{
105-
BaTime compileT = baParseDate(buf);
106-
if (compileT)
129+
BaTime t = baParseDate(buf);
130+
if (t)
107131
{
108-
compileT -= 24 * 60 * 60;
109-
while (baGetUnixTime() < compileT)
132+
t -= 24 * 60 * 60;
133+
while (baGetUnixTime() < t)
110134
{
111135
Thread_sleep(500);
112136
}
113137

114-
ThreadJob *job = ThreadJob_lcreate(sizeof(ThreadJob), executeXedgeEvent);
115-
ThreadMutex_set(soDispMutex);
138+
ThreadJob *job = ThreadJob_lcreate(sizeof(ThreadJob), execevent);
139+
ThreadMutex_set(dm);
116140
LThreadMgr_run(&ltMgr, job);
117-
ThreadMutex_release(soDispMutex);
141+
ThreadMutex_release(dm);
118142
}
119143
}
120144

121145
return NULL;
122146
}
123147

148+
static void panic(BaFatalErrorCodes ecode1,
149+
unsigned int ecode2,
150+
const char *file,
151+
int line)
152+
{
153+
syslog(LOG_ERR, "Fatal error in Barracuda %d %d %s %d\n",
154+
ecode1, ecode2, file, line);
155+
exit(1);
156+
}
157+
158+
/* Redirect server's HttpTrace to syslog.
159+
* https://realtimelogic.com/ba/doc/en/C/reference/html/structHttpTrace.html
160+
*/
161+
162+
static void flushtrace(char *buf, int bufLen)
163+
{
164+
buf[bufLen] = 0;
165+
syslog(LOG_INFO, "%s", buf);
166+
}
167+
168+
static void sighandler(int signo)
169+
{
170+
if (running)
171+
{
172+
printf("\nGot SIGTERM; exiting...\n");
173+
setDispExit();
174+
175+
/* NuttX feature: Must wait for socket select() to return */
176+
177+
Thread_sleep(2000);
178+
}
179+
}
180+
181+
/***************************************************************************
182+
* Public Functions
183+
***************************************************************************/
184+
124185
/* xedge.c calls this to initialize the IO.
125186
* Change "/mnt/lfs" to your preference.
126187
*/
188+
127189
int xedgeInitDiskIo(DiskIo *io)
128190
{
129191
if (DiskIo_setRootDir(io, "/mnt/lfs"))
@@ -135,10 +197,10 @@ int xedgeInitDiskIo(DiskIo *io)
135197
return 0;
136198
}
137199

138-
139200
/* xedge.c calls this; include your Lua bindings here.
140201
* Tutorial: https://tutorial.realtimelogic.com/Lua-Bindings.lsp
141-
*/
202+
*/
203+
142204
int xedgeOpenAUX(XedgeOpenAUX *aux)
143205
{
144206
pthread_t thread;
@@ -156,51 +218,19 @@ int xedgeOpenAUX(XedgeOpenAUX *aux)
156218
return 0;
157219
}
158220

159-
static void myErrHandler(BaFatalErrorCodes ecode1,
160-
unsigned int ecode2,
161-
const char *file,
162-
int line)
163-
{
164-
syslog(LOG_ERR, "Fatal error in Barracuda %d %d %s %d\n",
165-
ecode1, ecode2, file, line);
166-
exit(1);
167-
}
168-
169-
170-
/* Redirect server's HttpTrace to syslog.
171-
* https://realtimelogic.com/ba/doc/en/C/reference/html/structHttpTrace.html
172-
*/
173-
static void flushTrace(char *buf, int bufLen)
174-
{
175-
buf[bufLen] = 0;
176-
syslog(LOG_INFO, "%s", buf);
177-
}
178-
179-
static BaBool isRunning;
180-
181-
static void sigHandler(int signo)
182-
{
183-
if (isRunning)
184-
{
185-
isRunning = FALSE;
186-
printf("\nGot SIGTERM; exiting...\n");
187-
setDispExit();
188-
Thread_sleep(2000);
189-
}
190-
}
191-
192221
int main(int argc, FAR char *argv[])
193222
{
194-
signal(SIGINT, sigHandler);
195-
signal(SIGTERM, sigHandler);
223+
signal(SIGINT, sighandler);
224+
signal(SIGTERM, sighandler);
196225

197226
ntpc_start();
198-
init_dlmalloc(poolBuf, poolBuf + sizeof(poolBuf));
199-
HttpTrace_setFLushCallback(flushTrace);
200-
HttpServer_setErrHnd(myErrHandler);
227+
init_dlmalloc(poolbuf, poolbuf + sizeof(poolbuf));
228+
HttpTrace_setFLushCallback(flushtrace);
229+
HttpServer_setErrHnd(panic);
201230

202-
isRunning = TRUE;
231+
running = TRUE;
203232
barracuda();
233+
running = FALSE;
204234

205235
printf("Exiting Xedge\n");
206236
return 0;

0 commit comments

Comments
 (0)