Added ADC messages its own buffer

This commit is contained in:
Your Name
2026-10-04 15:55:09 +03:00
parent 2d7ed3b1d7
commit 9f8b9f7715
3 changed files with 47 additions and 35 deletions
+18 -31
View File
@@ -1,6 +1,6 @@
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/29.2.9 Chrome/140.0.7339.249 Electron/38.7.2 Safari/537.36" pages="3">
<diagram name="Blocks" id="qTBlaR7WWd7gh2COTHJy">
<mxGraphModel dx="1285" dy="882" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<mxGraphModel dx="1178" dy="808" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
@@ -896,9 +896,6 @@
<mxCell id="gFHrDWAFEzCY88qi_DX8-10" edge="1" parent="1" source="xkMDcVt49qT7mFQ4EbYJ-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" target="gFHrDWAFEzCY88qi_DX8-8">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-9" parent="1" style="rounded=0;whiteSpace=wrap;html=1;" value="ADC thread" vertex="1">
<mxGeometry height="60" width="90" x="1950" y="410" as="geometry" />
</mxCell>
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-17" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fontSize=10;" value="GPIO" vertex="1">
<mxGeometry height="40" width="50" x="1560" y="480" as="geometry" />
</mxCell>
@@ -908,14 +905,6 @@
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-10" edge="1" parent="1" source="COvur8ckIkHQRD2Fb0JY-94" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="xkMDcVt49qT7mFQ4EbYJ-9">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="gFHrDWAFEzCY88qi_DX8-15" edge="1" parent="1" source="xkMDcVt49qT7mFQ4EbYJ-26" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.25;entryDx=0;entryDy=0;" target="gFHrDWAFEzCY88qi_DX8-14">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1830" y="290" />
<mxPoint x="1830" y="305" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-26" parent="1" style="rounded=0;whiteSpace=wrap;html=1;" value="Digital in controller" vertex="1">
<mxGeometry height="60" width="90" x="1720" y="260" as="geometry" />
</mxCell>
@@ -936,14 +925,6 @@
</Array>
</mxGeometry>
</mxCell>
<mxCell id="gFHrDWAFEzCY88qi_DX8-62" edge="1" parent="1" source="xkMDcVt49qT7mFQ4EbYJ-68" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.75;entryDx=0;entryDy=0;" target="gFHrDWAFEzCY88qi_DX8-14">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1830" y="450" />
<mxPoint x="1830" y="375" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-68" parent="1" style="rounded=0;whiteSpace=wrap;html=1;" value="Power monitor thread" vertex="1">
<mxGeometry height="60" width="90" x="1720" y="420" as="geometry" />
</mxCell>
@@ -1086,9 +1067,6 @@
<mxCell id="gFHrDWAFEzCY88qi_DX8-8" parent="1" style="rounded=0;whiteSpace=wrap;html=1;" value="MUX controller" vertex="1">
<mxGeometry height="60" width="90" x="1950" y="330" as="geometry" />
</mxCell>
<mxCell id="gFHrDWAFEzCY88qi_DX8-14" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=light-dark(#1BBCE2,#1035C4);fontColor=default;strokeColor=#006EAF;" value="ZBUS" vertex="1">
<mxGeometry height="140" width="70" x="1845" y="270" as="geometry" />
</mxCell>
<mxCell id="gFHrDWAFEzCY88qi_DX8-21" edge="1" parent="1" source="gFHrDWAFEzCY88qi_DX8-20" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.25;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="COvur8ckIkHQRD2Fb0JY-174">
<mxGeometry relative="1" as="geometry">
<Array as="points">
@@ -1164,25 +1142,34 @@
<mxGeometry height="60" width="90" x="1950" y="610" as="geometry" />
</mxCell>
<mxCell id="pz70zx9ZGhry34nHQQIc-1" connectable="0" parent="1" style="group" value="" vertex="1">
<mxGeometry height="330" width="105" x="1827.5" y="610" as="geometry" />
<mxGeometry height="370" width="105" x="1828" y="570" as="geometry" />
</mxCell>
<mxCell id="gFHrDWAFEzCY88qi_DX8-16" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="STATE&lt;div&gt;controller&lt;/div&gt;" vertex="1">
<mxGeometry height="330" width="105" as="geometry" />
<mxCell id="gFHrDWAFEzCY88qi_DX8-16" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="STATE&lt;div&gt;controller&lt;/div&gt;&lt;div&gt;thread&lt;/div&gt;" vertex="1">
<mxGeometry height="370" width="105" as="geometry" />
</mxCell>
<mxCell id="GHP3okiXW9Laa2N-MtJK-4" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="BOOTING" vertex="1">
<mxGeometry height="40" width="70" x="17.5" y="45" as="geometry" />
<mxGeometry height="44.848484848484844" width="70" x="17.5" y="50.45454545454545" as="geometry" />
</mxCell>
<mxCell id="AYLe-5JP3gpOVYFiu9-b-1" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="MOTOR INIT" vertex="1">
<mxGeometry height="40" width="70" x="17.5" y="100" as="geometry" />
<mxGeometry height="44.848484848484844" width="70" x="17.5" y="112.12121212121212" as="geometry" />
</mxCell>
<mxCell id="AYLe-5JP3gpOVYFiu9-b-2" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="READY" vertex="1">
<mxGeometry height="40" width="70" x="17.5" y="158" as="geometry" />
<mxGeometry height="44.848484848484844" width="70" x="17.5" y="177.15151515151516" as="geometry" />
</mxCell>
<mxCell id="AYLe-5JP3gpOVYFiu9-b-3" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="IDLE" vertex="1">
<mxGeometry height="40" width="70" x="17.5" y="216" as="geometry" />
<mxGeometry height="44.848484848484844" width="70" x="17.5" y="242.18181818181816" as="geometry" />
</mxCell>
<mxCell id="AYLe-5JP3gpOVYFiu9-b-4" parent="pz70zx9ZGhry34nHQQIc-1" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="SLEEP" vertex="1">
<mxGeometry height="40" width="70" x="17.5" y="274" as="geometry" />
<mxGeometry height="44.848484848484844" width="70" x="17.5" y="307.2121212121212" as="geometry" />
</mxCell>
<mxCell id="0XTEijxMU6OlM955Z0Kw-2" connectable="0" parent="1" style="group" value="" vertex="1">
<mxGeometry height="60" width="90" x="1950" y="410" as="geometry" />
</mxCell>
<mxCell id="xkMDcVt49qT7mFQ4EbYJ-9" parent="0XTEijxMU6OlM955Z0Kw-2" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" value="ADC&amp;nbsp;&lt;div&gt;thread&lt;/div&gt;" vertex="1">
<mxGeometry height="60" width="90" as="geometry" />
</mxCell>
<mxCell id="0XTEijxMU6OlM955Z0Kw-1" parent="0XTEijxMU6OlM955Z0Kw-2" style="rounded=0;whiteSpace=wrap;html=1;" value="msg buffer" vertex="1">
<mxGeometry height="20" width="90" y="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
+28 -4
View File
@@ -35,6 +35,12 @@ struct k_msgq adc_mask_msgq;
// ADC TIMER
struct k_timer adc_timer;
// ADC BUFFER
#define ADC_BUFFER_SIZE 10
struct command_message_t adc_msg_buffer[ADC_BUFFER_SIZE];
struct command_message_t *adc_msg_buffer_ptr;
int *adc_data_type;
static void adc_timer_handler(struct k_timer *timer) {
// Timer trigger
@@ -67,9 +73,13 @@ static void adc_thread(void *p1, void *p2, void *p3) {
}
// Send to USB
struct command_message_t *msg = usb_get_next_tx_buf();
command_create_message(msg, sizeof(values), ADC_READ_ALL, (uint8_t *)values);
usb_send_command(msg);
command_create_message(adc_msg_buffer_ptr, sizeof(values), ADC_READ_ALL, (uint8_t *)values);
usb_send_command(adc_msg_buffer_ptr);
adc_msg_buffer_ptr++;
if (adc_msg_buffer_ptr > &adc_msg_buffer[ADC_BUFFER_SIZE-1]) {
adc_msg_buffer_ptr = adc_msg_buffer;
}
}
}
@@ -82,6 +92,10 @@ int adc_init_all(void) {
// TIMER
k_timer_init(&adc_timer, adc_timer_handler, NULL);
// BUFFER
memset(adc_msg_buffer, 0, sizeof(adc_msg_buffer));
adc_msg_buffer_ptr = adc_msg_buffer;
// MUX init
ret = mux_init();
if (ret != 0) {
@@ -137,7 +151,6 @@ int adc_init_all(void) {
return 0;
}
int adc_read_id(int id) {
int ret;
int val_mv = 0;
@@ -209,4 +222,15 @@ int adc_timer_set(int interval_ms) {
}
return 0;
}
void* adc_get_buffer() {
struct command_message_t *ptr = adc_msg_buffer_ptr;
ptr--;
if (ptr < &adc_msg_buffer[0]) {
ptr = &adc_msg_buffer[ADC_BUFFER_SIZE-1];
}
return (void *)ptr;
}
+1
View File
@@ -12,6 +12,7 @@ int adc_init_all();
int adc_read_id(int id);
int adc_add_mask(uint32_t mask);
int adc_timer_set(int interval_ms);
void* adc_get_buffer();
#endif // ADC_H