hi friends..
are there c libs available für the bare metal pi?
like the arduino libs?
thanks
Re: c libs
Is this what you are looking for: http://wiringpi.com/
Re: c libs
hi .
i am not sure..
that looks for me that there must be running a linux kernel.. or did i understand it wrong?
i am not sure..
that looks for me that there must be running a linux kernel.. or did i understand it wrong?
Re: c libs
I'm fairly certain those libraries are only for accessing the hardware from programs written to run under Linux, not with a bare metal system.
Accessing the majority of GPIO functions is fairly easy in bare metal, either from C or Assembler (my preferred method).
Accessing the majority of GPIO functions is fairly easy in bare metal, either from C or Assembler (my preferred method).
Re: c libs
The thing about bare metal is that its entirely up to you. Any C library is going to be based on a load of low-level functions that are specific to whatever bare-metal kernel they are written for (e.g. write to device, allocate memory, etc.). So a bare-metal C library is meaningless on its own. You need a kernel to go with it, or else have the source code and port the C library to use your own low-level kernel functions.
There is at least one open source C library out there I believe, called newlib, which you could try to port to your kernel. I've not looked at it myself.
Alternatively, perhaps the question is really, has anyone got a bare metal kernel + C library?
There is at least one open source C library out there I believe, called newlib, which you could try to port to your kernel. I've not looked at it myself.
Alternatively, perhaps the question is really, has anyone got a bare metal kernel + C library?
Re: c libs
yes.. the last thing would be great..
like this http://www.ti.com/tool/starterware-sitara for the BeageBoard..
is there not such a thing for the RI?
like this http://www.ti.com/tool/starterware-sitara for the BeageBoard..
is there not such a thing for the RI?
Re: c libs
All the Linux C libraries use /dev/mem to access the gpios. It should be simple to extract the low level routines (read/write/PUD up/down/off/read mode/set mode) and use them on bare metal.
For instance here is part of the source for the pigpio C library.
If you remove all the error checking and debugging paraphernalia it ends up as bare metal routines.
For instance here is part of the source for the pigpio C library.
Code: Select all
/* ----------------------------------------------------------------------- */
int gpioSetMode(unsigned gpio, unsigned mode)
{
int reg, shift;
DBG(DBG_USER, "gpio=%d mode=%d", gpio, mode);
CHECK_INITED;
if (gpio > PI_MAX_GPIO)
SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
if (mode > PI_ALT3)
SOFT_ERROR(PI_BAD_MODE, "gpio %d, bad mode (%d)", gpio, mode);
reg = gpio/10;
shift = (gpio%10) * 3;
if (gpio <= PI_MAX_USER_GPIO)
{
if (mode != PI_OUTPUT)
{
switch (gpioInfo[gpio].is)
{
case GPIO_SERVO:
/* switch servo off */
myGpioSetServo(gpio,
gpioInfo[gpio].width/gpioCfg.clockMicros, 0);
break;
case GPIO_PWM:
/* switch pwm off */
myGpioSetPwm(gpio, gpioInfo[gpio].width, 0);
break;
}
gpioInfo[gpio].is = GPIO_UNDEFINED;
}
}
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
return 0;
}
/* ----------------------------------------------------------------------- */
int gpioGetMode(unsigned gpio)
{
int reg, shift;
DBG(DBG_USER, "gpio=%d", gpio);
CHECK_INITED;
if (gpio > PI_MAX_GPIO)
SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
reg = gpio/10;
shift = (gpio%10) * 3;
return (*(gpioReg + reg) >> shift) & 7;
}
/* ----------------------------------------------------------------------- */
int gpioSetPullUpDown(unsigned gpio, unsigned pud)
{
DBG(DBG_USER, "gpio=%d pud=%d", gpio, pud);
CHECK_INITED;
if (gpio > PI_MAX_GPIO)
SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
if (pud > PI_PUD_UP)
SOFT_ERROR(PI_BAD_PUD, "gpio %d, bad pud (%d)", gpio, pud);
*(gpioReg + GPPUD) = pud;
myGpioDelay(20);
*(gpioReg + GPPUDCLK0 + BANK) = BIT;
myGpioDelay(20);
*(gpioReg + GPPUD) = 0;
*(gpioReg + GPPUDCLK0 + BANK) = 0;
return 0;
}
/* ----------------------------------------------------------------------- */
int gpioRead(unsigned gpio)
{
DBG(DBG_USER, "gpio=%d", gpio);
CHECK_INITED;
if (gpio > PI_MAX_GPIO)
SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
if ((*(gpioReg + GPLEV0 + BANK) & BIT) != 0) return PI_ON;
else return PI_OFF;
}
/* ----------------------------------------------------------------------- */
int gpioWrite(unsigned gpio, unsigned level)
{
DBG(DBG_USER, "gpio=%d level=%d", gpio, level);
CHECK_INITED;
if (gpio > PI_MAX_GPIO)
SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
if (level > PI_ON)
SOFT_ERROR(PI_BAD_LEVEL, "gpio %d, bad level (%d)", gpio, level);
if (gpio <= PI_MAX_USER_GPIO)
{
if (gpioInfo[gpio].is != GPIO_WRITE)
{
if (gpioInfo[gpio].is == GPIO_UNDEFINED)
{
if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT;
else *(gpioReg + GPSET0 + BANK) = BIT;
gpioSetMode(gpio, PI_OUTPUT);
}
else if (gpioInfo[gpio].is == GPIO_PWM)
{
/* switch pwm off */
myGpioSetPwm(gpio, gpioInfo[gpio].width, 0);
}
else if (gpioInfo[gpio].is == GPIO_SERVO)
{
/* switch servo off */
myGpioSetServo(
gpio, gpioInfo[gpio].width/gpioCfg.clockMicros, 0);
}
gpioInfo[gpio].is=GPIO_WRITE;
gpioInfo[gpio].width=0;
}
}
if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT;
else *(gpioReg + GPSET0 + BANK) = BIT;
return 0;
}
Re: c libs
Here's a really ancient all-c library that gives you most of the basic functions. It doesn't include printf as that's quite platform specific. I don't remember where this code came from now - it might even have been from a book!
Anyway, it might be enough to get you started.
http://pastebin.com/C8yhHi4E
Anyway, it might be enough to get you started.
http://pastebin.com/C8yhHi4E