Changeset a6ae6ac in avrstuff for EPRoxygen/device.h


Ignore:
Timestamp:
Jul 9, 2012, 11:05:43 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
16cf6ff
Parents:
34c57e8
Message:

Still not working...
Added very agressive timing, fixed some potential glitches, but still not enough to even read the device ID !

git-svn-id: svn://pulkomandy.tk/avrstuff@60 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EPRoxygen/device.h

    r34c57e8 ra6ae6ac  
    77#include <stdio.h>
    88#include <stdint.h>
     9#include <unistd.h>
    910
    1011// FreeBSD
     
    4243        protected:
    4344                typedef enum {
    44                         NONE =  0b0101, /* Nothing selected */
    45                         NYBLE = 0b0010, /* Read low nyble */
     45                        NONE =  0b0011, /* Nothing selected */
     46                        NYBLE = 0b0100, /* Read low nyble */
    4647                                /* When 0, status reg shows D0.3
    4748                                 * When 1, status reg shows D4.7
    4849                                 */
    49                         CTRL =  0b0011, /* Control reg. */
     50                        CTRL =  0b0101, /* Control reg. */
    5051                                /* b0: A16
    51                                  * b1: /A17
     52                                 * b1: /A17 (A17 is reversed !)
    5253                                 * b2: WE
    5354                                 * b3: A18
     
    7172                                 * b7: VCC enable (1 = power ON)
    7273                                 */
    73                         ADR0 =  0b1011, /* Low address byte A0.7 */
     74                        ADR0 =  0b1101, /* Low address byte A0.7 */
    7475                        DATA =  0b1110, /* Data byte */
    7576                        ADR1 =  0b1111, /* High address byte A8.15 */
     77                                /* A13 is reversed ! (also used as VCC pin in smaller packages)
     78                                 */
    7679                } Register;
     80
     81                static const uint8_t A13 = 1 << 5;
    7782
    7883                typedef enum {
     
    102107                static inline void write(const Register reg, const uint8_t val)
    103108                {
    104                         // The register latches the data only when another register gets
    105                         // selected. If this is a problem, select the NONE reg after
    106                         // writing !
     109                        // To avoid glitches, first set the bits that select the register,
     110                        // then enable the output. And disable the output when we are done
     111                        // while not touching the selected reg. This is the only way to
     112                        // avoid glitches (another reg may be selected long enough for
     113                        // losing some bits)
     114                        outb(port, val);
     115                        usleep(1000);
     116                        outb(port + 2, reg ^ 4);
     117                        usleep(1000);
    107118                        outb(port + 2, reg);
    108                         outb(port, val);
     119                        usleep(1000);
     120                        outb(port + 2, reg ^ 4);
     121                        usleep(1000);
    109122                }
    110123
    111124                static inline uint8_t read()
    112125                {
    113                         uint8_t byte = (inb(port + 1) ^ 0x80) & 0xF0;
     126                        outb(port+2, NYBLE ^ 4);
     127                        usleep(1000);
     128                        uint8_t byte = inb(port + 1) & 0xF0;
    114129
    115130                        outb(port+2, NYBLE);
    116                         byte |= (inb(port + 1) ^ 0x80) >> 4;
    117                         return byte;
     131                        usleep(1000);
     132                        byte |= inb(port + 1) >> 4;
     133printf("R %X", byte ^ 0x88);
     134getchar();
     135                        outb(port+2, NYBLE ^ 4);
     136                        usleep(1000);
     137                        return byte ^ 0x88;
    118138                }
    119139
     140                static int port;
    120141        private:
    121                 static int port;
    122142};
    123143
Note: See TracChangeset for help on using the changeset viewer.