Project

General

Profile

Revision 51

Import lab4/

View differences:

lab4/Makefile
1
# name of the program (Minix service)
2
PROG=lab4
3

  
4
# source code files to be compiled
5
SRCS = lab4.c
6

  
7
# additional compilation flags
8
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
9
CFLAGS += -pedantic
10

  
11
# list of library dependencies (for Lab 2, only LCF library)
12
DPADD += ${LIBLCF}
13
LDADD += -llcf
14

  
15
# include LCOM's makefile that does all the "heavy lifting"
16
.include <minix.lcom.mk>
0 17

  
lab4/errors.h
1
#ifndef _ERRORS_H_
2
#define _ERRORS_H_
3

  
4
enum errors {
5
    SUCESS = 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
    USBCR_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
};
13

  
14
#endif /* end of include guard: _ERRORS_H_ */
0 15

  
lab4/kbc.h
1
#ifndef _KBC_H_
2
#define _KBC_H_
3

  
4
/* KBC IRQ Line */
5

  
6
#define KBC_IRQ     1 /* @brief KBC Controller IRQ Line */
7

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

  
12
/* I/O Ports Addresses */
13

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

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

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

  
32
/* Status Byte Masking */
33

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

  
43
/* Scancode Constants */
44

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

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

  
55
#endif
0 56

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

  
3
#include <stdint.h>
4
#include <stdio.h>
5

  
6
// Any header files included below this line should have been created by you
7

  
8
int main(int argc, char *argv[]) {
9
  // sets the language of LCF messages (can be either EN-US or PT-PT)
10
  lcf_set_language("EN-US");
11

  
12
  // enables to log function invocations that are being "wrapped" by LCF
13
  // [comment this out if you don't want/need/ it]
14
  lcf_trace_calls("/home/lcom/labs/lab4/trace.txt");
15

  
16
  // enables to save the output of printf function calls on a file
17
  // [comment this out if you don't want/need it]
18
  lcf_log_output("/home/lcom/labs/lab4/output.txt");
19

  
20
  // handles control over to LCF
21
  // [LCF handles command line arguments and invokes the right function]
22
  if (lcf_start(argc, argv))
23
    return 1;
24

  
25
  // LCF clean up tasks
26
  // [must be the last statement before return]
27
  lcf_cleanup();
28

  
29
  return 0;
30
}
31

  
32

  
33
int (mouse_test_packet)(uint32_t cnt) {
34
}
35

  
36
int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
37
    /* To be completed */
38
    printf("%s(%u, %u): under construction\n", __func__, period, cnt);
39
    return 1;
40
}
41

  
42
int (mouse_test_async)(uint8_t idle_time) {
43
    /* To be completed */
44
    printf("%s(%u): under construction\n", __func__, idle_time);
45
    return 1;
46
}
47

  
48
int (mouse_test_gesture)() {
49
    /* To be completed */
50
    printf("%s: under construction\n", __func__);
51
    return 1;
52
}
0 53

  
lab4/mouse.h
1
#ifndef _MOUSE_H_
2
#define _MOUSE_H_
3

  
4
/* Mouse Data Packet */
5
// Byte 0 - Button States
6
#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
7
#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
8
#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
9
#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
10
#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
11
#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
12
#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
13
#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
14
// Byte 1 - X delta
15
// Byte 2 - Y delta
16

  
17
/* Mouse Commands */
18
#define RESET           0xFF /* @brief Reset mouse */
19
#define RESEND          0xFE /* @brief Resend command */
20
#define DEFAULT         0xF6 /* @brief Set default values */
21
#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
22
#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
23
#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
24
#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
25
#define READ_DATA       0xEB /* @brief Sends data packet request */
26
#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
27
#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
28
#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
29
#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
30
#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
31

  
32
/* Mouse Controller Responses */
33
#define ACK_OK      0xFA /* @brief Operation sucessful */
34
#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
35
#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
36

  
37
#endif // _MOUSE_H_
0 38

  
lab4/utils.c
1
#include "errors.h"
2

  
3
#include <lcom/lcf.h>
4

  
5
#include <stdint.h>
6

  
7
int (util_sys_inb)(int port, uint8_t *value) {
8
    if(value == NULL) return NULL_PTR;
9
    uint32_t n = 0;
10
    if(sys_inb(port, &n)) return READ_ERROR;
11
    *value = n;
12
    return SUCCESS;
13
}
0 14

  

Also available in: Unified diff