gpio-util.c

00001 
00002 #include <mc1322x.h>
00003 #include <board.h>
00004 
00005 #include "gpio-util.h"
00006 
00007 void gpio_select_function(uint8_t gpio, uint8_t func) {
00008         uint32_t mask = 3;
00009         uint8_t major, minor, shift;
00010         volatile uint32_t *base = GPIO_FUNC_SEL0;
00011         uint32_t value;
00012         major = gpio >> 4;
00013         minor = gpio & 0xF;
00014         shift = 2 * minor;
00015 
00016         value = base[major];
00017         value &= ~(mask << shift);
00018         value |= (func << shift);
00019         base[major] = value;
00020 }
00021 
00022 void gpio_reg_set(volatile uint32_t* reg, uint8_t bit) {
00023         uint8_t major, minor;
00024         major = bit / 32;
00025         minor = bit % 32;
00026         *(reg + major) |= (1UL << minor);
00027 }
00028 
00029 void gpio_reg_clear(volatile uint32_t* reg, uint8_t bit) {
00030         uint8_t major, minor;
00031         major = bit / 32;
00032         minor = bit % 32;
00033         *(reg + major) &= ~(1UL << minor);
00034 }
00035 
00036 void gpio_set_pad_dir(uint8_t gpio, uint8_t dir) {
00037         uint8_t major, minor;
00038         major = gpio / 32;
00039         minor = gpio % 32;
00040         if (dir) gpio_reg_set(GPIO_PAD_DIR0 + major, minor);
00041         else     gpio_reg_clear(GPIO_PAD_DIR0 + major, minor);
00042 }
00043 
00044 void gpio_set(uint8_t gpio) {
00045         uint8_t major, minor;
00046         major = gpio / 32;
00047         minor = gpio % 32;
00048         *(GPIO_DATA_SET0 + major) = (1UL << minor);
00049 }
00050 
00051 void gpio_reset(uint8_t gpio) {
00052         uint8_t major, minor;
00053         major = gpio / 32;
00054         minor = gpio % 32;
00055         *(GPIO_DATA_RESET0 + major) = (1UL << minor);
00056 }
00057 
00058 bool gpio_read(uint8_t gpio) {
00059         uint8_t major, minor;
00060         major = gpio / 32;
00061         minor = gpio % 32;
00062         return (*(GPIO_DATA0 + major) >> minor) & 1;
00063 }

Generated on Mon Apr 11 14:23:38 2011 for Contiki 2.5 by  doxygen 1.6.1