Skip to content

Commit

Permalink
Lua RTOS important changes
Browse files Browse the repository at this point in the history
This commit affects many parts of Lua RTOS, derived from the LMIC tests.

LMIC stack / LoRa WAN Lua module:

* Fire EV_JOIN_FAILED as soon as possible if join is not possible for save battery.
* If radio phy is not detect don't init the stack.
* Once LoRa WAN is setup user needs to reboot the board for change ISM band.
* If lora_tx can't allocate memory for payload returns an error.
* Lua lora module: band argument in setup function is mandatory.
* Support for ABP end-point activation
* Added setLinkChk / getLinkChk in Lora Lua Module
* Removed unused code in lora driver headers
* When LMIC is compiled with LMIC_DEBUG_LEVEL > 0, engine update show opmode in an
intelligible way
* hal_ticks is derived directed from RTC

Lua RTOS:

* Added driver.c / driver.h which contains function for basic driver management:

  - drivers array added
  - each driver mantain this information:
    * name
	* exception base: a constant to add to driver errors that allow the identifi
	  cation of an exception code globaly in Lua RTOS
	* error messages array
  - functions for access driver information, and for create erros

* All driver operation must return a driver_error_t structure, if NULL there are no
  errors

* Rewrite of udelay and delay functions, and adjust delays to experimental results.

Lua Modules:

* Error management adapted to new driver schema in Lua Modules that call Lua RTOS drivers
  • Loading branch information
jolivepetrus committed Nov 29, 2016
1 parent 3d90e36 commit 82f39f0
Show file tree
Hide file tree
Showing 23 changed files with 730 additions and 441 deletions.
81 changes: 67 additions & 14 deletions components/lua_rtos/Lua/modules/error.c
@@ -1,28 +1,58 @@
#include "error.h"
/*
* Lua RTOS, Lua helper functions for throw an error from a driver error
*
* Copyright (C) 2015 - 2016
* IBEROXARXA SERVICIOS INTEGRALES, S.L. & CSS IBÉRICA, S.L.
*
* Author: Jaume Olivé (jolive@iberoxarxa.com / jolive@whitecatboard.org)
*
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/

#include "error.h"
#include "lauxlib.h"

#include <string.h>
#include <stdlib.h>

int luaL_driver_error(lua_State* L, const char *msg, tdriver_error *error) {
tdriver_error err;
#include <sys/driver.h>

int luaL_driver_error(lua_State* L, driver_error_t *error) {
driver_error_t err;
int ret_val;

bcopy(error, &err, sizeof(tdriver_error));
bcopy(error, &err, sizeof(driver_error_t));
free(error);

if (err.type == LOCK) {
if (err.resource_unit == -1) {
ret_val = luaL_error(L,
"%s, no %s available",
msg,
driver_get_err_msg(error),
resource_name(err.resource)
);
} else {
ret_val = luaL_error(L,
"%s, %s is used by %s%d",
msg,
driver_get_err_msg(error),
resource_unit_name(err.resource, err.resource_unit),
owner_name(err.owner),
err.owner_unit + 1
Expand All @@ -31,13 +61,36 @@ int luaL_driver_error(lua_State* L, const char *msg, tdriver_error *error) {

return ret_val;
} else if (err.type == SETUP) {
ret_val = luaL_error(L,
"%s, %s (%s)",
msg,
resource_name(err.resource),
err.msg
);
if (err.msg) {
ret_val = luaL_error(L,
"%d:%s (%s)",
err.exception,
driver_get_err_msg(&err),
err.msg
);
} else {
ret_val = luaL_error(L,
"%d:%s",
err.exception,
driver_get_err_msg(&err)
);
}
} else if (err.type == OPERATION) {
if (err.msg) {
ret_val = luaL_error(L,
"%d:%s (%s)",
err.exception,
driver_get_err_msg(&err),
err.msg
);
} else {
ret_val = luaL_error(L,
"%d:%s",
err.exception,
driver_get_err_msg(&err)
);
}
}

return luaL_error(L, msg);
}
return luaL_error(L, driver_get_err_msg(error));
}
34 changes: 31 additions & 3 deletions components/lua_rtos/Lua/modules/error.h
@@ -1,11 +1,39 @@
/*
* Lua RTOS, Lua helper functions for throw an error from a driver error
*
* Copyright (C) 2015 - 2016
* IBEROXARXA SERVICIOS INTEGRALES, S.L. & CSS IBÉRICA, S.L.
*
* Author: Jaume Olivé (jolive@iberoxarxa.com / jolive@whitecatboard.org)
*
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/

#ifndef _LUA_ERROR_H
#define _LUA_ERROR_H

#include "lstate.h"

#include <sys/error.h>
#include <sys/resource.h>
#include <sys/driver.h>

int luaL_driver_error(lua_State* L, const char *msg, tdriver_error *error);
int luaL_driver_error(lua_State* L, driver_error_t *error);

#endif
5 changes: 2 additions & 3 deletions components/lua_rtos/Lua/modules/i2c.c
Expand Up @@ -36,11 +36,10 @@
#include "lauxlib.h"
#include "i2c.h"

#include <sys/error.h>
#include <drivers/i2c.h>

static int li2c_setup( lua_State* L ) {
tdriver_error *error;
driver_error_t *error;

int total = lua_gettop(L);
int id = luaL_checkinteger(L, 1);
Expand Down Expand Up @@ -73,7 +72,7 @@ static int li2c_setup( lua_State* L ) {

// Setup
if ((error = i2c_setup(id, speed, sda, scl))) {
return luaL_driver_error(L, "I2C can't setup", error);
return luaL_driver_error(L, error);
}

return 0;
Expand Down

0 comments on commit 82f39f0

Please sign in to comment.