summaryrefslogtreecommitdiff
path: root/sim/ucsim/stm8.src/test/s3.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /sim/ucsim/stm8.src/test/s3.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'sim/ucsim/stm8.src/test/s3.c')
-rw-r--r--sim/ucsim/stm8.src/test/s3.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/sim/ucsim/stm8.src/test/s3.c b/sim/ucsim/stm8.src/test/s3.c
new file mode 100644
index 0000000..9635bf6
--- /dev/null
+++ b/sim/ucsim/stm8.src/test/s3.c
@@ -0,0 +1,98 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#define DEVICE DEV_STM8S208
+
+#include "stm8.h"
+
+volatile unsigned char *sif= (unsigned char *)0x7fff;
+
+int sifchar(int c)
+{
+ *sif= 'p';
+ *sif= c;
+ return c;
+}
+
+int putchar(int c)
+{
+ while(!(USART->sr & USART_SR_TXE));
+ USART->dr = c;
+ return c;
+}
+
+volatile uint8_t rx_buf[8];
+volatile uint8_t first_free= 0;
+volatile uint8_t last_used= 0;
+
+void isr_rx(void) __interrupt(USART_RX_IRQ)
+{
+ volatile uint8_t d;
+ *sif='p';*sif='I';
+ if (USART->sr & USART_SR_RXNE)
+ {
+ uint8_t n;
+ d= USART->dr;
+ n= (first_free+1)%8;
+ if (n != last_used)
+ {
+ rx_buf[first_free]= d;
+ first_free= n;
+ }
+ }
+}
+
+char received()
+{
+ //return UART2_SR & UART_SR_RXNE;
+ return first_free != last_used;
+}
+
+char getchar()
+{
+ uint8_t o;
+ while (!received())
+ ;
+ o= last_used;
+ last_used= (last_used+1)%8;
+ return rx_buf[o];
+}
+
+void prints(char *s)
+{
+ char i= 0;
+ while (s[i])
+ {
+ putchar(s[i]);
+ i++;
+ }
+}
+
+
+void main(void)
+{
+ unsigned long i = 0;
+
+ CLK->ckdivr = 0x00; // Set the frequency to 16 MHz
+ CLK->pckenr1 = 0xFF; // Enable peripherals
+
+ USART->cr2 = USART_CR2_TEN | USART_CR2_REN; // Allow TX and RX
+ USART->cr3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit
+ USART->brr2 = 0x03;
+ USART->brr1 = 0x68; // 9600 baud
+
+ USART->cr2|= USART_CR2_RIEN;
+ EI;
+
+ printf("Hello World!\n");
+ for (;;)
+ {
+ if (received())
+ {
+ char c= getchar();
+ *sif= 'x';*sif= c;
+ putchar(toupper(c));
+ }
+ }
+}