Documentation‎ > ‎

Libraries




Simple Libraries

Parallax Education spent a great amount of time/effort making the Simple Libraries found in the SimpleIDE package. The main reason for Simple Libraries is for supporting the Propeller-C Learning System. Simple Libraries are designed to fit in the memory footprint of the Propeller chip, and have very good documentation.

For more on Simple Libraries, visit Learn Propeller C

Traditional standard C libraries are also available, and are presented below.

Propeller Library

The Propeller Library gives programmers access to Propeller hardware functions. 

Propeller Library API "propeller.h"

COG Library API "cog.h"



COG Device Library

COG devices are Propeller COG programs that emulate protocols or hardware.

I2C
The I2C library is part of the Propeller-GCC library and is used for ECOG programming.

FDS
The FDS library (Full Duplex Serial) can be used for serial IO in addition to the SimpleSerial console.

Other COG devices are being written during the Propeller-GCC Beta phase.


Stdio Devices Library

The stdio library in Propeller GCC is just one way to use IO devices. It is possible to use custom devices with Propeller that have a smaller memory footprint for simple IO. If lots of console or other IO is expected, the stdio devices may be a smaller alternative.

Propeller-GCC stdio methodology is detailed here:


Library APIs for setting up custom devices:


Some built-in console devices


Standard IO devices can be replaced with any driver that is written according to the driver API.
SSER is the default console IO device driver for stdin, stdout, and stderr.

Changing the default baud rate (115200bps) of the serial drivers requires using freopen.

/**
 * Main program function.
 */
void main(void)
{
  freopen("SSER:9600,31,30", "w", stdout);
  freopen("SSER:9600,31,30", "w", stderr);
  freopen("SSER:9600,31,30", "r", stdin);

  printf("Hello, World\n");
}



SSER
This names the Simple Serial default stdio console device and is used if there is no driver list.

FDS
This names the Full Duplex Serial stdio console device and can replace the SSER driver by defining a driver list like as:

/**
 * @file file.c
 * This is the main file program start point.
 */
#include <stdio.h>
#include <propeller.h>

extern _Driver _FullDuplexSerialDriver;

/* This is a list of all drivers we can use in the
 * program. The default _InitIO function opens stdin,
 * stdout, and stderr based on the first driver in
 * the list (the full duplex serial driver in this case).
 */
_Driver *_driverlist[] = {
  &_FullDuplexSerialDriver,
  NULL
};


NUL
The null driver can be used as a place-holder for the standard IO (stdin, stdout, stderr) driver instead of SSER and FDS. This allows us to install a stdio file driver for example without using the serial console.

/**
 * @file file.c
 * This is the main file program start point.
 */
#include <stdio.h>
#include <propeller.h>

extern _Driver _NullDriver;
extern _Driver _FileDriver;

/* This is a list of all drivers we can use in the
 * program. The default _InitIO function opens stdin,
 * stdout, and stderr based on the first driver in
 * the list (the null driver in this case).
 */
_Driver *_driverlist[] = {
  &_NullDriver,
  &_FileDriver,  // file driver must always be last on the list before NULL
  NULL
};


Console and File system driver initialization


Propeller GCC and propeller-load can automatically configure the console and file system based on parameters in the board configuration file. The SD card pins are defined in the board configuration file. The propeller-load start-up sequence does the mounting for you. Below is a minimal example for opening a file. An example board configuration file follows.

/**
 * @file file.c
 * This is the main file program start point.
 */
#include <stdio.h>
#include <propeller.h>

extern _Driver _SimpleSerialDriver;
extern _Driver _FileDriver;

/* This is a list of all drivers we can use in the
 * program. The default _InitIO function opens stdin,
 * stdout, and stderr based on the first driver in
 * the list (the serial driver, for us)
 */
_Driver *_driverlist[] = {
  &_SimpleSerialDriver,
  &_FileDriver,
  NULL
};

/**
 * Main program function.
 */
void main(void)
{
    char name[20];
    FILE *fp1;

    waitcnt(CLKFREQ+CNT); // pause for terminal to open

    sprintf(name,"Test"); // test file name
    printf("Opening file '%s'.\n", name);

    if((fp1=fopen(name,"w+"))==0) {
        printf("Can't open file %s.\n",name);
    }
    else {
        printf("File was opened.\n");
        fclose(fp1);
    }
    while(1);
}

Example board configuration file.

# ppusb.cfg
# IDE:SDXMMC
    clkfreq: 80000000
    clkmode: XTAL1+PLL16X
    baudrate: 115200
    rxpin: 31
    txpin: 30
    cache-driver: eeprom_cache.dat
    cache-size: 8K
    cache-param1: 0
    cache-param2: 0
    eeprom-first: TRUE
    sd-driver: sd_driver.dat
    sdspi-do: 0
    sdspi-clk: 1
    sdspi-di: 2
    sdspi-cs: 3



Standard C Library

Propeller GCC supports these libraries defined by ANSI C and the international standard ISO/IEC 9899 ("the standard"). Propeller-GCC library code is neither based on GNU libraries nor the Newlib library package because those libraries are simply too big for Propeller HUB memory. Library code is derived from BSD and public domain sources.

Links to library man pages are provided here for programming convenience. The cplusplus.com site is a very good reference. All the links below point to pages found here: http://www.cplusplus.com/reference/.


Diagnostics <assert.h>


Complex <complex.h>


Character types <ctype.h>


Errors <errno.h>

Not all errno defines above are supported in Propeller-GCC. The standard only requires a few errno types, i.e. EDOM, EILSEQ, ERANGE, and errno. Propeller-GCC supports these errno macros.


Floating-point environment <fenv.h>


Floating types <float.h>


Alternative spellings <iso646.h>


Sizes of integer types <limits.h>


Format conversion of integer types <inttypes.h>


Localization <locale.h>


Mathematics <math.h>


Nonlocal jumps <setjmp.h>


Signal handling <signal.h>


Variable arguments <stdarg.h>


Boolean type and values <stdbool.h>


Common definitions <stddef.h>


Integer types <stdint.h>


Input/output <stdio.h>

Please see Stdio Devices Library above for information on setting up standard IO devices.


General utilities <stdlib.h>


String handling <string.h>


Type-generic math <tgmath.h>


Date and time <time.h>


Extended multibyte and wide-character utilities <wchar.h>


Wide-character classification and mapping utilities <wctype.h>