RetroBSD

2.11BSD operating system for microcontrollers
It is currently Fri May 24, 2019 4:02 am

All times are UTC




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:01 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
I have just spent a fun evening completely abstracting the SPI interfaces in the partition branch.

I haven't yet converted the SPI driver (/dev/spi*) to the new abstracted system so it can't be used, but I'll get round to it.

What it means is that a device driver that wants to use SPI, instead of doing all the SPI works itself, it now calls some standard SPI manipulation functions.

Those functions keep track of the CS pins for each device on the bus, and also the baud rate and communications settings for each device.

It should mean that it is now possible to put multiple devices on to one bus that use different communications parameters, and have them work nicely together.

It also means that you have some nice functions available for your ramdisk drivers, including 32-bit bulk transfer functions for blistering performance:

Code:
# rdprof -w -r 10 -b 2000 -d /dev/rd1
RetroDisk Profiler
Write tests enabled!
Testing read of /dev/rd1 from 0 to 1999 with 1024 byte blocks...
Time taken: 17.305000 seconds.  Speed: 1155.735352 KBytes/second
Testing write of /dev/rd1 from 0 to 1999 with 1024 byte blocks...
Time taken: 17.350000 seconds.  Speed: 1152.737671 KBytes/second


I can't remember what it was before off hand, but that's running at 10MHz, using the blistering fast 32-bit enhanced buffer code from the SD driver.

It also means that the specification in the makefiles for SPI devices changes slightly. Instead of specifying "SPI2CON" as the SPI device, you just reference it by number (1 thru 4). For example:

Code:
DEFS            += -DSD_PORT=2


I'm not going to check the code in immediately - I want to do a little more cleaning up first, and ideally port the /dev/spi driver, but I just thought I'd let you know what I have been up to.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:05 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Fantastic! It was 2.21MB/sec with enhbuf@20MHz. I would use
DEFS += -DSPI_PORT=2
DEFS += -DI2C_PORT=4
;)

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:11 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Those results were my MRAM, by the way - forgot to mention.

The /dev/spi driver will let you access all the SPI busses, even if they're in use by other things like the SD card. Should all work together nicely.

I am going to try it by moving my MRAMS to SPI2 on this fubarino and see if it all still works.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:13 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
So something like SandForce chip - 3SPI channels with 4mrams on each :)

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:17 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
I'm not familiar with that chip. What is it?

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 10:20 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
SSD controller - used by Intel etc.
SATA III - SandForce - xChannels of 16GB flash chips
Does compression on the fly (500MB/sec wr/rd)

BTW what about compression with pic32 - we have a fast mcu but very slow external memories :D

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 11:12 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
The added load on the SPI bus means the SD card will no longer run at 20MHz, but apart from that:

Code:
2.11 BSD Unix for PIC32, revision 719M build 86:
     Compiled 2012-11-23 by matt@laptop01:
     /home/matt/retrobsd/retrobsd-partition/sys/pic32/fubarino
cpu: 795F512H 80 MHz, bus 80 MHz
oscillator: HS crystal, PLL div 1:2 mult x20
console: USB
sd0: port SPI2, select pin G9
mrams0: port SPI2, size 2048KB, speed 10 Mbit/sec
PP Schema:
sd0: type II, size 1931264 kbytes, speed 10 Mbit/sec
phys mem  = 128 kbytes
user mem  = 96 kbytes
root dev  = rd0a (0,1)
root size = 163840 kbytes
swap dev  = rd1a (1,1)
swap size = 2047 kbytes
/dev/rd0a: 399 files, 63135 used, 100064 free
/dev/rd0c: 142 files, 7645 used, 155554 free
Starting daemons: update cron


2.11 BSD UNIX (pic32) (console)

login:


SD and MRAM sharing the same SPI bus :)

Oh, this should also mean that you can have multiple SD cards (not just two - twenty-two ;) ) on the same bus, and you should be able to unmount / remove / reinsert / remount etc them happily.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 11:14 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Pito wrote:
BTW what about compression with pic32 - we have a fast mcu but very slow external memories :D

Image
You're havin' a giraffe!

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Fri Nov 23, 2012 11:49 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Tomorrows task:

Attach a second SD card slot to SPI2 and make the dual SD code work.

If successful, that would be 2 SD cards, and 4 MRAM chips all running together on the same SPI bus.

... and then I'll try adding something non-disk related to it too ... maybe my VGA controller...

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 10:56 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Gah

Formatting a 4GB card at 13MHz sure does take its sweet time...

Once this card has finished I will be removing it from the SD slot, inserting a different one, partitioning it, and formatting it. All without a reboot or anything

... I hope ...

Then I will try copying some files around.

Once that is done, I will be able to claim that I have 2 SD cards, and 4 MRAM chips, all one one SPI channel, and that you can swap SD cards on a live system (not the boot card of course).

Code:
2.11 BSD Unix for PIC32, revision 719M build 108:
     Compiled 2012-11-24 by matt@laptop01:
     /home/matt/retrobsd/retrobsd-partition/sys/pic32/fubarino
cpu: 795F512H 80 MHz, bus 80 MHz
oscillator: HS crystal, PLL div 1:2 mult x20
console: USB
sd0: port SPI2, select pin G9
sd1: port SPI2, select pin B4
mrams0: port SPI2, size 2048KB, speed 13 Mbit/sec
PP Schema:
sd0: type II, size 1931264 kbytes, speed 13 Mbit/sec
phys mem  = 128 kbytes
user mem  = 96 kbytes
root dev  = rd0a (0,1)
root size = 163840 kbytes
swap dev  = rd2a (2,1)
swap size = 2047 kbytes
/dev/rd0a: 411 files, 63683 used, 99516 free
/dev/rd0c: 6 files, 6 used, 163193 free
Starting daemons: update cron


2.11 BSD UNIX (pic32) (console)

login: root
Password:
Welcome to RetroBSD!
erase, kill ^U, intr ^C
# mkfs /dev/rd1a
Getting disk size for /dev/rd1a
sd1: type SDHC, size 3872256 kbytes, speed 13 Mbit/sec
sd1: type SDHC, size 3872256 kbytes, speed 13 Mbit/sec
Size: 3872255 kbytes
Inodes: 242000

... to be continued ...

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 11:22 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Pants

It doesn't like it.

Got 2 formatted cards. Copied data to one, unmounted it, swapped the cards, can't mount the other - incorrect superblock. Couple more attempts, pop the card in and out a few times, and it panics.

I think it may be caching something somewhere. Also, the act of inserting / removing card 2 might be breaking communications with card 1 somehow and killing things.

I think if you want 2 cards on the same bus, and have them so you can take them out and swap them, you are going to need some kind of buffer between the bus and the card. It could be done with a simple '244, but you'd need a second CS signal for enabling/disabling the '244 (you need to have card CS high while sending it clocks at times, so the '244 would need to be enabled while the card is disabled).

Doable - is it worth it though?

It is so close:

Code:
# mount /dev/rd1a /u
sd1: type SDHC, size 3872256 kbytes, speed 13 Mbit/sec
# cd /u
# ls
[            cp           head         nice         rz           touch
adb          cpp          hostid       nm           sb           tr
adc-demo     crontab      hostname     nohup        scm          true
aout         date         id           ntpdate      sed          tsort
apropos      dc           iostat       od           setty        tty
ar           dd           join         pagesize     sh           uname
as           df           kill         passwd       size         uncompress
awk          diff         la           picoc        sl           uniq
basename     du           last         portio       sleep        vi
basic        echo         lcc          pr           smallc       vmstat
bc           ed           lcpp         printenv     sort         w
cal          egrep        ld           printf       split        wall
cat          env          ln           ps           strip        wc
cb           expr         login        pwd          stty         web-client
cc           false        lol          pwm          su           web-server
chat-server  fgrep        lost+found   ranlib       sum          whatis
chflags      file         ls           rb           sx           whereis
chfn         find         mail         re           sync         who
chgrp        forth        make         renice       sysctl       whoami
chmod        fstat        man          renumber     sz           write
chpass       glcdtest     med          retroforth   tail         xargs
chsh         globdump     mesg         rev          tar          zcat
cmp          globread     mkdir        rm           tee
col          globwrite    more         rmail        telnet
comm         grep         msec         rmdir        test
compress     groups       mv           rx           time
# cd
# umount /u
# mount /dev/rd1a /u
sd1: type SDHC, size 3872256 kbytes, speed 13 Mbit/sec
# cd /u
# ls
lost+found
# cp /etc/* .
# cd
# sync
# ls /u
MAKEDEV     group       passwd      shadow      ttys
fstab       lost+found  rc          shells
gettytab    motd        rc.local    termcap
# umount /u
# mount /dev/rd1a /u
umount: /u: not currently mounted

************************************
*******STACK DUMP START*************
frame = 80007d48
stack data
....

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 11:50 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
I think you have to have those pmosfet switches in Vcc for SD1 and SD2 there.
You want to eject first card (disable cs, switch it off, wait 100ms, take it out), and insert second one (put it in, switch power on, wait 100ms, enable cs)..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 12:56 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Pito wrote:
I think you have to have those pmosfet switches in Vcc for SD1 and SD2 there.
You want to eject first card (disable cs, switch it off, wait 100ms, take it out), and insert second one (put it in, switch power on, wait 100ms, enable cs)..


Could be done that way, yes. Not sure how to go about toggling that IO port tho - you'd need a "remove card" and "insert card" command I guess, that you could run to turn it off and on.

Or could it be done from init/deinit in the SD driver? First open turns the card on, last close turns it off.

Still doesn't solve the fact that the OS gets completely confused and ends up trying to unmount a card that's not mounted when you tell it to mount one.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 1:03 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
I would not make sd1 (system) swappable. SD2 - maybe a button to push - telling the system "please eject it" and a small led (yellow) lits up saying "you can pull out the card". When inserting (while yellow lled lits) you push it in, and push the same button saying "install the card please"..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 1:31 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Pito wrote:
I would not make sd1 (system) swappable. SD2 - maybe a button to push - telling the system "please eject it" and a small led (yellow) lits up saying "you can pull out the card". When inserting (while yellow lled lits) you push it in, and push the same button saying "install the card please"..

I think it can be done automatically for you from the driver.

It does mean that when the card isn't "in use" (i.e., being written to / read from, or mounted and idle) it will be powered off, and when you mount it, or fdisk it, or fsck it, newfs it etc, it will power up. You could add a power LED to it so it lights up when active and goes off when it's safe to remove.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 1:41 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Olimex uses a trick to identify microsd cards on all their dev kits - 1meg resistor to the ground on /cs, I think (no pullup). You may read the /cs line of the sdcard, and when low - the card is pulled out. When the card is inserted, the /cs read is high (because of the internal pullup of most of the cards at /cs).

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 1:46 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Interesting... Gets around the lack of a card sense switch on the micro slots.

I might have to implement something like that as an option to the SD driver. For now though I am just going through all the targets updating them for the new SD settings before checking in the code. Hope it works for everyone ;)

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 2:06 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
OK, checked in to the partition branch lots of changes.

All the Makefiles for the targets have been edited, so you might want to note down any settings before doing an update.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 5:37 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Lot of changes at once ... So hopefully no rollback required :)
Could you add the r714 change (DOS command fix) from trunk please?

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: Abstracted SPI
PostPosted: Sat Nov 24, 2012 9:04 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
I can do better than that...

Code:
# basic
MICRO-BASIC 2.1 - Copyright 1982-2000 Dave Dunfield.
Ready
PRINT DATE$("%Y/%m/%d, %H:%i:%s, %T, ")
2012/11/24, 13:03:09, PST,
Ready


though I have added the fflush anyway.

Code:
# time /u/scripts/logger3 >d
        1.4 real         0.7 user         0.5 sys 

That's logger3 at 1000 iterations. Just a touch quicker :)

Oh, and you can see granularity in the ADC now:
Code:
2012/11/24, 13:15:51, PST,  276, 142, 110, 132, 1016, 0, 98, 129, 0, 1023, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  277, 141, 110, 132, 1016, 0, 98, 129, 0, 1009, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  283, 152, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  283, 163, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  295, 166, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  302, 167, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  313, 170, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  307, 176, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  314, 175, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  320, 174, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  317, 174, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  316, 173, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  320, 167, 67, 82, 1011, 0, 34, 56, 0, 1009, 0, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  304, 167, 80, 139, 1019, 0, 103, 129, 0, 1023, 0, 0, 0,,
2012/11/24, 13:15:51, PST,  304, 167, 80, 139, 1019, 0, 103, 129, 0, 1023, 0, 0, 0,,

About 11 iterations per ADC conversion.

Code:
AD1CON3 = 0b0000111100001111;

runs fast enough to not give granularity, and yet shouldn't swamp the system with interrupts.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission