]> code.bitgloo.com Git - clyne/stmos.git/commitdiff
began work to add privilege
authortcsullivan <tullivan99@gmail.com>
Tue, 25 Sep 2018 21:09:53 +0000 (17:09 -0400)
committertcsullivan <tullivan99@gmail.com>
Tue, 25 Sep 2018 21:09:53 +0000 (17:09 -0400)
include/priv_gpio.h [new file with mode: 0644]
src/gpio.c
src/main.c
src/svc.c [new file with mode: 0644]

diff --git a/include/priv_gpio.h b/include/priv_gpio.h
new file mode 100644 (file)
index 0000000..eee5e18
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef PRIV_GPIO_H_
+#define PRIV_GPIO_H_
+
+#define GPIO_MODE 0
+#define GPIO_TYPE 1
+#define GPIO_PUPD 2
+#define GPIO_SPEED 3
+#define GPIO_OUT 4
+
+void gpio(uint32_t call, uint32_t port, uint32_t pin, uint32_t value) 
+{
+       register uint32_t r0 asm("r0") = call;
+       register uint32_t r1 asm("r1") = port;
+       register uint32_t r2 asm("r2") = pin;
+       register uint32_t r3 asm("r3") = value;
+
+       asm("\
+               mov r0, %0; \
+               mov r1, %1; \
+               mov r2, %2; \
+               mov r3, %3; \
+               svc 1; \
+       " :: "r" (r0), "r" (r1), "r" (r2), "r" (r3));
+}
+
+#endif // PRIV_GPIO_H_
index 151779d982808b6f301bb5c7cb152b520ceebf0d..29ed763b8868e9e4894a5540ac4e630a33e9dbba 100644 (file)
 
 #include <gpio.h>
 
+void gpio_svc(uint32_t *args)
+{
+       switch (args[0]) {
+       case 0:
+               gpio_mode((GPIO_TypeDef *)args[1], args[2], args[3]);
+               break;
+       case 1:
+               gpio_type((GPIO_TypeDef *)args[1], args[2], args[3]);
+               break;
+       case 2:
+               gpio_pupd((GPIO_TypeDef *)args[1], args[2], args[3]);
+               break;
+       case 3:
+               gpio_speed((GPIO_TypeDef *)args[1], args[2], args[3]);
+               break;
+       case 4:
+               gpio_dout((GPIO_TypeDef *)args[1], args[2], args[3]);
+               break;
+       }
+}
+
 void gpio_init(void)
 {
        // enable clocks
index 8028f9326f82cbeaa173d84f4ee8b773cf81c693..c929d163c2a9106eab70f247f50fe8a158ff5439 100644 (file)
@@ -20,6 +20,7 @@
 \r
 #include <clock.h>\r
 #include <gpio.h>\r
+#include <priv_gpio.h>\r
 #include <heap.h>\r
 #include <stm32l476xx.h>\r
 #include <task.h>\r
@@ -53,19 +54,29 @@ int main(void)
 void task2(void);\r
 void kmain(void)\r
 {\r
-       gpio_mode(GPIOA, 5, OUTPUT);\r
+       gpio(GPIO_MODE, (uint32_t)GPIOA, 5, OUTPUT);\r
+       //gpio_mode(GPIOA, 5, OUTPUT);\r
        task_start(task2, 512);\r
 \r
        for (int i = 0; i < 8; i++) {\r
                gpio_dout(GPIOA, 5, !(i & 1));\r
                delay(200);\r
        }\r
-\r
-       return;\r
 }\r
 \r
+void task3(void);\r
 void task2(void)\r
 {\r
-       while (1)\r
-               delay(800);\r
+       delay(400);\r
+       task_start(task3, 1024);\r
+}\r
+\r
+void task3(void)\r
+{\r
+       int state = 0;\r
+       delay(2500);\r
+       while (1) {\r
+               gpio_dout(GPIOA, 5, state ^= 1);\r
+               delay(500);\r
+       }\r
 }\r
diff --git a/src/svc.c b/src/svc.c
new file mode 100644 (file)
index 0000000..4342a95
--- /dev/null
+++ b/src/svc.c
@@ -0,0 +1,53 @@
+/**
+ * @file svc.c
+ * An unused handler for SVC calls
+ * TODO: use SVC calls, possibly allowing for switch to unprivileged mode?
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+#include <gpio.h>
+#include <clock.h>
+
+extern void gpio_svc(uint32_t *);
+
+void svc_handler(uint32_t *args)
+{
+       uint32_t svc_number = ((char *)args[6])[-2];
+
+       switch (svc_number) {
+       case 1:
+               gpio_svc(args);
+               break;
+       default:
+               break;
+       }
+}
+
+void SVC_Handler(void) {
+       uint32_t *args;
+
+       asm("\
+               tst lr, #4; \
+               ite eq; \
+               mrseq %0, msp; \
+               mrsne %0, psp; \
+       " : "=r" (args));
+
+       svc_handler(args);
+}
+