-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample.c
More file actions
57 lines (44 loc) · 1.19 KB
/
Copy pathexample.c
File metadata and controls
57 lines (44 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* example.c
*
* Created: 7/6/2018 3:41:50 PM
* Author : lucah
*
* This example will write a pattern to sector 1024 before reading from the same sector
* and checking the pattern to test the connection to the drive and if data is stored correctly.
*
* If the test failed, pin PD4 is switched to high, if it succeeds, pin PD3 is switched to high.
*
* This test will also fail if any partition currently occupies said sector to prevent data loss.
*/
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "ata.h"
void error() {
PORTD |= (1 << PD4);
while(1);
}
int main(void) {
DDRD |= (1 << PD4) | (1 << PD3);
uint8_t err = ata_init();
if(err != 0) error();
for(uint8_t i = 0; i < 4; i++) {
if(ata_getPartitionSize(0) != 0 && ata_getPartitionLocation(i) <= 1024) error();
}
uint8_t buff[512];
for(uint16_t i = 0; i < 512; i++){
buff[i] = i % 64 + 7;
}
ata_writeSector(buff, 1024);
for(uint8_t i = 0; i < 100; i++) _delay_ms(10);
ata_readSector(buff, 1024);
for(uint16_t i = 0; i < 512; i++){
if(buff[i] != i % 64 + 7) error();
}
ata_writeByte(REG_STAT_CMD, CMD_STANDBY_NOW);
PORTD |= (1 << PD3);
while(1);
}