folder restructure
parent
231c796f50
commit
c66410f631
@ -1,24 +0,0 @@
|
||||
#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 pin, uint32_t value)
|
||||
{
|
||||
register uint32_t r0 asm("r0") = call;
|
||||
register uint32_t r1 asm("r1") = pin;
|
||||
register uint32_t r2 asm("r2") = value;
|
||||
|
||||
asm("\
|
||||
mov r0, %0; \
|
||||
mov r1, %1; \
|
||||
mov r2, %2; \
|
||||
svc 1; \
|
||||
" :: "r" (r0), "r" (r1), "r" (r2));
|
||||
}
|
||||
|
||||
#endif // PRIV_GPIO_H_
|
@ -0,0 +1,22 @@
|
||||
CFILES = $(wildcard *.c)
|
||||
AFILES = $(wildcard *.s)
|
||||
OFILES = $(patsubst %.c, %.o, $(CFILES)) \
|
||||
$(patsubst %.s, %.asm.o, $(AFILES))
|
||||
|
||||
CFLAGS += -I.. -I../arch/cmsis
|
||||
|
||||
all: $(OFILES)
|
||||
|
||||
%.o: %.c
|
||||
@echo " CC " $<
|
||||
@$(CROSS)$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.asm.o: %.s
|
||||
@echo " AS " $<
|
||||
@$(CROSS)$(AS) $(AFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@echo " CLEAN"
|
||||
@rm -f $(OFILES)
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
CFILES = $(wildcard *.c)
|
||||
AFILES = $(wildcard *.s)
|
||||
OFILES = $(patsubst %.c, %.o, $(CFILES)) \
|
||||
$(patsubst %.s, %.asm.o, $(AFILES))
|
||||
|
||||
CFLAGS += -I.. -I../arch/cmsis
|
||||
|
||||
all: $(OFILES)
|
||||
|
||||
%.o: %.c
|
||||
@echo " CC " $<
|
||||
@$(CROSS)$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.asm.o: %.s
|
||||
@echo " AS " $<
|
||||
@$(CROSS)$(AS) $(AFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@echo " CLEAN"
|
||||
@rm -f $(OFILES)
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file priv_gpio.h
|
||||
* GPIO access for unpriviledged processes
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef PRIV_GPIO_H_
|
||||
#define PRIV_GPIO_H_
|
||||
|
||||
// For value flags
|
||||
#include <kernel/gpio.h>
|
||||
|
||||
/**
|
||||
* Possible GPIO calls.
|
||||
*/
|
||||
enum GPIO_CALLS {
|
||||
GPIO_MODE = 0, /**< Change GPIO mode */
|
||||
GPIO_TYPE, /**< Change GPIO type (PuPd/ODrain) */
|
||||
GPIO_PUPD, /**< Set/clear pullup/pulldown */
|
||||
GPIO_SPEED, /**< Set GPIO speed */
|
||||
GPIO_OUT, /**< Set GPIO output state */
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides unpriviledged GPIO access.
|
||||
* @param call The type of GPIO call to make
|
||||
* @param pin The pin to modify (0-15 = A, 16-31 = B, ...)
|
||||
* @param value The value to pass to the call
|
||||
*/
|
||||
void gpio(uint32_t call, uint32_t pin, uint32_t value)
|
||||
{
|
||||
register uint32_t r0 asm("r0") = call;
|
||||
register uint32_t r1 asm("r1") = pin;
|
||||
register uint32_t r2 asm("r2") = value;
|
||||
|
||||
asm("\
|
||||
mov r0, %0; \
|
||||
mov r1, %1; \
|
||||
mov r2, %2; \
|
||||
svc 1; \
|
||||
" :: "r" (r0), "r" (r1), "r" (r2));
|
||||
}
|
||||
|
||||
#endif // PRIV_GPIO_H_
|
@ -0,0 +1,35 @@
|
||||
#include <kernel/clock.h>
|
||||
#include "priv_gpio.h"
|
||||
#include <kernel/task.h>
|
||||
|
||||
void task1(void);
|
||||
void task2(void);
|
||||
|
||||
|
||||
|
||||
void user_main(void)
|
||||
{
|
||||
gpio(GPIO_MODE, 5, OUTPUT);
|
||||
task_start(task1, 512);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
gpio(GPIO_OUT, 5, !(i & 1));
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
void task1(void)
|
||||
{
|
||||
delay(400);
|
||||
task_start(task2, 1024);
|
||||
}
|
||||
|
||||
void task2(void)
|
||||
{
|
||||
int state = 0;
|
||||
delay(2500);
|
||||
while (1) {
|
||||
gpio(GPIO_OUT, 5, state ^= 1);
|
||||
delay(500);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue