Merge branch 'GPIO_V2_IOCTL' into development
This commit is contained in:
@@ -303,35 +303,44 @@ void abReadall (int model, int rev)
|
||||
* Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's
|
||||
*********************************************************************************
|
||||
*/
|
||||
const char piModelNamesShort[PI_MODELS_MAX][11] =
|
||||
{
|
||||
"---Pi A---", // 0
|
||||
"---Pi B---", // 1
|
||||
"---Pi A+--", // 2
|
||||
"---Pi B+--", // 3
|
||||
"---Pi 2---", // 4
|
||||
"---Alpha--", // 5
|
||||
"----CM----", // 6
|
||||
"", // 07
|
||||
"---Pi 3B--", // 8
|
||||
"-Pi Zero--", // 9
|
||||
"---CM3----", // 10
|
||||
"", // 11
|
||||
"-Pi ZeroW-", // 12
|
||||
"---Pi 3B+-", // 13
|
||||
"---Pi 3A+-", // 14
|
||||
"", // 15
|
||||
"---CM3+---", // 16
|
||||
"---Pi 4B--", // 17
|
||||
"Pi Zero 2W", // 18
|
||||
"--Pi 400--", // 19
|
||||
"---CM4----", // 20
|
||||
"---CM4S---", // 21
|
||||
"", // 22
|
||||
"---Pi 5---", // 23
|
||||
"---CM5----", // 24
|
||||
"--Pi 500--", // 25
|
||||
"---CM5L---", // 24
|
||||
} ;
|
||||
|
||||
static void plus2header (int model)
|
||||
{
|
||||
/**/ if (model == PI_MODEL_AP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_BP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_ZERO)
|
||||
printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_ZERO_W)
|
||||
printf (" +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_ZERO_2W)
|
||||
printf (" +-----+-----+---------+------+---+Pi Zero 2W+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_2)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_3B)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_3BP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_3AP)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 3A+-+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_4B)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_400)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 400-+---+------+---------+-----+-----+\n") ;
|
||||
else if (model == PI_MODEL_5)
|
||||
printf (" +-----+-----+---------+------+---+---Pi 5---+---+------+---------+-----+-----+\n") ;
|
||||
else
|
||||
printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
|
||||
if (model<PI_MODELS_MAX && piModelNamesShort[model][0]!='\0') {
|
||||
printf (" +-----+-----+---------+------+---+%s+---+------+---------+-----+-----+\n", piModelNamesShort[model]);
|
||||
} else {
|
||||
printf (" +-----+-----+---------+------+---+---- ? ---+---+------+---------+-----+-----+\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -377,11 +386,11 @@ void doReadall (void)
|
||||
(model == PI_MODEL_2) ||
|
||||
(model == PI_MODEL_3AP) ||
|
||||
(model == PI_MODEL_3B) || (model == PI_MODEL_3BP) ||
|
||||
(model == PI_MODEL_4B) || (model == PI_MODEL_400) || (model == PI_MODEL_CM4) ||
|
||||
(model == PI_MODEL_4B) || (model == PI_MODEL_400) || (model == PI_MODEL_CM4) || (model == PI_MODEL_CM4S) ||
|
||||
(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W) || (model == PI_MODEL_ZERO_2W) ||
|
||||
(model == PI_MODEL_5) )
|
||||
(model == PI_MODEL_5) || (model == PI_MODEL_500) || (model == PI_MODEL_CM5) || (model == PI_MODEL_CM5L) )
|
||||
piPlusReadall (model) ;
|
||||
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P) )
|
||||
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P) ) //could be Compute Module 1/3/3+ IO Board 120 GPIO pins, legacy code
|
||||
allReadall () ;
|
||||
else
|
||||
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
||||
|
||||
@@ -3,7 +3,7 @@ CFLAGS = -Wall
|
||||
LDFLAGS =
|
||||
|
||||
# Need BCM19 <-> BCM26, +PWM: BCM12 <-> BCM13, BCM18 <-> BCM17 connected (1kOhm)
|
||||
tests = wiringpi_test0_version wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test8_pwm wiringpi_test9_pwm
|
||||
tests = wiringpi_test0_version wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_bench wiringpi_test8_pwm wiringpi_test9_pwm
|
||||
|
||||
# Need XO hardware
|
||||
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574 wiringpi_test8_pwm wiringpi_test9_pwm
|
||||
@@ -13,6 +13,9 @@ pifacetests = wiringpi_piface_test1 wiringpi_test8_pwm wiringpi_test9_pwm
|
||||
|
||||
all: $(tests) $(xotests) $(pifacetests)
|
||||
|
||||
wiringpi_test0_version:
|
||||
${CC} ${CFLAGS} wiringpi_test0_version.c -o wiringpi_test0_version -lwiringPi
|
||||
|
||||
wiringpi_test1_sysfs:
|
||||
${CC} ${CFLAGS} wiringpi_test1_sysfs.c -o wiringpi_test1_sysfs -lwiringPi
|
||||
|
||||
@@ -31,8 +34,8 @@ wiringpi_test5_default:
|
||||
wiringpi_test6_isr:
|
||||
${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi
|
||||
|
||||
wiringpi_test0_version:
|
||||
${CC} ${CFLAGS} wiringpi_test0_version.c -o wiringpi_test0_version -lwiringPi
|
||||
wiringpi_test7_bench:
|
||||
${CC} ${CFLAGS} wiringpi_test7_bench.c -o wiringpi_test7_bench -lwiringPi
|
||||
|
||||
wiringpi_test8_pwm:
|
||||
${CC} ${CFLAGS} wiringpi_test8_pwm.c -o wiringpi_test8_pwm -lwiringPi
|
||||
|
||||
@@ -30,7 +30,7 @@ void SetAndCheckMode(int pin, int mode) {
|
||||
case PM_OFF:
|
||||
pinMode(pin, PM_OFF);
|
||||
AltGpio = getPinModeAlt(pin);
|
||||
CheckSame("Pin mode off(input)", AltGpio, (PI_MODEL_5 == RaspberryPiModel) ? WPI_NONE : WPI_ALT_INPUT);
|
||||
CheckSame("Pin mode off(input)", AltGpio, (piRP1Model()) ? WPI_NONE : WPI_ALT_INPUT);
|
||||
break;
|
||||
default:
|
||||
pinMode(pin, mode);
|
||||
@@ -53,8 +53,8 @@ int main (void) {
|
||||
int rev, mem, maker, overVolted;
|
||||
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
|
||||
CheckNotSame("Model: ", RaspberryPiModel, -1);
|
||||
if (PI_MODEL_5 == RaspberryPiModel) {
|
||||
printf("Raspberry Pi 5 with RP1 found\n");
|
||||
if (piRP1Model()) {
|
||||
printf("Raspberry Pi with RP1 chip found\n");
|
||||
} else {
|
||||
printf("Raspberry Pi with BCM GPIO found (not Pi 5)\n");
|
||||
}
|
||||
@@ -66,7 +66,7 @@ int main (void) {
|
||||
|
||||
enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN;
|
||||
AltGpio = getPinModeAlt(23);
|
||||
CheckSame("Pin mode default", AltGpio, PI_MODEL_5 == RaspberryPiModel ? WPI_NONE : WPI_ALT_INPUT);
|
||||
CheckSame("Pin mode default", AltGpio, piRP1Model() ? WPI_NONE : WPI_ALT_INPUT);
|
||||
|
||||
SetAndCheckMode(GPIOIN, INPUT);
|
||||
SetAndCheckMode(GPIO, OUTPUT);
|
||||
|
||||
189
wiringPi/test/wiringpi_test7_bench.c
Normal file
189
wiringPi/test/wiringpi_test7_bench.c
Normal file
@@ -0,0 +1,189 @@
|
||||
// WiringPi test program: benchmark
|
||||
// Compile: gcc -Wall wiringpi_test7_bench.c -o wiringpi_test7_bench -lwiringPi
|
||||
|
||||
#include "wpi_test.h"
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
int ToggleValue = 240000000;
|
||||
float fExpectTimedigitalWrite = 0.1;
|
||||
float fExpectTimedigitalRead = 0.1;
|
||||
float fExpectTimepinMode = 0.1;
|
||||
float fWriteReadDelayFactor = 1.0;
|
||||
float fWriteReadFactor = 1.0;
|
||||
float fPi4ExpectTimedigitalWrite = 0.020;
|
||||
int GPIO = 19;
|
||||
int GPIOIN = 26;
|
||||
int RaspberryPiModel = -1;
|
||||
|
||||
|
||||
double ReportElapedTime(const char* msg, int multiop, const float fExpectTime, struct timeval t1, struct timeval t2) {
|
||||
double elapsedTime, fTimePerOperation, fFreq;
|
||||
|
||||
elapsedTime = (t2.tv_sec-t1.tv_sec)+(t2.tv_usec-t1.tv_usec)/1000000.0;
|
||||
fTimePerOperation = elapsedTime*1000000.0/ToggleValue/multiop;
|
||||
fFreq = 1.0f/(fTimePerOperation*2); //ToggleValue/elapsedTime/1000000.0;
|
||||
printf(" % 9d took %.3f s, Time per operation %.3f us (toggle Freq %.3f MHz) \n",
|
||||
ToggleValue, elapsedTime, fTimePerOperation, fFreq);
|
||||
CheckSameFloat(msg, fTimePerOperation, fExpectTime, fExpectTime*0.2f);
|
||||
|
||||
return fTimePerOperation;
|
||||
}
|
||||
|
||||
|
||||
int main (void) {
|
||||
struct timeval t1, t2;
|
||||
|
||||
if (wiringPiSetupGpio() == -1) {
|
||||
printf("wiringPiSetupGpio failed\n\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int rev, mem, maker, overVolted;
|
||||
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
|
||||
CheckNotSame("Model: ", RaspberryPiModel, -1);
|
||||
if (!piBoard40Pin()) {
|
||||
GPIO = 23;
|
||||
GPIOIN = 24;
|
||||
}
|
||||
|
||||
switch(RaspberryPiModel) {
|
||||
case PI_MODEL_A:
|
||||
case PI_MODEL_B: //ARM=800MHz
|
||||
case PI_MODEL_BP:
|
||||
case PI_MODEL_AP:
|
||||
case PI_MODEL_CM:
|
||||
fExpectTimedigitalWrite = 0.132; //us;
|
||||
fExpectTimedigitalRead = 0.171; //us
|
||||
fExpectTimepinMode = 0.334; //us
|
||||
break;
|
||||
case PI_MODEL_ZERO:
|
||||
case PI_MODEL_ZERO_W: //ARM=1000MHz
|
||||
fExpectTimedigitalWrite = 0.104; //us;
|
||||
fExpectTimedigitalRead = 0.135; //us
|
||||
fExpectTimepinMode = 0.250; //us
|
||||
break;
|
||||
case PI_MODEL_2:
|
||||
ToggleValue /= 4;
|
||||
break;
|
||||
case PI_MODEL_3B:
|
||||
case PI_MODEL_CM3:
|
||||
case PI_MODEL_3BP:
|
||||
case PI_MODEL_3AP:
|
||||
case PI_MODEL_CM3P:
|
||||
case PI_MODEL_ZERO_2W:
|
||||
ToggleValue /= 2;
|
||||
break;
|
||||
case PI_MODEL_4B: //ARM=1500MHz
|
||||
case PI_MODEL_400:
|
||||
case PI_MODEL_CM4:
|
||||
case PI_MODEL_CM4S:
|
||||
fExpectTimedigitalWrite = 0.020; //us
|
||||
fExpectTimedigitalRead = 0.038; //us
|
||||
fExpectTimepinMode = 0.121; //us
|
||||
fWriteReadDelayFactor = 1.86;
|
||||
break;
|
||||
default:
|
||||
if (piRP1Model()) {
|
||||
// So far expect all Pi5 / RP1 hardware has same performance
|
||||
printf("Raspberry Pi with RP1 chip found\n");
|
||||
fExpectTimedigitalWrite = 0.025; //us
|
||||
fExpectTimedigitalRead = 0.323; //us
|
||||
fExpectTimepinMode = 0.200; //us
|
||||
fWriteReadDelayFactor = 3.2;
|
||||
} else {
|
||||
printf("Unknown Raspberry Pi found, exit\n");
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
fWriteReadFactor = fExpectTimedigitalRead/fExpectTimedigitalWrite;
|
||||
ToggleValue /= (fExpectTimedigitalWrite/fPi4ExpectTimedigitalWrite);
|
||||
|
||||
printf("WiringPi GPIO operation time test program (using GPIO %d/%d)\n", GPIO, GPIOIN);
|
||||
pinMode(GPIO, OUTPUT);
|
||||
|
||||
printf("\n% 3d million times digitalWrite ...\n", ToggleValue/1000000);
|
||||
gettimeofday(&t1, NULL);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
digitalWrite(GPIO, HIGH);
|
||||
digitalWrite(GPIO, LOW);
|
||||
}
|
||||
gettimeofday(&t2, NULL);
|
||||
double OpTimeWrite = ReportElapedTime("digitalWrite", 2, fExpectTimedigitalWrite, t1, t2);
|
||||
|
||||
digitalWrite(GPIO, LOW);
|
||||
pinMode(GPIOIN, INPUT);
|
||||
|
||||
ToggleValue /=(fExpectTimedigitalRead/fExpectTimedigitalWrite);
|
||||
printf("\n% 3d million times digitalRead ...\n", ToggleValue/1000000);
|
||||
gettimeofday(&t1, NULL);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
digitalRead(GPIOIN);
|
||||
digitalRead(GPIOIN);
|
||||
}
|
||||
gettimeofday(&t2, NULL);
|
||||
double OpTimeRead = ReportElapedTime("digitalRead", 2, fExpectTimedigitalRead, t1, t2);
|
||||
|
||||
if (!piRP1Model()) {
|
||||
ToggleValue /= 4;
|
||||
} else {
|
||||
ToggleValue *= 1.5;
|
||||
}
|
||||
printf("\n% 3d million times pinMode...\n", ToggleValue/1000000);
|
||||
gettimeofday(&t1, NULL);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
pinMode(GPIO, OUTPUT);
|
||||
pinMode(GPIOIN, INPUT);
|
||||
}
|
||||
gettimeofday(&t2, NULL);
|
||||
ReportElapedTime("pinMode", 2, fExpectTimepinMode, t1, t2);
|
||||
|
||||
printf("\nToggle % 3d million times pinMode and digitalWrite ..\n", ToggleValue/1000000);
|
||||
gettimeofday(&t1, NULL);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
pinMode(GPIO, OUTPUT);
|
||||
digitalWrite(GPIO, LOW);
|
||||
digitalWrite(GPIO, HIGH);
|
||||
pinMode(GPIO, INPUT);
|
||||
}
|
||||
gettimeofday(&t2, NULL);
|
||||
ReportElapedTime("pinMode and digitalWrite", 2, fExpectTimepinMode+fExpectTimedigitalWrite, t1, t2);
|
||||
|
||||
if (!piRP1Model()) {
|
||||
ToggleValue *= 1.5;
|
||||
} else {
|
||||
ToggleValue /= 5;
|
||||
}
|
||||
pinMode(GPIO, OUTPUT);
|
||||
printf("\nToggle % 3d million times digitalRead and digitalWrite ..\n", ToggleValue/1000000);
|
||||
gettimeofday(&t1, NULL);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
digitalWrite(GPIO, HIGH);
|
||||
digitalRead(GPIOIN);
|
||||
digitalWrite(GPIO, LOW);
|
||||
digitalRead(GPIOIN);
|
||||
}
|
||||
gettimeofday(&t2, NULL);
|
||||
double fTimePerOperation = ReportElapedTime("digitalRead and digitalWrite", 2, (fExpectTimedigitalWrite+fExpectTimedigitalRead)*fWriteReadDelayFactor, t1, t2);
|
||||
|
||||
printf("\n");
|
||||
CheckSameFloat("digitalWrite vs. digitalRead factor", OpTimeRead/OpTimeWrite, fWriteReadFactor, 0.3);
|
||||
CheckSameFloat("digitalWrite and digitalRead alternating factor", fTimePerOperation/(fExpectTimedigitalWrite+fExpectTimedigitalRead), fWriteReadDelayFactor, 0.2);
|
||||
if (piRP1Model()) {
|
||||
printf("\nRasperry Pi with RP1 chip:\n");
|
||||
printf(" * digitalRead has very slow speed, much slower then digitalWrite, factor %.1f (typical Pi4 ~1.9)\n", fWriteReadFactor);
|
||||
printf(" * Alternating read/write operation has slow speed, factor %.2f (typical Pi4 ~1.86) to single operation time\n", fWriteReadDelayFactor);
|
||||
}
|
||||
|
||||
digitalWrite(GPIO, LOW);
|
||||
pinMode(GPIO, INPUT);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ int main (void) {
|
||||
int pwmr;
|
||||
int pwm;
|
||||
|
||||
if (RaspberryPiModel!=PI_MODEL_5) {
|
||||
if (!piRP1Model()) {
|
||||
pwmSetMode(PWM_MODE_BAL);
|
||||
pwmc = 1000;
|
||||
pwmr = 1024;
|
||||
@@ -133,7 +133,7 @@ int main (void) {
|
||||
delay(1000);
|
||||
MeasureAndCheckFreq("PMW off", 0.0);
|
||||
|
||||
if (RaspberryPiModel!=PI_MODEL_5) {
|
||||
if (!piRP1Model()) {
|
||||
pwmc = 800;
|
||||
pwmr = 2048;
|
||||
pwm = 768;
|
||||
|
||||
@@ -107,6 +107,9 @@ int main (void) {
|
||||
Pi4 = 1;
|
||||
break;
|
||||
case PI_MODEL_5:
|
||||
case PI_MODEL_CM5:
|
||||
case PI_MODEL_500:
|
||||
case PI_MODEL_CM5L:
|
||||
Pi5 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
|
||||
|
||||
// maybe faster then piRP1Model
|
||||
#define ISRP1MODEL (PI_MODEL_5==RaspberryPiModel || PI_MODEL_CM5==RaspberryPiModel|| PI_MODEL_500==RaspberryPiModel || PI_MODEL_CM5L==RaspberryPiModel)
|
||||
|
||||
//RP1 chip (@Pi5) RIO address
|
||||
const unsigned int RP1_RIO_OUT = 0x0000;
|
||||
const unsigned int RP1_RIO_OE = (0x0004/4);
|
||||
|
||||
@@ -144,7 +144,6 @@ extern const char *piRevisionNames [16] ;
|
||||
extern const char *piMakerNames [16] ;
|
||||
extern const int piMemorySize [ 8] ;
|
||||
|
||||
|
||||
// Intended for the GPIO program Use at your own risk.
|
||||
|
||||
// Threads
|
||||
|
||||
Reference in New Issue
Block a user