FireBirdLib - Topfield TMS PVR TAP Programming Library
FBLib_hdd.h
Go to the documentation of this file.
1#ifndef FBLIB_HDD_H
2#define FBLIB_HDD_H
3
4#include <sys/types.h>
5#include "tap.h"
6#include "libFireBird.h"
7
8//HDD Functions
9// CCD DD
10// SSA AA
11// 102 10
12//ATA Controller H/W Address: 1011 0000 0000 0001 0010 1101 0... ..xx
13//
14//
15// CS1 CS0 DA2 DA1 DA0 R/W
16//Data Port (DMA) 0 0 X X X RW 0xB0012D00
17
18//Data Reg (PIO) 0 1 0 0 0 RW 0xB0012D20
19//Error Reg 0 1 0 0 1 R (W=Feature Reg) 0xB0012D24
20//Feature Reg 0 1 0 0 1 W (R=Error Reg) 0xB0012D24
21//SectorCount Reg 0 1 0 1 0 RW 0xB0012D28
22//LBALow Reg 0 1 0 1 1 RW 0xB0012D2C
23//LBAMid Reg 0 1 1 0 0 RW 0xB0012D30
24//LBAHigh Reg 0 1 1 0 1 RW 0xB0012D34
25//Device Reg 0 1 1 1 0 RW 0xB0012D38
26//Status Reg 0 1 1 1 1 R (W=Command Reg) 0xB0012D3C
27//Command Reg 0 1 1 1 1 W (R=Status) 0xB0012D3C
28//
29//Alternate Status Reg 1 0 1 1 0 R (W=Control) 0xB0012D58
30//Device Control Reg 1 0 1 1 0 W (R=Alternate Status) 0xB0012D58
31//Invalid 1 1 X X X X 0xB0012D60-0xB0012D7F
32
33#define oTAP_Hdd_ReadSectorDMA 0x00
34#define oTAP_Hdd_WriteSectorDMA 0x01
35#define oTAP_Hdd_Move 0x13
36
37#define FBHDIO_DRIVE_CMD_HDR_SIZE (4 * sizeof(unsigned char))
38#define FBHDIO_DRIVE_TASK_HDR_SIZE (8 * sizeof(unsigned char))
39#define WIN_SMART 0xB0
40#define SMART_READ_VALUES 0xD0
41#define SMART_READ_THRESHOLDS 0xD1
42#define SMART_STATUS 0xDA
43#define SMART_AUTOSAVE 0xD2
44#define WIN_SETFEATURES 0xEF
45#define SETFEATURES_EN_AAM 0x42 /* Enable Automatic Acoustic Management */
46#define SETFEATURES_DIS_AAM 0xC2 /* Disable Automatic Acoustic Management */
47#define SETFEATURES_EN_APM 0x05 /* Enable advanced power management */
48#define SETFEATURES_DIS_APM 0x85 /* Disable advanced power management */
49#define SMART_ENABLE 0xD8
50#define SMART_DISABLE 0xD9
51#define HDIO_DRIVE_TASK 0x031e /* execute task and special drive command */
52#define HDIO_DRIVE_CMD 0x031f /* execute a special drive command */
53
54
55typedef dword (*tTAP_Hdd_ReadSectorDMA)(dword SectorNr, dword NrSectors, void *Buffer);
56typedef dword (*tTAP_Hdd_WriteSectorDMA)(dword SectorNr, dword NrSectors, void *Buffer);
57typedef dword (*tTAP_Hdd_Move)(char *from_dir, char *to_dir, char *filename);
58
59#define endian_swap_word(x) *x = (*x << 8) | (*x >> 8)
60
61#define DIR_MAX_STACK 16
62#define FATENTRYSIZE 3
63
64typedef struct
65{
66 dword Cluster;
67 dword Entry;
68 dword DirLen;
69} DirEntry;
70
71//We've to use the 64-bit version of lstat() else it will fail with files >= 4GB
72typedef struct
73{
74 __dev_t st_dev;
75 long int st_pad1[2];
76 __ino64_t st_ino;
77 __mode_t st_mode;
78 __nlink_t st_nlink;
79 __uid_t st_uid;
80 __gid_t st_gid;
81 __dev_t st_rdev;
82 long int st_pad2[2];
83 __off64_t st_size;
84 __time_t st_atime;
85 long int __reserved0;
86 __time_t st_mtime;
87 long int __reserved1;
88 __time_t st_ctime;
89 long int __reserved2;
90 __blksize_t st_blksize;
91 long int st_pad4;
92 __blkcnt64_t st_blocks;
93 long int st_pad5[14];
94} tstat64;
95
96extern int lstat64(__const char *__restrict __file, tstat64 *__restrict __buf) __THROW;
97extern int stat64(__const char *__restrict __file, tstat64 *__restrict __buf) __THROW;
98
99extern volatile word *HDD_pData;
100extern volatile byte *HDD_pError;
101extern volatile byte *HDD_pFeature;
102extern volatile byte *HDD_pSecCount;
103extern volatile byte *HDD_pLBALow;
104extern volatile byte *HDD_pLBAMid;
105extern volatile byte *HDD_pLBAHigh;
106extern volatile byte *HDD_pDevice;
107extern volatile byte *HDD_pStatus;
108extern volatile byte *HDD_pCommand;
109extern volatile byte *HDD_pAltStatus;
110//extern volatile byte *HDD_pDevControl; /* = (byte*) 0xb0012d5b; // device control register */
113
114extern int _appl_version;
115extern bool LibInitialized;
116extern void* (*TAP_GetSystemProc)(int);
117
118void busyWait(void);
119void Delay(dword);
121
122int SendHDDCommand(dword, const byte*, int);
123
124void SwapWords(word *);
125void SwapDWords(dword *);
126int ReceiveSector(word *);
127bool ChangeDirRoot(void);
128dword CalcAbsSectorFromFAT(TYPE_File *, dword);
129bool PushDirEntry (dword Cluster, dword Entry, dword DirLen);
130bool PopDirEntry (dword *Cluster, dword *Entry, dword *DirLen);
131inline dword getNextCluster(dword c);
132
133//The latest version of the SmartFiler Recycle Bin
134
135#define RECYCLEPATH "/DataFiles/RecycleBin-/"
136
137typedef struct __STDIO_FILE_STRUCT FILE;
138
139extern FILE *fopen64 (__const char *__restrict __filename, __const char *__restrict __modes);
140extern int fseeko64(FILE *__stream, __off64_t __off, int __whence);
141
142#endif
void busyWait(void)
dword(* tTAP_Hdd_WriteSectorDMA)(dword SectorNr, dword NrSectors, void *Buffer)
Definition: FBLib_hdd.h:56
volatile byte * HDD_pSecCount
int SendHDDCommand(dword, const byte *, int)
Definition: SendHDDCommand.c:4
int _appl_version
bool PopDirEntry(dword *Cluster, dword *Entry, dword *DirLen)
struct __STDIO_FILE_STRUCT FILE
Definition: FBLib_hdd.h:137
volatile byte * HDD_pLBALow
dword getNextCluster(dword c)
int stat64(__const char *__restrict __file, tstat64 *__restrict __buf) __THROW
volatile byte * HDD_pCommand
bool LibInitialized
Definition: InitTAPex.c:8
void Delay(dword)
Definition: Delay.c:3
dword(* tTAP_Hdd_ReadSectorDMA)(dword SectorNr, dword NrSectors, void *Buffer)
Definition: FBLib_hdd.h:55
volatile word * HDD_pData
volatile byte * HDD_pAltStatus
bool PushDirEntry(dword Cluster, dword Entry, dword DirLen)
void SwapDWords(dword *)
Definition: SwapDWords.c:3
volatile byte * HDD_pFeature
int ReceiveSector(word *)
int fseeko64(FILE *__stream, __off64_t __off, int __whence)
FILE * fopen64(__const char *__restrict __filename, __const char *__restrict __modes)
dword CalcAbsSectorFromFAT(TYPE_File *, dword)
volatile byte * HDD_pDevice
tTAP_Hdd_WriteSectorDMA TAP_Hdd_WriteSectorDMA
volatile byte * HDD_pStatus
volatile byte * HDD_pError
dword(* tTAP_Hdd_Move)(char *from_dir, char *to_dir, char *filename)
Definition: FBLib_hdd.h:57
void SwapWords(word *)
Definition: SwapWords.c:3
int lstat64(__const char *__restrict __file, tstat64 *__restrict __buf) __THROW
volatile byte * HDD_pLBAHigh
int GetClusterPointer(int)
bool ChangeDirRoot(void)
Definition: ChangeDirRoot.c:5
volatile byte * HDD_pLBAMid
tTAP_Hdd_ReadSectorDMA TAP_Hdd_ReadSectorDMA
dword DirLen
Definition: FBLib_hdd.h:68
dword Cluster
Definition: FBLib_hdd.h:66
dword Entry
Definition: FBLib_hdd.h:67
__blksize_t st_blksize
Definition: FBLib_hdd.h:90
__time_t st_mtime
Definition: FBLib_hdd.h:86
__blkcnt64_t st_blocks
Definition: FBLib_hdd.h:92
__gid_t st_gid
Definition: FBLib_hdd.h:80
__time_t st_ctime
Definition: FBLib_hdd.h:88
long int __reserved1
Definition: FBLib_hdd.h:87
__mode_t st_mode
Definition: FBLib_hdd.h:77
__time_t st_atime
Definition: FBLib_hdd.h:84
long int st_pad4
Definition: FBLib_hdd.h:91
__nlink_t st_nlink
Definition: FBLib_hdd.h:78
long int __reserved0
Definition: FBLib_hdd.h:85
long int __reserved2
Definition: FBLib_hdd.h:89
__dev_t st_rdev
Definition: FBLib_hdd.h:81
__dev_t st_dev
Definition: FBLib_hdd.h:74
__off64_t st_size
Definition: FBLib_hdd.h:83
__uid_t st_uid
Definition: FBLib_hdd.h:79
__ino64_t st_ino
Definition: FBLib_hdd.h:76