Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano-7 committed May 10, 2023
2 parents 09fb1d4 + 60d5f0d commit bff3391
Show file tree
Hide file tree
Showing 47 changed files with 1,162 additions and 968 deletions.
73 changes: 0 additions & 73 deletions lab2/.clang-format

This file was deleted.

19 changes: 0 additions & 19 deletions lab2/.vscode/c_cpp_properties.json

This file was deleted.

11 changes: 0 additions & 11 deletions lab2/.vscode/extensions.json

This file was deleted.

12 changes: 4 additions & 8 deletions lab2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"git.ignoreLimitWarning": true,
"C_Cpp.clang_format_fallbackStyle": "LLVM",
"diffEditor.ignoreTrimWhitespace": true,
"editor.formatOnSave": false,
"editor.tabSize": 2,
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 100,
"files.associations": { },
"files.associations": {
"*.embeddedhtml": "html",
"i8254.h": "c"
}
}
8 changes: 2 additions & 6 deletions lab2/i8254.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

/* I/O port addresses */

#define TIMER_0 0x40 /**< @brief Timer 0 count register */
#define TIMER_1 0x41 /**< @brief Timer 1 count register */
#define TIMER_2 0x42 /**< @brief Timer 2 count register */
#define TIMER_REG(n) 0x40+n
#define TIMER_CTRL 0x43 /**< @brief Control register */

#define SPEAKER_CTRL 0x61 /**< @brief Register for speaker control */
Expand All @@ -25,9 +23,7 @@

/* Timer selection: bits 7 and 6 */

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

/* Register selection: bits 5 and 4 */
Expand Down
88 changes: 42 additions & 46 deletions lab2/lab2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#include <stdbool.h>
#include <stdint.h>
#include <i8254.h>

extern int counter;
extern int timer_counter;

int main(int argc, char *argv[]) {
// sets the language of LCF messages (can be either EN-US or PT-PT)
Expand All @@ -32,66 +31,63 @@ int main(int argc, char *argv[]) {
}

int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
if(timer < 0 || timer > 2){
printf("There's only 3 timers\n");
return 1;
}

uint8_t st;
if(timer_get_conf(timer, &st)){
printf("Error getting config from timer %d\n", timer);
return 1;
printf("timer_test_read_config() -> Error geting the timer configuration\n");
return 1;
}

return timer_display_conf(timer, st, field);
if(timer_display_conf (timer, st, field)){
printf("timer_test_read_config() -> Error while displaying the timer's configuration");
return 1;
}
return 0;
}

int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
if(timer < 0 || timer > 2){
printf("There's only 3 timers\n");
return 1;
if(timer_set_frequency(timer, freq)){
printf("timer_test_time_base() -> Error setting timer %d frequency", timer);
return 1;
}
return timer_set_frequency(timer, freq);
return 0;
}

int(timer_test_int)(uint8_t time) {
int r;
int ipc_status;
message msg;
uint8_t bit_no;

if(timer_subscribe_int(&bit_no)) {
printf("Error while calling subscribing the timer\n"); return 1;}

uint8_t irq_set = BIT(bit_no);
int ipc_status, r;
message msg;
uint8_t timer_bit_no;

if(timer_subscribe_int(&timer_bit_no)){
printf("timer_test_int() -> Error subscribing timer interrupts\n");
return 1;
}

while(time > 0){
if((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
printf("driver_receive failed with: %d", r);
continue;
}

if (is_ipc_notify(ipc_status)) {
switch (_ENDPOINT_P(msg.m_source)) {
case HARDWARE:
if (msg.m_notify.interrupts & irq_set) {
timer_int_handler();

if(counter % 60 ==0){
timer_print_elapsed_time();
time--;
}
while(time) {
if ( (r = driver_receive(ANY, &msg, &ipc_status))) {
printf("driver_receive failed with: %d", r);
continue;
}
if (is_ipc_notify(ipc_status)){
switch (_ENDPOINT_P(msg.m_source)) {
case HARDWARE:
if (msg.m_notify.interrupts & BIT(timer_bit_no)) {
timer_int_handler();
if(timer_counter % 60==0){
time--;
timer_print_elapsed_time();
}
break;

default:
break;
}
break;
default:
break;
}
}
}

if(timer_unsubscribe_int()) {printf("Error while calling timer_unsubscribe_int\n"); return 1;}

return 0;
if(timer_unsubscribe_int()){
printf("timer_test_int() -> Error unsubscribing timer interrupts\n");
return 1;
}

return 0;
}
Loading

0 comments on commit bff3391

Please sign in to comment.