2014-06-08 10:51:01 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
2014-06-08 10:58:31 +04:00
|
|
|
* This file is part of ToaruOS and is released under the terms
|
2014-06-08 10:13:29 +04:00
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2014 Kevin Lange
|
|
|
|
*/
|
2014-04-27 07:12:06 +04:00
|
|
|
#include <module.h>
|
|
|
|
#include <printf.h>
|
|
|
|
#include <mod/shell.h>
|
|
|
|
|
|
|
|
static void note(int length, int freq) {
|
|
|
|
|
|
|
|
uint32_t div = 11931800 / freq;
|
|
|
|
uint8_t t;
|
|
|
|
|
|
|
|
outportb(0x43, 0xb6);
|
|
|
|
outportb(0x42, (uint8_t)(div));
|
|
|
|
outportb(0x42, (uint8_t)(div >> 8));
|
|
|
|
|
|
|
|
t = inportb(0x61);
|
|
|
|
outportb(0x61, t | 0x3);
|
|
|
|
|
|
|
|
unsigned long s, ss;
|
2015-05-01 02:34:23 +03:00
|
|
|
relative_time(0, length * 10, &s, &ss);
|
2014-04-27 07:12:06 +04:00
|
|
|
sleep_until((process_t *)current_process, s, ss);
|
|
|
|
switch_task(0);
|
|
|
|
|
|
|
|
t = inportb(0x61) & 0xFC;
|
|
|
|
outportb(0x61, t);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-19 03:11:14 +04:00
|
|
|
struct spkr {
|
|
|
|
int length;
|
|
|
|
int frequency;
|
|
|
|
};
|
2014-04-27 07:12:06 +04:00
|
|
|
|
2014-05-19 03:11:14 +04:00
|
|
|
static uint32_t write_spkr(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
|
|
|
if (!size % (sizeof(struct spkr))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct spkr * s = (struct spkr *)buffer;
|
|
|
|
while ((uintptr_t)s < (uintptr_t)buffer + size) {
|
|
|
|
note(s->length, s->frequency);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (uintptr_t)s - (uintptr_t)buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fs_node_t * spkr_device_create(void) {
|
|
|
|
fs_node_t * fnode = malloc(sizeof(fs_node_t));
|
|
|
|
memset(fnode, 0x00, sizeof(fs_node_t));
|
|
|
|
sprintf(fnode->name, "spkr");
|
2016-12-14 15:21:32 +03:00
|
|
|
fnode->mask = 0666; /* TODO need a speaker group */
|
2014-05-19 03:11:14 +04:00
|
|
|
fnode->flags = FS_CHARDEVICE;
|
|
|
|
fnode->write = write_spkr;
|
|
|
|
return fnode;
|
2014-04-27 07:12:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int init(void) {
|
2014-05-19 03:11:14 +04:00
|
|
|
fs_node_t * node = spkr_device_create();
|
|
|
|
vfs_mount("/dev/spkr", node);
|
2014-04-27 07:12:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fini(void) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:16:59 +04:00
|
|
|
MODULE_DEF(pcspkr, init, fini);
|
2014-04-27 07:12:06 +04:00
|
|
|
MODULE_DEPENDS(debugshell);
|