Hi John,
Attached is my user space code to transmit 1 byte of data stored in buffer
- data using spidev. Would this then call dma controller automatically if i
increase the size of my buffer data to 64 bytes? Also, I want to setup a
interrupt handler that gets called when data is received or transmitted by
the dma. How do i do this?
Thanks!
On Tue, Aug 19, 2014 at 5:19 PM, John Syn <[email protected]> wrote:
>
> From: Siddarth Sharma <[email protected]>
> Reply-To: "[email protected]" <[email protected]>
> Date: Tuesday, August 19, 2014 at 9:02 AM
> To: "[email protected]" <[email protected]>
> Subject: [beagleboard] Re: SPI with DMA
>
> I'm using BeagleBone with AM3517 and Linux kernel version: 2.6.37
>
> BeagleBone use AM3359 or AM3358 processors. When using the mcspi driver,
> DMA is automatically invoked when the size of your transfer exceeds a
> defined threshold which you will find in the mcspi driver. If you want to
> see how this is done, look at examples of SPI drivers in the /drivers/iio
> or /drivers/staging/iio folder. BTW, you don’t invoke the mcspi driver
> functions directly. Instead you use the generic linux SPI functions which
> in turn call the mcspi functions. Read the /Documentation/spi docs.
>
> Regards,
> John
>
>
>
> On Tuesday, August 19, 2014 5:00:24 PM UTC+1, Siddarth Sharma wrote:
>>
>> Hi Folks,
>>
>> I have recently decided to learn embedded linux development and I am
>> currently working on a project to use the SPI on Beagle Bone to transfer
>> 64+bytes of data as one block in one write cycle to an Atmel SAM 32 bit uC.
>> I would like to use DMA with the SPI and I have read online that this is
>> not possible from user space with spidev. I came across omap2_mcspi.c
>> driver and I noticed that this has dma functions in it. I would like to
>> enable two DMA channels(tx and rx) to provide and receive data from the
>> respective registers on the SPI. Could someone guide as to how I am to go
>> about using omap2_mcspi? Would i need to make a module?
>>
>> Thanks!
>>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "BeagleBoard" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/beagleboard/ZtfEPoACcXE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
/*
* main.cpp
*
* Created on: 4 Aug 2014
* Author: siddharth
*/
#include "Spi.h"
using namespace std;
int main(void)
{
Spi spi("/dev/spidev1.0", SPI_MODE_0, 5000000, 8);
//Spi spi;
int i = 6;
unsigned char data[1];
int rx_data=0;
while(i > 0)
{
data[0] = 1;
//data[1] = 'A';
//data[2] = 0;
spi.spiWriteRead(data, sizeof(data) );
rx_data = (int)data[0];
cout<<"the received data is:"<<rx_data<<endl;
i--;
}
return 0;
}
/*
* Spi.cpp
*
* Created on: 4 Aug 2014
* Author: siddharth
*/
#include "Spi.h"
#include <iostream>
using namespace std;
int Spi::spiOpen(std::string devspi){
int statusVal = -1;
this->spifd = open(devspi.c_str(), O_RDWR);
if(this->spifd < 0){
perror("could not open SPI device");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_WR_MODE, &(this->mode));
if(statusVal < 0){
perror("Could not set SPIMode (WR)...ioctl fail");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_RD_MODE, &(this->mode));
if(statusVal < 0) {
perror("Could not set SPIMode (RD)...ioctl fail");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_WR_BITS_PER_WORD, &(this->bitsPerWord));
if(statusVal < 0) {
perror("Could not set SPI bitsPerWord (WR)...ioctl fail");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_RD_BITS_PER_WORD, &(this->bitsPerWord));
if(statusVal < 0) {
perror("Could not set SPI bitsPerWord(RD)...ioctl fail");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_WR_MAX_SPEED_HZ, &(this->speed));
if(statusVal < 0) {
perror("Could not set SPI speed (WR)...ioctl fail");
exit(1);
}
statusVal = ioctl (this->spifd, SPI_IOC_RD_MAX_SPEED_HZ, &(this->speed));
if(statusVal < 0) {
perror("Could not set SPI speed (RD)...ioctl fail");
exit(1);
}
return statusVal;
}
int Spi::spiClose(){
int statusVal = -1;
statusVal = close(this->spifd);
if(statusVal < 0) {
perror("Could not close SPI device");
exit(1);
}
return statusVal;
}
int Spi::spiWriteRead( unsigned char *data, int length){
struct spi_ioc_transfer spi[length];
int i = 0;
int retVal = -1;
// one spi transfer for each byte
for (i = 0 ; i < length ; i++){
spi[i].tx_buf = (unsigned long)(data + i); // transmit from "data"
spi[i].rx_buf = (unsigned long)(data + i) ; // receive into "data"
spi[i].len = sizeof(*(data + i)) ;
spi[i].delay_usecs = 0 ;
spi[i].speed_hz = this->speed ;
spi[i].bits_per_word = this->bitsPerWord ;
spi[i].cs_change = 0;
}
retVal = ioctl (this->spifd, SPI_IOC_MESSAGE(length), &spi) ;
if(retVal < 0){
perror("Problem transmitting spi data..ioctl");
exit(1);
}
return retVal;
}
Spi::Spi(){
this->mode = SPI_MODE_0 ;
this->bitsPerWord = 8;
this->speed = 48000000;
this->spifd = -1;
this->spiOpen(std::string("/dev/spidev1.0"));
}
Spi::Spi(std::string devspi, unsigned char spiMode, unsigned int spiSpeed, unsigned char spibitsPerWord){
this->mode = spiMode ;
this->bitsPerWord = spibitsPerWord;
this->speed = spiSpeed;
this->spifd = -1;
this->spiOpen(devspi);
}
Spi::~Spi(){
this->spiClose();
}
/*
* Spi.h
*
* Created on: 4 Aug 2014
* Author: siddharth
*/
#ifndef SPI_H_
#define SPI_H_
#include <string>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
class Spi{
private:
unsigned char mode;
unsigned char bitsPerWord;
unsigned int speed;
int spifd;
int spiOpen(std::string devspi);
int spiClose();
public:
Spi();
Spi(std::string devspi, unsigned char spiMode, unsigned int spiSpeed, unsigned char spibitsPerWord);
~Spi();
int spiWriteRead( unsigned char *data, int length);
};
#endif /* SPI_H_ */