Commit 06c9a359fc67f1cd5254c4bb6e36a496b8f65588
authorMichel Pollet <buserror@gmail.com>
Wed, 23 Dec 2009 22:42:51 +0000 (22:42 +0000)
committerMichel Pollet <buserror@gmail.com>
Wed, 23 Dec 2009 22:42:51 +0000 (22:42 +0000)
Forget about it, it doesn't work yet. Loads the bootloader
and thats about it.

Signed-off-by: Michel Pollet <buserror@gmail.com>
4 files changed:
examples/board_simduino/ATmegaBOOT_168_atmega328.ihex [new file with mode: 0644]
examples/board_simduino/README [new file with mode: 0644]
examples/parts/uart_udp.c [new file with mode: 0644]
examples/parts/uart_udp.h [new file with mode: 0644]

diff --git a/examples/board_simduino/ATmegaBOOT_168_atmega328.ihex b/examples/board_simduino/ATmegaBOOT_168_atmega328.ihex
new file mode 100644 (file)
index 0000000..43a8b30
--- /dev/null
@@ -0,0 +1,125 @@
+:107800000C94343C0C94513C0C94513C0C94513CE1\r
+:107810000C94513C0C94513C0C94513C0C94513CB4\r
+:107820000C94513C0C94513C0C94513C0C94513CA4\r
+:107830000C94513C0C94513C0C94513C0C94513C94\r
+:107840000C94513C0C94513C0C94513C0C94513C84\r
+:107850000C94513C0C94513C0C94513C0C94513C74\r
+:107860000C94513C0C94513C11241FBECFEFD8E036\r
+:10787000DEBFCDBF11E0A0E0B1E0ECE9FFE702C060\r
+:1078800005900D92A230B107D9F712E0A2E0B1E065\r
+:1078900001C01D92AD30B107E1F70E942D3D0C945F\r
+:1078A000CC3F0C94003C982F959595959595959582\r
+:1078B000905D8F708A307CF0282F295A8091C0000B\r
+:1078C00085FFFCCF9093C6008091C00085FFFCCF60\r
+:1078D0002093C6000895282F205DF0CF982F809127\r
+:1078E000C00085FFFCCF9093C6000895EF92FF92F1\r
+:1078F0000F931F93EE24FF2487018091C00087FD22\r
+:1079000017C00894E11CF11C011D111D81E4E8164B\r
+:1079100082E4F8068FE0080780E0180770F3E09132\r
+:107920000401F091050109958091C00087FFE9CF1E\r
+:107930008091C6001F910F91FF90EF9008950E94D3\r
+:10794000763C982F8091C00085FFFCCF9093C600B5\r
+:1079500091362CF490330CF09053892F089597555D\r
+:10796000892F08951F930E949F3C182F0E949F3CCF\r
+:107970001295107F810F1F9108951F93182F882350\r
+:1079800021F00E94763C1150E1F71F9108951F935A\r
+:10799000182F0E94763C803249F0809103018F5F5E\r
+:1079A000809303018530C1F01F9108958091C0003C\r
+:1079B00085FFFCCF84E18093C6008091C00085FFE5\r
+:1079C000FCCF1093C6008091C00085FFFCCF80E102\r
+:1079D0008093C6001F910895E0910401F091050184\r
+:1079E00009951F9108950E94763C803241F0809164\r
+:1079F00003018F5F80930301853081F008958091AA\r
+:107A0000C00085FFFCCF84E18093C6008091C00058\r
+:107A100085FFFCCF80E18093C6000895E0910401CA\r
+:107A2000F09105010995089540E951E08823A1F0FE\r
+:107A30002D9A28EE33E0FA013197F1F721503040CA\r
+:107A4000D1F72D9828EE33E0FA013197F1F7215064\r
+:107A50003040D1F7815061F708953F924F925F9285\r
+:107A60006F927F928F929F92AF92BF92CF92DF924E\r
+:107A7000EF92FF920F931F93CF93DF93000080E16B\r
+:107A80008093C4001092C50088E18093C10086E015\r
+:107A90008093C2005098589A259A81E00E94143D24\r
+:107AA00024E1F22E9EE1E92E85E9D82E0FE0C02ECA\r
+:107AB00010E1B12EAA24A394B1E49B2EA6E58A2E50\r
+:107AC000F2E57F2EE0E26E2E79E4572E63E5462E36\r
+:107AD00050E5352E0E94763C8033B1F18133B9F107\r
+:107AE000803409F46FC0813409F476C0823409F41B\r
+:107AF00085C0853409F488C0803531F1823521F1A3\r
+:107B0000813511F1853509F485C0863509F48DC0BC\r
+:107B1000843609F496C0843709F403C1853709F423\r
+:107B200072C1863709F466C0809103018F5F80932C\r
+:107B30000301853079F6E0910401F0910501099582\r
+:107B40000E94763C803351F60E94F33CC3CF0E94E2\r
+:107B5000763C803249F78091C00085FFFCCFF092DF\r
+:107B6000C6008091C00085FFFCCF9092C600809136\r
+:107B7000C00085FFFCCF8092C6008091C00085FFC9\r
+:107B8000FCCF7092C6008091C00085FFFCCF609250\r
+:107B9000C6008091C00085FFFCCF5092C600809146\r
+:107BA000C00085FFFCCF4092C6008091C00085FFD9\r
+:107BB000FCCF3092C6008091C00085FFFCCFB09210\r
+:107BC000C60088CF0E94763C863808F4BDCF0E945C\r
+:107BD000763C0E94F33C7ECF0E94763C803809F4CC\r
+:107BE0009CC0813809F40BC1823809F43CC1883942\r
+:107BF00009F48FC080E00E94C73C6CCF84E10E94F2\r
+:107C0000BD3C0E94F33C66CF85E00E94BD3C0E94D3\r
+:107C1000F33C60CF0E94763C809306010E94763C44\r
+:107C2000809307010E94F33C55CF0E94763C80333D\r
+:107C300009F41DC183E00E94BD3C80E00E94C73C66\r
+:107C400049CF0E94763C809309020E94763C809343\r
+:107C5000080280910C028E7F80930C020E94763C79\r
+:107C6000853409F415C18091080290910902892B8D\r
+:107C700089F000E010E00E94763CF801E85FFE4FDA\r
+:107C800080830F5F1F4F80910802909109020817AF\r
+:107C9000190788F30E94763C803209F045CF809125\r
+:107CA0000C0280FF01C16091060170910701660F0F\r
+:107CB000771F7093070160930601A0910802B091AD\r
+:107CC00009021097C9F0E8E0F1E09B01AD014E0F09\r
+:107CD0005F1FF999FECF32BD21BD819180BDFA9A17\r
+:107CE000F99A2F5F3F4FE417F50799F76A0F7B1F4B\r
+:107CF00070930701609306018091C00085FFFCCF5F\r
+:107D0000F092C6008091C00085FFFCCFB092C60003\r
+:107D1000E1CE83E00E94C73CDDCE82E00E94C73CFA\r
+:107D2000D9CE0E94763C809309020E94763C8093D3\r
+:107D300008028091060190910701880F991F909386\r
+:107D40000701809306010E94763C853409F4A6C0A1\r
+:107D500080910C028E7F80930C020E94763C8032D0\r
+:107D600009F0B8CE8091C00085FFFCCFF092C6002C\r
+:107D7000609108027091090261157105B9F140E046\r
+:107D800050E080910C02A82FA170B82FB27011C0E2\r
+:107D9000BB2309F45CC0E0910601F0910701319624\r
+:107DA000F0930701E09306014F5F5F4F46175707B7\r
+:107DB000E8F4AA2369F3F999FECF209106013091E6\r
+:107DC000070132BD21BDF89A90B58091C00085FFB2\r
+:107DD000FCCF9093C6002F5F3F4F30930701209355\r
+:107DE00006014F5F5F4F4617570718F38091C00099\r
+:107DF00085FDE5CE8091C00085FFF8CFE0CE81E023\r
+:107E00000E94C73C67CE0E94763C803209F08CCE3F\r
+:107E10008091C00085FFFCCFF092C6008091C00029\r
+:107E200085FFFCCFE092C6008091C00085FFFCCFAB\r
+:107E3000D092C6008091C00085FFFCCFC092C600E2\r
+:107E40008091C00085FFFCCFB092C60043CEE09188\r
+:107E50000601F091070194918091C00085FFFCCF4D\r
+:107E60009093C6009CCF80E10E94C73C33CE0E9415\r
+:107E7000763C0E94763C182F0E94763C112309F430\r
+:107E800083C0113009F484C08FE00E94C73C22CE29\r
+:107E900080910C02816080930C02E5CE80910C02EF\r
+:107EA000816080930C0259CF809107018823880F4D\r
+:107EB000880B8A2180930B02809106019091070123\r
+:107EC000880F991F90930701809306018091080203\r
+:107ED00080FF09C080910802909109020196909359\r
+:107EE000090280930802F894F999FECF1127E091D6\r
+:107EF0000601F0910701C8E0D1E08091080290915D\r
+:107F00000902103091F40091570001700130D9F34B\r
+:107F100003E000935700E89500915700017001308D\r
+:107F2000D9F301E100935700E89509901990009169\r
+:107F3000570001700130D9F301E000935700E89534\r
+:107F40001395103498F011270091570001700130FB\r
+:107F5000D9F305E000935700E895009157000170B0\r
+:107F60000130D9F301E100935700E895329602976A\r
+:107F700009F0C7CF103011F00296E5CF112480919F\r
+:107F8000C00085FFB9CEBCCE8EE10E94C73CA2CD19\r
+:0C7F900085E90E94C73C9ECDF894FFCF0D\r
+:027F9C00800063\r
+:040000030000780081\r
+:00000001FF\r
diff --git a/examples/board_simduino/README b/examples/board_simduino/README
new file mode 100644 (file)
index 0000000..e7ac83a
--- /dev/null
@@ -0,0 +1,8 @@
+
+It's not working. don't get all excited. It loads and run the bootloader, but
+thats all.
+It /will/ work at some point, but it's not. It's missing a heck of a lot.
+
+Told ya. forget about it ! :=)
+
+Michel Pollet <buserror@gmail.com>
diff --git a/examples/parts/uart_udp.c b/examples/parts/uart_udp.c
new file mode 100644 (file)
index 0000000..cebf41c
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+       uart_udp.c
+
+       Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
+
+       This file is part of simavr.
+
+       simavr is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       simavr is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <pthread.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "uart_udp.h"
+#include "avr_uart.h"
+#include "sim_hex.h"
+
+DEFINE_FIFO(uint8_t,uart_udp_fifo, 128);
+
+/*
+ * called when a byte is send via the uart on the AVR
+ */
+static void uart_udp_in_hook(struct avr_irq_t * irq, uint32_t value, void * param)
+{
+       uart_udp_t * p = (uart_udp_t*)param;
+}
+
+/*
+ * Called when the uart has room in it's input buffer. This is called repeateadly
+ * if necessary, while the xoff is called only when the uart fifo is FULL
+ */
+static void uart_udp_xon_hook(struct avr_irq_t * irq, uint32_t value, void * param)
+{
+       uart_udp_t * p = (uart_udp_t*)param;
+       if (!p->xon)
+               printf("uart_udp_xon_hook\n");
+       p->xon = 1;
+       // try to empty our fifo, the uart_udp_xoff_hook() will be called when
+       // other side is full
+       while (p->xon && !uart_udp_fifo_isempty(&p->out)) {
+               avr_raise_irq(p->irq + IRQ_UART_UDP_BYTE_OUT, uart_udp_fifo_read(&p->out));
+       }
+}
+
+/*
+ * Called when the uart ran out of room in it's input buffer
+ */
+static void uart_udp_xoff_hook(struct avr_irq_t * irq, uint32_t value, void * param)
+{
+       uart_udp_t * p = (uart_udp_t*)param;
+       if (p->xon)
+               printf("uart_udp_xoff_hook\n");
+       p->xon = 0;
+}
+
+static void * uart_udp_thread(void * param)
+{
+       uart_udp_t * p = (uart_udp_t*)param;
+
+       while (1) {
+               fd_set read_set;
+               int max;
+               FD_ZERO(&read_set);
+
+               FD_SET(p->s, &read_set);
+               max = p->s + 1;
+
+               struct timeval timo = { 0, 100 };       // short, but not too short interval
+               int ret = select(max, &read_set, NULL, NULL, &timo);
+
+               if (FD_ISSET(p->s, &read_set)) {
+                       uint8_t buffer[1024];
+
+                       socklen_t len = sizeof(p->peer);
+                       ssize_t r = recvfrom(p->s, buffer, sizeof(buffer)-1, 0, (struct sockaddr*)&p->peer, &len);
+
+                       hdump("udp", buffer, len);
+
+                       // write them in fifo
+                       uint8_t * src = buffer;
+                       while (r-- && !uart_udp_fifo_isfull(&p->out))
+                               uart_udp_fifo_write(&p->out, *src++);
+               }
+       }
+}
+
+
+void uart_udp_init(struct avr_t * avr, uart_udp_t * p)
+{
+       p->avr = avr;
+       p->irq = avr_alloc_irq(0, IRQ_UART_UDP_COUNT);
+       avr_irq_register_notify(p->irq + IRQ_UART_UDP_BYTE_IN, uart_udp_in_hook, p);
+
+       if ((p->s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+               fprintf(stderr, "%s: Can't create socket: %s", __FUNCTION__, strerror(errno));
+               return ;
+       }
+
+       struct sockaddr_in address = { 0 };
+       address.sin_family = AF_INET;
+       address.sin_port = htons (4321);
+
+       if (bind(p->s, (struct sockaddr *) &address, sizeof(address))) {
+               fprintf(stderr, "%s: Can not bind socket: %s", __FUNCTION__, strerror(errno));
+               return ;
+       }
+
+       pthread_create(&p->thread, NULL, uart_udp_thread, p);
+
+}
+
+void uart_udp_connect(uart_udp_t * p, char uart)
+{
+       avr_irq_t * src = avr_io_getirq(p->avr, AVR_IOCTL_UART_GETIRQ(uart), UART_IRQ_OUTPUT);
+       avr_irq_t * dst = avr_io_getirq(p->avr, AVR_IOCTL_UART_GETIRQ(uart), UART_IRQ_INPUT);
+       avr_irq_t * xon = avr_io_getirq(p->avr, AVR_IOCTL_UART_GETIRQ(uart), UART_IRQ_OUT_XON);
+       avr_irq_t * xoff = avr_io_getirq(p->avr, AVR_IOCTL_UART_GETIRQ(uart), UART_IRQ_OUT_XOFF);
+       if (src && dst) {
+               avr_connect_irq(src, p->irq + IRQ_UART_UDP_BYTE_IN);
+               avr_connect_irq(p->irq + IRQ_UART_UDP_BYTE_OUT, dst);
+       }
+       if (xon)
+               avr_irq_register_notify(xon, uart_udp_xon_hook, p);
+       if (xoff)
+               avr_irq_register_notify(xoff, uart_udp_xoff_hook, p);
+}
+
diff --git a/examples/parts/uart_udp.h b/examples/parts/uart_udp.h
new file mode 100644 (file)
index 0000000..20bdd74
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+       uart_udp.h
+
+       Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
+
+       This file is part of simavr.
+
+       simavr is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       simavr is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __UART_UDP_H___
+#define __UART_UDP_H___
+
+#include <netinet/in.h>
+#include "sim_irq.h"
+#include "fifo_declare.h"
+
+enum {
+       IRQ_UART_UDP_BYTE_IN = 0,
+       IRQ_UART_UDP_BYTE_OUT,
+       IRQ_UART_UDP_COUNT
+};
+
+DECLARE_FIFO(uint8_t,uart_udp_fifo, 128);
+
+typedef struct uart_udp_t {
+       avr_irq_t *     irq;            // irq list
+       struct avr_t *avr;              // keep it around so we can pause it
+
+       pthread_t       thread;
+       int             s;                      // socket we chat on
+       struct sockaddr_in peer;
+
+       int                     xon;
+       uart_udp_fifo_t in;
+       uart_udp_fifo_t out;
+} uart_udp_t;
+
+void uart_udp_init(struct avr_t * avr, uart_udp_t * b);
+
+void uart_udp_connect(uart_udp_t * p, char uart);
+
+#endif /* __UART_UDP_H___ */