source: trunk/softs/tsar_boot/drivers/reset_bdv.c @ 897

Last change on this file since 897 was 758, checked in by cfuguet, 10 years ago

tsar_boot: improving configuration infrastructure

  • Using hard_config.h which respects the same sintax that the hard_config.h file of all TSAR platforms. This file can be then generated by the GIET-VM genmap tool or written manually.
  • All peripheral drivers have been moved to a drivers directory and they are compiled as a static library. This allows GCC to only include in the final .ELF the object files of used peripherals and not all of them.
  • Example hard_config.h and ldscripts have been introduced in the conf directory.
  • Improving comments in all files
File size: 2.0 KB
Line 
1/**
2 * \file   reset_bdv.c
3 * \date   December 14, 2014
4 * \author Cesar Fuguet
5 */
6#include <reset_bdv.h>
7#include <reset_tty.h>
8#include <reset_inval.h>
9#include <io.h>
10#include <defs.h>
11
12#ifndef SEG_IOC_BASE
13#    error "SEG_IOC_BASE constant must be defined in the hard_config.h file"
14#endif
15
16static int* const ioc_address = (int* const)SEG_IOC_BASE;
17
18enum block_device_registers {
19    BLOCK_DEVICE_BUFFER,
20    BLOCK_DEVICE_LBA,
21    BLOCK_DEVICE_COUNT,
22    BLOCK_DEVICE_OP,
23    BLOCK_DEVICE_STATUS,
24    BLOCK_DEVICE_IRQ_ENABLE,
25    BLOCK_DEVICE_SIZE,
26    BLOCK_DEVICE_BLOCK_SIZE,
27};
28
29enum block_device_operations {
30    BLOCK_DEVICE_NOOP,
31    BLOCK_DEVICE_READ,
32    BLOCK_DEVICE_WRITE,
33};
34
35enum block_device_status {
36    BLOCK_DEVICE_IDLE,
37    BLOCK_DEVICE_BUSY,
38    BLOCK_DEVICE_READ_SUCCESS,
39    BLOCK_DEVICE_WRITE_SUCCESS,
40    BLOCK_DEVICE_READ_ERROR,
41    BLOCK_DEVICE_WRITE_ERROR,
42    BLOCK_DEVICE_ERROR,
43};
44
45int reset_bdv_init()
46{
47    return 0;
48}
49
50int reset_bdv_read( unsigned int lba, void* buffer, unsigned int count )
51{
52    /*
53     * block_device configuration
54     */
55    iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER], (unsigned int) buffer );
56    iowrite32( &ioc_address[BLOCK_DEVICE_COUNT], count );
57    iowrite32( &ioc_address[BLOCK_DEVICE_LBA], lba );
58    iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE], 0 );
59
60    /*
61     * block_device trigger transfer
62     */
63    iowrite32( &ioc_address[BLOCK_DEVICE_OP], ( unsigned int )
64               BLOCK_DEVICE_READ );
65
66    unsigned int status = 0;
67    while ( 1 )
68    {
69        status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]);
70        if ( status == BLOCK_DEVICE_READ_SUCCESS )
71        {
72            break;
73        }
74        if ( status == BLOCK_DEVICE_READ_ERROR   ) {
75            reset_puts("ERROR during read on the BLK device\n");
76            return 1;
77        }
78    }
79
80#if (RESET_HARD_CC == 0) || USE_IOB
81    reset_buf_invalidate(buffer, count * 512, USE_IOB);
82#endif
83    return 0;
84}
85
86/*
87 * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
88 */
Note: See TracBrowser for help on using the repository browser.