Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z by Axeda Corp

Committer:
AxedaCorp
Date:
Tue Jul 01 21:31:54 2014 +0000
Revision:
0:65004368569c
Made initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AxedaCorp 0:65004368569c 1 // Simple USBHost for FRDM-KL46Z
AxedaCorp 0:65004368569c 2 #pragma once
AxedaCorp 0:65004368569c 3 #include "mbed.h"
AxedaCorp 0:65004368569c 4 #include "USBHostTypes.h"
AxedaCorp 0:65004368569c 5 #include "USBEndpoint.h"
AxedaCorp 0:65004368569c 6
AxedaCorp 0:65004368569c 7 struct SETUP_PACKET {
AxedaCorp 0:65004368569c 8 uint8_t bmRequestType;
AxedaCorp 0:65004368569c 9 uint8_t bRequest;
AxedaCorp 0:65004368569c 10 uint16_t wValue;
AxedaCorp 0:65004368569c 11 uint16_t wIndex;
AxedaCorp 0:65004368569c 12 uint16_t wLength;
AxedaCorp 0:65004368569c 13 };
AxedaCorp 0:65004368569c 14
AxedaCorp 0:65004368569c 15 #define GET_CONFIGURATION 8
AxedaCorp 0:65004368569c 16
AxedaCorp 0:65004368569c 17 // TOK_PID[5:2]
AxedaCorp 0:65004368569c 18 #define Bus_Timeout 0x00
AxedaCorp 0:65004368569c 19 #define Data_Error 0x0f
AxedaCorp 0:65004368569c 20
AxedaCorp 0:65004368569c 21 enum ODD_EVEN {
AxedaCorp 0:65004368569c 22 ODD = 0,
AxedaCorp 0:65004368569c 23 EVEN = 1,
AxedaCorp 0:65004368569c 24 };
AxedaCorp 0:65004368569c 25
AxedaCorp 0:65004368569c 26 class Report {
AxedaCorp 0:65004368569c 27 public:
AxedaCorp 0:65004368569c 28 void clear();
AxedaCorp 0:65004368569c 29 void print_errstat();
AxedaCorp 0:65004368569c 30 // error count
AxedaCorp 0:65004368569c 31 uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR]
AxedaCorp 0:65004368569c 32 uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF]
AxedaCorp 0:65004368569c 33 uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16]
AxedaCorp 0:65004368569c 34 uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8]
AxedaCorp 0:65004368569c 35 uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR]
AxedaCorp 0:65004368569c 36 uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR]
AxedaCorp 0:65004368569c 37 uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR]
AxedaCorp 0:65004368569c 38 //
AxedaCorp 0:65004368569c 39 uint32_t nak;
AxedaCorp 0:65004368569c 40 uint32_t stall;
AxedaCorp 0:65004368569c 41 };
AxedaCorp 0:65004368569c 42
AxedaCorp 0:65004368569c 43 class USBHALHost {
AxedaCorp 0:65004368569c 44 public:
AxedaCorp 0:65004368569c 45 uint8_t LastStatus;
AxedaCorp 0:65004368569c 46 uint8_t prev_LastStatus;
AxedaCorp 0:65004368569c 47 Report report;
AxedaCorp 0:65004368569c 48
AxedaCorp 0:65004368569c 49 protected:
AxedaCorp 0:65004368569c 50 USBHALHost();
AxedaCorp 0:65004368569c 51 void init();
AxedaCorp 0:65004368569c 52 virtual bool addDevice(int port, int hub, bool lowSpeed) = 0;
AxedaCorp 0:65004368569c 53 void setAddr(int addr, bool lowSpeed = false);
AxedaCorp 0:65004368569c 54 void setEndpoint();
AxedaCorp 0:65004368569c 55 void token_transfer_init();
AxedaCorp 0:65004368569c 56 int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0);
AxedaCorp 0:65004368569c 57 int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10);
AxedaCorp 0:65004368569c 58 int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10);
AxedaCorp 0:65004368569c 59 int token_iso_in(USBEndpoint* ep, uint8_t* data, int size);
AxedaCorp 0:65004368569c 60 void token_ready();
AxedaCorp 0:65004368569c 61 private:
AxedaCorp 0:65004368569c 62 static void _usbisr(void);
AxedaCorp 0:65004368569c 63 void UsbIrqhandler();
AxedaCorp 0:65004368569c 64 __IO bool attach_done;
AxedaCorp 0:65004368569c 65 __IO bool token_done;
AxedaCorp 0:65004368569c 66 bool wait_attach();
AxedaCorp 0:65004368569c 67 bool root_lowSpeed;
AxedaCorp 0:65004368569c 68 ODD_EVEN tx_ptr;
AxedaCorp 0:65004368569c 69 ODD_EVEN rx_ptr;
AxedaCorp 0:65004368569c 70 static USBHALHost * instHost;
AxedaCorp 0:65004368569c 71 };