mirror of
git://projects.qi-hardware.com/sie-ceimtun.git
synced 2025-04-21 12:27:27 +03:00
Uploaded the first Beta to test in the development group
This commit is contained in:
76
Examples/Beta1/src/ADCw.cpp
Normal file
76
Examples/Beta1/src/ADCw.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "ADCw.h"
|
||||
|
||||
ADCw::ADCw()
|
||||
{
|
||||
BUFFER_OFFSET = 8; //Ignore first 16 samples
|
||||
ADC_SPI_CLKDIV=ADC_SPI_CLKDIV_MAX; //Set clock to minimum speed
|
||||
BUFFER_LEN=16;
|
||||
MUX_CHANNELS =0;
|
||||
|
||||
ADCBuffer = jz_adc_init();
|
||||
|
||||
//Clean FPGA RAM memory
|
||||
for (int i = 0; i < 512; i++) //RAMB16_s9_s9 has 2048 bytes 8-bit
|
||||
{
|
||||
ADCBuffer[i] = 0x00000000; //Clean 4 register by cicle
|
||||
}
|
||||
|
||||
adcConfig(ADC_CMD_SET_SPI_CLKDIV);
|
||||
adcConfig(ADC_CMD_SET_FAST_CONV);
|
||||
printf("\nADC in Fast Convertion Mode (10us) and Fs=9.8KHz (Min)\n");
|
||||
}
|
||||
|
||||
void ADCw::testADC()
|
||||
{
|
||||
/******************************* TEST 1 ***********************************/
|
||||
printf("\nINIT TEST1: Autoselft {(Vref+) - (Vref-)}/2 -> Return 0x0200 \n");
|
||||
adcConfig(ADC_CMD_SET_AUTOSELFT_1);
|
||||
adcConfig(ADC_CMD_READ_AUTOSELFT_1);
|
||||
for(int i=BUFFER_OFFSET; i< BUFFER_LEN/2+BUFFER_OFFSET; i++)
|
||||
printf("[%08X]", ADCBuffer[i]);
|
||||
fflush (stdout);
|
||||
|
||||
/******************************* TEST 2 ***********************************/
|
||||
printf("\n\nINIT TEST2: Autoselft (Vref-) -> Return 0x0000 \n");
|
||||
adcConfig(ADC_CMD_SET_AUTOSELFT_2);
|
||||
adcConfig(ADC_CMD_READ_AUTOSELFT_2);
|
||||
for(int i=BUFFER_OFFSET; i< BUFFER_LEN/2+BUFFER_OFFSET; i++)
|
||||
printf("[%08X]", ADCBuffer[i]);
|
||||
fflush (stdout);
|
||||
|
||||
/******************************* TEST 3 ***********************************/
|
||||
printf("\n\nINIT TEST3: Autoselft (Vref+) -> Return 0x03FF \n");
|
||||
adcConfig(ADC_CMD_SET_AUTOSELFT_3);
|
||||
adcConfig(ADC_CMD_READ_AUTOSELFT_3);
|
||||
for(int i=BUFFER_OFFSET; i< BUFFER_LEN/2+BUFFER_OFFSET; i++)
|
||||
printf("[%08X]", ADCBuffer[i]);
|
||||
fflush (stdout);
|
||||
|
||||
printf("\n\nTESTS complete\n");
|
||||
}
|
||||
|
||||
void ADCw::powerDownADC()
|
||||
{
|
||||
adcConfig(ADC_CMD_SET_POWER_DOWN);
|
||||
printf("\nADC in Power Down Mode \n");
|
||||
}
|
||||
|
||||
JZ_REG* ADCw::takeSamplesADC(int CHANNEL)
|
||||
{
|
||||
adcConfig(ADC_CMD_SET_CHANNEL0+CHANNEL);
|
||||
adcConfig(ADC_CMD_READ_CHANNEL0+CHANNEL);
|
||||
return (JZ_REG*)(ADCBuffer+BUFFER_OFFSET);
|
||||
}
|
||||
|
||||
void ADCw::adcConfig(uchar CMD)
|
||||
{
|
||||
ADCBuffer[0] = (((MUX_CHANNELS<<6) + CMD)<<24) + \
|
||||
((BUFFER_LEN+BUFFER_OFFSET*2) << 8) + \
|
||||
(ADC_SPI_CLKDIV);
|
||||
while(adcCheckBufferFull()) usleep (10);
|
||||
}
|
||||
|
||||
int ADCw::adcCheckBufferFull()
|
||||
{
|
||||
return ADCBuffer[0]&0x20000000;
|
||||
}
|
||||
31
Examples/Beta1/src/ADCw.h
Normal file
31
Examples/Beta1/src/ADCw.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef ADCW_H
|
||||
#define ADCW_H
|
||||
|
||||
#include "jz_adc_peripheral.c"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
class ADCw
|
||||
{
|
||||
public:
|
||||
ADCw();
|
||||
~ADCw(){}
|
||||
|
||||
void testADC();
|
||||
void powerDownADC();
|
||||
JZ_REG * takeSamplesADC(int CHANNEL);
|
||||
void setClockDiv(uchar value){ ADC_SPI_CLKDIV = value;}
|
||||
void setBufferLen(int value){ BUFFER_LEN = value;}
|
||||
void setMuxChannels(uchar value){ MUX_CHANNELS = value;}
|
||||
private:
|
||||
void adcConfig(uchar CMD);
|
||||
int adcCheckBufferFull();
|
||||
|
||||
JZ_REG * ADCBuffer;
|
||||
uchar ADC_SPI_CLKDIV;
|
||||
int BUFFER_LEN;
|
||||
int BUFFER_OFFSET;
|
||||
uchar MUX_CHANNELS;
|
||||
};
|
||||
|
||||
#endif // ADCW_H
|
||||
33
Examples/Beta1/src/Makefile
Normal file
33
Examples/Beta1/src/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
CC = mipsel-openwrt-linux-gcc
|
||||
|
||||
all: UNROBOT_pwm_test
|
||||
|
||||
DEBUG = -O3 -g0
|
||||
|
||||
COMMON_SOURCES = UNROBOT_pwm_test.c jz47xx_gpio.c jz47xx_mmap.c
|
||||
|
||||
H_SOURCES = jz47xx_gpio.h jz47xx_mmap.h
|
||||
|
||||
INCLUDE = -I.
|
||||
|
||||
WARNINGS= -Wcast-align -Wpacked -Wpadded -Wall
|
||||
|
||||
CCFLAGS = ${INCLUDE} ${DEBUG} ${WARNINGS}
|
||||
|
||||
LDFLAGS =
|
||||
|
||||
COMMON_OBJECTS = $(COMMON_SOURCES:.cpp=.o)
|
||||
|
||||
|
||||
ADCw : $(COMMON_OBJECTS) ram_test.o
|
||||
$(CC) $(LDFLAGS) $(COMMON_OBJECTS) ram_test.o -o ram_test
|
||||
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CCFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o ram_test ${EXEC} *~ ram_test
|
||||
|
||||
indent:
|
||||
indent -bad -bap -nbc -bl -nce -i2 --no-tabs --line-length120 $(COMMON_SOURCES) $(H_SOURCES)
|
||||
BIN
Examples/Beta1/src/UNROBOT_pwm_test
Normal file
BIN
Examples/Beta1/src/UNROBOT_pwm_test
Normal file
Binary file not shown.
80
Examples/Beta1/src/UNROBOT_pwm_test.c
Normal file
80
Examples/Beta1/src/UNROBOT_pwm_test.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jz47xx_gpio.c"
|
||||
#include "jz47xx_mmap.c"
|
||||
|
||||
#define CS2_PORT JZ_GPIO_PORT_B
|
||||
#define CS2_PIN 26
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
#ifdef DOUBLE
|
||||
set_fpu (0x27F); /* use double-precision rounding */
|
||||
#endif
|
||||
|
||||
int i;
|
||||
int pwm1=10; //PWM Led en SIE, entre 0 y 255
|
||||
int pwm2=255; //PWM Led fuera SIE, entre 0 y 255
|
||||
int dutycycle1; //PWM Led en SIE
|
||||
int dutycycle2; //PWM Led fuera SIE
|
||||
|
||||
JZ_PIO *pio;
|
||||
int *virt_addr;
|
||||
|
||||
// Set GPIOB26 as part of External Memory Controller
|
||||
pio = jz_gpio_map (CS2_PORT);
|
||||
jz_gpio_as_func (pio, CS2_PIN, 0);
|
||||
|
||||
virt_addr = (int *) jz_mmap (0x13010000) + 0x18;
|
||||
|
||||
printf ("\nIniciado: \nPrueba Beta Alpha3 UNROBOT \n");
|
||||
|
||||
if (*virt_addr != 0xFFF7700)
|
||||
{ // 0 WS, 8 bits
|
||||
*virt_addr = 0xFFF7700;
|
||||
printf ("Configuring CS2 8 bits \n");
|
||||
}
|
||||
else
|
||||
printf ("CS2, already configured\n");
|
||||
|
||||
virt_addr = (int *) jz_fpga_map (0x14000000);
|
||||
|
||||
dutycycle1=(int)((float)((100.0/255.0)*pwm1));
|
||||
dutycycle2=(int)((float)((100.0/255.0)*pwm2));
|
||||
|
||||
|
||||
|
||||
printf ("DUTY1:%d%% \n", dutycycle1);
|
||||
printf ("DUTY2:%d%% \n", dutycycle2);
|
||||
|
||||
printf ("Setting PWM1..\n");
|
||||
virt_addr[1024] = pwm1;
|
||||
|
||||
|
||||
printf ("Setting PWM2..\n");
|
||||
virt_addr[1536] = pwm2;
|
||||
virt_addr[1537] = pwm2;
|
||||
virt_addr[1535] = pwm2;
|
||||
|
||||
printf ("Writing In Memory1 the Dutycycles and pwm references from 0x100 to 0x103..\n");
|
||||
|
||||
virt_addr[512] = pwm1;
|
||||
virt_addr[513] = dutycycle1;
|
||||
virt_addr[514] = pwm2;
|
||||
virt_addr[515] = dutycycle2;
|
||||
|
||||
printf ("Reading from Memory1 the Dutycycles and pwm references..\n");
|
||||
|
||||
printf("1- PWM_REF:%d, Duty Cycle:%d%% \n", virt_addr[512], virt_addr[513]);
|
||||
printf("2- PWM_REF:%d, Duty Cycle:%d%% \n", virt_addr[514], virt_addr[515]);
|
||||
|
||||
printf("1- Encoder:%d\n", virt_addr[0]);
|
||||
printf("1- Encoder:%d\n", virt_addr[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
119
Examples/Beta1/src/jz47xx_gpio.c
Normal file
119
Examples/Beta1/src/jz47xx_gpio.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
JZ47xx GPIO at userspace
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
#include "jz47xx_mmap.h"
|
||||
|
||||
|
||||
#define JZ_GPIO_BASE 0x10010000
|
||||
|
||||
void
|
||||
jz_gpio_as_output (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_as_input (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_as_irq (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELS = (1 << (o));
|
||||
pio->PXDIRC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_set_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val)
|
||||
{
|
||||
if (val == 0)
|
||||
pio->PXDATC = (1 << (o));
|
||||
else
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
unsigned int
|
||||
jz_gpio_get_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
return (pio->PXPIN & (1 << o)) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func)
|
||||
{
|
||||
switch (func)
|
||||
{
|
||||
case 0:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 1:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELS = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGS = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
JZ_PIO *
|
||||
jz_gpio_map (int port)
|
||||
{
|
||||
JZ_PIO *pio;
|
||||
|
||||
pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE);
|
||||
pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100);
|
||||
|
||||
return pio;
|
||||
}
|
||||
110
Examples/Beta1/src/jz47xx_gpio.cpp
Normal file
110
Examples/Beta1/src/jz47xx_gpio.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
JZ47xx GPIO at userspace
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
#include "jz47xx_mmap.h"
|
||||
|
||||
|
||||
#define JZ_GPIO_BASE 0x10010000
|
||||
|
||||
void
|
||||
jz_gpio_as_output (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_as_input (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_set_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val)
|
||||
{
|
||||
if (val == 0)
|
||||
pio->PXDATC = (1 << (o));
|
||||
else
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
unsigned int
|
||||
jz_gpio_get_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
return (pio->PXPIN & (1 << o)) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func)
|
||||
{
|
||||
switch (func)
|
||||
{
|
||||
case 0:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 1:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELS = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGS = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
JZ_PIO *
|
||||
jz_gpio_map (int port)
|
||||
{
|
||||
JZ_PIO *pio;
|
||||
|
||||
pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE);
|
||||
pio = (JZ_PIO *) (pio + port * 0x100);
|
||||
|
||||
// pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100);
|
||||
|
||||
return pio;
|
||||
}
|
||||
84
Examples/Beta1/src/jz47xx_gpio.h
Normal file
84
Examples/Beta1/src/jz47xx_gpio.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
JZ47xx GPIO at userspace
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#ifndef __jz47xx_gpio_h__
|
||||
#define __jz47xx_gpio_h__
|
||||
|
||||
#define JZ_GPIO_PORT_A 0
|
||||
#define JZ_GPIO_PORT_B 1
|
||||
#define JZ_GPIO_PORT_C 2
|
||||
#define JZ_GPIO_PORT_D 3
|
||||
|
||||
typedef volatile unsigned int JZ_REG; /* Hardware register definition */
|
||||
|
||||
typedef struct _JZ_PIO
|
||||
{
|
||||
JZ_REG PXPIN; /* PIN Level Register */
|
||||
JZ_REG Reserved0;
|
||||
JZ_REG Reserved1;
|
||||
JZ_REG Reserved2;
|
||||
JZ_REG PXDAT; /* Port Data Register */
|
||||
JZ_REG PXDATS; /* Port Data Set Register */
|
||||
JZ_REG PXDATC; /* Port Data Clear Register */
|
||||
JZ_REG Reserved3;
|
||||
JZ_REG PXIM; /* Interrupt Mask Register */
|
||||
JZ_REG PXIMS; /* Interrupt Mask Set Reg */
|
||||
JZ_REG PXIMC; /* Interrupt Mask Clear Reg */
|
||||
JZ_REG Reserved4;
|
||||
JZ_REG PXPE; /* Pull Enable Register */
|
||||
JZ_REG PXPES; /* Pull Enable Set Reg. */
|
||||
JZ_REG PXPEC; /* Pull Enable Clear Reg. */
|
||||
JZ_REG Reserved5;
|
||||
JZ_REG PXFUN; /* Function Register */
|
||||
JZ_REG PXFUNS; /* Function Set Register */
|
||||
JZ_REG PXFUNC; /* Function Clear Register */
|
||||
JZ_REG Reserved6;
|
||||
JZ_REG PXSEL; /* Select Register */
|
||||
JZ_REG PXSELS; /* Select Set Register */
|
||||
JZ_REG PXSELC; /* Select Clear Register */
|
||||
JZ_REG Reserved7;
|
||||
JZ_REG PXDIR; /* Direction Register */
|
||||
JZ_REG PXDIRS; /* Direction Set Register */
|
||||
JZ_REG PXDIRC; /* Direction Clear Register */
|
||||
JZ_REG Reserved8;
|
||||
JZ_REG PXTRG; /* Trigger Register */
|
||||
JZ_REG PXTRGS; /* Trigger Set Register */
|
||||
JZ_REG PXTRGC; /* Trigger Set Register */
|
||||
JZ_REG Reserved9;
|
||||
JZ_REG PXFLG; /* Port Flag Register */
|
||||
JZ_REG PXFLGC; /* Port Flag clear Register */
|
||||
} JZ_PIO, *PJZ_PIO;
|
||||
|
||||
void jz_gpio_as_output (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_as_input (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_set_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val);
|
||||
|
||||
unsigned int jz_gpio_get_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
int jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func);
|
||||
|
||||
JZ_PIO *jz_gpio_map (int port);
|
||||
|
||||
#endif
|
||||
64
Examples/Beta1/src/jz47xx_mmap.c
Normal file
64
Examples/Beta1/src/jz47xx_mmap.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* JZ47xx GPIO lines
|
||||
*
|
||||
* Written 2010 by Andres Calderon andres.calderon@emqbit.com
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_mmap.h"
|
||||
|
||||
|
||||
void *
|
||||
jz_mmap (off_t address)
|
||||
{
|
||||
int fd;
|
||||
|
||||
void *pio;
|
||||
|
||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot open /dev/mem.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pio = (void *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
|
||||
|
||||
if (pio == (void *) -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot mmap.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pio;
|
||||
}
|
||||
|
||||
void *
|
||||
jz_fpga_map (off_t address)
|
||||
{
|
||||
int fd;
|
||||
|
||||
void *fpga;
|
||||
|
||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot open /dev/mem.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fpga = (void *) mmap (0, FPGA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
|
||||
|
||||
if (fpga == (void *) -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot mmap.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return fpga;
|
||||
}
|
||||
|
||||
17
Examples/Beta1/src/jz47xx_mmap.h
Normal file
17
Examples/Beta1/src/jz47xx_mmap.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* JZ47xx GPIO lines
|
||||
*
|
||||
* Written 2010 by Andres Calderon andres.calderon@emqbit.com
|
||||
*/
|
||||
|
||||
#ifndef __jz47xx_mmap_h__
|
||||
#define __jz47xx_mmap_h__
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define FPGA_SIZE (1 << 15)
|
||||
|
||||
void *jz_mmap (off_t address);
|
||||
void *jz_fpga_map (off_t address);
|
||||
|
||||
#endif
|
||||
47
Examples/Beta1/src/jz_adc_peripheral.c
Normal file
47
Examples/Beta1/src/jz_adc_peripheral.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ADC Peripheral.c
|
||||
|
||||
Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
|
||||
Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz_adc_peripheral.h"
|
||||
|
||||
JZ_REG *
|
||||
jz_adc_init()
|
||||
{
|
||||
JZ_PIO *pio;
|
||||
JZ_REG *virt_addr;
|
||||
|
||||
pio = jz_gpio_map (CS2_PORT);
|
||||
jz_gpio_as_func (pio, CS2_PIN, 0);
|
||||
|
||||
virt_addr = (JZ_REG *) (jz_mmap(0x13010000) + 0x18);
|
||||
|
||||
if (*virt_addr != 0x0FFF7700)
|
||||
{
|
||||
*virt_addr = 0x0FFF7700;
|
||||
printf ("ADC: Configuring CS2 8 bits and 0 WS: %08X\n", *virt_addr);
|
||||
}
|
||||
else
|
||||
printf ("ADC: CS2, already configured: %08X\n", *virt_addr);
|
||||
|
||||
virt_addr = (JZ_REG *) jz_mmap (0x14000000);
|
||||
|
||||
return virt_addr;
|
||||
}
|
||||
81
Examples/Beta1/src/jz_adc_peripheral.h
Normal file
81
Examples/Beta1/src/jz_adc_peripheral.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/* ADC Peripheral.h
|
||||
|
||||
Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
|
||||
Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#ifndef __adc_peripheral_h__
|
||||
#define __adc_peripheral_h__
|
||||
|
||||
#include "jz47xx_mmap.c"
|
||||
#include "jz47xx_gpio.c"
|
||||
|
||||
#define ADC_CMD_NONE 0x00 /* Nothing to do */
|
||||
#define ADC_CMD_SET_SPI_CLKDIV 0x00 /* Set clock divider for ADC sclk */
|
||||
#define ADC_CMD_SET_BUFFER_SIZE 0x00 /* Set clock divider for ADC sclk */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL0 0x30 /* Set channel 0 */
|
||||
#define ADC_CMD_READ_CHANNEL0 0x20 /* Read channel 0 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL1 0x31 /* Set channel 1 */
|
||||
#define ADC_CMD_READ_CHANNEL1 0x21 /* Read channel 1 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL2 0x32 /* Set channel 2 */
|
||||
#define ADC_CMD_READ_CHANNEL2 0x22 /* Read channel 2 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL3 0x33 /* Set channel 3 */
|
||||
#define ADC_CMD_READ_CHANNEL3 0x23 /* Read channel 3 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL4 0x34 /* Set channel 4 */
|
||||
#define ADC_CMD_READ_CHANNEL4 0x24 /* Read channel 4 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL5 0x35 /* Set channel 5 */
|
||||
#define ADC_CMD_READ_CHANNEL5 0x25 /* Read channel 5 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL6 0x36 /* Set channel 6 */
|
||||
#define ADC_CMD_READ_CHANNEL6 0x26 /* Read channel 6 */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL7 0x37 /* Set channel 7 */
|
||||
#define ADC_CMD_READ_CHANNEL7 0x27 /* Read channel 8 */
|
||||
|
||||
#define ADC_CMD_SET_POWER_DOWN 0X38 /* Set ADC power down mode (1uA) */
|
||||
|
||||
#define ADC_CMD_SET_FAST_CONV 0X39 /* Initialize ADC Fast Convertion(<10us)*/
|
||||
|
||||
#define ADC_CMD_SET_LOW_CONV 0X3A /* Initialize ADC Slow Convertion(<40us)*/
|
||||
|
||||
#define ADC_CMD_SET_AUTOSELFT_1 0x3B /* Set Autoselft ADC {(Vref+)-(Vref-)}/2*/
|
||||
#define ADC_CMD_READ_AUTOSELFT_1 0x2B /* Read Autoselft ADC 1 (0x0200) */
|
||||
|
||||
#define ADC_CMD_SET_AUTOSELFT_2 0x3C /* Set Autoselft ADC (Vref-) */
|
||||
#define ADC_CMD_READ_AUTOSELFT_2 0x2C /* Read Autoselft ADC 2 (0x0000) */
|
||||
|
||||
#define ADC_CMD_SET_AUTOSELFT_3 0x3D /* Set Autoselft ADC (Vref+) */
|
||||
#define ADC_CMD_READ_AUTOSELFT_3 0x2D /* Read Autoselft ADC 3 (0x03FF) */
|
||||
|
||||
#define ADC_SPI_CLKDIV_MIN 0x08 /* 50/(2*9) -> 2.78MHz (MAX=2.8MHz) */
|
||||
#define ADC_SPI_CLKDIV_MAX 0xFF /* 50/(2*256) -> 97.65KHz */
|
||||
|
||||
#define ADC_MAX_BUFFER 0x3FE/* 1022 reads/commands */
|
||||
|
||||
#define CS2_PORT JZ_GPIO_PORT_B
|
||||
#define CS2_PIN 26
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
JZ_REG *jz_adc_init();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user