Skip to content

Commit

Permalink
again
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Varanda committed Apr 14, 2021
1 parent 1ec2283 commit 042705b
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 160 deletions.
173 changes: 18 additions & 155 deletions esp32-kaluga/main/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
/* Camera Example
/***************************************************************
*
* This code is part of LUA_EOS
*
* Copyrights 2021 - Varanda Labs Inc.
*
* License:
* Creative Commons: CC BY-NC-SA 4.0
* Attribution-NonCommercial-ShareAlike 4.0 International
* https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
*
* Note: for purchasing a commertial license contact:
* [email protected]
*
***************************************************************
*/

This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
Expand All @@ -26,6 +36,7 @@
#include "linenoise/linenoise.h"

#include "mos.h"
#include "mos_test.h"

// #define SHOW_ANIMATED_SPLASH

Expand Down Expand Up @@ -174,155 +185,6 @@ static void initialize_console(void)
#endif
}

//////////////////////////// MOS Test ///////////////////////
#ifdef MOS_TEST

#define UNITY_TEST_ASSERT(c,l,m) do { \
if (c) break; \
printf("Fail line %d: %s\r\n", l, m); \
} while(0)

#define UNITY_TEST_ASSERT_RET(c,l,m) do { \
if (c) break; \
printf("Fail line %d: %s\r\n", l, m); \
return; \
} while(0)

#define TEST_ASSERT(condition,m) UNITY_TEST_ASSERT( (condition), __LINE__, m)
#define TEST_ASSERT_FALSE(condition,m) UNITY_TEST_ASSERT( !(condition), __LINE__, m)
#define TEST_ASSERT_NULL(pointer,m) UNITY_TEST_ASSERT( (pointer == NULL), __LINE__, m)
#define TEST_ASSERT_RET(condition,m) UNITY_TEST_ASSERT_RET((condition), __LINE__, m)

static mos_queue_h_t myQ;
static mos_mutex_h_t mutex;
static uint32_t cnt1 = 0;
static uint32_t cnt2 = 0;
static bool mos_test_end = false;
//mos_queue_create ( uint32_t len, uint32_t item_size);

static void myQueuReader(void * params)
{
uint32_t entry;
int ret;
uint32_t stop_val = 0xffffffff;
while(1) {
ret = mos_queue_get(myQ, &entry, MOS_WAIT_FOREVER);
if (ret == MOS_TRUE) {
if (entry == stop_val) {
printf("myQueuReader: got stop val\r\n");
mos_thread_delete(0);
return;
}
printf("myQueuReader: got value %d\r\n", entry);
}
else {
LOG_E("myQueuReader: error\r\n");
}
}

}

static void myTimerCallback( mos_timer_id_t id) {
if (mos_test_end) {
printf("myTimerCallback: timer id %d, but test MOS is ending\r\n", id);
uint32_t stop_val = 0xffffffff;
mos_queue_put (myQ, &stop_val);
return;
}

if (id == 1) {
mos_queue_put (myQ, &cnt1);
cnt1++;

if (! mos_timer_create_single_shot( 1000, myTimerCallback, 1 )) {
LOG_E("fail to to create timer 1");
}

}
else if (id == 2) {
mos_queue_put (myQ, &cnt2);
cnt2++;
if (! mos_timer_create_single_shot( 2000, myTimerCallback, 2 )) {
LOG_E("fail to to create timer 2");
}
}
else {
printf("bad timer ID");
}
}
#define RET_IF_NULL(ptr) do { if (ptr == NULL) { LOG_E("%s: NULL pointer at %d\r\n", __func__, __LINE__); return;} } while(0)

static void myTestTask(void * params)
{
int c = 0;
printf("Starting myTestTask...\r\n");

mos_mutex_lock(mutex);
cnt1 = 1;
cnt2 = 1001;
mos_mutex_unlock(mutex);

if (! mos_timer_create_single_shot( 1000, myTimerCallback, 1 )) {
LOG_E("fail to to create timer 1");
}
if (! mos_timer_create_single_shot( 2000, myTimerCallback, 2 )) {
LOG_E("fail to to create timer 2");
}

while ( ! mos_test_end) {
printf("myTestTask: c = %d\r\n", c++);
mos_thread_sleep(10000);
}
mos_thread_delete(0);
}
static void mosTest()
{
//TEST_ASSERT((1 != 1),"");
myQ = mos_queue_create ( 5, sizeof(uint32_t));
TEST_ASSERT_RET(myQ, "Fail to create queue");
mutex = mos_mutex_create();
TEST_ASSERT_RET(mutex, "Fail to create mutex");

// get max memo allocation
int m = 0;
int s = 1024;
void * ptr;
while ( (ptr = MOS_MALLOC(s)) != NULL) {
m = s;
s *= 2;
MOS_FREE(ptr);
}
printf("Max heap allocation = %d\r\n", m); // 1048576 about 1~2 mega.
TEST_ASSERT_RET(m >= 1048576, "Heap size lower than expected");


// take mutex
mos_mutex_lock(mutex);

mos_thread_h_t task1 = mos_thread_new( "myTestTask", myTestTask, 0, 3000, 6 );
TEST_ASSERT_RET(task1, "Fail to create task1");
mos_thread_h_t task2 = mos_thread_new( "myQueuReader", myQueuReader, 0, 3000, 6 );
TEST_ASSERT_RET(task2, "Fail to create task2");

// sleep to check that myTestTask is locked
mos_thread_sleep(10);
TEST_ASSERT_RET(cnt1 == 0, "mutex fail to block myTestTask");
mos_mutex_unlock(mutex);
mos_thread_sleep(10);
TEST_ASSERT_RET(cnt1 > 0, "mutex fail to unblock myTestTask");

mos_thread_sleep(7000);

printf("cnt1 = %d, cnt2 = %d\r\n", cnt1, cnt2);
// cnt1 = 8, cnt2 = 1004
TEST_ASSERT_RET(cnt1 == 8, "undexpected cnt1 value, it should be 8");
TEST_ASSERT_RET(cnt2 == 1004, "undexpected cnt2 value, it should be 1004");
mos_test_end = true; // end test
}

#else
static void mosTest(){} // do nothing
#endif
/////////////////////////// END of MOS Test /////////////////////

static void lua_task_wrapper(void * args)
Expand Down Expand Up @@ -418,6 +280,7 @@ void app_main()
#else
render_splash_animation(false);
#endif
mos_thread_sleep(1000);

////// test ///////
mosTest();
Expand Down
2 changes: 1 addition & 1 deletion esp32-kaluga/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ CONFIG_LV_THEME_MATERIAL=y
# CONFIG_LV_THEME_DEFAULT_INIT_TEMPLATE is not set
CONFIG_LV_THEME_DEFAULT_INIT_MATERIAL=y
# CONFIG_LV_THEME_DEFAULT_INIT_MONO is not set
CONFIG_LV_THEME_DEFAULT_COLOR_PRIMARY=0xFF0000
CONFIG_LV_THEME_DEFAULT_COLOR_PRIMARY=0x1a2b1
CONFIG_LV_THEME_DEFAULT_COLOR_SECONDARY=0x0000FF
CONFIG_LV_THEME_DEFAULT_FLAG_LIGHT=y
# CONFIG_LV_THEME_DEFAULT_FLAG_DARK is not set
Expand Down
6 changes: 3 additions & 3 deletions lua_eos/native/bidings.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void lua_bindings_registration(lua_State *L)
{
#ifdef HAS_LVGL
lvgl_lua_init(L);
#ifdef HAS_LVGL_SPLASH
lvgl_splash_init(L);
#endif
// #ifdef HAS_LVGL_SPLASH
// lvgl_splash_init(L);
// #endif
#endif // HAS_LVGL
}

Expand Down
3 changes: 2 additions & 1 deletion lua_eos/native/eos_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

//#ifdef MOS_DESKTOP
#define HAS_LVGL // has LVGL
// #define HAS_LVGL_SPLASH
// #define HAS_LVGL_SPLASH
#define SHOW_ANIMATED_SPLASH
//#endif

#define EV_QUEUE_LENGTH 32
Expand Down
Loading

0 comments on commit 042705b

Please sign in to comment.