This commit is contained in:
Tristan Krause 2019-05-29 11:07:42 +02:00
parent 63d81c6e7e
commit 0ec3988c58
4 changed files with 70 additions and 76 deletions

View file

@ -38,11 +38,11 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="206">
<caret line="98" column="61" selection-start-line="98" selection-start-column="61" selection-end-line="98" selection-end-column="61" />
<state relative-caret-position="506">
<caret line="106" column="35" selection-start-line="106" selection-start-column="35" selection-end-line="106" selection-end-column="35" />
</state>
</provider>
</entry>
@ -50,17 +50,26 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/drv/usart.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="87" column="65" selection-start-line="87" selection-start-column="65" selection-end-line="87" selection-end-column="65" />
<state relative-caret-position="554">
<caret line="102" column="11" selection-start-line="102" selection-start-column="11" selection-end-line="102" selection-end-column="11" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/drv/usartexception.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="13" column="27" selection-start-line="13" selection-start-column="13" selection-end-line="13" selection-end-column="27" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-528">
<caret line="362" column="52" selection-start-line="362" selection-start-column="52" selection-end-line="362" selection-end-column="52" />
<state relative-caret-position="192">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
</state>
</provider>
</entry>
@ -86,9 +95,9 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/drv/usart.h" />
<option value="$PROJECT_DIR$/drv/usart.cpp" />
<option value="$PROJECT_DIR$/drv/b15f.cpp" />
<option value="$PROJECT_DIR$/drv/usart.cpp" />
<option value="$PROJECT_DIR$/drv/usart.h" />
</list>
</option>
</component>
@ -128,7 +137,7 @@
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="CMakeSettings" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -159,24 +168,24 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1559118962147</updated>
<workItem from="1559118964304" duration="620000" />
<workItem from="1559118964304" duration="1887000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="620000" />
<option name="totallyTimeSpent" value="1887000" />
</component>
<component name="ToolWindowManager">
<frame x="67" y="25" width="1853" height="1055" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24958494" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24958494" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Messages" weight="0.32937366" />
<window_info anchor="bottom" id="Terminal" visible="true" weight="0.32937366" />
<window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.23434125" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="CMake" weight="0.33045357" />
<window_info anchor="bottom" id="Message" order="0" />
@ -204,27 +213,34 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<entry file="file://$PROJECT_DIR$/drv/b15f.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/drv/usartexception.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="206">
<caret line="98" column="61" selection-start-line="98" selection-start-column="61" selection-end-line="98" selection-end-column="61" />
<state relative-caret-position="180">
<caret line="13" column="27" selection-start-line="13" selection-start-column="13" selection-end-line="13" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/usart.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="87" column="65" selection-start-line="87" selection-start-column="65" selection-end-line="87" selection-end-column="65" />
<state relative-caret-position="554">
<caret line="102" column="11" selection-start-line="102" selection-start-column="11" selection-end-line="102" selection-end-column="11" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/drv/b15f.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/drv/b15f.cpp">
<entry file="file://$PROJECT_DIR$/drv/usart.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-528">
<caret line="362" column="52" selection-start-line="362" selection-start-column="52" selection-end-line="362" selection-end-column="52" />
<state relative-caret-position="506">
<caret line="106" column="35" selection-start-line="106" selection-start-column="35" selection-end-line="106" selection-end-column="35" />
</state>
</provider>
</entry>

View file

@ -229,9 +229,7 @@ uint16_t B15F::analogRead(uint8_t channel)
channel
};
int n_sent = usart.receive(&rq[0], 0, sizeof(rq));
if(n_sent != sizeof(rq))
abort("Sent failed");
usart.transmit(&rq[0], 0, sizeof(rq));
uint16_t adc = usart.readInt();
@ -302,9 +300,7 @@ uint8_t B15F::pwmSetFrequency(uint32_t freq)
static_cast<uint8_t>((freq >> 24) & 0xFF)
};
int n_sent = usart.receive(&rq[0], 0, sizeof(rq));
if(n_sent != sizeof(rq))
abort("Sent failed");
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t byte = usart.readByte();
delay_us(10);
@ -321,9 +317,7 @@ bool B15F::pwmSetValue(uint8_t value)
value
};
int n_sent = usart.receive(&rq[0], 0, sizeof(rq));
if(n_sent != sizeof(rq))
abort("Sent failed");
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw = usart.readByte();
delay_us(10);
@ -341,9 +335,7 @@ bool B15F::setRegister(uint8_t adr, uint8_t val)
val
};
int n_sent = usart.receive(&rq[0], 0, sizeof(rq));
if(n_sent != sizeof(rq))
abort("Sent failed");
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t byte = usart.readByte();
delay_us(10);
@ -360,9 +352,7 @@ uint8_t B15F::getRegister(uint8_t adr)
adr
};
int n_sent = usart.receive(&rq[0], 0, sizeof(rq));
if(n_sent != sizeof(rq))
abort("Sent failed");
usart.transmit(&rq[0], 0, sizeof(rq));
uint8_t aw = usart.readByte();
delay_us(10);

View file

@ -85,43 +85,18 @@ void USART::writeU32(uint32_t w)
throw USARTException("Fehler beim Senden: writeU32()");
}
int USART::transmit(uint8_t *buffer, uint16_t offset, uint8_t len)
void USART::receive(uint8_t *buffer, uint16_t offset, uint8_t len)
{
uint32_t elapsed = 0;
int n_read = -1;
auto start = std::chrono::steady_clock::now();
auto end = start;
while(elapsed < timeout)
{
n_read = read(file_desc, buffer + offset, len);
if (n_read == len)
return n_read;
end = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
}
return 0;
int n = read(file_desc, buffer + offset, len);
if(n != len)
throw USARTException(std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
}
int USART::receive(uint8_t *buffer, uint16_t offset, uint8_t len)
void USART::transmit(uint8_t *buffer, uint16_t offset, uint8_t len)
{
uint32_t elapsed = 0;
int n_sent = -1;
auto start = std::chrono::steady_clock::now();
auto end = start;
while(elapsed < timeout)
{
n_sent = write(file_desc, buffer + offset, len);
flushOutputBuffer();
if (n_sent == len)
return n_sent;
end = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
}
return n_sent;
int n = write(file_desc, buffer + offset, len);
if(n != len)
throw USARTException(std::string(__FUNCTION__) + " failed: " + std::string(__FILE__) + "#" + std::to_string(__LINE__));
}
uint8_t USART::readByte(void)
{

View file

@ -95,8 +95,21 @@ public:
*/
uint16_t readInt(void);
int transmit(uint8_t *buffer, uint16_t offset, uint8_t len);
int receive(uint8_t *buffer, uint16_t offset, uint8_t len);
/**
* Sends n bytes from the buffer over USART
* \param buffer target buffer
* \param offset in buffer (mostly 0)
* \throws USARTException
*/
void transmit(uint8_t *buffer, uint16_t offset, uint8_t len);
/**
* Receives n bytes from USART and writes them into the buffer
* \param buffer target buffer
* \param offset in buffer (mostly 0)
* \throws USARTException
*/
void receive(uint8_t *buffer, uint16_t offset, uint8_t len);
/*************************************/