Skip to content
Permalink
Browse files

added timeout functionality.

  • Loading branch information...
ErichStyger committed Sep 24, 2013
1 parent 2453e4c commit 6482c57a66a4c6a19b9b1357ef3687ae30837d56
@@ -4,7 +4,7 @@
<Name>24AA_EEPROM</Name>
<Description>Microchip 24AA Serial EEPROM</Description>
<Author>Erich Styger</Author>
<Version>01.023</Version>
<Version>01.028</Version>
<Icon>24AA_EEPROM</Icon>
<TypesFiles>PE,24AA_EEPROM\24AA_EEPROM</TypesFiles>
<FileVersion>6</FileVersion>
@@ -202,6 +202,72 @@ Typical values:\n
</Children>
</TGrupItem>
</Property>
<Property>
<TBoolGrupItem>
<Name>Timeout</Name>
<Symbol>TimeoutEnabled</Symbol>
<TypeSpec>typeEnaDis</TypeSpec>
<Hint>If enabled, the component is using a timer based timeout</Hint>
<ItemLevel>BASIC</ItemLevel>
<BoldName>true</BoldName>
<EditLine>false</EditLine>
<Description>Disabled</Description>
<Expanded>Yes</Expanded>
<DefaultValue>false</DefaultValue>
<DefineSymbol>YES_NO</DefineSymbol>
<IfDisabled>setNOTHING</IfDisabled>
<Children>
<GrupItem>
<TInhrLinkItem>
<Name>Timeout</Name>
<Symbol>Timeout</Symbol>
<TypeSpec>24AA_EEPROM\Timeout</TypeSpec>
<Hint>Interface to timeout module</Hint>
<ItemLevel>BASIC</ItemLevel>
<EditLine>false</EditLine>
<DefaultValue/>
<CanDelete>false</CanDelete>
<IconPopup>false</IconPopup>
<SortStyle/>
</TInhrLinkItem>
</GrupItem>
<GrupItem>
<TIntgItem>
<Name>Timeout Byte (ms)</Name>
<Symbol>timeoutByteMs</Symbol>
<Hint>Timeout value in milli seconds for byte write. Note that values are always a multiple of timeout ticks.</Hint>
<ItemLevel>BASIC</ItemLevel>
<EditLine>true</EditLine>
<DefaultValue>10</DefaultValue>
<MinValue>0</MinValue>
<MaxValue>-1</MaxValue>
<Bases>DEC</Bases>
<DefaultBase>DEC</DefaultBase>
<ExtraHintDisabled>false</ExtraHintDisabled>
<ChangeValueIntoRange>false</ChangeValueIntoRange>
<RuntimeProperty>false</RuntimeProperty>
</TIntgItem>
</GrupItem>
<GrupItem>
<TIntgItem>
<Name>Timeout Block (ms)</Name>
<Symbol>timeoutBlockMs</Symbol>
<Hint>Timeout value in milli seconds for block write. Note that values are always a multiple of timeout ticks.</Hint>
<ItemLevel>BASIC</ItemLevel>
<EditLine>true</EditLine>
<DefaultValue>60</DefaultValue>
<MinValue>0</MinValue>
<MaxValue>-1</MaxValue>
<Bases>DEC</Bases>
<DefaultBase>DEC</DefaultBase>
<ExtraHintDisabled>false</ExtraHintDisabled>
<ChangeValueIntoRange>false</ChangeValueIntoRange>
<RuntimeProperty>false</RuntimeProperty>
</TIntgItem>
</GrupItem>
</Children>
</TBoolGrupItem>
</Property>
<Property>
<TBoolGrupItem>
<Name>Shell</Name>
@@ -1,8 +1,8 @@

[USED_FACES]
BeanVersion=01.023
BeanVersion=01.028

InterfacesCount=5
InterfacesCount=6

Symbol=Wait
Link=Yes
@@ -19,6 +19,11 @@ Link=No
Interface=24AA_EEPROM\WP
Version=01.003

Symbol=Timeout
Link=Yes
Interface=24AA_EEPROM\Timeout
Version=01.000

Symbol=Shell
Link=Yes
Interface=24AA_EEPROM\Shell
@@ -283,6 +283,26 @@
</ul>
</li>
<li>
<a name="TimeoutEnabled">
<b>Timeout</b></a> - If enabled, the component is using a timer based timeout<br />
The following items are available only if the group is enabled (the value is "Enabled"):<br />

<ul>
<li>
<a name="Timeout">
<b>Timeout</b></a> - Interface to timeout module
</li>
<li>
<a name="timeoutByteMs">
<b>Timeout Byte (ms)</b></a> - Timeout value in milli seconds for byte write. Note that values are always a multiple of timeout ticks.
</li>
<li>
<a name="timeoutBlockMs">
<b>Timeout Block (ms)</b></a> - Timeout value in milli seconds for block write. Note that values are always a multiple of timeout ticks.
</li>
</ul>
</li>
<li>
<a name="ShellEnabled">
<b>Shell</b></a> - If shell support is enabled. This enables/disables the method ParseCommand().<br />
The following items are available only if the group is enabled (the value is "Enabled"):<br />
@@ -16,6 +16,13 @@
%;**%>16 WP %>60: %get(WP,Text)
%else %- WriteProtectionGroup
%endif %- WriteProtectionGroup
%;**%>12 Timeout %>60: %get(TimeoutEnabled,Text)
%if %get(TimeoutEnabled, Bool) = 'yes'
%;**%>14 Timeout %>60: %get(Timeout,Text)
%;**%>14 Timeout Byte (ms) %>60: %get(timeoutByteMs,Text)
%;**%>14 Timeout Block (ms) %>60: %get(timeoutBlockMs,Text)
%else %- TimeoutEnabled
%endif %- TimeoutEnabled
%;**%>12 Shell %>60: %get(ShellEnabled,Text)
%if %get(ShellEnabled, Bool) = 'yes'
%;**%>14 Shell %>60: %get(Shell,Text)
@@ -298,6 +298,12 @@ byte %'ModuleName'%.%GetSelectedDevice(void);
%- Example:
%- #include "header_name.h"
%-
%if defined(Timeout)
#define %'ModuleName'%.TIMEOUT_BYTE_MS %timeoutByteMs /* number of milli seconds as specified in properties for byte write */
#define %'ModuleName'%.TIMEOUT_BYTE_TICKS (%'ModuleName'%.TIMEOUT_BYTE_MS/(%@Timeout@'ModuleName'%.TICK_PERIOD_MS))
#define %'ModuleName'%.TIMEOUT_BLOCK_MS %timeoutBlockMs /* number of milli seconds as specified in properties for block write */
#define %'ModuleName'%.TIMEOUT_BLOCK_TICKS (%'ModuleName'%.TIMEOUT_BLOCK_MS/(%@Timeout@'ModuleName'%.TICK_PERIOD_MS))
%endif
%-BW_CUSTOM_INCLUDE_END_M

%-BW_CUSTOM_VARIABLE_START
@@ -383,6 +389,12 @@ static uint8_t PrintHelp(const %@Shell@'ModuleName'%.StdIOType *io) {
byte %'ModuleName'%.%WriteByte(%'ModuleName'_Address addr, byte data)
{
uint8_t res, block[3];
%if defined(Timeout)
#if %'ModuleName'%.DO_ACKNOWLEDGE_POLLING && %'ModuleName'%.TIMEOUT_BYTE_TICKS>0
%@Timeout@'ModuleName'%.CounterHandle timeout;
bool isTimeout;
#endif
%endif

res = %@I2C@'ModuleName'%.SelectSlave(%'ModuleName'%.DEVICE_ADDR(addr));
if (res != ERR_OK) {
@@ -401,9 +413,34 @@ byte %'ModuleName'%.%WriteByte(%'ModuleName'_Address addr, byte data)
/* do acknowledge polling */
//%@Wait@'ModuleName'%.WaitOSms(%'ModuleName'%.PAGE_WRITE_TIME_MS);
block[0] = 0xff; /* dummy value */
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BYTE_TICKS>0
timeout = %@Timeout@'ModuleName'%.GetCounter(%'ModuleName'%.TIMEOUT_BYTE_TICKS); /* set up timeout counter */
if (timeout==%@Timeout@'ModuleName'%.OUT_OF_HANDLE) {
(void)%@I2C@'ModuleName'%.UnselectSlave();
return ERR_FAILED;
}
#endif
%endif
do {
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BYTE_TICKS>0
isTimeout = %@Timeout@'ModuleName'%.CounterExpired(timeout);
if (isTimeout) {
break; /* break while() */
}
#endif
%endif
res = %@I2C@'ModuleName'%.WriteBlock(block, 1, %@I2C@'ModuleName'%.SEND_STOP);%>40 /* send address and data */
} while(res!=ERR_OK); /* wait until we get an ACK */
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BYTE_TICKS>0
%@Timeout@'ModuleName'%.LeaveCounter(timeout);
if (isTimeout) {
res = ERR_FAILED;
}
#endif
%endif
#endif
if (res != ERR_OK) {
(void)%@I2C@'ModuleName'%.UnselectSlave();
@@ -508,6 +545,12 @@ byte %'ModuleName'%.%ReadBlock(%'ModuleName'_Address addr, byte *data, word data
#endif
byte %'ModuleName'%.%WriteBlock(%'ModuleName'_Address addr, byte *data, word dataSize)
{
%if defined(Timeout)
#if %'ModuleName'%.DO_ACKNOWLEDGE_POLLING && %'ModuleName'%.TIMEOUT_BLOCK_TICKS>0
%@Timeout@'ModuleName'%.CounterHandle timeout;
bool isTimeout;
#endif
%endif
uint8_t res, i, *p, block[%'ModuleName'%.BLOCK_BUF_SIZE+2]; %>40 /* additional 2 bytes for the address */
uint16_t eepromPage = (uint16_t)(addr/%'ModuleName'%.PAGE_SIZE);
uint8_t offset = (uint8_t)(addr%%%'ModuleName'%.PAGE_SIZE);
@@ -540,10 +583,36 @@ byte %'ModuleName'%.%WriteBlock(%'ModuleName'_Address addr, byte *data, word dat
#if %'ModuleName'%.DO_ACKNOWLEDGE_POLLING
/* do acknowledge polling */
//%@Wait@'ModuleName'%.WaitOSms(%'ModuleName'%.PAGE_WRITE_TIME_MS);
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BLOCK_TICKS>0
timeout = %@Timeout@'ModuleName'%.GetCounter(%'ModuleName'%.TIMEOUT_BLOCK_TICKS); /* set up timeout counter */
if (timeout==%@Timeout@'ModuleName'%.OUT_OF_HANDLE) {
(void)%@I2C@'ModuleName'%.UnselectSlave();
return ERR_OVERFLOW;
}
#endif
%endif
block[0] = 0xff; /* dummy value */
do {
res = %@I2C@'ModuleName'%.WriteBlock(block, 1, %@I2C@'ModuleName'%.SEND_STOP);%>40 /* send address and data */
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BLOCK_TICKS>0
isTimeout = %@Timeout@'ModuleName'%.CounterExpired(timeout);
if (isTimeout) {
res = ERR_FAULT;
break;
}
#endif
%endif
} while(res!=ERR_OK); /* wait until we get an ACK */
%if defined(Timeout)
#if %'ModuleName'%.TIMEOUT_BLOCK_TICKS>0
%@Timeout@'ModuleName'%.LeaveCounter(timeout);
if (isTimeout) {
res = ERR_FAILED;
}
#endif
%endif
if (res != ERR_OK) {
(void)%@I2C@'ModuleName'%.UnselectSlave();
return res;

0 comments on commit 6482c57

Please sign in to comment.
You can’t perform that action at this time.