--- /dev/null
+#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_
#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
\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
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
--- /dev/null
+/**
+ * @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);
+}
+