65 lines
2.1 KiB
C
65 lines
2.1 KiB
C
|
//
|
||
|
// Gertboard test suite
|
||
|
//
|
||
|
// main header file
|
||
|
//
|
||
|
// Copyright (C) Gert Jan van Loo & Myra VanInwegen 2012
|
||
|
// No rights reserved
|
||
|
// You may treat this program as if it was in the public domain
|
||
|
//
|
||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||
|
//
|
||
|
// Try to strike a balance between keep code simple for
|
||
|
// novice programmers but still have reasonable quality code
|
||
|
// (e.g. do not use #ifndef big_demo_h....)
|
||
|
//
|
||
|
|
||
|
|
||
|
#include <stdio.h>
|
||
|
|
||
|
// I/O access
|
||
|
extern volatile unsigned *gpio;
|
||
|
extern volatile unsigned *pwm;
|
||
|
extern volatile unsigned *clk;
|
||
|
extern volatile unsigned *spi0;
|
||
|
extern volatile unsigned *uart;
|
||
|
|
||
|
void short_wait();
|
||
|
void long_wait(int v);
|
||
|
|
||
|
void setup_io();
|
||
|
void restore_io();
|
||
|
void make_binary_string(int, int, char *);
|
||
|
|
||
|
// GPIO setup macros.
|
||
|
// Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
|
||
|
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
|
||
|
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
|
||
|
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
|
||
|
|
||
|
#define GPIO_SET0 *(gpio+7) // Set GPIO high bits 0-31
|
||
|
#define GPIO_CLR0 *(gpio+10) // Set GPIO low bits 0-31
|
||
|
|
||
|
#define GPIO_IN0 *(gpio+13) // Reads GPIO input bits 0-31
|
||
|
|
||
|
#define GPIO_PULL *(gpio+37) // Pull up/pull down
|
||
|
#define GPIO_PULLCLK0 *(gpio+38) // Pull up/pull down clock
|
||
|
|
||
|
|
||
|
//
|
||
|
// UART 0
|
||
|
//
|
||
|
|
||
|
#define UART0_BAUD_HI *(uart+9)
|
||
|
#define UART0_BAUD_LO *(uart+10)
|