Commit e74861f7 authored by julien.delange's avatar julien.delange
Browse files

clean code



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@622 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 01c8c7cc
...@@ -244,15 +244,11 @@ void __po_hi_c_driver_1553_rasta_controller () ...@@ -244,15 +244,11 @@ void __po_hi_c_driver_1553_rasta_controller ()
__DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\n"); __DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\n");
__DEBUGMSG("[RASTA 1553] Start CMD list processing.\n"); __DEBUGMSG("[RASTA 1553] Start CMD list processing.\n");
if ( __po_hi_c_driver_1553_rasta_proccess_list(po_hi_c_driver_1553_rasta_fd,cmd_list,0) ){ if ( __po_hi_c_driver_1553_rasta_proccess_list(po_hi_c_driver_1553_rasta_fd,cmd_list,0) )
sleep(1); {
return; return;
} }
__DEBUGMSG("[RASTA 1553] Sleeping 20s\n");
sleep(20);
__DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\n"); __DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\n");
__DEBUGMSG("[RASTA 1553] Start RESULT list processing.\n"); __DEBUGMSG("[RASTA 1553] Start RESULT list processing.\n");
...@@ -268,7 +264,6 @@ void __po_hi_c_driver_1553_rasta_controller () ...@@ -268,7 +264,6 @@ void __po_hi_c_driver_1553_rasta_controller ()
if ( __po_hi_c_driver_1553_rasta_proccess_list(po_hi_c_driver_1553_rasta_fd,result_list,1) ) if ( __po_hi_c_driver_1553_rasta_proccess_list(po_hi_c_driver_1553_rasta_fd,result_list,1) )
{ {
sleep(1);
return; return;
} }
...@@ -294,7 +289,6 @@ void __po_hi_c_driver_1553_rasta_controller () ...@@ -294,7 +289,6 @@ void __po_hi_c_driver_1553_rasta_controller ()
} }
__DEBUGMSG("[RASTA 1553] -----------------------------------------------------\n"); __DEBUGMSG("[RASTA 1553] -----------------------------------------------------\n");
sleep(15);
} }
...@@ -303,7 +297,7 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id) ...@@ -303,7 +297,7 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id)
{ {
__DEBUGMSG ("[RASTA 1553] Init\n"); __DEBUGMSG ("[RASTA 1553] Init\n");
init_pci(); init_pci();
__DEBUGMSG ("[RASTA 1553] Initializing RASTA ...\n"); __DEBUGMSG ("[RASTA 1553] Initializing RASTA (rasta_register()) ...\n");
if (rasta_register()) if (rasta_register())
{ {
__DEBUGMSG(" ERROR !\n"); __DEBUGMSG(" ERROR !\n");
...@@ -312,7 +306,6 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id) ...@@ -312,7 +306,6 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id)
__DEBUGMSG(" OK !\n"); __DEBUGMSG(" OK !\n");
po_hi_c_driver_1553_rasta_fd = __po_hi_c_driver_1553_rasta_brmlib_open (__PO_HI_DRIVER_RASTA_1553_DEVICE); po_hi_c_driver_1553_rasta_fd = __po_hi_c_driver_1553_rasta_brmlib_open (__PO_HI_DRIVER_RASTA_1553_DEVICE);
if (po_hi_c_driver_1553_rasta_fd < 0) if (po_hi_c_driver_1553_rasta_fd < 0)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <b1553brm.h> #include <b1553brm.h>
#include <po_hi_debug.h>
#include <drivers/po_hi_driver_rasta_1553_brmlib.h> #include <drivers/po_hi_driver_rasta_1553_brmlib.h>
/* The stupid rtems name to errno table, in fact I hate it.... :) /* The stupid rtems name to errno table, in fact I hate it.... :)
...@@ -47,22 +48,34 @@ __po_hi_c_driver_rasta_1553_brm_t __po_hi_c_driver_1553_rasta_brmlib_open(char * ...@@ -47,22 +48,34 @@ __po_hi_c_driver_rasta_1553_brm_t __po_hi_c_driver_1553_rasta_brmlib_open(char *
int fd; int fd;
__po_hi_c_driver_rasta_1553_brm_t ret = NULL; __po_hi_c_driver_rasta_1553_brm_t ret = NULL;
printf("__po_hi_c_driver_1553_rasta_brmlib_open: Opening driver %s\n",driver_name); __DEBUGMSG("[RASTA 1553 BRMLIB] Opening driver %s ...",driver_name);
fd = open(driver_name,O_RDWR); fd = open(driver_name,O_RDWR);
if ( fd >= 0 ){ if ( fd >= 0 )
printf("__po_hi_c_driver_1553_rasta_brmlib_open: allocating memory %d\n",sizeof(*ret)); {
ret = calloc(sizeof(*ret),1); ret = calloc(sizeof(*ret),1);
ret->fd = fd; ret->fd = fd;
/* Initial state of driver */ /* Initial state of driver */
ret->mode = BRM_MODE_RT; ret->mode = BRM_MODE_RT;
}else{ __DEBUGMSG("OK !\n");
if ( errno == ENODEV ){
printf("__po_hi_c_driver_1553_rasta_brmlib_open: driver %s doesn't exist\n",driver_name); }
}else if ( errno == EBUSY ){ else
printf("__po_hi_c_driver_1553_rasta_brmlib_open: channel already taken\n"); {
}else{ if ( errno == ENODEV )
printf("__po_hi_c_driver_1553_rasta_brmlib_open: errno: %d, ret: %d\n",errno,fd); {
__DEBUGMSG(" driver %s doesn't exist\n",driver_name);
}
else
{
if ( errno == EBUSY )
{
__DEBUGMSG(" channel already taken\n");
}
else
{
__DEBUGMSG(" unknown error, errno: %d, ret: %d\n",errno,fd);
}
} }
} }
...@@ -71,37 +84,50 @@ __po_hi_c_driver_rasta_1553_brm_t __po_hi_c_driver_1553_rasta_brmlib_open(char * ...@@ -71,37 +84,50 @@ __po_hi_c_driver_rasta_1553_brm_t __po_hi_c_driver_1553_rasta_brmlib_open(char *
void __po_hi_c_driver_1553_rasta_brmlib_close(__po_hi_c_driver_rasta_1553_brm_t chan){ void __po_hi_c_driver_1553_rasta_brmlib_close(__po_hi_c_driver_rasta_1553_brm_t chan){
if ( !chan || (chan->fd<0) ) if ( !chan || (chan->fd<0) )
{
return; return;
}
close(chan->fd); close(chan->fd);
free(chan); free(chan);
} }
int __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msgs, int msgcnt){ int __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msgs, int msgcnt)
{
int ret; int ret;
if ( !chan || !msgs || (msgcnt<0) )
if ( !chan || !msgs || (msgcnt < 0) )
{
return -1; return -1;
}
if ( msgcnt == 0 ) if ( msgcnt == 0 )
{
return 0; return 0;
}
ret = write(chan->fd,msgs,msgcnt); ret = write(chan->fd,msgs,msgcnt);
if ( ret < 0 ){
if ( ret < 0 )
{
/* something went wrong /* something went wrong
* OR in non-blocking mode * OR in non-blocking mode
* that would block * that would block
*/ */
if ( !chan->txblk && (errno == EBUSY) ){ if ( !chan->txblk && (errno == EBUSY) )
{
/* would block ==> 0 sent is ok */ /* would block ==> 0 sent is ok */
return 0; return 0;
} }
if ( errno == EINVAL ){ if ( errno == EINVAL )
{
/* CAN must be started before receiving */ /* CAN must be started before receiving */
printf("__po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple: input descriptor numbering error\n"); __DEBUGMSG("[RASTA 1553 BRMLIB] input descriptor numbering error\n");
return -1; return -1;
} }
printf("__po_hi_c_driver_1553_rasta_brmlib_send_multiple: error in write, errno: %d, returned: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] error in write, errno: %d, returned: %d\n",errno,ret);
return -1; return -1;
} }
...@@ -109,31 +135,41 @@ int __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(__po_hi_c_driver_rasta_1 ...@@ -109,31 +135,41 @@ int __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(__po_hi_c_driver_rasta_1
return ret; return ret;
} }
int __po_hi_c_driver_1553_rasta_brmlib_rt_send(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msg){ int __po_hi_c_driver_1553_rasta_brmlib_rt_send(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msg)
return __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(chan,msg,1); {
return __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(chan,msg,1);
} }
int __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, void *msgs, int msglen){ int __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, void *msgs, int msglen)
{
int ret; int ret;
if ( !chan || !msgs || (msglen<0) ) if ( !chan || !msgs || (msglen<0) )
{
return -1; return -1;
}
if ( msglen == 0 ) if ( msglen == 0 )
{
return 0; return 0;
}
errno = 0; errno = 0;
ret = read(chan->fd,msgs,msglen); ret = read(chan->fd,msgs,msglen);
if ( ret < 0 ){
if ( ret < 0 )
{
/* something went wrong /* something went wrong
* OR in non-blocking mode * OR in non-blocking mode
* that would block * that would block
*/ */
if ( !chan->rxblk && (errno == EBUSY) ){ if ( !chan->rxblk && (errno == EBUSY) )
{
return 0; return 0;
} }
printf("__po_hi_c_driver_1553_rasta_brmlib_recv_multiple: error in read, errno: %d, returned: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] error in read, errno: %d, returned: %d\n",errno,ret);
return -1; return -1;
} }
...@@ -144,7 +180,9 @@ int __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(__po_hi_c_driver_rasta_1553 ...@@ -144,7 +180,9 @@ int __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(__po_hi_c_driver_rasta_1553
int __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msgs, int msgcnt) int __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msgs, int msgcnt)
{ {
if ( !chan || (chan->mode!=BRM_MODE_RT) ) if ( !chan || (chan->mode!=BRM_MODE_RT) )
{
return -1; return -1;
}
/* Read the messages */ /* Read the messages */
return __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(chan,(void *)msgs,msgcnt); return __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(chan,(void *)msgs,msgcnt);
...@@ -153,44 +191,55 @@ int __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(__po_hi_c_driver_rasta_1 ...@@ -153,44 +191,55 @@ int __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(__po_hi_c_driver_rasta_1
int __po_hi_c_driver_1553_rasta_brmlib_bm_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct bm_msg *msgs, int msgcnt) int __po_hi_c_driver_1553_rasta_brmlib_bm_recv_multiple(__po_hi_c_driver_rasta_1553_brm_t chan, struct bm_msg *msgs, int msgcnt)
{ {
if ( !chan || (chan->mode!=BRM_MODE_BM) ) if ( !chan || (chan->mode!=BRM_MODE_BM) )
{
return -1; return -1;
}
/* Read the messages */ /* Read the messages */
return __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(chan,(void *)msgs,msgcnt); return __po_hi_c_driver_1553_rasta_brmlib_recv_multiple(chan,(void *)msgs,msgcnt);
} }
int __po_hi_c_driver_1553_rasta_brmlib_rt_recv(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msg){ int __po_hi_c_driver_1553_rasta_brmlib_rt_recv(__po_hi_c_driver_rasta_1553_brm_t chan, struct rt_msg *msg)
{
return __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(chan,msg,1); return __po_hi_c_driver_1553_rasta_brmlib_rt_recv_multiple(chan,msg,1);
} }
int __po_hi_c_driver_1553_rasta_brmlib_bm_recv(__po_hi_c_driver_rasta_1553_brm_t chan, struct bm_msg *msg){
int __po_hi_c_driver_1553_rasta_brmlib_bm_recv(__po_hi_c_driver_rasta_1553_brm_t chan, struct bm_msg *msg)
{
return __po_hi_c_driver_1553_rasta_brmlib_bm_recv_multiple(chan,msg,1); return __po_hi_c_driver_1553_rasta_brmlib_bm_recv_multiple(chan,msg,1);
} }
int __po_hi_c_driver_1553_rasta_brmlib_set_mode(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int mode){ int __po_hi_c_driver_1553_rasta_brmlib_set_mode(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int mode)
{
int ret; int ret;
unsigned int arg = mode; unsigned int arg = mode;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
ret = ioctl(chan->fd,BRM_SET_MODE,&arg); ret = ioctl(chan->fd,BRM_SET_MODE,&arg);
if ( ret < 0 ){
if ( ret < 0 )
if ( errno == EINVAL ){ {
printf("__po_hi_c_driver_1553_rasta_brmlib_set_mode: invalid mode: %d\n",arg); if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_mode invalid mode: %d\n",arg);
return -2; return -2;
} }
if ( errno == ENOMEM ){ if ( errno == ENOMEM )
{
/* started */ /* started */
printf("__po_hi_c_driver_1553_rasta_brmlib_set_mode: not enough memory\n"); __DEBUGMSG("[RASTA 1553 BRMLIB] set_mode: not enough memory\n");
return -3; return -3;
} }
/* unhandeled errors */ /* unhandeled errors */
printf("__po_hi_c_driver_1553_rasta_brmlib_set_mode: failed, errno: %d, ret: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] set_mode: failed, errno: %d, ret: %d\n",errno,ret);
return -1; return -1;
} }
...@@ -200,75 +249,94 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_mode(__po_hi_c_driver_rasta_1553_brm_ ...@@ -200,75 +249,94 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_mode(__po_hi_c_driver_rasta_1553_brm_
return 0; return 0;
} }
int __po_hi_c_driver_1553_rasta_brmlib_set_bus(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int bus){ int __po_hi_c_driver_1553_rasta_brmlib_set_bus(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int bus)
{
int ret; int ret;
unsigned int arg = bus; unsigned int arg = bus;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
/* only for RT mode */ /* only for RT mode */
if ( chan->mode != BRM_MODE_RT ){ if ( chan->mode != BRM_MODE_RT )
printf("__po_hi_c_driver_1553_rasta_brmlib_set_bus: Only possible to set bus in RT mode\n"); {
__DEBUGMSG("[RASTA 1553 BRMLIB] set_bus: Only possible to set bus in RT mode\n");
return -2; /* fast EINVAL... */ return -2; /* fast EINVAL... */
} }
ret = ioctl(chan->fd,BRM_SET_BUS,&arg); ret = ioctl(chan->fd,BRM_SET_BUS,&arg);
if ( ret < 0 ){
if ( ret < 0 )
if ( errno == EINVAL ){ {
printf("__po_hi_c_driver_1553_rasta_brmlib_set_bus: invalid bus: %d\n",arg); if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_bus: invalid bus: %d\n",arg);
return -2; return -2;
} }
/* unhandeled errors */ /* unhandeled errors */
printf("__po_hi_c_driver_1553_rasta_brmlib_set_bus: failed, errno: %d, ret: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] set_bus: failed, errno: %d, ret: %d\n",errno,ret);
return -1; return -1;
} }
return 0; return 0;
} }
int __po_hi_c_driver_1553_rasta_brmlib_set_msg_timeout(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int timeout){ int __po_hi_c_driver_1553_rasta_brmlib_set_msg_timeout(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int timeout)
{
int ret; int ret;
unsigned int arg = timeout; unsigned int arg = timeout;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
if ( !((chan->mode==BRM_MODE_BM) || (chan->mode==BRM_MODE_BC)) ){ if ( !((chan->mode==BRM_MODE_BM) || (chan->mode==BRM_MODE_BC)) )
printf("__po_hi_c_driver_1553_rasta_brmlib_set_msg_timeout: Only possible to set bus in BC & BM mode\n"); {
__DEBUGMSG("[RASTA 1553 BRMLIB] set_msg_timeout: Only possible to set bus in BC & BM mode\n");
return -2; return -2;
} }
ret = ioctl(chan->fd,BRM_SET_MSGTO,&arg); ret = ioctl(chan->fd,BRM_SET_MSGTO,&arg);
if ( ret < 0 ){
if ( errno == EBUSY ){ if ( ret < 0 )
{
if ( errno == EBUSY )
{
/* started */ /* started */
printf("__po_hi_c_driver_1553_rasta_brmlib_set_msg_timeout: started\n"); __DEBUGMSG("[RASTA 1553 BRMLIB] set_msg_timeout: started\n");
return -2; return -2;
} }
printf("__po_hi_c_driver_1553_rasta_brmlib_set_msg_timeout: failed, errno: %d, ret: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] set_msg_timeout: failed, errno: %d, ret: %d\n",errno,ret);
return -1; return -1;
} }
return 0; return 0;
} }
int __po_hi_c_driver_1553_rasta_brmlib_set_rt_addr(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int address){ int __po_hi_c_driver_1553_rasta_brmlib_set_rt_addr(__po_hi_c_driver_rasta_1553_brm_t chan, unsigned int address)
{
int ret; int ret;
unsigned int arg = address; unsigned int arg = address;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
if ( chan->mode != BRM_MODE_RT ){ if ( chan->mode != BRM_MODE_RT )
printf("__po_hi_c_driver_1553_rasta_brmlib_set_rt_addr: not in RT mode\n"); {
__DEBUGMSG("[RASTA 1553 BRMLIB] set_rt_addr: not in RT mode\n");
return -2; return -2;
} }
ret = ioctl(chan->fd,BRM_SET_RT_ADDR,&arg); ret = ioctl(chan->fd,BRM_SET_RT_ADDR,&arg);
if ( ret < 0 ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_rt_addr: failed, errno: %d, ret: %d\n",errno,ret); if ( ret < 0 )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_rt_addr: failed, errno: %d, ret: %d\n",errno,ret);
return -1; return -1;
} }
...@@ -280,18 +348,22 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_std(__po_hi_c_driver_rasta_1553_brm_t ...@@ -280,18 +348,22 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_std(__po_hi_c_driver_rasta_1553_brm_t
unsigned int arg = std; unsigned int arg = std;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
ret = ioctl(chan->fd,BRM_SET_STD,&arg); ret = ioctl(chan->fd,BRM_SET_STD,&arg);
if ( ret < 0 ){
if ( ret < 0 )
if ( errno == EINVAL ){ {
if ( errno == EINVAL )
{
/* started */ /* started */
printf("__po_hi_c_driver_1553_rasta_brmlib_set_std: new standard not valid: %d\n",arg); __DEBUGMSG("[RASTA 1553 BRMLIB] set_std: new standard not valid: %d\n",arg);
return -2; return -2;
} }
printf("__po_hi_c_driver_1553_rasta_brmlib_set_filter: failed, errno: %d, ret: %d\n",errno,ret); __DEBUGMSG("[RASTA 1553 BRMLIB] set_filter: failed, errno: %d, ret: %d\n",errno,ret);
return -1; return -1;
} }
...@@ -299,18 +371,24 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_std(__po_hi_c_driver_rasta_1553_brm_t ...@@ -299,18 +371,24 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_std(__po_hi_c_driver_rasta_1553_brm_t
} }
int __po_hi_c_driver_1553_rasta_brmlib_set_txblock(__po_hi_c_driver_rasta_1553_brm_t chan, int txblocking){ int __po_hi_c_driver_1553_rasta_brmlib_set_txblock(__po_hi_c_driver_rasta_1553_brm_t chan, int txblocking)
{
unsigned int arg = (txblocking) ? 1 : 0; unsigned int arg = (txblocking) ? 1 : 0;
int ret; int ret;
if ( !chan ) if ( !chan )
{
return -1; return -1;
}
ret = ioctl(chan->fd,BRM_TX_BLOCK,&arg); ret = ioctl(chan->fd,BRM_TX_BLOCK,&arg);
if ( ret < 0 ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_txblock: failed, errno: %d, ret: %d\n",errno,ret); if ( ret < 0 )