2015-04-06 19:40:12 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2015-04-04 22:08:32 +08:00
|
|
|
#include "exceptions.h"
|
2015-04-16 21:47:05 +08:00
|
|
|
#include "bridge.h"
|
2015-04-05 22:04:50 +08:00
|
|
|
#include "mailbox.h"
|
|
|
|
#include "messages.h"
|
2015-04-04 22:08:32 +08:00
|
|
|
#include "rtio.h"
|
|
|
|
#include "dds.h"
|
|
|
|
|
2015-04-29 12:58:37 +08:00
|
|
|
/* for the prototypes for watchdog_set() and watchdog_clear() */
|
|
|
|
#include "clock.h"
|
2015-04-22 01:31:31 +08:00
|
|
|
/* for the prototype for rpc() */
|
|
|
|
#include "session.h"
|
|
|
|
/* for the prototype for log() */
|
|
|
|
#include "log.h"
|
2015-04-06 19:40:12 +08:00
|
|
|
|
2015-04-03 17:44:56 +08:00
|
|
|
void exception_handler(unsigned long vect, unsigned long *sp);
|
|
|
|
void exception_handler(unsigned long vect, unsigned long *sp)
|
|
|
|
{
|
2015-04-05 22:04:50 +08:00
|
|
|
struct msg_exception msg;
|
|
|
|
|
|
|
|
msg.type = MESSAGE_TYPE_EXCEPTION;
|
|
|
|
msg.eid = EID_INTERNAL_ERROR;
|
2015-05-02 23:41:49 +08:00
|
|
|
msg.eparams[0] = 256;
|
|
|
|
msg.eparams[1] = 256;
|
|
|
|
msg.eparams[2] = 256;
|
2015-04-05 22:04:50 +08:00
|
|
|
mailbox_send_and_wait(&msg);
|
|
|
|
while(1);
|
2015-04-03 17:44:56 +08:00
|
|
|
}
|
|
|
|
|
2015-04-04 22:08:32 +08:00
|
|
|
typedef void (*kernel_function)(void);
|
2015-04-03 17:44:56 +08:00
|
|
|
|
|
|
|
int main(void);
|
|
|
|
int main(void)
|
|
|
|
{
|
2015-04-04 22:08:32 +08:00
|
|
|
kernel_function k;
|
|
|
|
void *jb;
|
|
|
|
|
2015-04-16 21:47:05 +08:00
|
|
|
k = mailbox_receive();
|
|
|
|
|
|
|
|
if(k == NULL)
|
|
|
|
bridge_main();
|
|
|
|
else {
|
|
|
|
jb = exception_push();
|
|
|
|
if(exception_setjmp(jb)) {
|
|
|
|
struct msg_exception msg;
|
|
|
|
|
|
|
|
msg.type = MESSAGE_TYPE_EXCEPTION;
|
|
|
|
msg.eid = exception_getid(msg.eparams);
|
|
|
|
mailbox_send_and_wait(&msg);
|
|
|
|
} else {
|
|
|
|
struct msg_base msg;
|
|
|
|
|
|
|
|
k();
|
|
|
|
exception_pop(1);
|
|
|
|
|
|
|
|
msg.type = MESSAGE_TYPE_FINISHED;
|
|
|
|
mailbox_send_and_wait(&msg);
|
|
|
|
}
|
2015-04-04 22:08:32 +08:00
|
|
|
}
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
2015-05-02 23:41:49 +08:00
|
|
|
long long int now_init(void);
|
|
|
|
long long int now_init(void)
|
|
|
|
{
|
|
|
|
struct msg_base request;
|
|
|
|
struct msg_now_init_reply *reply;
|
|
|
|
long long int now;
|
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_NOW_INIT_REQUEST;
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
|
|
|
|
reply = mailbox_wait_and_receive();
|
|
|
|
if(reply->type != MESSAGE_TYPE_NOW_INIT_REPLY)
|
|
|
|
exception_raise_params(EID_INTERNAL_ERROR, 1, 0, 0);
|
|
|
|
now = reply->now;
|
|
|
|
mailbox_acknowledge();
|
|
|
|
|
|
|
|
if(now < 0) {
|
|
|
|
rtio_init();
|
2015-09-03 23:52:04 +08:00
|
|
|
now = rtio_get_counter() + (272000 << RTIO_FINE_TS_WIDTH);
|
2015-05-02 23:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return now;
|
|
|
|
}
|
|
|
|
|
|
|
|
void now_save(long long int now);
|
|
|
|
void now_save(long long int now)
|
|
|
|
{
|
|
|
|
struct msg_now_save request;
|
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_NOW_SAVE;
|
|
|
|
request.now = now;
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
}
|
|
|
|
|
2015-04-29 12:58:37 +08:00
|
|
|
int watchdog_set(int ms)
|
|
|
|
{
|
|
|
|
struct msg_watchdog_set_request request;
|
|
|
|
struct msg_watchdog_set_reply *reply;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_WATCHDOG_SET_REQUEST;
|
|
|
|
request.ms = ms;
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
|
|
|
|
reply = mailbox_wait_and_receive();
|
|
|
|
if(reply->type != MESSAGE_TYPE_WATCHDOG_SET_REPLY)
|
2015-05-02 23:41:49 +08:00
|
|
|
exception_raise_params(EID_INTERNAL_ERROR, 2, 0, 0);
|
2015-04-29 12:58:37 +08:00
|
|
|
id = reply->id;
|
|
|
|
mailbox_acknowledge();
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void watchdog_clear(int id)
|
|
|
|
{
|
|
|
|
struct msg_watchdog_clear request;
|
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_WATCHDOG_CLEAR;
|
|
|
|
request.id = id;
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
}
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
int rpc(int rpc_num, ...)
|
2015-04-04 22:08:32 +08:00
|
|
|
{
|
2015-04-06 19:40:12 +08:00
|
|
|
struct msg_rpc_request request;
|
|
|
|
struct msg_rpc_reply *reply;
|
2015-04-06 22:28:10 +08:00
|
|
|
int eid, retval;
|
2015-04-06 19:40:12 +08:00
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_RPC_REQUEST;
|
|
|
|
request.rpc_num = rpc_num;
|
|
|
|
va_start(request.args, rpc_num);
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
va_end(request.args);
|
|
|
|
|
|
|
|
reply = mailbox_wait_and_receive();
|
|
|
|
if(reply->type != MESSAGE_TYPE_RPC_REPLY)
|
2015-05-02 23:41:49 +08:00
|
|
|
exception_raise_params(EID_INTERNAL_ERROR, 3, 0, 0);
|
2015-04-06 22:28:10 +08:00
|
|
|
eid = reply->eid;
|
|
|
|
retval = reply->retval;
|
2015-04-06 19:40:12 +08:00
|
|
|
mailbox_acknowledge();
|
2015-04-06 22:28:10 +08:00
|
|
|
|
|
|
|
if(eid != EID_NONE)
|
|
|
|
exception_raise(eid);
|
|
|
|
return retval;
|
2015-04-06 19:40:12 +08:00
|
|
|
}
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
void log(const char *fmt, ...)
|
2015-04-06 19:40:12 +08:00
|
|
|
{
|
|
|
|
struct msg_log request;
|
|
|
|
|
|
|
|
request.type = MESSAGE_TYPE_LOG;
|
|
|
|
request.fmt = fmt;
|
|
|
|
va_start(request.args, fmt);
|
|
|
|
mailbox_send_and_wait(&request);
|
|
|
|
va_end(request.args);
|
2015-04-03 17:44:56 +08:00
|
|
|
}
|