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 ()
__DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\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) ){
sleep(1);
if ( __po_hi_c_driver_1553_rasta_proccess_list(po_hi_c_driver_1553_rasta_fd,cmd_list,0) )
{
return;
}
__DEBUGMSG("[RASTA 1553] Sleeping 20s\n");
sleep(20);
__DEBUGMSG("[RASTA 1553] ------------- BC: START LIST EXECUTION -------------\n");
__DEBUGMSG("[RASTA 1553] Start RESULT list processing.\n");
......@@ -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) )
{
sleep(1);
return;
}
......@@ -294,7 +289,6 @@ void __po_hi_c_driver_1553_rasta_controller ()
}
__DEBUGMSG("[RASTA 1553] -----------------------------------------------------\n");
sleep(15);
}
......@@ -303,7 +297,7 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id)
{
__DEBUGMSG ("[RASTA 1553] Init\n");
init_pci();
__DEBUGMSG ("[RASTA 1553] Initializing RASTA ...\n");
__DEBUGMSG ("[RASTA 1553] Initializing RASTA (rasta_register()) ...\n");
if (rasta_register())
{
__DEBUGMSG(" ERROR !\n");
......@@ -312,7 +306,6 @@ void __po_hi_c_driver_1553_rasta_init (__po_hi_device_id id)
__DEBUGMSG(" OK !\n");
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)
......
......@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <b1553brm.h>
#include <po_hi_debug.h>
#include <drivers/po_hi_driver_rasta_1553_brmlib.h>
/* 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 *
int fd;
__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);
if ( fd >= 0 ){
printf("__po_hi_c_driver_1553_rasta_brmlib_open: allocating memory %d\n",sizeof(*ret));
if ( fd >= 0 )
{
ret = calloc(sizeof(*ret),1);
ret->fd = fd;
/* Initial state of driver */
ret->mode = BRM_MODE_RT;
}else{
if ( errno == ENODEV ){
printf("__po_hi_c_driver_1553_rasta_brmlib_open: driver %s doesn't exist\n",driver_name);
}else if ( errno == EBUSY ){
printf("__po_hi_c_driver_1553_rasta_brmlib_open: channel already taken\n");
}else{
printf("__po_hi_c_driver_1553_rasta_brmlib_open: errno: %d, ret: %d\n",errno,fd);
__DEBUGMSG("OK !\n");
}
else
{
if ( errno == ENODEV )
{
__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 *
void __po_hi_c_driver_1553_rasta_brmlib_close(__po_hi_c_driver_rasta_1553_brm_t chan){
if ( !chan || (chan->fd<0) )
{
return;
}
close(chan->fd);
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;
if ( !chan || !msgs || (msgcnt<0) )
if ( !chan || !msgs || (msgcnt < 0) )
{
return -1;
}
if ( msgcnt == 0 )
{
return 0;
}
ret = write(chan->fd,msgs,msgcnt);
if ( ret < 0 ){
if ( ret < 0 )
{
/* something went wrong
* OR in non-blocking mode
* that would block
*/
if ( !chan->txblk && (errno == EBUSY) ){
if ( !chan->txblk && (errno == EBUSY) )
{
/* would block ==> 0 sent is ok */
return 0;
}
if ( errno == EINVAL ){
if ( errno == EINVAL )
{
/* 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;
}
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;
}
......@@ -109,31 +135,41 @@ int __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(__po_hi_c_driver_rasta_1
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){
return __po_hi_c_driver_1553_rasta_brmlib_rt_send_multiple(chan,msg,1);
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);
}
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;
if ( !chan || !msgs || (msglen<0) )
{
return -1;
}
if ( msglen == 0 )
{
return 0;
}
errno = 0;
ret = read(chan->fd,msgs,msglen);
if ( ret < 0 ){
if ( ret < 0 )
{
/* something went wrong
* OR in non-blocking mode
* that would block
*/
if ( !chan->rxblk && (errno == EBUSY) ){
if ( !chan->rxblk && (errno == EBUSY) )
{
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;
}
......@@ -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)
{
if ( !chan || (chan->mode!=BRM_MODE_RT) )
{
return -1;
}
/* Read the messages */
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
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) )
{
return -1;
}
/* Read the messages */
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);
}
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);
}
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;
unsigned int arg = mode;
if ( !chan )
{
return -1;
}
ret = ioctl(chan->fd,BRM_SET_MODE,&arg);
if ( ret < 0 ){
if ( errno == EINVAL ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_mode: invalid mode: %d\n",arg);
if ( ret < 0 )
{
if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_mode invalid mode: %d\n",arg);
return -2;
}
if ( errno == ENOMEM ){
if ( errno == ENOMEM )
{
/* 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;
}
/* 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;
}
......@@ -200,75 +249,94 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_mode(__po_hi_c_driver_rasta_1553_brm_
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;
unsigned int arg = bus;
if ( !chan )
{
return -1;
}
/* only for RT mode */
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");
if ( chan->mode != BRM_MODE_RT )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_bus: Only possible to set bus in RT mode\n");
return -2; /* fast EINVAL... */
}
ret = ioctl(chan->fd,BRM_SET_BUS,&arg);
if ( ret < 0 ){
if ( errno == EINVAL ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_bus: invalid bus: %d\n",arg);
if ( ret < 0 )
{
if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_bus: invalid bus: %d\n",arg);
return -2;
}
/* 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 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;
unsigned int arg = timeout;
if ( !chan )
{
return -1;
}
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");
if ( !((chan->mode==BRM_MODE_BM) || (chan->mode==BRM_MODE_BC)) )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_msg_timeout: Only possible to set bus in BC & BM mode\n");
return -2;
}
ret = ioctl(chan->fd,BRM_SET_MSGTO,&arg);
if ( ret < 0 ){
if ( errno == EBUSY ){
if ( ret < 0 )
{
if ( errno == EBUSY )
{
/* 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;
}
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 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;
unsigned int arg = address;
if ( !chan )
{
return -1;
}
if ( chan->mode != BRM_MODE_RT ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_rt_addr: not in RT mode\n");
if ( chan->mode != BRM_MODE_RT )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_rt_addr: not in RT mode\n");
return -2;
}
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;
}
......@@ -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;
if ( !chan )
{
return -1;
}
ret = ioctl(chan->fd,BRM_SET_STD,&arg);
if ( ret < 0 ){
if ( errno == EINVAL ){
if ( ret < 0 )
{
if ( errno == EINVAL )
{
/* 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;
}
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;
}
......@@ -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;
int ret;
if ( !chan )
{
return -1;
}
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 )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_txblock: failed, errno: %d, ret: %d\n",errno,ret);
return -1;
}
/* remember blocking state */
chan->txblk = arg;
return 0;
......@@ -322,24 +400,34 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_rxblock(__po_hi_c_driver_rasta_1553_b
int ret;
if ( !chan )
{
return -1;
}
ret = ioctl(chan->fd,BRM_RX_BLOCK,&arg);
if ( ret < 0 ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_rxblock: failed, errno: %d, ret: %d\n",errno,ret);
if ( ret < 0 )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_rxblock: failed, errno: %d, ret: %d\n",errno,ret);
return -1;
}
/* remember blocking state */
chan->rxblk = arg;
return 0;
}
int __po_hi_c_driver_1553_rasta_brmlib_set_block(__po_hi_c_driver_rasta_1553_brm_t chan, int txblocking, int rxblocking){
int ret;
ret = __po_hi_c_driver_1553_rasta_brmlib_set_txblock(chan,txblocking);
if ( !ret ){
if ( !ret )
{
return __po_hi_c_driver_1553_rasta_brmlib_set_rxblock(chan,rxblocking);
}
return ret;
}
......@@ -348,11 +436,15 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_broadcast(__po_hi_c_driver_rasta_1553
int ret;
if ( !chan )
{
return -1;
}
ret = ioctl(chan->fd,BRM_SET_BCE,&arg);
if ( ret < 0 ){
printf("__po_hi_c_driver_1553_rasta_brmlib_set_broadcast: failed, errno: %d, ret: %d\n",errno,ret);
if ( ret < 0 )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] set_broadcast: failed, errno: %d, ret: %d\n",errno,ret);
return -1;
}
......@@ -361,91 +453,125 @@ int __po_hi_c_driver_1553_rasta_brmlib_set_broadcast(__po_hi_c_driver_rasta_1553
return 0;
}
int __po_hi_c_driver_1553_rasta_brmlib_bc_dolist(__po_hi_c_driver_rasta_1553_brm_t chan, struct bc_msg *msgs){
int __po_hi_c_driver_1553_rasta_brmlib_bc_dolist(__po_hi_c_driver_rasta_1553_brm_t chan, struct bc_msg *msgs)
{
int ret;
ret = ioctl(chan->fd, BRM_DO_LIST, msgs);
if ( ret < 0 ){
if ( errno == EINVAL ){
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: not in BC mode\n");
if ( ret < 0 )
{
if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] bc_dolist: not in BC mode\n");
return -2;
}
if ( errno == EBUSY ){
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: busy\n");
if ( errno == EBUSY )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] bc_dolist: busy\n");
return -3;
}
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: errno %d, ret: %d\n",errno,ret);
__DEBUGMSG("[RASTA 1553 BRMLIB] dolist: errno %d, ret: %d\n",errno,ret);
return -1;
}
return 0;
}
int __po_hi_c_driver_1553_rasta_brmlib_bc_dolist_wait(__po_hi_c_driver_rasta_1553_brm_t chan){
int __po_hi_c_driver_1553_rasta_brmlib_bc_dolist_wait(__po_hi_c_driver_rasta_1553_brm_t chan)
{
int ret;
unsigned int result;
ret = ioctl(chan->fd, BRM_LIST_DONE, &result);
if ( ret < 0 ){
if ( errno == EINVAL ){
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: not in BC mode\n");
if ( ret < 0 )
{
if ( errno == EINVAL )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] bc_dolist: not in BC mode\n");
return -2;
}
if ( errno == EBUSY ){
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: busy\n");
if ( errno == EBUSY )
{
__DEBUGMSG("[RASTA 1553 BRMLIB] dolist: busy\n");
return -3;
}
printf("__po_hi_c_driver_1553_rasta_brmlib_bc_dolist: errno %d, ret: %d\n",errno,ret);
__DEBUGMSG("[RASTA 1553 BRMLIB] bc_dolist: errno %d, ret: %d\n",errno,ret);
return -1;
}
return result;
}
void __po_hi_c_driver_rasta_1553_print_rt_msg(int i, struct rt_msg *msg){
void __po_hi_c_driver_rasta_1553_print_rt_msg(int i, struct rt_msg *msg)
{
int k, wc;
wc = msg->miw >> 11;
printf("MSG[%d]: miw: 0x%x, time: 0x%x, desc: 0x%x, len: %d\n ",i,msg->miw,msg->time,msg->desc,wc);
__DEBUGMSG("[RASTA 1553 BRMLIB] MSG[%d]: miw: 0x%x, time: 0x%x, desc: 0x%x, len: %d\n ",i,msg->miw,msg->time,msg->desc,wc);
/* print data */
for (k = 0; k < wc; k++){
if ( isalnum(msg->data[k]) ){
printf("0x%x (%c)",msg->data[k],msg->data[k]);
}else{
printf("0x%x (.)",msg->data[k]);
for (k = 0; k < wc; k++)
{
if ( isalnum(msg->data[k]) )
{
__DEBUGMSG("0x%x (%c)",msg->data[k],msg->data[k]);
}
else
{
__DEBUGMSG("0x%x (.)",msg->data[k]);
}
}
if ( k > 0 )
printf("\n");
{
__DEBUGMSG("\n");
}
}
void __po_hi_c_driver_rasta_1553_print_bm_msg(int i, struct bm_msg *msg){
void __po_hi_c_driver_rasta_1553_print_bm_msg(int i, struct bm_msg *msg)