Merge pull request #321 from joan2937/Release-v74

Release v74: closes #274, closes #298, closes #266, closes #316, closes #223.
This commit is contained in:
Guy McSwain 2020-02-03 09:45:03 -06:00 committed by GitHub
commit bab05ceb97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 139 deletions

266
pigpio.c
View File

@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
/* pigpio version 73 */
/* pigpio version 74 */
/* include ------------------------------------------------------- */
@ -3242,7 +3242,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
unsigned numIn2, numOut;
uint32_t tNow, tNext1, tNext2, tDelay;
uint32_t tNow, tNext1, tNext2, tDelay, tMax;
rawWave_t *in2, *out;
@ -3253,6 +3253,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
out = wf[1-wfcur];
tNow = 0;
tMax = 0;
if (!numIn1) tNext1 = -1; else tNext1 = 0;
if (!numIn2) tNext2 = -1; else tNext2 = 0;
@ -3275,6 +3276,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
out[outPos].flags = in1[inPos1].flags;
tNext1 = tNow + in1[inPos1].usDelay; ++inPos1;
if (tMax < tNext1) tMax = tNext1;
}
else if (tNext2 < tNext1)
{
@ -3292,6 +3294,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
out[outPos].flags = in2[inPos2].flags;
tNext2 = tNow + in2[inPos2].usDelay; ++inPos2;
if (tMax < tNext2) tMax = tNext2;
}
else
{
@ -3310,6 +3313,8 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
tNext1 = tNow + in1[inPos1].usDelay; ++inPos1;
tNext2 = tNow + in2[inPos2].usDelay; ++inPos2;
if (tMax < tNext1) tMax = tNext1;
if (tMax < tNext2) tMax = tNext2;
}
if (tNext1 <= tNext2) { tDelay = tNext1 - tNow; tNow = tNext1; }
@ -3342,6 +3347,13 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
}
if (tNow < tMax)
{
/* extend previous delay */
out[outPos-1].usDelay += (tMax - tNow);
tNow = tMax;
}
if ((outPos < numOut) && (outPos < level))
{
wfStats.micros = tNow;
@ -8159,7 +8171,8 @@ static void initReleaseResources(void)
int initInitialise(void)
{
int rev, i, model;
int i;
unsigned rev, model;
struct sockaddr_in server;
struct sockaddr_in6 server6;
char * portStr;
@ -8207,13 +8220,27 @@ int initInitialise(void)
7=Unknown
8=Pi3B
9=Zero
12=Zero W
13=Pi3B+
14=Pi3A+
17=Pi4B
*/
if (model < 2) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2;
else if (model < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS;
else if (model == 4) gpioMask = PI_DEFAULT_UPDATE_MASK_PI2B;
else if (model == 6) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE;
else if (model == 8) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B;
else if (model == 9) gpioMask = PI_DEFAULT_UPDATE_MASK_ZERO;
else if (model == 6
|| model ==10
|| model ==16) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE;
else if (model == 8
|| model ==13
|| model ==14) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B;
else if (model == 9
|| model ==12) gpioMask = PI_DEFAULT_UPDATE_MASK_ZERO;
else if (model ==17) gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B;
else gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN;
}
@ -8292,7 +8319,7 @@ int initInitialise(void)
}
server6.sin6_port = htons(port);
int opt;
int opt = 1;
setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
if (bind(fdSock,(struct sockaddr *)&server6, sizeof(server6)) < 0)
SOFT_ERROR(PI_INIT_FAILED, "bind to port %d failed (%m)", port);
@ -8307,7 +8334,7 @@ int initInitialise(void)
SOFT_ERROR(PI_INIT_FAILED, "socket failed (%m)");
else
{
int opt;
int opt = 1;
setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
}
server.sin_family = AF_INET;
@ -13431,13 +13458,14 @@ W warranty void if either bit is set
S 0=old (bits 0-22 are revision number) 1=new (following fields apply)
M 0=256 1=512 2=1024
M 0=256 1=512 2=1024 3=2GB 4=4GB
B 0=Sony 1=Egoman 2=Embest 3=Unknown 4=Embest
B 0=Sony 1=Egoman 2=Embest 3=Sony Japan 4=Embest 5=Stadium
P 0=2835, 1=2836, 2=2837
P 0=2835, 1=2836, 2=2837 3=2711
T 0=A 1=B 2=A+ 3=B+ 4=Pi2B 5=Alpha 6=Compute Module 7=Unknown 8=Pi3B 9=Zero
T 0=A 1=B 2=A+ 3=B+ 4=Pi2B 5=Alpha 6=CM1 8=Pi3B 9=Zero a=CM3 c=Zero W
d=3B+ e=3A+ 10=CM3+ 11=4B
R PCB board revision
@ -13455,157 +13483,119 @@ unsigned gpioHardwareRevision(void)
if (rev) return rev;
piCores = 0;
filp = fopen ("/proc/cpuinfo", "r");
if (filp != NULL)
{
while (fgets(buf, sizeof(buf), filp) != NULL)
{
if (piCores == 0)
{
if (!strncasecmp("model name", buf, 10))
{
if (strstr (buf, "ARMv6") != NULL)
{
piCores = 1;
pi_peri_phys = 0x20000000;
pi_dram_bus = 0x40000000;
pi_mem_flag = 0x0C;
}
else if (strstr (buf, "ARMv7") != NULL)
{
piCores = 4;
pi_peri_phys = 0x3F000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
}
else if (strstr (buf, "ARMv8") != NULL)
{
piCores = 4;
pi_peri_phys = 0x3F000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
}
}
}
if (!strncasecmp("hardware\t: BCM", buf, 14))
{
int bcmno = atoi(buf+14);
if ((bcmno == 2708) ||
(bcmno == 2709) ||
(bcmno == 2710) ||
(bcmno == 2835) ||
(bcmno == 2836) ||
(bcmno == 2837))
{
pi_ispi = 1;
}
}
if (!strncasecmp("revision\t:", buf, 10))
{
if (sscanf(buf+10, "%x%c", &rev, &term) == 2)
{
if (term != '\n') rev = 0;
else rev &= 0xFFFFFF; /* mask out warranty bit */
switch (rev&0xFFF0) /* just interested in BCM model */
{
case 0x3110: /* Pi4B */
piCores = 4;
pi_peri_phys = 0xFE000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
pi_is_2711 = 1;
pi_ispi = 1;
clk_osc_freq = CLK_OSC_FREQ_2711;
clk_plld_freq = CLK_PLLD_FREQ_2711;
hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711;
hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711;
hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711;
fclose(filp);
if (!gpioMaskSet)
{
gpioMaskSet = 1;
gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B;
}
return rev;
break;
}
}
}
}
fclose(filp);
}
/*
Raspberry pi 3 running arm64 don't put all the
information we need in /proc/cpuinfo, but we can
get it elsewhere.
*/
/* (some) arm64 operating systems get revision number here */
if (!pi_ispi)
if (rev == 0)
{
DBG(DBG_USER, "searching /proc/device-tree for revision");
filp = fopen ("/proc/device-tree/system/linux,revision", "r");
if (filp != NULL)
{
filp = fopen ("/proc/device-tree/model", "r");
if (filp != NULL)
uint32_t tmp;
if (fread(&tmp,1 , 4, filp) == 4)
{
if (fgets(buf, sizeof(buf), filp) != NULL)
{
if (!strncmp("Raspberry Pi 3", buf, 14))
{
pi_ispi = 1;
piCores = 4;
pi_peri_phys = 0x3F000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
}
else if (!strncmp("Raspberry Pi 4 Model B", buf, 22))
{
pi_ispi = 1;
piCores = 4;
pi_peri_phys = 0xFE000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
pi_is_2711 = 1;
clk_osc_freq = CLK_OSC_FREQ_2711;
clk_plld_freq = CLK_PLLD_FREQ_2711;
hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711;
hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711;
hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711;
if (!gpioMaskSet)
{
gpioMaskSet = 1;
gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B;
}
}
}
fclose(filp);
/*
for some reason the value returned by reading
this /proc entry seems to be big endian,
convert it.
*/
rev = ntohl(tmp);
rev &= 0xFFFFFF; /* mask out warranty bit */
}
}
fclose(filp);
}
if (rev == 0)
piCores = 0;
pi_ispi = 0;
rev &= 0xFFFFFF; /* mask out warranty bit */
/* Decode revision code */
if ((rev & 0x800000) == 0) /* old rev code */
{
if (rev < 0x0016) /* all BCM2835 */
{
filp = fopen ("/proc/device-tree/system/linux,revision", "r");
if (filp != NULL)
{
uint32_t tmp;
if (fread(&tmp,1 , 4, filp) == 4)
{
/*
for some reason the value returned by reading
this /proc entry seems to be big endian,
convert it.
*/
rev = ntohl(tmp);
rev &= 0xFFFFFF; /* mask out warranty bit */
}
}
fclose(filp);
pi_ispi = 1;
piCores = 1;
pi_peri_phys = 0x20000000;
pi_dram_bus = 0x40000000;
pi_mem_flag = 0x0C;
}
else
{
DBG(DBG_ALWAYS, "unknown revision=%x", rev);
rev = 0;
}
}
else /* new rev code */
{
switch ((rev >> 12) & 0xF) /* just interested in BCM model */
{
case 0x0: /* BCM2835 */
pi_ispi = 1;
piCores = 1;
pi_peri_phys = 0x20000000;
pi_dram_bus = 0x40000000;
pi_mem_flag = 0x0C;
break;
case 0x1: /* BCM2836 */
case 0x2: /* BCM2837 */
pi_ispi = 1;
piCores = 4;
pi_peri_phys = 0x3F000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
break;
case 0x3: /* BCM2711 */
pi_ispi = 1;
piCores = 4;
pi_peri_phys = 0xFE000000;
pi_dram_bus = 0xC0000000;
pi_mem_flag = 0x04;
pi_is_2711 = 1;
clk_osc_freq = CLK_OSC_FREQ_2711;
clk_plld_freq = CLK_PLLD_FREQ_2711;
hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711;
hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711;
hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711;
break;
default:
DBG(DBG_ALWAYS, "unknown rev code (%x)", rev);
rev=0;
pi_ispi = 0;
break;
}
}
DBG(DBG_USER, "revision=%x", rev);
DBG(DBG_USER, "pi_peri_phys=%x", pi_peri_phys);
DBG(DBG_USER, "pi_dram_bus=%x", pi_dram_bus);
DBG(DBG_USER, "pi_mem_flag=%x", pi_mem_flag);
return rev;
}

View File

@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
#include <stdint.h>
#include <pthread.h>
#define PIGPIO_VERSION 73
#define PIGPIO_VERSION 74
/*TEXT