#include <stdint.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <hw/inout.h>
#include <time.h>
#include <fcntl.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#include <sys/mman.h>

#include <forksafe_mutex.h>
#include <pthread.h>
#include <threads.h>

#define IMX_GPIO0_BASE                         0x5D080000
#define IMX_GPIO1_BASE                         0x5D090000
#define IMX_GPIO2_BASE                         0x5D0A0000
#define IMX_GPIO3_BASE                         0x5D0B0000
#define IMX_GPIO4_BASE                         0x5D0C0000
#define IMX_GPIO5_BASE                         0x5D0D0000
#define IMX_GPIO6_BASE                         0x5D0E0000
#define IMX_GPIO7_BASE                         0x5D0F0000

#define IMX_GPIO_DR            0x0U
#define IMX_GPIO_GDIR          0x4U
#define IMX_GPIO_PSR           0x8U


/*timer regisger */
#define IMX_GPT0_BASE    	0x5D140000
#define IMX_GPT_SIZE     	0x10000
#define IMX_GPT0_IRQ     	112
#define GPT_CR              0x00U
#define GPT_PR              0x04U
#define GPT_SR              0x08U
#define GPT_IR              0x0cU
#define GPT_OCR1            0x10U
#define GPT_CNT             0x24U

#define OFF    0
#define GREEN  1
#define RED    2
#define YELLOW 3

extern char drv_vsr[4];

int imx8_gpio_init(void);
int imx8_input_collect(int channel);
int imx8_output(int channel, int level);
int imx8_gpio_release(void);
int imx8_led_REA_REB(int light);
int imx8_led_R_E(int light);
int imx8_led_M_S(int light);

unsigned int imx8_read_cpuid(void);
int imx8_dcdc_1_ctrl(int level);
int imx8_dcdc_2_ctrl(int level);
unsigned int imx8_Safe_gate_overvoltage_state_1(void);
unsigned int imx8_Safe_gate_undervoltage_state_1(void);
unsigned int imx8_Safe_gate_overvoltage_state_2(void);
unsigned int imx8_Safe_gate_undervoltage_state_2(void);
unsigned int imx8_ethernet_switch_state_1_1(void);
unsigned int imx8_ethernet_switch_state_1_2(void);
unsigned int imx8_ethernet_switch_state_2_1(void);
unsigned int imx8_ethernet_switch_state_2_2(void);
unsigned int imx8_24V_voltage_state(void);
unsigned int imx8_5V_overvoltage_state(void);
unsigned int imx8_5V_undervoltage_state(void);
unsigned char imx8_read_boardID(void);
int imx8_switch_button(void);
int imx8_safty_ethernet_off(void);



int imx8_create_timer_pthread_25(void);
int imx8_create_timer_pthread(void);
const struct sigevent *handler_25 (void *not_used, int id);
const struct sigevent *handler (void *not_used, int id);
void* timer_25( void * arg);
void* timer( void * arg);
