diff --git a/doc/eluadoc.lua b/doc/eluadoc.lua index 2a9df272..aed90635 100644 --- a/doc/eluadoc.lua +++ b/doc/eluadoc.lua @@ -15,7 +15,7 @@ local doc_sections = { "arch_platform", "refman_gen", "refman_ps_lm3s" } local components = { arch_platform = { "ll", "pio", "spi", "uart", "timers", "pwm", "cpu", "eth", "adc" }, - refman_gen = { "bit", "pd", "cpu", "pack", "adc", "term", "pio", "uart", "spi", "tmr", "pwm", "net" }, + refman_gen = { "bit", "pd", "cpu", "pack", "adc", "term", "pio", "uart", "spi", "tmr", "pwm", "net", "can" }, refman_ps_lm3s = { "disp" } } diff --git a/doc/eluadoc/refman_gen_can.lua b/doc/eluadoc/refman_gen_can.lua new file mode 100644 index 00000000..329c05ff --- /dev/null +++ b/doc/eluadoc/refman_gen_can.lua @@ -0,0 +1,136 @@ +-- eLua reference manual - CAN module + +data_en = +{ + + -- Title + title = "eLua reference manual - CAN module", + + -- Menu name + menu_name = "can", + + -- Overview + overview = [[This module contains functions for accessing the CAN interfaces of the eLua CPU]], + + -- Structures + structures = + { + { text = [[// eLua CAN ID types +enum +{ + ELUA_CAN_ID_STD = 0, // exported as $net.ID_STD$ + ELUA_CAN_ID_EXT, // exported as $can.ID_EXT$ +};]], + name = "CAN ID types", + desc = "These are the CAN identifier types supported by eLua. Standard identifiers are 11 bits in length, extended identifiers are 29 bits.", + } + }, + + -- Functions + funcs = + { + { sig = "clock = #can.setup#( id, clock )", + desc = "Setup the CAN interface", + args = + { + "$id$ - the ID of the CAN interface.", + "$clock$ - the clock of the CAN interface.", + }, + ret = "The actual clock set on the CAN interface. Depending on the hardware, this might have a different value than the $clock$ parameter." + }, + + { sig = "#can.send#( id, canid, canidtype, message )", + desc = "Send message over the CAN bus.", + args = + { + "$id$ - the ID of the CAN interface.", + "$canid$ - CAN identifier number.", + "$canidtype$ - identifier type as defined @#can_id_types@here@.", + "$message$ - message in string format, 8 or fewer bytes." + }, + }, + + { sig = "canid, canidtype, message = #can.recv#( id )", + desc = "Receive CAN bus message.", + args = + { + "$id$ - the ID of the CAN interface.", + }, + ret = + { + "$canid$ - CAN identifier number.", + "$canidtype$ - identifier type as defined @#can_id_types@here@.", + "$message$ - message in string format, 8 or fewer bytes." + } + } + + }, +} + +data_pt = +{ + + -- Title + title = "eLua reference manual - CAN module", + + -- Menu name + menu_name = "can", + + -- Overview + overview = [[This module contains functions for accessing the CAN interfaces of the eLua CPU]], + + -- Structures + structures = + { + { text = [[// eLua CAN ID types +enum +{ + ELUA_CAN_ID_STD = 0, // exported as $net.ID_STD$ + ELUA_CAN_ID_EXT, // exported as $can.ID_EXT$ +};]], + name = "CAN ID types", + desc = "These are the CAN identifier types supported by eLua. Standard identifiers are 11 bits in length, extended identifiers are 29 bits.", + } + }, + + -- Functions + funcs = + { + { sig = "clock = #can.setup#( id, clock )", + desc = "Setup the CAN interface", + args = + { + "$id$ - the ID of the CAN interface.", + "$clock$ - the clock of the CAN interface.", + }, + ret = "The actual clock set on the CAN interface. Depending on the hardware, this might have a different value than the $clock$ parameter." + }, + + { sig = "#can.send#( id, canid, canidtype, message )", + desc = "Send message over the CAN bus.", + args = + { + "$id$ - the ID of the CAN interface.", + "$canid$ - CAN identifier number.", + "$canidtype$ - identifier type as defined @#can_id_types@here@.", + "$message$ - message in string format, 8 or fewer bytes." + }, + }, + + { sig = "canid, canidtype, message = #can.recv#( id )", + desc = "Receive CAN bus message.", + args = + { + "$id$ - the ID of the CAN interface.", + }, + ret = + { + "$canid$ - CAN identifier number.", + "$canidtype$ - identifier type as defined @#can_id_types@here@.", + "$message$ - message in string format, 8 or fewer bytes." + } + } + + }, +} + diff --git a/inc/platform.h b/inc/platform.h index b813f552..97dd402b 100644 --- a/inc/platform.h +++ b/inc/platform.h @@ -72,6 +72,13 @@ pio_type platform_pio_op( unsigned port, pio_type pinmask, int op ); // Maximum length for any CAN message #define PLATFORM_CAN_MAXLEN 8 +// eLua CAN ID types +enum +{ + ELUA_CAN_ID_STD = 0, + ELUA_CAN_ID_EXT +}; + int platform_can_exists( unsigned id ); u32 platform_can_setup( unsigned id, u32 clock ); void platform_can_send( unsigned id, u32 canid, u8 idtype, u8 len, const u8 *data ); diff --git a/src/modules/can.c b/src/modules/can.c index 5e8483b1..ed0d4fbc 100644 --- a/src/modules/can.c +++ b/src/modules/can.c @@ -69,6 +69,10 @@ const LUA_REG_TYPE can_map[] = { LSTRKEY( "setup" ), LFUNCVAL( can_setup ) }, { LSTRKEY( "send" ), LFUNCVAL( can_send ) }, { LSTRKEY( "recv" ), LFUNCVAL( can_recv ) }, +#if LUA_OPTIMIZE_MEMORY > 0 + { LSTRKEY( "ID_STD" ), LNUMVAL( ELUA_CAN_ID_STD ) }, + { LSTRKEY( "ID_EXT" ), LNUMVAL( ELUA_CAN_ID_EXT ) }, +#endif { LNILKEY, LNILVAL } }; @@ -79,6 +83,10 @@ LUALIB_API int luaopen_can( lua_State *L ) #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_CAN, can_map ); + // Module constants + MOD_REG_NUMBER( L, "ID_STD", ELUA_CAN_ID_STD ); + MOD_REG_NUMBER( L, "ID_EXT", ELUA_CAN_ID_EXT ); + return 1; #endif // #if LUA_OPTIMIZE_MEMORY > 0 }