Преглед изворни кода

update:提供更多的spi从机c api

alienwalker пре 1 година
родитељ
комит
656fa0d8e8
4 измењених фајлова са 90 додато и 1 уклоњено
  1. 5 1
      luat/include/luat_can.h
  2. 2 0
      luat/include/luat_libs.h
  3. 17 0
      luat/include/luat_spi.h
  4. 66 0
      luat/modules/luat_lib_can.c

+ 5 - 1
luat/include/luat_can.h

@@ -58,7 +58,7 @@ typedef struct
  */
 typedef void (*luat_can_callback_t)(int can_id, LUAT_CAN_CB_E cb_type, void *cb_param);
 /**
- * @brief can总线基础初始化,并且无任何消息过滤
+ * @brief can总线基础初始化
  *
  * @param can_id 总线序号,如果只有一条,填0,有多条的根据实际情况填写
  * @param rx_msg_cache_max 最大接收消息缓存数量,如果写0则是使用平台默认值
@@ -153,4 +153,8 @@ int luat_can_close(uint8_t can_id);
  * @return >=0 成功并返回状态值,其他失败,状态值见LUAT_CAN_STATE_E
  */
 int luat_cat_get_state(uint8_t can_id);
+
+#ifdef __LUATOS__
+int l_can_handler(lua_State *L, void* ptr);
+#endif
 #endif

+ 2 - 0
luat/include/luat_libs.h

@@ -200,4 +200,6 @@ LUAMOD_API int luaopen_netdrv( lua_State *L );
 // iperf
 LUAMOD_API int luaopen_iperf( lua_State *L );
 
+/** can库*/
+LUAMOD_API int luaopen_can( lua_State *L );
 #endif

+ 17 - 0
luat/include/luat_spi.h

@@ -148,6 +148,23 @@ int luat_spi_slave_transfer(int spi_id, const char* send_buf,  char* recv_buf, s
  * @return int 成功返回本次接收长度,其他-1
  */
 int luat_spi_slave_transfer_pause_and_read_data(int spi_id);
+/**
+ * @brief 在中断中收发从机SPI数据
+ *
+ * @param spi_id spi id
+ * @param send_buf 发送数据
+ * @param recv_buf 接收数据
+ * @param recv_length 总缓冲区长度,不能大于8188
+ * @return int 成功返回0,其他-1
+ */
+int luat_spi_slave_fast_transfer_in_irq(int spi_id, const char* send_buf,  char* recv_buf, size_t total_length);
+/**
+ * @brief 在中断中从机SPI暂停工作,并返回已经接收的数据长度,不允许进入休眠状态
+ *
+ * @param spi_id spi id
+ * @return int 成功返回本次接收长度,其他-1
+ */
+int luat_spi_slave_transfer_fast_pause_and_read_data_in_irq(int spi_id);
 /**
  * @brief 从机SPI暂停工作,不允许进入休眠状态,在irq中使用
  *

+ 66 - 0
luat/modules/luat_lib_can.c

@@ -0,0 +1,66 @@
+/*
+@module  can
+@summary can操作库
+@version 1.0
+@date    2025.2.24
+@demo can
+@tag LUAT_USE_CAN
+*/
+#include "luat_base.h"
+#include "luat_log.h"
+#include "luat_sys.h"
+#include "luat_msgbus.h"
+#include "luat_mem.h"
+#include "luat_can.h"
+#include "luat_zbuff.h"
+
+#include "rotable2.h"
+static const rotable_Reg_t reg_can[] =
+{
+//    { "init",      ROREG_FUNC(l_uart_write)},
+//    { "read",       ROREG_FUNC(l_uart_read)},
+//    { "wait485",    ROREG_FUNC(l_uart_wait485_tx_done)},
+//    { "tx",      	ROREG_FUNC(l_uart_tx)},
+//    { "rx",       	ROREG_FUNC(l_uart_rx)},
+//	{ "rxClear",	ROREG_FUNC(l_uart_rx_clear)},
+//	{ "rxSize",		ROREG_FUNC(l_uart_rx_size)},
+//	{ "rx_size",	ROREG_FUNC(l_uart_rx_size)},
+//	{ "createSoft",	ROREG_FUNC(l_uart_soft)},
+//    { "close",      ROREG_FUNC(l_uart_close)},
+//    { "on",         ROREG_FUNC(l_uart_on)},
+//    { "setup",      ROREG_FUNC(l_uart_setup)},
+//    { "exist",      ROREG_FUNC(l_uart_exist)},
+//
+//	//@const Odd number 奇校验,大小写兼容性
+//    { "Odd",        ROREG_INT(LUAT_PARITY_ODD)},
+//	//@const Even number 偶校验,大小写兼容性
+//    { "Even",       ROREG_INT(LUAT_PARITY_EVEN)},
+//	//@const None number 无校验,大小写兼容性
+//    { "None",       ROREG_INT(LUAT_PARITY_NONE)},
+//    //@const ODD number 奇校验
+//    { "ODD",        ROREG_INT(LUAT_PARITY_ODD)},
+//    //@const EVEN number 偶校验
+//    { "EVEN",       ROREG_INT(LUAT_PARITY_EVEN)},
+//    //@const NONE number 无校验
+//    { "NONE",       ROREG_INT(LUAT_PARITY_NONE)},
+//    //高低位顺序
+//    //@const LSB number 小端模式
+//    { "LSB",        ROREG_INT(LUAT_BIT_ORDER_LSB)},
+//    //@const MSB number 大端模式
+//    { "MSB",        ROREG_INT(LUAT_BIT_ORDER_MSB)},
+//
+//    //@const VUART_0 number 虚拟串口0
+//	{ "VUART_0",       ROREG_INT(LUAT_VUART_ID_0)},
+//    //@const ERROR_DROP number 遇到错误时抛弃缓存的数据
+//	{ "ERROR_DROP",       ROREG_INT(LUAT_UART_RX_ERROR_DROP_DATA)},
+//    //@const DEBUG number 开启调试功能
+//	{ "DEBUG",       ROREG_INT(LUAT_UART_DEBUG_ENABLE)},
+
+    { NULL,         ROREG_INT(0) }
+};
+
+LUAMOD_API int luaopen_can( lua_State *L )
+{
+    luat_newlib2(L, reg_can);
+    return 1;
+}