2015-06-25 04:26:54 +02:00
|
|
|
// Module for RTC user memory access
|
|
|
|
|
2015-12-16 06:04:58 +01:00
|
|
|
#include "module.h"
|
2015-06-25 04:26:54 +02:00
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "rtc/rtcaccess.h"
|
|
|
|
|
|
|
|
static int rtcmem_read32 (lua_State *L)
|
|
|
|
{
|
2020-08-29 18:48:24 +02:00
|
|
|
int idx = luaL_checkinteger (L, 1);
|
|
|
|
int n = (lua_gettop(L) < 2) ? 1 : lua_tointeger (L, 2);
|
|
|
|
if (n == 0 || !lua_checkstack (L, n)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-25 04:26:54 +02:00
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
while (n > 0 && idx >= 0 && idx < RTC_USER_MEM_NUM_DWORDS)
|
|
|
|
{
|
|
|
|
lua_pushinteger (L, rtc_mem_read (idx++));
|
|
|
|
--n;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int rtcmem_write32 (lua_State *L)
|
|
|
|
{
|
2020-08-29 18:48:24 +02:00
|
|
|
int idx = luaL_checkinteger (L, 1);
|
2015-06-25 04:26:54 +02:00
|
|
|
int n = lua_gettop (L) - 1;
|
|
|
|
luaL_argcheck (
|
|
|
|
L, idx + n <= RTC_USER_MEM_NUM_DWORDS, 1, "RTC mem would overrun");
|
|
|
|
int src = 2;
|
|
|
|
while (n-- > 0)
|
|
|
|
{
|
2020-08-29 18:48:24 +02:00
|
|
|
rtc_mem_write (idx++, (uint32_t) lua_tointeger (L, src++));
|
2015-06-25 04:26:54 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Module function map
|
2020-04-27 02:13:38 +02:00
|
|
|
LROT_BEGIN(rtcmem, NULL, 0)
|
2019-05-08 13:08:20 +02:00
|
|
|
LROT_FUNCENTRY( read32, rtcmem_read32 )
|
|
|
|
LROT_FUNCENTRY( write32, rtcmem_write32 )
|
2020-04-27 02:13:38 +02:00
|
|
|
LROT_END(rtcmem, NULL, 0)
|
2015-06-25 04:26:54 +02:00
|
|
|
|
2019-05-08 13:08:20 +02:00
|
|
|
|
|
|
|
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL);
|