configuration option for kernel's multiboot-compliance
[quarnos.git] / resources / rs232.cpp
blobc29b3acbc62461990ae88f51ba4043dbf44e478f
1 #include "resource_id.h"
2 #include "rs232.h"
3 #include "resource_manager.h"
4 #include "arch/x86/rs232.h"
5 #include "services/service_manager.h"
6 #include "libs/delegate.h"
7 #include "spinlock.h"
9 using namespace resources;
11 rs232::rs232() : res_stream((resource_type*)RESOURCE(rs232)) {
12 set_access_control(new spinlock);
14 delegate<resource_result *, rs232_mode, int, int, parity_check, int> *m_conf = new delegate<resource_result *, rs232_mode, int, int, parity_check, int>;
15 m_conf->method(this,&rs232::configure);
16 add_ord_response("configure",m_conf);
19 void rs232::read_bytes(char *data, int count) {
23 void rs232::write_dwords(const int *data, int count) {
27 void rs232::write_bytes(const char *data, int count) {
28 access_write();
29 for (int i = 0; i < count; i++) {
30 arch::rs232_send(descr.isaaddr, data[i]);
32 release();
35 void rs232::received(const char a) {
36 write_bytes(&a,1);
39 resource_result *rs232::configure(rs232_mode mode, int speed, int bits,
40 parity_check parity, int stop) {
41 arch::rs232_configure(descr.isaaddr, mode, speed, bits, parity, stop);
42 return GET_RESOURCES()->create_result();
45 bool rs232::init_device(isa_address iadr) {
46 descr.isaaddr = iadr;
48 delegate<void, const char> sp_hndl;
49 sp_hndl.method(this,&rs232::received);
51 arch::rs232_init(descr.isaaddr, sp_hndl);
53 descr.inited = true;
55 return descr.inited;
58 void rs232::register_resource() {
59 resource_manager *rman = GET_RESOURCES();
61 delegate<manes::object *> *res = new delegate<manes::object *>;
63 /* rs232 console */
64 res->function(create_object<manes::object,rs232>);
65 resource_type *rs232_type = new resource_type(resource_type::device, resource_type::stream_dev,"rs232",*res);
66 rman->register_type(rs232_type);