I had so much difficulty early on doing what you are attempting but finally go it running. I do not use libprio but use rpmsg (the TI recommendation at the time.)
We write in C and avoid assembly and we’ve done ok so far. As you know the PRU has limited memory so we’re generally doing everything we can to minimize the code. We aren’t currently using the shared 12k at all.
if you have not thoroughly gone through the TI documentation on the ADC (the touchscreen controller or TSC as TI intended it to be), I suggest you do that. I benefitted greatly from that. Especially pay attention to the relationship and difference between channels and steps. It can be a bit confusing.
TI has a very decent engineering forum with fairly good help from their engineers too.
This may not be what you are after but we initialize the ADC with the PRU code in C. I think I got this from a TI example and modified it. I’m posting it here ‘as-is’ in hopes it might help you.
static void ADCConfigure(void)
{
unsigned int i, count, data;
/* Enable ADC module clock */
HWREG(SOC_CM_WKUP_REGS + CM_WKUP_ADC_TSC_CLKCTRL) = 0x02;
/* Disable ADC module for configuration */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_CTRL) &= ~0x01;
/* fs = 24MHz / ((CLKDIV+1)*2*Channels*(OpenDly+Average*(14+SampleDly)))
* = 53.57kHz
* CLKDIV = 0
* Channels = 1
* Average = 16
* OpenDly = 0
* SampleDly = 0
*/
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_ADC_CLKDIV) = 0;
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_ADCRANGE) = 0xFFF << 16;
/* Disable all steps for now */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPENABLE) &= 0xFF;
/* Unlock step configuration */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_CTRL) |= 0x04;
// Step 1 config: SW mode, one shot mode, fifo 0, channel 0, AIN4 on the Beaglebone Black, 4 samples averaged
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPCONFIG(0)) = 0x00000008;
// Step 2 config: SW mode, one shot mode, fifo 0, channel 4, AIN4 on the Beaglebone Black, 4 samples averaged
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPCONFIG(1)) = 0x00200008;
// Step 3 config: SW mode, one shot mode, fifo 0, channel 5, AIN5 on the Beaglebone Black, 4 samples averaged
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPCONFIG(2)) = 0x00280008;
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPDELAY(0)) = 0xFF000000;
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPDELAY(1)) = 0xFF000000;
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPDELAY(2)) = 0xFF000000;
/* Enable channel ID tag */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_CTRL) |= 0x02;
/* Clear end-of-sequence interrupt */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_IRQSTATUS) = 0x02;
/* Enable end-of-sequence interrupt */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_IRQENABLE_SET) = 0x02;
/* Lock step configuration */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_CTRL) &= ~0x04;
/* Empty FIFO 0 */
count = HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_FIFOCOUNT(0));
for (i = 0; i < count; i++) {
data = HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_FIFODATA(0));
}
/* Enable ADC module */
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_CTRL) |= 0x01;
}
Next, here’s a short piece of our code that reads a channel of the ADC. This code is not the complete routine because there is some proprietary computation/handling in the remaining section that would take some time to redact and that would probably introduce some errors. Anyway, I hope this helps. This forum has been very helpful to me and I try to ‘pay it foward’ when I can. Best of luck
static void ReadSensor()
{
// Reads the sensor and stores the value if it is within the threshold of a possible seed.
// If a seed is found, stores the cycles to extrude that seed in an Extrustion array.
int i;
int j;
int m;
// Start step
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_STEPENABLE) = 0xE; // enables steps 1,2 and 3. TSC Charge is not enabled (bit 0)
// Wait for interrupt
while (!(HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_IRQSTATUS)&0x02));
// Clear interrupt
HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_IRQSTATUS) = 0x02;
Data = 0xFFFFFFFF;
count = HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_FIFOCOUNT(0));
// #PRAGMA MUST_ITERATE
for (i = 0; i < count; i++) // count is the number of readings
// in the ADC FIFO buffer
{
Data = HWREG(SOC_ADC_TSC_0_REGS + TSC_ADC_SS_FIFODATA(0));
StepRead = (Data >> 16) & 0xF;
RawAnalog = Data & 0xFFF;