Changeset 8659a17 in avrstuff


Ignore:
Timestamp:
Sep 3, 2012, 8:21:47 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
c8ec8ce
Parents:
f0689d3
Message:

Progress on the host driver. Still untested.

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

Location:
V-USB_Dev/firmwares/herePic
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • V-USB_Dev/firmwares/herePic/driver/Makefile

    rf0689d3 r8659a17  
    1 herepic: herepic.cpp
    2         g++ -o $@ $^ -Os -Wall -ldevice
     1herepic: herepic.cpp icsp.h ../shared.h
     2        g++ -o $@ $< -Os -Wall -ldevice
  • V-USB_Dev/firmwares/herePic/driver/herepic.cpp

    rf0689d3 r8659a17  
    1515#include <USBKit.h>
    1616
     17#include "../shared.h"
     18#include "icsp.h"
    1719
    18 // We need a subclass of USBRoster to enumerate devices. The Deviceadded hook
    19 // will be called for all plugged devices. If we don't find the correct one,
    20 // it will also be called later, as devices are plugged. So we can wait for the
    21 // right device to come in !
     20
     21// We need a subclass of USBRoster to enumerate devices.
    2222class MyUSBRoster: public BUSBRoster {
    2323        public:
     
    3535                }
    3636
     37                /* The DeviceAdded hook will be called for all plugged devices.
     38                If we don't find the correct one, the method will also be called later,
     39                as devices are plugged. So we can wait for the right device to come in!
     40                */
    3741                status_t DeviceAdded(BUSBDevice* device)
    3842                {
     
    4145                                && strcmp(device->ProductString(), "HerePic") == 0)
    4246                        {
    43                                 std::cout << "Programmer found !" << std::endl;
    44                                 // TODO send message to main app to tell it we're ready to go.
    4547                                fDevice = device;
     48                                // Notify main thread it's ok to continue
    4649                                sem_post(&fDeviceLock);
    4750                        }
     
    121124        } while(nextopt != -1);
    122125
    123         if (action <= 0)
     126        // If we found no valid action request, print usage and exit
     127        if (action <= 0 || action == 'h')
    124128        {
    125129                usage(argv[0]);
    126                 exit(action);
     130                // Exit code is EXIT_SUCCESS if we reach this by -h option. Otherwise
     131                // the arguments are incorrect
     132                exit(action < 0 ? action : 0);
    127133        }
    128134
    129         // TODO take action depending on command request in CLI
    130135        // TODO handle the boring usb stuff... (might be nice to abstract it so we
    131136        // can use both libusb and haiku usb kit)
     
    140145
    141146        int deviceAvailable;
     147        // TODO we rely on the initial device scan being done when we get here. Is
     148        // that always true ? If not, we may print this message in cases where it
     149        // is not needed.
    142150        sem_getvalue(&deviceLock, &deviceAvailable);
    143151        if(deviceAvailable == 0)
    144152        {
    145                 std::cout << "Programmer not connected. Waiting for it..." << std::endl;
     153                std::cout << "Programmer hardware not detected. Please connect it now..." << std::endl;
    146154        }
    147155
     156        // Wait for the device
    148157        sem_wait(&deviceLock);
    149158
    150         // Here, perform the programming cycle !
     159        ICSP icsp(*theDevice);
     160
     161        // take action depending on command request in CLI
    151162        switch(action)
    152163        {
    153164                case 'r':
     165                        // read the chip
     166                        icsp.Read(filename);
     167                        break;
    154168                case 'w':
     169                        icsp.Write(filename);
     170                        // Here, perform the programming cycle !
     171                        break;
    155172                case 'e':
    156                         ;
     173                        icsp.Erase();
     174                        // erase the chip
     175                        break;
    157176        }
     177
     178        exit(0);
    158179}
  • V-USB_Dev/firmwares/herePic/main.c

    rf0689d3 r8659a17  
    1 /* HEREPIC - AVR-based ICSP programmer for microchip PIC16F6xx and 16F8xx devices
    2  * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.tk>
    3  *
    4  * This file is distributed under the terms of the MIT licence.
    5  */
    61
    72/* This project is targetted at the VUSBDev hacking board. */
     
    1712
    1813#include "usbdrv/usbdrv.h"
     14#include "shared.h"
    1915
    2016// IO pins:
     
    3935// Timers may make it easier to do that in parallel with the USB handling, since
    4036// timings are in the nanosecond range.
    41 
    42 
    43 // ICSP commands are 6-bit wide, for most of them (but not all) the 2 MSb are
    44 // ignored.
    45 // We also use these as USB commands for now, but we may do otherwise, since
    46 // transferring only 14 data bytes in an USB frame is quite a bit of waste.
    47 // We need some custom commands on USB side as well, to reset the PIC and such
    48 // things.
    49 typedef enum
    50 {
    51         // HOST to DEVICE
    52         LoadConfigWord          =   0b0000,
    53         LoadCodeWord            =   0b0010,
    54         LoadDataWord            =   0b0011,
    55 
    56         // Configuration
    57         NextAddress                     =   0b0110,
    58         BeginEraseProgram       = 0b001000,
    59         BeginProgramOnly        = 0b011000,
    60         BulkEraseCode           =   0b1001,
    61         BulkEraseData           =   0b1011,
    62         BulkEraseConfig1        = 0b000001,
    63         BulkEraseConfig2        = 0b000111,
    64 
    65         // DEVICE to HOST
    66         ReadCodeWord            =   0b0100,
    67         ReadDataWord            =   0b0101,
    68 } ICSPCommands;
    6937
    7038
Note: See TracChangeset for help on using the changeset viewer.