Project

General

Profile

Revision 144

import proj

View differences:

proj/Makefile
1
PROG=proj
2

  
3
SRCS= proj.c utils.c
4

  
5
CPPFLAGS += -pedantic -D __LCOM_OPTIMIZED_
6

  
7
DPADD += ${LIBLCF}
8
LDADD += -llcf
9

  
10
.include <minix.lcom.mk>
0 11

  
proj/errors.h
1
#ifndef ERRORS_H_INCLUDED
2
#define ERRORS_H_INCLUDED
3

  
4
enum errors {
5
    SUCCESS = 0,        /* @brief Sucessful */
6
    NULL_PTR,           /* @brief Null Pointer Error */
7
    LCF_ERROR,          /* @brief Error originated on LCF */
8
    SBCR_ERROR,         /* @brief Error on Subscribing Interrupt */
9
    UNSBCR_ERROR,       /* @brief Error on Unsubscring Interrupt*/
10
    READ_ERROR,         /* @brief Error on Reading from Port */
11
    WRITE_ERROR,        /* @brief Error on Writing to Port */
12
    TIMEOUT_ERROR,      /* @brief Timeout error */
13
    INVALID_COMMAND,    /* @brief Invalid Command issued */
14
    INVALID_STATE,      /* @brief State machine reached an invalid state */
15
    BIOS_CALL_ERROR,    /* @brief Error upon BIOS call */
16
    OUT_OF_RANGE,       /* @brief Accessing area out of range of memory */
17
    OTHER_ERROR         /* @brief Unspecified error */
18
};
19

  
20
#endif //ERRORS_H_INCLUDED
0 21

  
proj/graphics_macros.h
1
#ifndef GRAPHICS_MACROS_H_INCLUDED
2
#define GRAPHICS_MACROS_H_INCLUDED
3

  
4
#define VC_BIOS_SERV  0x10 /** @brief Interrupt service of video card */
5
#define VBE_CALL      0x4F /** @brief VBE call function specifier */
6

  
7
#define MBYTE_BASE  0x0         /** @brief Base address (zero address) */
8
#define MBYTE_SIZE  0xFFFFF     /** @brief Size of a mebibyte */
9

  
10
// Graphics Functions
11
#define VBE_CTRL_INFO       0x00    /** @brief Get VBE Controller Information */
12
#define VBE_MD_INFO         0x01    /** @brief Get VBE Mode Information */
13
#define SET_VBE_MD          0x02    /** @brief Set VBE Mode */
14

  
15
// Error codes (AH)
16
#define AH_SUCCESS          0x00    /** @brief Success code on BIOS call */
17
#define AH_FUNC_CALL_FAIL   0x01    /** @brief Function call failed */
18
#define AH_FUNC_NOT_SUPP    0x02    /** @brief Function call is not supported in current HW configuration */
19
#define AH_FUNC_INVALID     0x03    /** @brief Invalid function in current video mode */
20

  
21
// Graphics modes
22
#define INDEXED_1024_768        0x105
23
#define DIRECT_640_480          0x110
24
#define DIRECT_800_600          0x115
25
#define DIRECT_1280_1024_565    0x11A
26
#define DIRECT_1280_1024_888    0x11B
27
#define LINEAR_FRAME_BUFFER_MD  BIT(14)
28

  
29
// Colors in RBG (8 bit)
30
#define BLACK               0x000000
31

  
32
#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */
0 33

  
proj/i8254.h
1
#ifndef _LCOM_I8254_H_
2
#define _LCOM_I8254_H_
3

  
4
#include <lcom/lcf.h>
5

  
6
/** @defgroup i8254 i8254
7
 *
8
 * Constants for programming the i8254 Timer. Needs to be completed.
9
 */
10

  
11
#define TIMER_FREQ     1193182                                                          /**< @brief clock frequency for timer in PC and AT */
12
#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0)    /**< @brief mininum frequency for timer */
13
#define TIMER0_IRQ     0                                                                /**< @brief Timer 0 IRQ line */
14

  
15
/* I/O port addresses */
16

  
17
#define TIMER_0    0x40         /**< @brief Timer 0 count register */
18
#define TIMER_1    0x41         /**< @brief Timer 1 count register */
19
#define TIMER_2    0x42         /**< @brief Timer 2 count register */
20
#define TIMER_CTRL 0x43         /**< @brief Control register */
21

  
22
#define SPEAKER_CTRL 0x61       /**< @brief Register for speaker control  */
23

  
24
/* Timer control */
25

  
26
/* Timer selection: bits 7 and 6 */
27

  
28
#define TIMER_SEL0   0x00              /**< @brief Control Word for Timer 0 */
29
#define TIMER_SEL1   BIT(6)            /**< @brief Control Word for Timer 1 */
30
#define TIMER_SEL2   BIT(7)            /**< @brief Control Word for Timer 2 */
31
#define TIMER_RB_CMD (BIT(7) | BIT(6)) /**< @brief Read Back Command */
32

  
33
/* Register selection: bits 5 and 4 */
34

  
35
#define TIMER_LSB     BIT(4)                    /**< @brief Initialize Counter LSB only */
36
#define TIMER_MSB     BIT(5)                    /**< @brief Initialize Counter MSB only */
37
#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB)   /**< @brief Initialize LSB first and MSB afterwards */
38
#define TIMER_INMODE_MASK 0x30                  /**< @brief Mask for Timer Counter Mode */
39
#define TIMER_INMODE_POS  4                     /**< @brief Bit position of Timer Counter Mode */
40

  
41
/* Operating mode: bits 3, 2 and 1 */
42

  
43
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45
#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
46
#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
47
#define TIMER_MODE_2ALT 0x6              /**< @brief Alternative notation for mode 2 */
48
#define TIMER_MODE_3ALT 0x7              /**< @brief Alternative notation for mode 3 */
49
#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
50

  
51
/* Counting mode: bit 0 */
52

  
53
#define TIMER_BCD 0x01 /**< @brief Count in BCD */
54
#define TIMER_BIN 0x00 /**< @brief Count in binary */
55

  
56
/* READ-BACK COMMAND FORMAT */
57

  
58
#define TIMER_RB_COUNT_  BIT(5)         /**< @brief Read counter value on read-back (0 to activate) */
59
#define TIMER_RB_STATUS_ BIT(4)         /**< @brief Read status value on read-back (0 to activate) */
60
#define TIMER_RB_SEL(n)  BIT((n) + 1)   /**< @brief Select timer to read information from */
61

  
62
/**@}*/
63

  
64
#endif /* _LCOM_I8254_H */
0 65

  
proj/kbc_macros.h
1
#ifndef KBC_MACROS_H_INCLUDED
2
#define KBC_MACROS_H_INCLUDED
3

  
4
/* KBC IRQ Line */
5

  
6
#define KBC_IRQ     1   /* @brief KBC Controller IRQ Line */
7
#define MOUSE_IRQ   12  /* @brief Mouse IRQ Line */
8

  
9
/* Delay for KBC */
10
#define DELAY           20000 /* @brief KBC Response Delay */
11
#define KBC_NUM_TRIES   20    /* @brief Number of tries to issue command before timeout */
12

  
13
/* I/O Ports Addresses */
14

  
15
#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
16
#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
17
#define STATUS_REG  0x64 /* @brief KBC Status Register address */
18

  
19
#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
20

  
21
/* KBC Commands */
22
#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
23
#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
24
#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
25
#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
26
#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
27
#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
28
#define MOUSE_DISABLE   0xA7 /* @brief Disable Mouse */
29
#define MOUSE_ENABLE    0xA8 /* @brief Enable Mouse */
30
#define MOUSE_INT_TEST  0xA9 /* @brief Tests Mouse data line */
31
#define MOUSE_WRITE_B   0xD4 /* @brief Write a byte directly to the mouse */
32

  
33
/* Status Byte Masking */
34

  
35
#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
36
#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
37
#define SYS_FLAG        BIT(2) /* @brief System Flag */
38
#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
39
#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
40
#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
41
#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
42
#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
43

  
44
/* Scancode Constants */
45

  
46
#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
47
#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
48
#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
49

  
50
/* Command byte masks */
51
#define INT_KBD         BIT(0)  /* @brief Enable Keyboard Interrupts */
52
#define INT_MOU         BIT(1)  /* @brief Enable Mouse Interrupts */
53
#define DIS_KBD         BIT(4)  /* @brief Disable Keyboard */
54
#define DIS_MOU         BIT(5)  /* @brief Disable Mouse */
55

  
56
#endif //KBC_MACROS_H_INCLUDED
0 57

  
proj/proj.c
1
#include <lcom/lcf.h>
2
#include <lcom/proj.h>
3
#include <lcom/liblm.h>
4

  
5
#include <stdint.h>
6

  
7
int main(int argc, char* argv[]) {
8

  
9
    lcf_set_language("EN-US");
10

  
11
    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
12

  
13
    //lcf_log_output("/home/lcom/labs/proj/output.txt");
14

  
15
    if (lcf_start(argc, argv)) return 1;
16

  
17
    lcf_cleanup();
18

  
19
    return 0;
20
}
0 21

  
proj/temp_macros.h
1
#ifndef TEMP_MACROS_H_INCLUDED
2
#define TEMP_MACROS_H_INCLUDED
3

  
4
// WASD Movement Keys
5
#define W_MAKE_CODE     0x11    /* @brief W Make Code */
6
#define W_BREAK_CODE    0x91    /* @brief W Make Code */
7
#define A_MAKE_CODE     0x1E    /* @brief A Make Code */
8
#define A_BREAK_CODE    0x9E    /* @brief A Make Code */
9
#define S_MAKE_CODE     0x1F    /* @brief S Make Code */
10
#define S_BREAK_CODE    0x9F    /* @brief S Make Code */
11
#define D_MAKE_CODE     0x20    /* @brief D Make Code */
12
#define D_BREAK_CODE    0xA0    /* @brief D Make Code */
13

  
14
// Extra Keys
15
#define ESC_MAKE_CODE   0x01    /* @brief ESC Make Code */
16
#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
17

  
18
#endif /* end of include guard: TEMP_MACROS_H_INCLUDED */
0 19

  
proj/utils.c
1
#include <lcom/lcf.h>
2

  
3
#include "utils.h"
4

  
5
#include <stdint.h>
6
#include "errors.h"
7

  
8
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
9
    if (lsb == NULL) return NULL_PTR;
10
    *lsb = val;
11
    return SUCCESS;
12
}
13

  
14
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
15
    if (msb == NULL) return NULL_PTR;
16
    *msb = (val >> 8);
17
    return SUCCESS;
18
}
19

  
20
#ifdef LAB3
21
    uint32_t sys_inb_counter = 0;
22
#endif
23

  
24
int (util_sys_inb)(int port, uint8_t *value) {
25
    if(value == NULL) return NULL_PTR;
26
    uint32_t n = 0;
27
    if(sys_inb(port, &n)) return READ_ERROR;
28
    *value = n;
29
    return SUCCESS;
30
}
31

  
32
int16_t abs16(int16_t x) {
33
    return (x >= 0) ? (int16_t)(x) : (int16_t)(-x);
34
}
35

  
36
int16_t min(int16_t a, int16_t b){ return (b < a ? b : a); }
37
int16_t max(int16_t a, int16_t b){ return (a < b ? b : a); }
0 38

  
proj/utils.h
1
#ifndef UTILS_H_INCLUDED
2
#define UTILS_H_INCLUDED
3

  
4
/**
5
 * @brief Gets the least significant byte of a 16-bit variable
6
 * @param val 16-bit variable
7
 * @param lsb Pointer to a 8-bit variable to store the value of the LSB
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 */
10
int(util_get_LSB)(uint16_t val, uint8_t *lsb);
11

  
12
/**
13
 * @brief Gets the most significant byte of a 16-bit variable
14
 * @param val 16-bit variable
15
 * @param lsb Pointer to a 8-bit variable to store the value of the MSB
16
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
17
 */
18
int(util_get_MSB)(uint16_t val, uint8_t *msb);
19

  
20
/**
21
 * @brief sys_inb wrapper
22
 * @param port Port to read from
23
 * @param value Pointer to byte to store value read
24
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
25
 */
26
int (util_sys_inb)(int port, uint8_t *value);
27

  
28
/**
29
 * @brief Gets the minimum value out of two values.
30
 * @param a     First value
31
 * @param b     Second value
32
 * @return  The minimum of the two values
33
 */
34
int16_t min(int16_t a, int16_t b);
35

  
36
/**
37
 * @brief Gets the maximum value out of two values.
38
 * @param a     First value
39
 * @param b     Second value
40
 * @return  The maximum of the two values
41
 */
42
int16_t max(int16_t a, int16_t b);
43

  
44

  
45
#endif //UTILS_H_INCLUDED
0 46

  

Also available in: Unified diff