📄 manual.html
字号:
<HTML> <HEAD> <TITLE>Pico-IrDA Manual</TITLE> </HEAD> <BODY> <H1>Pico-IrDA Manual</H1> <DL> <DT> <H3>Overview</H3> <DD> Pico-IrDA is a minimalistic IrDA stack for microcontrollers.<BR> It supports IrOBEX in primary and secondary IrDA mode and IrCOMM in secondary mode only.<BR> Pico-IrDA works with a fixed baudrate of 9600 bps and is restricted to two communication peers. <DT> <H3>Library Initialization</H3> <DD> An application needs to reset the physical layer and initialize an <B>IrLAP_Context</B>, which holds state information about the session. <HR> <CODE> IrLAP_Context ctx;<BR> <BR> irphy_reset();<BR> irlap_init_context(&ctx);<BR> </CODE> <HR> <DT> <H3>Physical Interface</H3> <DD> The library uses four functions defined in "<B>irphy.h</B>" to interface with the physical IrDA transceiver.<BR> <UL> <LI> <B>void irphy_reset(void);</B><BR> Initializes the physical interface and sets the baudrate to 9600 bps. <LI> <B>void irphy_send(uint8_t v);</B><BR> Sends a byte of data "<B>v</B>" via IrDA. <LI> <B>uint8_t irphy_wait(int16_t timeout);</B><BR> Returns a non-zero value if incoming data is available within a given "<B>timeout</B>".<BR> If the "<B>timeout</B>" given in milliseconds expires before a byte of data is available, this function shall return zero.<BR> If the "<B>timeout</B>" is negative, this function should wait for incoming data indefinitely. <LI> <B>uint8_t irphy_receive(void);</B><BR> Receives an incoming byte of data and returns it. </UL> <DT> <H3>IrOBEX Interface</H3> <DD> The simplest form of using the library is to send and/or receive data via IrOBEX.<BR> Sending data is done by selecting the IrDA primary mode, receiving data puts the device into IrDA secondary mode.<BR> <UL> <LI> <B>uint8_t irobex_send(<BR> IrLAP_Context *context_p,<BR> IrLAP_Device_Addr addr_p,<BR> int16_t (*get_name_cb)(char *name, uint16_t size, void *user_data),<BR> int16_t (*get_data_cb)(uint8_t *data, uint16_t size, void *user_data),<BR> void *user_data);</B><BR> <UL> <LI> <B>context_p</B><BR> A previously initialized <B>IrLAP_Context</B>. <LI> <B>addr_p</B><BR> The device address of the intended peer or "<B>0</B>" if no specific peer is known and discovery should be performed. <LI> <B>get_name_cb</B><BR> A callback function that is used to retrieve the name of the message to be sent.<BR> "<B>name</B>" points to a destination buffer to store the name, which holds a maximum number of "<B>size</B>" bytes.<BR> The number of bytes actually written to "<B>name</B>" should become the return value of the callback.<BR> If an error occurred, the callback can return a negative value and the transmission is cancelled.<BR> "<B>user_data</B>" contains the same value as the one passed to the "<B>irobex_send</B>" function.<BR> If "<B>get_name_cb</B>" is "<B>0</B>", no name will be included in the message. <LI> <B>get_data_cb</B><BR> A callback function that is used to retrieve a data chunk for the message to be sent.<BR> "<B>data</B>" points to a destination buffer to store the data, which holds a maximum number of "<B>size</B>" bytes.<BR> The number of bytes actually written to "<B>data</B>" should become the return value of the callback.<BR> If an error occurred, the callback can return a negative value and the transmission is cancelled.<BR> "<B>user_data</B>" contains the same value as the one passed to the "<B>irobex_send</B>" function.<BR> If "<B>get_data_cb</B>" is "<B>0</B>", no data will be included in the message. <LI> <B>user_data</B><BR> An application defined pointer that is passed to the callback functions. </UL> If the transmission was successful, "<B>irobex_send</B>" returns a non-zero value. A return value of "<B>0</B>" indicates failure. <LI> <B>uint8_t irobex_receive(<BR> IrLAP_Context *context_p,<BR> uint8_t (*put_name_cb)(char *name, void *user_data),<BR> uint8_t (*put_data_cb)(uint8_t *data, uint16_t size, void *user_data),<BR> void *user_data);</B><BR> <UL> <LI> <B>context_p</B><BR> A previously initialized <B>IrLAP_Context</B>. <LI> <B>put_name_cb</B><BR> A callback function that is used to handle the name of a received message.<BR> The name of the message is stored at "<B>name</B>" and is terminated with a "<B>0</B>" character.<BR> "<B>user_data</B>" contains the same value as the one passed to the "<B>irobex_receive</B>" function.<BR> If "<B>put_name_cb</B>" is "<B>0</B>", the name part of a received message remains unhandled. <LI> <B>put_data_cb</B><BR> A callback function that is used to handle a data chunk of a received message.<BR> The data chunk is stored at "<B>data</B>" and contains "<B>size</B>" bytes.<BR> "<B>user_data</B>" contains the same value as the one passed to the "<B>irobex_receive</B>" function.<BR> If "<B>put_data_cb</B>" is "<B>0</B>", the data part of a received message remains unhandled. <LI> <B>user_data</B><BR> An application defined pointer that is passed to the callback functions. </UL> If the message was received successfully, "<B>irobex_receive</B>" returns a non-zero value. A return value of "<B>0</B>" indicates failure. </UL> <DT> <H3>IrCOMM Interface</H3> <DD> The IrCOMM protocol is only supported in IrDA secondary mode. <UL> <LI> <B>void ircomm2_serve(<BR> IrLAP_Context *context_p,<BR> int16_t (*put_data_cb)(<BR> uint8_t *data, uint16_t size,<BR> uint8_t *resp_buf, uint16_t resp_buf_size,<BR> uint8_t *terminate_p,<BR> void *user_data),<BR> void *user_data);</B><BR> <UL> <LI> <B>context_p</B><BR> A previously initialized <B>IrLAP_Context</B>. <LI> <B>put_data_cb</B><BR> A callback function that is used to handle an incoming data chunk.<BR> The data chunk is stored at "<B>data</B>" and contains "<B>size</B>" bytes.<BR> Up to "<B>resp_buf_size</B>" bytes can be stored into "<B>resp_buf</B>" which is the data chunk that is sent back to the communication peer.<BR> The number of bytes actually written to "<B>resp_buf</B>" should become the return value of the callback.<BR> If an error occurred, the callback can return a negative value and the transmission is cancelled.<BR> If a non-zero value is written to the byte pointed to by "<B>terminate_p</B>" the transmission will be terminated after the response buffer is sent. <LI> <B>user_data</B><BR> An application defined pointer that is passed to the callback function. </UL> </UL> <DT> <H3>Selecting Protocol</H3> <DD> In IrDA secondary mode, it is possible to distinguish between incoming IrOBEX and IrCOMM messages using the "<B>irttp2_accept</B>" function.<BR> You need to announce the availability of the <B>IrIAS LsapSel</B> values that relate to the corresponding protocols and set the proper <B>IrLMP</B> hints.<BR> Example: <HR> <CODE> IrLAP_Context ctx;<BR> IrIAS_Node *ias_nodes[3];<BR> int16_t dlsap_sel;<BR> <BR> irphy_reset();<BR> irlap_init_context(&ctx);<BR> <BR> /* ias_nodes contains all the IrIAS LsapSel values we support */<BR> ias_nodes[0]=&irobex_ias_node;<BR> ias_nodes[1]=&ircomm_ias_node;<BR> ias_nodes[2]=0;<BR> <BR> for(;;) {<BR> irphy_wait(-1);<BR> if((dlsap_sel=irttp2_accept(&ctx, IRLMP_HINT1_OBEX | IRLMP_HINT1_COMM, ias_nodes))<0)<BR> continue;<BR> switch(dlsap_sel) {<BR> case IRCOMM_LSAP_SEL_VAL:<BR> handle_ircomm();<BR> break;<BR> case IROBEX_LSAP_SEL_VAL:<BR> handle_irobex();<BR> break;<BR> }<BR> }<BR> </CODE> <HR> <DT> <H3>Copyright Notice</H3> <DD> Copyright © 2002-2003 Gerd Rausch, <A HREF="http://blaulogic.com">BlauLogic</A><BR> All rights reserved. <P> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <OL> <LI> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <LI> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <LI> Except as contained in this notice, neither the name of BlauLogic nor the name(s) of the author(s) may be used to endorse or promote products derived from this software without specific prior written permission. </OL> <P> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) OR BLAULOGIC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. </DL> </BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -