ML-Cai / BBBIOlib

simple I/O library for Beaglebone Black , include some demo
BSD 3-Clause "New" or "Revised" License
70 stars 61 forks source link

Transmit-Only SPI Problem #7

Closed phrogger closed 10 years ago

phrogger commented 10 years ago

I have had good experiences with the GPIO portion of the library, but recently found a bug in the SPI library.

I was using the SPI in a transmit only application, and the library would not run.

It looks like there are two SPI receiver calls in BBBIO_McSPI_work() involving MCSPI_GET_CHSTAT_RXS() and "copy receive data" that are still active, even though it is transmit only. This causes BBBIO_McSPI_work() to hang forever, since receiver is disabled.

I made my application run by commenting out that part of the code, but a general solution would be to make it conditional upon having a receiver enabled.

Thanks for all your work and contributions.

--- Graham

ML-Cai commented 10 years ago

Hi phrogger,

Thank you for reminding me , i'm so sorry , i didn't fixed this issue immediately .

i modified some code for this problem , but i don't have chip to test transmit only application .

could you please help me test these code ?


#modified : BBBio_lib / BBBiolib_McSPI.c

- /* waiting for EOT ,not support interrupt yet , using polling waiting for the moment*/
- reg_value =0;
- while(!MCSPI_GET_CHSTAT_EOT(reg_value)) {
-   reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);
-   sched_yield();
- }
- while(!MCSPI_GET_CHSTAT_RXS(reg_value)) {
-   reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);
-   sched_yield();
- }
- /* copy receive data */
- if(McSPI_Module[McSPI_ID].CH[chn].flag & McSPI_TxRx_Rx) {
-   McSPI_Module[McSPI_ID].CH[chn].Rx = read_reg(mcspi_ptr[McSPI_ID], MCSPI_RX0 + chn_offset);
- }

#modified : BBBio_lib / BBBiolib_McSPI.c

+ /* waiting for EOT ,not support interrupt yet , using polling waiting for the moment*/
+ reg_value =0;
+ if(chn_ptr->flag & McSPI_TxRx_Tx) {
+   while(!MCSPI_GET_CHSTAT_EOT(reg_value)) {
+       reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);
+       sched_yield();
+   }
+ }
+ 
+ if(chn_ptr->flag & McSPI_TxRx_Rx) {
+   while(!MCSPI_GET_CHSTAT_RXS(reg_value)) {
+       reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);
+       sched_yield();
+   }
+   chn_ptr->Rx = read_reg(mcspi_ptr[McSPI_ID], MCSPI_RX0 + chn_offset);
+ }
phrogger commented 10 years ago

Hi Avenger:

I will be glad to test the code.

I am traveling this week, so it may be a week from now before I get back to you.

Thanks, --- Graham

On Mon, Aug 4, 2014 at 6:16 PM, VegetableAvenger notifications@github.com wrote:

Hi phrogger,

Thank you for reminding me , i'm so sorry , i didn't fixed this issue immediately .

i modified some code for this problem , but i don't have chip to test transmit only application .

could you please help me test these code ?

modified : BBBio_lib / BBBiolib_McSPI.c

  • /* waiting for EOT ,not support interrupt yet , using polling waiting for the moment_/- reg_value =0;- while(!MCSPI_GET_CHSTAT_EOT(reg_value)) {- reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);- sched_yield();- }- while(!MCSPI_GET_CHSTAT_RXS(reg_value)) {- reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);- schedyield();- }- / copy receive data */- if(McSPI_Module[McSPI_ID].CH[chn].flag & McSPI_TxRx_Rx) {- McSPI_Module[McSPI_ID].CH[chn].Rx = read_reg(mcspi_ptr[McSPI_ID], MCSPI_RX0 + chn_offset);- }

modified : BBBio_lib / BBBiolib_McSPI.c

  • /* waiting for EOT ,not support interrupt yet , using polling waiting for the moment*/+ reg_value =0;+ if(chn_ptr->flag & McSPI_TxRx_Tx) {+ while(!MCSPI_GET_CHSTAT_EOT(reg_value)) {+ reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);+ sched_yield();+ }+ }+ + if(chn_ptr->flag & McSPI_TxRx_Rx) {+ while(!MCSPI_GET_CHSTAT_RXS(reg_value)) {+ reg_value = read_reg(mcspi_ptr[McSPI_ID], MCSPI_CH0STAT + chn_offset);+ sched_yield();+ }+ chn_ptr->Rx = read_reg(mcspi_ptr[McSPI_ID], MCSPI_RX0 + chn_offset);+ }

Reply to this email directly or view it on GitHub https://github.com/VegetableAvenger/BBBIOlib/issues/7#issuecomment-51130761 .

ML-Cai commented 10 years ago

Thank you for helping me.

I ordered L3G4200D and ADXL345 chip , and i'll test them in this week .

if this patch doesn't work in transmit only mode , i will fixed it as soon as possible.

Thank you VegetableAvenger

phrogger commented 10 years ago

VegetableAvenger: _I can confirm that the changes you made to "BBBiolibMcSPI.c"

_did resolve the problem with SPI TransmitOnly.

I tested this with the latest code that you posted to GitHub two days ago.

Thank you very much for the BBBiolib. It works very well for controllingthe SPI and GPIO functions.

Thanks,

--- Graham==

On Thu, Aug 7, 2014 at 3:06 AM, VegetableAvenger notifications@github.com wrote:

Thank you for helping me.

I ordered L3G4200D and ADXL345 chip , and i'll test them in this week .

if this patch doesn't work in transmit only mode , i will fixed it as soon as possible.

Thank you VegetableAvenger

Reply to this email directly or view it on GitHub https://github.com/VegetableAvenger/BBBIOlib/issues/7#issuecomment-51442643 .

ML-Cai commented 10 years ago

Hi , phrogger

Thank you very much for your help and test !

This issue will be closed .