Skip to content

Commit

Permalink
Added IACM driver
Browse files Browse the repository at this point in the history
  • Loading branch information
azertyfun committed Oct 14, 2016
1 parent c255def commit b5be64e
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 13 deletions.
124 changes: 124 additions & 0 deletions src/drivers/iacm/iacm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "iacm.h"

typedef enum {
ACTION_SET_MODE,
ACTION_SET_RUN_TIME,
ACTION_SET_SLEEP_TIME,
ACTION_SET_INTERRUPT_MESSAGE,
ACTION_GET_CLOCK_RATE,
ACTION_GET_RCLOCK_RATE,
ACTION_RESET_SYSTEM = 0x505
} iacm_action;

void *iacm_init (u16 iacm, u16 UNUSED (int_number), Int_handler *UNUSED (int_handler_location)) {
Iacm_driver_data *data = kmalloc (0, sizeof (Iacm_driver_data));
data->iacm = iacm;

return data;
}


void iacm_destroy (Iacm_driver_data *UNUSED (data)) {
// Nothing to free
}

u16 iacm_update_function (void *data, u16 message, u16 arg1, u16 arg2) {
switch ((Iacm_message)message) {
case IACM_SET_MODE:
iacm_set_mode (data, arg1);
break;
case IACM_SET_RUN_TIME:
iacm_set_run_time (data, arg1);
break;
case IACM_SET_SLEEP_TIME:
iacm_set_sleep_time (data, arg1);
break;
case IACM_SET_INTERRUPT_MESSAGE:
iacm_set_interrupt_message (data, arg1);
break;
case IACM_GET_CLOCK_RATE:
iacm_get_clock_rate (data, (u16 *)arg1, (u16 *)arg2);
break;
case IACM_GET_RCLOCK_RATE:
iacm_get_rclock_rate (data, (u16 *)arg1, (u16 *)arg2);
break;
case IACM_RESET_SYSTEM:
iacm_reset_system (data);
break;
}

return 0;
}


void iacm_set_mode (Iacm_driver_data *data, u16 mode) {
register u16 action __asm("A") = ACTION_SET_MODE;
register u16 arg_b __asm("B") = mode;
__asm volatile("hwi %0"
:
: "X"(data->iacm),
"r"(action),
"r"(arg_b));
}


void iacm_set_run_time (Iacm_driver_data *data, u16 time) {
register u16 action __asm("A") = ACTION_SET_RUN_TIME;
register u16 arg_b __asm("B") = time;
__asm volatile("hwi %0"
:
: "X"(data->iacm),
"r"(action),
"r"(arg_b));
}


void iacm_set_sleep_time (Iacm_driver_data *data, u16 time) {
register u16 action __asm("A") = ACTION_SET_SLEEP_TIME;
register u16 arg_b __asm("B") = time;
__asm volatile("hwi %0"
:
: "X"(data->iacm),
"r"(action),
"r"(arg_b));
}


void iacm_set_interrupt_message (Iacm_driver_data *data, u16 message) {
register u16 action __asm("A") = ACTION_SET_INTERRUPT_MESSAGE;
register u16 arg_b __asm("B") = message;
__asm volatile("hwi %0"
:
: "X"(data->iacm),
"r"(action),
"r"(arg_b));
}


void iacm_get_clock_rate (Iacm_driver_data *data, u16 *rate_high, u16 *rate_low) {
register u16 action __asm("A") = ACTION_GET_CLOCK_RATE;
__asm volatile("hwi %2"
: "=X"(*rate_high),
"=X"(*rate_low)
: "X"(data->iacm),
"r"(action));
}


void iacm_get_rclock_rate (Iacm_driver_data *data, u16 *rate_high, u16 *rate_low) {
register u16 action __asm("A") = ACTION_GET_RCLOCK_RATE;
__asm volatile("hwi %2"
: "=X"(*rate_high),
"=X"(*rate_low)
: "X"(data->iacm),
"r"(action));
}


void iacm_reset_system (Iacm_driver_data *data) {
register u16 action __asm("A") = ACTION_RESET_SYSTEM;
__asm volatile("hwi %0"
:
: "X"(data->iacm),
"r"(action));
}
28 changes: 28 additions & 0 deletions src/drivers/iacm/iacm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "kernel/interrupt_handler/interrupt_handler.h"
#include "types.h"

typedef enum {
IACM_SET_MODE,
IACM_SET_RUN_TIME,
IACM_SET_SLEEP_TIME,
IACM_SET_INTERRUPT_MESSAGE,
IACM_GET_CLOCK_RATE,
IACM_GET_RCLOCK_RATE,
IACM_RESET_SYSTEM
} Iacm_message;

typedef struct {
u16 iacm;
} Iacm_driver_data;


void *iacm_init (u16 iacm, u16 UNUSED (int_number), Int_handler *UNUSED (int_handler_location));
void iacm_destroy (Iacm_driver_data *UNUSED (data));
u16 iacm_update_function (void *data, u16 message, u16 arg1, u16 arg2);
void iacm_set_mode (Iacm_driver_data *data, u16 mode);
void iacm_set_run_time (Iacm_driver_data *data, u16 time);
void iacm_set_sleep_time (Iacm_driver_data *data, u16 time);
void iacm_set_interrupt_message (Iacm_driver_data *data, u16 message);
void iacm_get_clock_rate (Iacm_driver_data *data, u16 *rate_high, u16 *rate_low);
void iacm_get_rclock_rate (Iacm_driver_data *data, u16 *rate_high, u16 *rate_low);
void iacm_reset_system (Iacm_driver_data *data);
3 changes: 1 addition & 2 deletions src/drivers/keyboard/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void *keyboard_init (u16 keyboard, u16 UNUSED (int_number), Int_handler *UNUSED
return data;
}

void keyboard_destroy (void *UNUSED(data)) {
void keyboard_destroy (void *UNUSED (data)) {
}

u16 keyboard_update_function (void *data, u16 message, u16 arg1, u16 UNUSED (arg2)) {
Expand Down Expand Up @@ -76,4 +76,3 @@ void keyboard_set_int_msg (Keyboard_driver_data *data, u16 msg) {
"r"(action),
"r"(arg_b));
}

18 changes: 16 additions & 2 deletions src/kernel/FrOSt.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
#include "usr/console/console.h"

#include "drivers/clock/clock.h"
#include "drivers/iacm/iacm.h"
#include "drivers/keyboard/keyboard.h"
#include "drivers/lem1802/lem1802.h"

Driver driver_iacm;
Driver driver_lem1802;
Driver driver_keyboard;
Driver driver_clock;

#define N_DRIVERS 3
static Driver *drivers[] = { &driver_lem1802, &driver_keyboard, &driver_clock };
#define N_DRIVERS 4
static Driver *drivers[] = { &driver_iacm, &driver_lem1802, &driver_keyboard, &driver_clock };

int main (void) {
mm_init ();
Expand Down Expand Up @@ -83,6 +85,18 @@ int main (void) {
}
}

Driver driver_iacm = (Driver){
.hardware_info = (Hardware_info){.hardware_id_a = 0xdacc,
.hardware_id_b = 0x11e0,
.hardware_version = 0x0004,
.manufacturer_a = 0x0000, // Vendor code is defined as "(Various)"
.manufacturer_b = 0x0000 },
.update_function = iacm_update_function,
.init_function = iacm_init,
.destroy_function = iacm_destroy,
.devices_list = (Devices_list){.n_devices = 0 }
};

Driver driver_lem1802 = (Driver){
.hardware_info = (Hardware_info){.hardware_id_a = 0xf615,
.hardware_id_b = 0x7349,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/stdio/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ char stdio_getc () {
char c = '\0';
switch (input_type) {
case generic_keyboard:
c = keyboard_get_next(input_driver->devices_list.data[current_input]);
c = keyboard_get_next (input_driver->devices_list.data[current_input]);

break;
case no_input:
Expand Down
4 changes: 2 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ typedef long long i64;
typedef unsigned long long u64;
typedef float f32;

#define NULL ((void*)0)
#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#define NULL ((void *)0)
#define UNUSED(x) UNUSED_##x __attribute__ ((__unused__))
12 changes: 6 additions & 6 deletions src/usr/console/programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include "types.h"

void console_help(u16 UNUSED(n_arguments), char** UNUSED(arguments));
void console_about(u16 UNUSED(n_arguments), char** UNUSED(arguments));
void console_echo(u16 n_arguments, char** arguments);
void console_ps(u16 UNUSED(n_arguments), char** UNUSED(arguments));
void console_kill(u16 n_arguments, char** arguments);
void console_no_such_command(u16 UNUSED(n_arguments), char** UNUSED(arguments));
void console_help (u16 UNUSED (n_arguments), char **UNUSED (arguments));
void console_about (u16 UNUSED (n_arguments), char **UNUSED (arguments));
void console_echo (u16 n_arguments, char **arguments);
void console_ps (u16 UNUSED (n_arguments), char **UNUSED (arguments));
void console_kill (u16 n_arguments, char **arguments);
void console_no_such_command (u16 UNUSED (n_arguments), char **UNUSED (arguments));

0 comments on commit b5be64e

Please sign in to comment.