TS-7600 NBUS example

From Technologic Systems Manuals
/* When compiling use the following gcc command:
 * gcc -oexample example.c nbus.c -mcpu=arm9
 *
 * nbus.c and nbus.h must be in the same folder where the gcc command is being run from
 */
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "nbus.h"

int main (int argc, char **argv)
{
	uint16_t val;
	int i;
	nbuslock();

	/* Set DIO 7 low
	 * Set output value to 0
         */
	val = nbuspeek16(0xa);
	nbuspoke16(0xa, val & ~(1 << 7));
	// Set dio 7 direction to output
	val = nbuspeek16(0xc);
	nbuspoke16(0xc, val | (1 << 7));

	/* Set DIO 7 high
	 * DDR is already set to output, so
	 * set output value
         */
	val = nbuspeek16(0xa);

	nbuspoke16(0xa, val | (1 << 7));

	// Toggle Red LED 10 times
	val = nbuspeek16(0x2);

	/* The NBUS lock should be held as little as possible
	 * since other peripherals will need access.  When 
	 * going into an operation like a sleep, a flush, or
	 * any other syscal that will stall the system without
	 * actually needing the lock, it should be released first.
         */
        nbusunlock();
        printf("Starting loop\n");
        nbuslock();

	for(i = 0; i < 10; i++) {
		if(i % 2) {
			nbuspoke16(0x2, val & ~(1 << 14));
		} else {
			nbuspoke16(0x2, val | ( 1 << 14));
		}

                /* nbuspreempt() can be used to check if there
                 * are other processes waiting to use the bus. If there
                 * are, then the bus is unlocked, given to other processes
                 * and then the bus is re-locked.  When nbuspreempt()
                 * returns the calling process will have the lock again
                 */
		nbuspreempt();
	}
        nbusunlock();

	return 0;
}

Another NBUS example can be found in dio.c, this also requires the nbus.c and nbus.h files in order to compile.