syscon.h 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#ifndef __SYSCON_H
#define __SYSCON_H

#include <inttypes.h>

#include "board.h"
#include <hw/wrc_syscon_regs.h>

struct SYSCON_WB
{
  uint32_t RSTR;  /*Syscon Reset Register*/  
  uint32_t GPSR;  /*GPIO Set/Readback Register*/
  uint32_t GPCR;  /*GPIO Clear Register*/
  uint32_t HWFR;  /*Hardware Feature Register*/
  uint32_t TCR;   /*Timer Control Register*/
  uint32_t TVR;   /*Timer Counter Value Register*/
};

/*GPIO pins*/
#define GPIO_LED_LINK SYSC_GPSR_LED_LINK
#define GPIO_LED_STAT SYSC_GPSR_LED_STAT
#define GPIO_SCL      SYSC_GPSR_FMC_SCL
#define GPIO_SDA      SYSC_GPSR_FMC_SDA
#define GPIO_BTN1     SYSC_GPSR_BTN1
#define GPIO_BTN2     SYSC_GPSR_BTN2

void timer_init(uint32_t enable);
uint32_t timer_get_tics();
void timer_delay(uint32_t how_long);

static volatile struct SYSCON_WB *syscon = (volatile struct SYSCON_WB *) BASE_SYSCON;

/****************************
 *        GPIO
 ***************************/
static inline void gpio_out(int pin, int val)
{
  if(val)
    syscon->GPSR = pin;
  else
    syscon->GPCR = pin;
}

static inline int gpio_in(int pin)
{
  return syscon->GPSR & pin ? 1: 0;
}
        
#endif