Gorgon_Meducer 发表于 2010-4-14 13:52:02

[LIB][ICC][IAR][GCC] 经过严格测试的TWI从机发送和接收模块

本帖最后由 Gorgon_Meducer 于 2014-3-5 15:08 编辑

[ 使用说明 ]
    这是一个经过严格测试的TWI从机发送/接受模块。带有自动总线错误恢复机制。
现在发布的版本屏蔽了对Sleep模式的支持。感兴趣的人可以跟贴。使用方法看twi.h
就知道了,twi.c里面的内容我贴出来给有兴趣读代码的人,但是从使用的角度来说
完全不用考虑里面的内容。
    这里就一些注意事项说一下:
    a. 除了idle模式下,其他sleep模式下,该模块无法正常工作,需要一个额外的
       插件。
    b. 如果注册了读取服务,无论发生什么情况,甚至是总线出错,系统都会保留
       这个任务,直到正确的读取到数据,非常省心。
    c. 如果注册了发送任务,如果数据没有被正确的发送,比如发送到一半,比如
       总线出错之类,系统会自动注销当前的任务,并调用report函数,用户可以
       在report函数被自动调用的时候,检测report函数的result来获取发送任务
       的结果——成功/失败/取消
    d. 在app_cfg.h中定义宏TWI_PINS_INIT来完成对TWI引脚的初始化——如果需要
       的话。
    e. 模块经过IAR 5.30 5.40最高等级优化测试。

[ 相关下载 ]
    如果你不幸下载到了老板本(twi_slave.c里面twi中断处理程序的尾部有一个测
    试用的do{}while(false)结构,请手动删除或者下载这里的新版本)

点击此处下载 ourdev_546390.rar(文件大小:650K) (原文件名:ES.rar)

Gorgon_Meducer 发表于 2010-4-14 13:52:28

Gorgon_Meducer 发表于 2010-4-14 13:54:21

<font color=red> twi.h <font color=brown>


//! \brief import configurations
#include "app_cfg.h"


#define REQ_FAILED          0xE0
#define REQ_RCV_BUFFER_OVF0xE1
#define REQ_BUS_ERROR       0xE2
#define REQ_CANCELLED       0xE3
#define REQ_UNKONW_ERROR    0xFF

#define REQ_SUCCESS         0x01
#define REQ_ON_GOING      0x00


typedef void TWI_WRITE_REQ_REPORT(uint8_t chResult);
typedef void TWI_READ_REQ_REPORT(uint8_t chResult, uint8_t *pchStream, uint8_t chLength);

            

/*! \note twi slave model initializing function
*!
*! \paramnone
*!
*! \return none
*/
extern void twi_slave_init(void);

#define reset_twi()         twi_slave_init()



/*! \note request send stream to master
*!
*! \param pStreama point of stream
*!
*! \param chLength byte count of stream
*!
*! \param fnHandler a callback function pointer
*!
*! \return a boolean value to indicate the resule of accessing
*/
extern bool request_send_stream(volatile void *pStream, uint8_t chLength, TWI_WRITE_REQ_REPORT *fnHandler);


/*! \note try to cancel current sending request
*!
*! \param none
*!
*! \return a boolean value to indicate the resule of accessing
*/
extern bool try_to_cancel_send_request(void);


/*! \note request receive data from master
*!
*! \param pStreama point of stream
*!
*! \param chLength stream buffer size
*!
*! \param fnHandler a callback function pointer
*!
*! \return a boolean value to indicate the resule of accessing
*/
extern bool request_receive_stream(volatile void *pStream, uint8_t chLength, TWI_READ_REQ_REPORT *fnHandler);


/*! \note try to cancel current receive request
*!
*! \param none
*!
*! \return a boolean value to indicate the resule of accessing
*/
extern bool try_to_cancel_receive_request(void);


/*! \note release SCL
*!
*! \paramnone
*!
*! \return none
*/
extern void release_twi(void);


//! \brief twi task locker
extern ES_LOCKER g_lkTWILocker;

fool_boy 发表于 2010-4-14 13:54:22

火速占位,感谢傻孩子:)

jj3055 发表于 2010-4-14 14:00:41

地板

erxun 发表于 2010-4-14 14:18:08

地下室~~~

lookavr 发表于 2010-4-14 14:18:23

支持傻孩子

shaoye 发表于 2010-4-14 14:26:52

支持,正在做这方面的项目,谢谢

mcu_lover 发表于 2010-4-14 15:00:13

傻孩子的帖子,死了都要顶。

yuangaoping 发表于 2010-4-14 15:20:21

帮顶下

snail0204 发表于 2010-4-14 15:30:25

tsb0574 发表于 2010-4-14 15:47:44

顶,没什么好说的,顶就是了^^^^

kanprin 发表于 2010-4-14 15:55:54

不错,基于中断方式的,还支持GCC

yangyi 发表于 2010-4-14 16:39:57

正准备做类似的东西.谢谢共享!

xczxwy 发表于 2010-4-14 17:09:12

为什么高手的程序里总是用了很多的结构体和指针,而我们自己的程序中更多的是if和switch,为什么呢

Gorgon_Meducer 发表于 2010-4-14 17:44:31

用指针和结构体的原因不是因为我是高手,而是对AVR来说,能产生高效率的代码。

ilawp 发表于 2010-4-14 18:03:38

zlei 发表于 2010-4-14 18:09:12

mark 以后用

cgbabc 发表于 2010-4-14 18:44:22

ivws 发表于 2010-4-14 18:59:25

占位,学习!

laolu 发表于 2010-4-14 19:05:42

MARK

jielove2003 发表于 2010-4-14 19:49:34

好帖标记

hongyancl 发表于 2010-4-14 19:58:39

回复【楼主位】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------

dddd

lenyuye 发表于 2010-4-14 20:00:03

以后有用

haigerl 发表于 2010-7-22 18:08:27

mark

hpdell 发表于 2010-8-13 15:27:00

hao!!!!!!!!!

plc_avr 发表于 2010-8-13 15:40:22

才看到,傻孩子的贴要顶!

ADO1234 发表于 2010-8-18 08:15:15

MARK

span42 发表于 2010-10-14 12:16:47

dd更健康

gtzhangzr 发表于 2011-3-12 11:34:03

mark

elecfun 发表于 2011-3-12 11:41:28

不怎么懂~~

tomhe666 发表于 2011-3-12 12:01:05

收藏

gwh1128 发表于 2011-3-12 14:42:55

boat030 发表于 2011-4-27 01:08:57

请问傻孩子 ES_LOCKER 这个结构体在哪里定义的?

Gorgon_Meducer 发表于 2011-4-27 09:30:47

压缩包里面的signal.h里面?或者是compiler.h里面?

loveskangaroo 发表于 2011-5-18 00:42:06

一定要顶

pisgah 发表于 2011-5-18 20:11:21

mark

myyule 发表于 2011-6-10 09:28:45

mark

zhouaheng 发表于 2011-8-20 00:05:02

MARK !!!!!!!!!

zwhlxl 发表于 2011-8-24 11:38:00

mark 正学习

yuzr 发表于 2011-8-24 11:59:26

mark

yelvAVR 发表于 2011-10-6 22:02:02

顶傻孩子
mark

hanxinyu 发表于 2014-3-5 13:56:40

学习中。。。

alanse 发表于 2014-4-9 14:51:16

頂{:lol:}
页: [1]
查看完整版本: [LIB][ICC][IAR][GCC] 经过严格测试的TWI从机发送和接收模块