Project

General

Profile

Revision 4

Import Lab2/

View differences:

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

  
4
# source code files to be compiled
5
SRCS = lab2.c timer.c utils.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

  
lab2/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
 *
9
 * Constants for programming the i8254 Timer. Needs to be completed.
10
 */
11

  
12
#define TIMER_FREQ 1193182 /**< @brief clock frequency for timer in PC and AT */
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

  
39
/* Operating mode: bits 3, 2 and 1 */
40

  
41
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
42
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
43

  
44
/* Counting mode: bit 0 */
45

  
46
#define TIMER_BCD 0x01 /**< @brief Count in BCD */
47
#define TIMER_BIN 0x00 /**< @brief Count in binary */
48

  
49
/* READ-BACK COMMAND FORMAT */
50

  
51
#define TIMER_RB_COUNT_  BIT(5)
52
#define TIMER_RB_STATUS_ BIT(4)
53
#define TIMER_RB_SEL(n)  BIT((n) + 1)
54

  
55
/**@}*/
56

  
57
#endif /* _LCOM_I8254_H */
0 58

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

  
4
#include <stdbool.h>
5
#include <stdint.h>
6

  
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/lab2/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/lab2/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
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
33
  /* To be implemented by the students */
34
  printf("%s is not yet implemented!\n", __func__);
35

  
36
  return 1;
37
}
38

  
39
int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
40
  /* To be implemented by the students */
41
  printf("%s is not yet implemented!\n", __func__);
42

  
43
  return 1;
44
}
45

  
46
int(timer_test_int)(uint8_t time) {
47
  /* To be implemented by the students */
48
  printf("%s is not yet implemented!\n", __func__);
49

  
50
  return 1;
51
}
0 52

  
lab2/timer.c
1
#include <lcom/lcf.h>
2
#include <lcom/timer.h>
3

  
4
#include <stdint.h>
5

  
6
#include "i8254.h"
7

  
8
int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
9
  /* To be implemented by the students */
10
  printf("%s is not yet implemented!\n", __func__);
11

  
12
  return 1;
13
}
14

  
15
int (timer_subscribe_int)(uint8_t *bit_no) {
16
    /* To be implemented by the students */
17
  printf("%s is not yet implemented!\n", __func__);
18

  
19
  return 1;
20
}
21

  
22
int (timer_unsubscribe_int)() {
23
  /* To be implemented by the students */
24
  printf("%s is not yet implemented!\n", __func__);
25

  
26
  return 1;
27
}
28

  
29
void (timer_int_handler)() {
30
  /* To be implemented by the students */
31
  printf("%s is not yet implemented!\n", __func__);
32
}
33

  
34
int (timer_get_conf)(uint8_t timer, uint8_t *st) {
35
  /* To be implemented by the students */
36
  printf("%s is not yet implemented!\n", __func__);
37

  
38
  return 1;
39
}
40

  
41
int (timer_display_conf)(uint8_t timer, uint8_t st,
42
                        enum timer_status_field field) {
43
  /* To be implemented by the students */
44
  printf("%s is not yet implemented!\n", __func__);
45

  
46
  return 1;
47
}
0 48

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

  
3
#include <stdint.h>
4

  
5
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
6
  /* To be implemented by the students */
7
  printf("%s is not yet implemented!\n", __func__);
8

  
9
  return 1;
10
}
11

  
12
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
13
  /* To be implemented by the students */
14
  printf("%s is not yet implemented!\n", __func__);
15

  
16
  return 1;
17
}
18

  
19
int (util_sys_inb)(int port, uint8_t *value) {
20
  /* To be implemented by the students */
21
  printf("%s is not yet implemented!\n", __func__);
22

  
23
  return 1;
24
}
0 25

  

Also available in: Unified diff