Configuring Sound Card in BeagleBone Black - codec

I am trying to integrate the ADAU1761 codec with the Beaglebone Black. I need to configure a sound card in order to play audio through the codec.
I tried writing device tree overlay but did not succeed. Then I tried changing directly in the device tree.
Now the modes of the PINS are changed but the sound card is not getting configured.
am I going in the right direction? Please help.
Below are the changes I made in the device tree:
Pins mode change i2c:
pinmux_i2c2_pins {
pinctrl-single,pins = <0x178 0x0b 0x17c 0x0b>;
linux,phandle = <0x30>;
phandle = <0x30>;
Pins mode change i2s:
mcasp0_pins {
pinctrl-single,pins = <0x1ac 0x08 0x19c 0x2 0x194 0x08 0x190 0x08
0x6c 0x7 0x198 0x08>;
linux,phandle = <0x47>;
phandle = <0x47>;
};
Driver loading:
i2c#4819c000 {
compatible = "ti,omap4-i2c";
#address-cells = <0x1>;
#size-cells = <0x0>;
ti,hwmods = "i2c3";
reg = <0x4819c000 0x1000>;
interrupts = <0x1e>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <0x30>;
clock-frequency = <0x186a0>;
linux,phandle = <0x9d>;
phandle = <0x9d>;
adau1761: adau1361#38 {
compatible = "adi,adau1761";
reg = <0x38>;
};
Sound Card:
sound {
compatible = "adi,adau1761-evm-audio";
ti,model = "ADI ADAU1761";
ti,audio-codec = <&adau1761>;
ti,mcasp-controller = <0x52>;
ti,audio-routing =
"Headphone Jack", "LOUT",
"Headphone Jack", "ROUT",
"LINE1L", "LAUX",
"LINE1R", "RAUX";
clocks = <0x53>;
clock-names = "mclk";
};

Related

cannot simplify float function in multiarray

I've tried to read everything including this post:
2D-array as argument to function
I'm getting error: "cannot convert 'float' to 'float ()[8]' for argument '1' to 'float pzemGetter(float ()[8], PZEM004Tv30, byte)'"
Anyway, I couldn't make this code to work with arduino mega and pzem-004t v3 module... I'm just interested to get it in such way only to get a flexible code when using loops and things like that
`#include <PZEM004Tv30.h>`
`byte disabled = 150;`
`byte enabled = 180;`
`byte busyIndex = 0; //To ensure arduino mega is not busy before sending float array from PZEM`
`#define FLOATS_SENT 8`
`//============Arrays definition to be reported to raspberry through serial connection`
`float pzemGroup[8][8]; //A testing way to group pzem modules into array of arrays`
`byte statusArray[32];`
`PZEM004Tv30 pzemFrameGroup[] = {PZEM004Tv30(&Serial3, 0x42), PZEM004Tv30(&Serial3, 0x43),`
` PZEM004Tv30(&Serial3, 0x44), PZEM004Tv30(&Serial3, 0x45),`
` PZEM004Tv30(&Serial3, 0x46), PZEM004Tv30(&Serial3, 0x47),`
` PZEM004Tv30(&Serial3, 0x48), PZEM004Tv30(&Serial3, 0x49)`
};
`void setup() {`
`Serial.begin(115200); //This is the speed for serial monitoring`
`Serial2.begin(9600); //Speed for serial comm with raspberry pi through USB Serial FTDI adapter`
`delay(200);`
`}`
`void loop() {`
`pzemGetter(pzemGroup[3][], pzemFrameGroup[0], busyIndex = 8);`
`float testValue1 = pzemGroup[3][0];`
`float testValue2 = pzemGroup[3][1];`
`float testValue3 = pzemGroup[3][2];`
`}//End loop function`
`//Function definition to get data from energy modules pzem004t installed in the same bus`
`float pzemGetter (float (*frmEnergy)[8], PZEM004Tv30 pzemModule, byte busyFlagLocator) {`
`statusArray[busyFlagLocator] = enabled;`
`frmEnergy[0][0] = 26.10; //I added this one as a personal initial element verification in raspberry`
`frmEnergy[0][1] = pzemModule.voltage();`
`frmEnergy[0][2] = pzemModule.power();`
`frmEnergy[0][3] = pzemModule.current();`
`frmEnergy[0][4] = pzemModule.energy();`
`frmEnergy[0][5] = pzemModule.frequency();`
`frmEnergy[0][6] = pzemModule.pf();`
`frmEnergy[0][7] = 26.10; //I added this one as a personal final element verification in raspberry`
`statusArray[busyFlagLocator] = disabled;`
`}`

pic18f47q43 Reading from program flash memory problem

I am using MPLAB X IDE and MPLAB Code Configurator (MCC).
i generated the library of the flash read/write and erase with MCC.
then when i used "FLASH_ReadPage" built in function created from the MCC its not working, and after debugging i found it stucked in a while loop that is checking for "NVMCON0bits.GO" to be cleared and its never cleared thats why its stucked.
here is the function:
void FLASH_ReadPage(uint32_t flashAddr)
{
uint8_t GIEBitValue = INTCON0bits.GIE; // Save interrupt enable
//Set NVMADR with the target word address
NVMADRU = (uint8_t) ((flashAddr & 0x00FF0000) >> 16);
NVMADRH = (uint8_t) ((flashAddr & 0x0000FF00) >> 8);
NVMADRL = (uint8_t) (flashAddr & 0x000000FF);
//Set the NVMCMD control bits for Page Read operation
NVMCON1bits.NVMCMD = 0b010;
//Disable all interrupt
INTCON0bits.GIE = 0;
//Perform the unlock sequence
NVMLOCK = 0x55;
NVMLOCK = 0xAA;
//Start page read and wait for the operation to complete
NVMCON0bits.GO = 1;
while (NVMCON0bits.GO); **<----- Stucked here**
//Restore the interrupts
INTCON0bits.GIE = GIEBitValue;
//Set the NVMCMD control bits for Word Read operation to avoid accidental writes
NVMCON1bits.NVMCMD = 0b000;
}

Parallel Programming stuck on 4th instance of Concurrency::create_task call for serial devices

I am currently developing a program where Raspberry Pi 3 will read contents sent by 4 Arduino (USB) devices through serial communication every 100ms. The UI gets stuck on the fourth call (serialDeviceIndex = 3) of Concurrency::create_task but if there are only 3 Arduino devices, the problem is not happening and the thread execution continues to the .then lambda body. Can you help me pin point what is the problem? Here's the function called when the connect button from the xaml devices is pressed.
void MainPage::comPortInput_Click(Object^ sender, RoutedEventArgs^ e)
{
m_timer->Start();
auto selectionIndex = ConnectDevices->SelectedIndex;
if (selectionIndex < 0)
{
status->Text = "Select a device and connect";
return;
}
auto selectedItems = ConnectDevices->SelectedItems;
for (unsigned serialDeviceIndex = 0; serialDeviceIndex < selectedItems->Size; serialDeviceIndex++)
{
Device ^device = static_cast<Device ^>(selectedItems->GetAt(serialDeviceIndex));
textBox->Text = textBox->Text + "\n<START>:" + device->Id->ToString() + "<END>";
Windows::Devices::SerialCommunication::SerialDevice ^serial_device;
Windows::Devices::Enumeration::DeviceInformation ^entry = device->DeviceInfo;
auto childTokenSource = Concurrency::cancellation_token_source::create_linked_source(cancellationTokenSource->get_token());
auto childToken = childTokenSource.get_token();
Concurrency::create_task(
Windows::Devices::SerialCommunication::SerialDevice::FromIdAsync(entry->Id), childToken)
.then([this, serialDeviceIndex](Windows::Devices::SerialCommunication::SerialDevice ^serial_device)
{
_serialPort = serial_device;
Platform::String ^deviceString1 = _serialPort->ToString();
// Disable the 'Connect' button
//comPortInput->IsEnabled = false;
Windows::Foundation::TimeSpan _timeOut;
_timeOut.Duration = 100000L; //100000 works with delay(200)
// Configure serial settings
_serialPort->WriteTimeout = _timeOut;
_serialPort->ReadTimeout = _timeOut;
_serialPort->BaudRate = 9600;
_serialPort->Parity = Windows::Devices::SerialCommunication::SerialParity::None;
_serialPort->StopBits = Windows::Devices::SerialCommunication::SerialStopBitCount::One;
_serialPort->DataBits = 8;
_serialPort->Handshake = Windows::Devices::SerialCommunication::SerialHandshake::None;
_dataReaderObject = ref new Windows::Storage::Streams::DataReader(_serialPort->InputStream);
_dataReaderObject->InputStreamOptions = Windows::Storage::Streams::InputStreamOptions::Partial;
_dataReaderObjects.Append(_dataReaderObject);
_serialPorts.Append(_serialPort);
int serialPortsSize = _serialPorts.Size;
Listen(_serialPorts.GetAt(serialDeviceIndex), _dataReaderObject, serialDeviceIndex);
});
Sleep(5);
}
}
EDIT:
Okay, I simplified now the code to JUST this one
for (unsigned serialDeviceIndex = 0; serialDeviceIndex < selectedItems->Size; serialDeviceIndex++){
Device ^device = static_cast<Device ^>(selectedItems->GetAt(serialDeviceIndex));
textBox->Text = textBox->Text + "\n<START>:" + device->Id->ToString() + "<END>";
Windows::Devices::Enumeration::DeviceInformation ^entry = device->DeviceInfo;
auto it = Concurrency::create_task(Windows::Devices::SerialCommunication::SerialDevice::FromIdAsync(entry->Id));
while (!it.is_done())
textBoxStatus->Text = "processing" + deviceIndex.ToString();
it.get();
}
FYI, this code runs normally fine in my pc. no errors. When I try to run this in my RaspberryPi3 under Windows IoT the program hungs up at the fourth time I try to get the device using it.get()

USB/IP emulated device not listed by libusb

There's USB/IP tool which allows share access USB devices over TCP/IP network. USB device connected to Linux PC which running TCP server and Windows PC running VHCI driver which connects to Linux.
This approach makes possible to emulate any USB device without hardware at all. All you need is write TCP server which will handle USB requests. (like here)
But the problem with it that emulated device is not really correct. When you try to list connected USB devices using libusb you'll get an error 'unlisted ancestor for..' since emulated device has no parent in device-tree.
From other hand some tools like Zadig show emulated device.
Exactly problem discussed here and no real solution provided.
So question is it bug in USB/IP windows driver? Can anybody experienced with Windows drivers development helps? What's a deal about parent device? Why it is so important?
Any hint will be very very appreciated! Thanks a lot in advance for any help
UDPATE : technically problem is that parent of emulated device (USB/IP enumerator) not recognized by libusb as HUB. This makes emulated devices ignored due-to NULL parent. So question is how to patch USB/IP driver to be visible by libusb as normal USB HUB
The problem was that USB/IP windows driver v0.2.0.0 does not reply on IRP_MN_QUERY_CAPABILITIES IRPs. It dispatch only IRP_MN_QUERY_CAPABILITIES targeted on emulated devices, but not to bus driver itself.
I have added IRP_MN_QUERY_CAPABILITIES processing to USB/IP driver and now it is detected by libusb as normal USB HUB device.
UPD:
in pnp.c inside method
NTSTATUS Bus_FDO_PnP (
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp,
__in PIO_STACK_LOCATION IrpStack,
__in PFDO_DEVICE_DATA DeviceData )
I have added new 'case' inside switch (IrpStack->MinorFunction) :
case IRP_MN_QUERY_CAPABILITIES:
{
status = _PDO_QueryDeviceCaps(DeviceData, Irp);
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
Bus_DecIoCount(DeviceData);
return status;
}
UPD2: and also this:
NTSTATUS _PDO_QueryDeviceCaps(__in PFDO_DEVICE_DATA DeviceData, __in PIRP Irp)
{
PIO_STACK_LOCATION stack;
PDEVICE_CAPABILITIES deviceCapabilities;
DEVICE_CAPABILITIES parentCapabilities;
PAGED_CODE();
stack = IoGetCurrentIrpStackLocation(Irp);
deviceCapabilities = stack->Parameters.DeviceCapabilities.Capabilities;
if (deviceCapabilities->Version != 1 || deviceCapabilities->Size < sizeof(DEVICE_CAPABILITIES))
{
return STATUS_UNSUCCESSFUL;
}
deviceCapabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
if (deviceCapabilities->DeviceState[PowerSystemSleeping1] != PowerDeviceD0)
deviceCapabilities->DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
if (deviceCapabilities->DeviceState[PowerSystemSleeping2] != PowerDeviceD0)
deviceCapabilities->DeviceState[PowerSystemSleeping2] = PowerDeviceD3;
if (deviceCapabilities->DeviceState[PowerSystemSleeping3] != PowerDeviceD0)
deviceCapabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3;
deviceCapabilities->DeviceWake = PowerDeviceD1;
deviceCapabilities->DeviceD1 = TRUE; // Yes we can
deviceCapabilities->DeviceD2 = FALSE;
deviceCapabilities->WakeFromD0 = FALSE;
deviceCapabilities->WakeFromD1 = TRUE;
deviceCapabilities->WakeFromD2 = FALSE;
deviceCapabilities->WakeFromD3 = FALSE;
deviceCapabilities->D1Latency = 0;
deviceCapabilities->D2Latency = 0;
deviceCapabilities->D3Latency = 0;
deviceCapabilities->EjectSupported = FALSE;
deviceCapabilities->HardwareDisabled = FALSE;
deviceCapabilities->Removable = TRUE;
deviceCapabilities->SurpriseRemovalOK = TRUE;
deviceCapabilities->UniqueID = FALSE;
deviceCapabilities->SilentInstall = FALSE;
deviceCapabilities->Address = 1;
deviceCapabilities->UINumber = 1;
return STATUS_SUCCESS;
}

DHCP Multiple IP address request

I am trying to mimic a DHCP client from my end using C++ Code. My objective is to get some free/unused IP's from the DHCP server to assign it to different equipments - similar to a DHCP Relay, but not technically the same. My CLIENT is running on an Embedded linux platform and talks to a DHCP server via our internal network.
As per the DHCP protocol there is a formal procedure (DISCOVER, OFFER, REQUEST, ACK/NAK, RELEASE) to communicate with the DHCP server.According to the RFC's(2131), when I do a DISCOVER, I receive and OFFER with an unused IP address in the YIAddr field. I further use this IP address in my REQUEST message using option 50 as mentioned in RFC 2132.
My main router, make- Edgewater(which is also the DHCP server) on sending a DISCOVER message, sends back an OFFER message with an unused IP address in the YIAddr field (I used this unused IP in my consequent REQUEST message), which is my requirement. I did the same experiment with few other router's (NetGear, Dlink, Broadcom) and found that the OFFER message is sending me back the same IP address of the CLIENT that is requesting the unused IP's. I am curious to know why this is happening. As I understand, I'm following the steps mentioned in RFC2131/RFC2131/RFC4361 for creating my DHCP packet format.
Is there a specific format or specific option that the other DHCP server/Routers are expecting to give out unused IP's? I am using a unique client identifier in my option field as mentioned in RFC4361.
This is a snap shot of the section where I'm creating the dhcp packet.
request_packet.m_OperationCode = 0x01;
request_packet.m_HwareType = 0x01;
request_packet.m_HwareLen = 0x06;
request_packet.m_Hops = 0x01;
request_packet.m_XID = htonl(XID[m_numberOfIPs]);
request_packet.m_Secs = htons(0x10);
request_packet.m_flags = htons(0x8000);
request_packet.m_CIAddr = 0x000000; //Client IP
request_packet.m_YIAddr = 0x000000; //Your IP
request_packet.m_SIAddr = 0x000000; //Server IP
request_packet.m_GIAddr = 0x000000;
request_packet.m_CHAddr[0] = MACADDRESS[m_numberOfIPs][0];
request_packet.m_CHAddr[1] = MACADDRESS[m_numberOfIPs][1];//[1];
request_packet.m_CHAddr[2] = MACADDRESS[m_numberOfIPs][2];//[2];
request_packet.m_CHAddr[3] = MACADDRESS[m_numberOfIPs][3];//[3];
request_packet.m_CHAddr[4] = MACADDRESS[m_numberOfIPs][4];//[4];
request_packet.m_CHAddr[5] = MACADDRESS[m_numberOfIPs][5];//[5];
memset(request_packet.m_CHAddr+6, 0, 10);
memset(request_packet.m_SName, 0, 64);
memset(request_packet.m_File, 0, 128);
request_packet.m_pOptions[0] = 99; //Start of magic cookie
request_packet.m_pOptions[1] = 130;
request_packet.m_pOptions[2] = 83;
request_packet.m_pOptions[3] = 99; //end of magic cookie
Options Field
DISCOVER message
CID and DUID are random unique numbers to create a unique client identifier
request_packet.m_pOptions[4] = 53; //DHCP MESSAGE TYPE OPTION CODE
request_packet.m_pOptions[5] = 1; //OPTION DATA LEN
request_packet.m_pOptions[6] = 1; //DHCP DISCOVER
request_packet.m_pOptions[7] = 55; //Parameter Request List
request_packet.m_pOptions[8] = 7; //Length
request_packet.m_pOptions[9] = 1; //Subnet Mask
request_packet.m_pOptions[10] = 3; //Router
request_packet.m_pOptions[11] = 6; //Domain Name Server
request_packet.m_pOptions[12] = 12; // Host Name
request_packet.m_pOptions[13] = 15; //Domain Name
request_packet.m_pOptions[14] = 28; //Broadcast Address
request_packet.m_pOptions[15] = 42; //NTP servers
request_packet.m_pOptions[16] = 51; //IP Address Lease Time
request_packet.m_pOptions[17] = 4;
request_packet.m_pOptions[18] = 0x00;
request_packet.m_pOptions[19] = 0x00;
request_packet.m_pOptions[20] = 0xFF;
request_packet.m_pOptions[21] = 0xFF;
request_packet.m_pOptions[22] = 61;//Client Identifier code
request_packet.m_pOptions[23] = 15;//Length
request_packet.m_pOptions[24] = 255;//IAID Type
printf("The CID generated inside REQUEST is %x\n", CID[m_numberOfIPs]);
request_packet.m_pOptions[25] = CID[m_numberOfIPs][0];
request_packet.m_pOptions[26] = CID[m_numberOfIPs][1];
request_packet.m_pOptions[27] = CID[m_numberOfIPs][2];
request_packet.m_pOptions[28] = CID[m_numberOfIPs][3];
request_packet.m_pOptions[29] = 0x00;//DUID Type
request_packet.m_pOptions[30] = 0x03;//DUID Type
request_packet.m_pOptions[31] = 0x00;//HW Type code - Ethernet
request_packet.m_pOptions[32] = 0x01;//HW Type code - Ethernet
request_packet.m_pOptions[33] = DUID[m_numberOfIPs][0];
request_packet.m_pOptions[34] = DUID[m_numberOfIPs][1];
request_packet.m_pOptions[35] = DUID[m_numberOfIPs][2];
request_packet.m_pOptions[36] = DUID[m_numberOfIPs][3];
request_packet.m_pOptions[37] = DUID[m_numberOfIPs][4];
request_packet.m_pOptions[38] = DUID[m_numberOfIPs][5];
request_packet.m_pOptions[39] = (0xff); // End option
REQUEST message
request_packet.m_pOptions[4] = 53; //DHCP MESSAGE TYPE OPTION CODE
request_packet.m_pOptions[5] = 1; //OPTION DATA LEN
request_packet.m_pOptions[6] = 3; //DHCP REQUEST
request_packet.m_pOptions[7] = 50; //DHCP REQUESTION OPTION
request_packet.m_pOptions[8] = 4; //OPTION DATA LEN
request_packet.m_pOptions[9] = (m_YourIP & 0xff000000)>>24; //first byte
request_packet.m_pOptions[10] = (m_YourIP & 0xff0000)>>16; //second byte
request_packet.m_pOptions[11] = (m_YourIP & 0xff00)>>8; //third byte
request_packet.m_pOptions[12] = (m_YourIP & 0xff); //fourth byte
/*- Added by JA. Refer 3.1.3 Section of RFC2131.txt - Server identifier option*/
request_packet.m_pOptions[13] = 54;
request_packet.m_pOptions[14] = 4;
request_packet.m_pOptions[15] = (m_ServerIP & 0xff000000) >> 24; //first byte
request_packet.m_pOptions[16] = (m_ServerIP & 0xff0000)>>16; //second byte
request_packet.m_pOptions[17] = (m_ServerIP & 0xff00)>>8; //third byte
request_packet.m_pOptions[18] = (m_ServerIP & 0xff); //fourth byte
request_packet.m_pOptions[19] = 55; //Parameter Request List
request_packet.m_pOptions[20] = 7; //Length
request_packet.m_pOptions[21] = 1; //Subnet Mask
request_packet.m_pOptions[22] = 3; //Router
request_packet.m_pOptions[23] = 6; //Domain Name Server
request_packet.m_pOptions[24] = 12; // Host Name
request_packet.m_pOptions[25] = 15; //Domain Name
request_packet.m_pOptions[26] = 28; //Broadcast Address
request_packet.m_pOptions[27] = 42; //NTP servers
request_packet.m_pOptions[28] = 51; //IP Address Lease Time
request_packet.m_pOptions[29] = 4;
request_packet.m_pOptions[30] = 0x00;
request_packet.m_pOptions[31] = 0x00;
request_packet.m_pOptions[32] = 0xFF;
request_packet.m_pOptions[33] = 0xFF;
/*- Added by JA. Refer 6.1 Section of RFC4361.txt - Client identifier option*/
request_packet.m_pOptions[34] = 61;//Client Identifier code
request_packet.m_pOptions[35] = 15;//Length
request_packet.m_pOptions[36] = 255;//IAID Type
printf("The CID generated inside REQUEST is %x\n", CID[m_numberOfIPs]);
request_packet.m_pOptions[37] = CID[m_numberOfIPs][0];
request_packet.m_pOptions[38] = CID[m_numberOfIPs][1];
request_packet.m_pOptions[39] = CID[m_numberOfIPs][2];
request_packet.m_pOptions[40] = CID[m_numberOfIPs][3];
request_packet.m_pOptions[41] = 0x00;//DUID Type
request_packet.m_pOptions[42] = 0x03;//DUID Type
request_packet.m_pOptions[43] = 0x00;//HW Type code - Ethernet
request_packet.m_pOptions[44] = 0x01;//HW Type code - Ethernet
request_packet.m_pOptions[45] = DUID[m_numberOfIPs][0];
request_packet.m_pOptions[46] = DUID[m_numberOfIPs][1];
request_packet.m_pOptions[47] = DUID[m_numberOfIPs][2];
request_packet.m_pOptions[48] = DUID[m_numberOfIPs][3];
request_packet.m_pOptions[49] = DUID[m_numberOfIPs][4];
request_packet.m_pOptions[50] = DUID[m_numberOfIPs][5];
request_packet.m_pOptions[51] = (0xff); // End option
Using router as DHCP relay and server it will assign you Unique IP based DHCP subnetwork configured on it say 10.1.2.0/24 is the pool defined on router for DHCP requests it will assign you very first non-allocated IP against your MAC only and this assignment is random you can not reserve mac on router.After DORA it triggers lease timer for that MAC-IP .
If you use DHCP server Microsoft/Unix they they have extended functionality as reserving IP for particular mac permanently.

Resources