From: Michal Sojka Date: Sat, 11 Nov 2006 09:19:00 +0000 (+0000) Subject: An unsucesfull attempt to clean bluetooth library and make it working. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/mirosot.git/commitdiff_plain/ba111b946b45f8493ad0e2b10430c296f2f08cb8 An unsucesfull attempt to clean bluetooth library and make it working. * Bluetooth library renamed to mirobt to not colide with linux bluez based library. * An attempt to create test application bth_test, which run the mirobt library on top the Linux raw HCI socket. This is not finished - mirobt library needs to be heavily cleaned or, mybe better, rewritten. darcs-hash:20061111091916-f2ef6-30345faafa833fd5549a4e7014c0522a9aa91765.gz --- diff --git a/bluetooth/.emacs-dirvars b/bluetooth/.emacs-dirvars new file mode 100644 index 0000000..346c0d8 --- /dev/null +++ b/bluetooth/.emacs-dirvars @@ -0,0 +1,11 @@ +;; -*- emacs-lisp -*- +;; +;; This file is processed by the dirvars emacs package. Each variable +;; setting below is performed when this dirvars file is loaded. +;; +c-basic-offset: 2 +indent-tabs-mode: nil +tab-width: 2 +;show-trailing-whitespace: t +;indicate-empty-lines: t + diff --git a/bluetooth/Makefile.omk b/bluetooth/Makefile.omk index 077597f..ae33731 100644 --- a/bluetooth/Makefile.omk +++ b/bluetooth/Makefile.omk @@ -10,9 +10,20 @@ #bth_comp2_LIBS = boot_fn arch_drivers excptvec misc pxmc m sci_channels bluetooth #bth_comp2_MOREOBJS = $(USER_LIB_DIR)/system_stub.o -lib_LIBRARIES = bluetooth +lib_LIBRARIES = mirobt -bluetooth_SOURCES = bth_command.c bth_event_acc.c bth_error.c bth_cmd_complete_ev.c l2cap.c bth_inface.c bth_main.c h2638_pkt_controll.c +mirobt_SOURCES = bth_command.c bth_event_acc.c bth_error.c \ +bth_cmd_complete_ev.c l2cap.c bth_inface.c bth_main.c + +ifeq ($(CONFIG_BLUETOOTH_LINUX),y) +mirobt_SOURCES += hci_bluez.c fake_pkt_controll.c +else +mirobt_SOURCES += hci_sci.c h2638_pkt_controll.c +endif include_HEADERS = bth_inface.h bth_fce_out.h bth_h8s2638.h -default_CONFIG = CONFIG_BLUETOOTH=y \ No newline at end of file +default_CONFIG += CONFIG_BLUETOOTH=y +default_CONFIG += CONFIG_BLUETOOTH_LINUX=n + +config_include_HEADERS = bth_config.h +bth_config_DEFINES = $(default_CONFIG) diff --git a/bluetooth/bth_cmd_complete_ev.c b/bluetooth/bth_cmd_complete_ev.c index 77d2b16..538edfd 100644 --- a/bluetooth/bth_cmd_complete_ev.c +++ b/bluetooth/bth_cmd_complete_ev.c @@ -7,14 +7,14 @@ *******************************************************************/ +#include #include #include #ifdef BTH_LX #include -#include //#include #endif -#include "types.h" +#include #include "hci.h" #include "inline_fce.h" #include "hci_event.h" @@ -485,7 +485,7 @@ int cmd_ev_04x0009(uint8_t *bth_p, uint8_t size) read_bd_addr_rp bth_q; int index; - store16(bth_q.status,*((uint8_t*)bth_p+READ_BD_ADDR_RP____status)); + store8(bth_q.status,*((uint8_t*)bth_p+READ_BD_ADDR_RP____status)); memcpy(&bth_local_info.bdaddr,((uint8_t*)bth_p+READ_BD_ADDR_RP____bdaddr),6); index=bth_del_event(btohs(0x0910)); //obcode read_bd_addr if(index==-1) @@ -498,15 +498,15 @@ int cmd_ev_04x0009(uint8_t *bth_p, uint8_t size) // assert(index >= 0 && index < LANCOMMAND); if(*((uint8_t*)bth_p+READ_BD_ADDR_RP____status)==0) { - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; return 0; //prikaz probehl bez komplikaci } else { /*status is not OK */ - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; return((int)*((uint8_t*)bth_p+READ_BD_ADDR_RP____status)); //NOTE probably I put * here, but I don't remember it. It was yesterday >-] }; }; diff --git a/bluetooth/bth_command.c b/bluetooth/bth_command.c index 6979574..f275b10 100644 --- a/bluetooth/bth_command.c +++ b/bluetooth/bth_command.c @@ -11,15 +11,12 @@ #include #include -#ifdef BTH_LX #include +#ifdef BTH_LX #include #include #include #include - -#else -#include "types.h" #endif #include "hci.h" @@ -63,13 +60,13 @@ int bth_cmd_inqury(uint8_t length, uint8_t rsp, uint8_t *lap) /*-- determine the size of memory needed for command in buff and determine if it fit there */ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+INQUIRY_CP_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //possition in buff, which is assigned to the packet + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //possition in buff, which is assigned to the packet hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer to head bth_cmd_packet=(inquiry_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer to parametrs @@ -109,12 +106,12 @@ int change_connection_packet_type(uint16_t handle, uint16_t ptype) /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+SET_CONN_PTYPE_CP_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(set_conn_ptype_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -143,13 +140,13 @@ int bth_cmd_disconnect(uint16_t handle, uint8_t reason) /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+DISCONNECT_CP_SIZE; - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(disconnect_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -185,13 +182,13 @@ int bth_cmd_write_link_policy_settings(uint16_t handle, uint16_t policy) /*obcod /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+WRITE_LINK_POLICY_CP_SIZE; - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(write_link_policy_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -224,13 +221,13 @@ int bth_cmd_reset(void) /*opcode=0x0C03 OCF = 0x0003, OGF = 0x03*/ /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE; - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head store16(*typ_hci_paket, HCI_COMMAND_PKT); @@ -265,13 +262,13 @@ int bth_accept_conn_req_cp(bdaddr_t *bdaddr) /*0x01 - 0x0009*/ /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+ACCEPT_CONN_REQ_CP_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(accept_conn_req_cp*)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -298,13 +295,13 @@ int bth_cmd_write_page_scan(uint16_t interval, uint16_t window) /*obcode= /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(write_page_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -336,12 +333,12 @@ int bth_cmd_write_inquiry_scan_activity(uint16_t interval, uint16_t window) //0x /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(write_inq_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs @@ -367,12 +364,12 @@ int bth_cmd_read_bd_addr(void) /*opcode=0x0910 OCF = 0x0009, OGF = 0x04*/ /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head store16(*typ_hci_paket, HCI_COMMAND_PKT); @@ -397,12 +394,12 @@ int bth_cmd_write_scan_enable(uint8_t set_ing_scan) //0x001A /*-------------------------------------------------------------------------------*/ /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/ - if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL) {return 1;}; /*setup adresses for packet parts + filling of inidividual fields*/ int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_SCAN_ENABLE_SIZE); - bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); - typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu + bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size); + typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE); //pointer on head bth_cmd_packet=(uint8_t *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE); //pointer on parametrs diff --git a/bluetooth/bth_error.c b/bluetooth/bth_error.c index c19fb2e..2996a22 100644 --- a/bluetooth/bth_error.c +++ b/bluetooth/bth_error.c @@ -1,11 +1,9 @@ -#ifdef BTH_LX #include +#ifdef BTH_LX #include #include #include #include -#else -#include "types.h" #endif #include @@ -52,7 +50,7 @@ static struct { */ void bth_error_detect_status(uint8_t status_num) { - uint8_t *message; + char *message; int i=0; if(status_num #include -#include "types.h" +#include #include "hci.h" #include "l2cap.h" #include "hci_event.h" @@ -76,9 +76,9 @@ int bth_del_event(uint16_t opcode) uint16_t opcode_pkt; for(i=0;ihandle),2); sci_rs232_sendch('c',sci_rs232_chan_default); //do PC*/ - store16(bth_q->link_type,*((uint8_t*)bth_p+EVT_CONN_COMPLETE____link_type)); - store16(bth_q->encr_mode,*((uint8_t*)bth_p+EVT_CONN_COMPLETE____encr_mode)); + store8(bth_q->link_type,*((uint8_t*)bth_p+EVT_CONN_COMPLETE____link_type)); + store8(bth_q->encr_mode,*((uint8_t*)bth_p+EVT_CONN_COMPLETE____encr_mode)); bth_cmd_write_link_policy_settings(bth_q->handle,htobs(0x000f)); //reply return (*((uint8_t*)bth_p+EVT_CONN_COMPLETE____status)); @@ -216,7 +216,7 @@ int bth_evt_cmd_complete(uint8_t *bth_p, uint8_t size) //0x0E uint16_t opcode,ogf,ocf; int index=-1; - store16(bth_q.ncmd,*((uint8_t*)bth_p+EVT_CMD_COMPLETE____ncmd)); + store8(bth_q.ncmd,*((uint8_t*)bth_p+EVT_CMD_COMPLETE____ncmd)); // store_le16(&bth_q.opcode,*((uint16_t*)((uint8_t*)bth_p+EVT_CMD_COMPLETE____opcode))); __bthtomc16(&bth_q.opcode,(((uint8_t*)bth_p+EVT_CMD_COMPLETE____opcode))); index=bth_del_event(bth_q.opcode); @@ -230,16 +230,16 @@ int bth_evt_cmd_complete(uint8_t *bth_p, uint8_t size) //0x0E { if(*((uint8_t*)bth_p+3)==0) { - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; bth_local_info.busy=0; return 0; //no complications was encountered during command execution } else { /*status is not OK - an error occured - the sent command is still in the confirmation queue */ - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; bth_local_info.busy=0; return((int)*((uint8_t*)bth_p+EVT_CMD_COMPLETE_SIZE)); }; @@ -287,10 +287,10 @@ int bth_evt_cmd_complete(uint8_t *bth_p, uint8_t size) //0x0E int bth_evt_cmd_status(uint8_t *bth_p, uint8_t size) //0x0F { evt_cmd_status bth_q; - store16(bth_q.status,*((uint8_t*)bth_p+EVT_CMD_STATUS____status)); - store16(bth_q.ncmd,*((uint8_t*)bth_p+EVT_CMD_STATUS____ncmd)); + store8(bth_q.status,*((uint8_t*)bth_p+EVT_CMD_STATUS____status)); + store8(bth_q.ncmd,*((uint8_t*)bth_p+EVT_CMD_STATUS____ncmd)); // store_le16(&bth_q.opcode,*((uint16_t*)((uint8_t*)bth_p+EVT_CMD_STATUS____opcode))); - __bthtomc16(&bth_q.opcode,(((uint8_t*)bth_p+EVT_CMD_STATUS____opcode))); + __bthtomc8(&bth_q.opcode,(((uint8_t*)bth_p+EVT_CMD_STATUS____opcode))); // memcpy(&bth_q.opcode,(((uint8_t*)bth_p+EVT_CMD_STATUS____opcode)),2); uint8_t ogf, ocf; int index; @@ -307,14 +307,14 @@ int bth_evt_cmd_status(uint8_t *bth_p, uint8_t size) //0x0F { if(bth_q.status==0) { - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; } else { /*status is not OK - an error occured - the sent command is still in the confirmation queue */ - free(bth_pole_adrr_check_packet[index]); - bth_pole_adrr_check_packet[index]=NULL; + free(bth_array_adrr_check_packet[index]); + bth_array_adrr_check_packet[index]=NULL; }; } else diff --git a/bluetooth/bth_fce_out.h b/bluetooth/bth_fce_out.h index fe27d41..d03967d 100644 --- a/bluetooth/bth_fce_out.h +++ b/bluetooth/bth_fce_out.h @@ -7,6 +7,8 @@ *******************************************************************/ +#include + int bth_send_queue(void); diff --git a/bluetooth/bth_inface.c b/bluetooth/bth_inface.c index 2043104..c3ce8df 100644 --- a/bluetooth/bth_inface.c +++ b/bluetooth/bth_inface.c @@ -6,6 +6,8 @@ Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com *******************************************************************/ + +#include #ifdef BTH_LX #include @@ -18,7 +20,9 @@ #include "bth_inface.h" #include "bth_inface.h" +#ifndef CONFIG_BLUETOOTH_LINUX #include +#endif /* the number of communication structures i.e. how many channels can be used for communication. It alse specifies howmany independent couples of I/O buffers is here.*/ @@ -52,32 +56,6 @@ int bth_inface_t_isr(int chan) return (-1); } -/** - * fce write one char to out-buffer. Fce return a code of char. If a value is -1 its signal for error -*/ -int bth_inface_sendch(int val, int chan) -{ - if(bth_inface_que_put(&(bth_inface_chan_array[chan].bth_inface_que_out),val)<0) - {return (-1);}; - return (val); -}; - - -/** - * fce read one char of in-buffer. Fce return a code of char. If is a value -1 than is not new char -*/ -int bth_inface_recch(int chan) -{ - short val; - if((val=bth_inface_que_get(&(bth_inface_chan_array[chan].bth_inface_que_in)))>=0) - { - sci_rs232_sendch(val,sci_rs232_chan_default); - return val; - } - return (-1); -}; - - /** * init buffer for first chanal - 0 (nm. is index of array) */ diff --git a/bluetooth/bth_inface.h b/bluetooth/bth_inface.h index 2ff1528..02d1f58 100644 --- a/bluetooth/bth_inface.h +++ b/bluetooth/bth_inface.h @@ -12,6 +12,11 @@ #ifndef _ID_BTH_INFACE_H_ #define _ID_BTH_INFACE_H_ +#include +#include +#ifdef CONFIG_BLUETOOTH_LINUX +#endif + #define BTH_INFACE_CHANAL (1) #define BTH_INFACE_BUF_LEN (70) @@ -69,7 +74,6 @@ int bth_inface_sendstr(const char *s, int chan); int bth_inface_r_isr(int chan, int val); int bth_inface_t_isr(int chan); -/* HACK: Include machine specific definitions */ #endif /* _ID_BTH_INFACE_H_ */ diff --git a/bluetooth/bth_main.c b/bluetooth/bth_main.c index 69e95b1..4a049ca 100644 --- a/bluetooth/bth_main.c +++ b/bluetooth/bth_main.c @@ -6,15 +6,15 @@ Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com *******************************************************************/ -#ifdef BTH_LX +#include #include +#ifdef BTH_LX #include #include #include #include #include #else -#include "types.h" #include #endif @@ -32,7 +32,9 @@ #include "bth_inface.h" #include "bth_fce_out.h" #include "bth_h8s2638.h" -#include + + +#define BTH_BUF_LEN 300 /*--------BD address whitch are accept for connection-------------*/ bdaddr_t bth_accept_bd_addr[]={}; @@ -44,20 +46,16 @@ bths_dev_info bth_local_info;//={0,{0,0,0,0,0,0,0,0},{0,0,0},0,{0,0,0},0}; bths_connect_bluet* bth_connected[8]; /*-------------------------------- recieve data buffer -----------------------------*/ -uint8_t bth_pole_char_in[SCI_BTH_BUF_LEN]; bth_que_t bth_rs232_que_in; -uint8_t bth_rs232_buf_in[SCI_BTH_BUF_LEN]; -//-- --- ----- ----- ---- ------ ----- -- ---- -- -//-- --- ----- ----- ---- ------ ----- -- ---- -- -bth_que_t bth_inface_que_in; -bth_que_t bth_inface_que_out; +//bth_que_t bth_inface_que_in; +//bth_que_t bth_inface_que_out; -void *bth_pole_adrr_comm_packet[LENCOMMAND]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; +void *bth_array_adrr_comm_packet[LENCOMMAND]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; bths_command_buf_info bth_com_buf_info={LENCOMMAND,0,0}; /***********************************************************************************/ -void *bth_pole_adrr_check_packet[LENCOMMAND]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; +void *bth_array_adrr_check_packet[LENCOMMAND]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; bths_command_buf_info bth_check_buf_info={LENCOMMAND,0,0}; /***********************************************************************************/ @@ -84,58 +82,58 @@ int bth_send_queue(void) int i; int hp_size; if(bth_local_info.busy!=0) - {return 1;}; //device is busy + {return 1;}; //device is busy if(bth_com_buf_info.aktual==bth_com_buf_info.sent) //PRAVDEPODOBNE neni co odesilat { if(bth_com_buf_info.sent<(LENCOMMAND-2)) { - if(bth_pole_adrr_comm_packet[bth_com_buf_info.sent+1]==NULL) + if(bth_array_adrr_comm_packet[bth_com_buf_info.sent+1]==NULL) {return 1;}; //There is certainly nothing to send } else { - if(bth_pole_adrr_comm_packet[0]==NULL) + if(bth_array_adrr_comm_packet[0]==NULL) {return 1;}; //There is certainly nothing to send }; }; /*bth_send_packet(AdrFrom,howmanyBytes;)*/ - switch(*(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.sent]) - { - case HCI_ACLDATA_PKT: - __bthtomc16((uint8_t*)&(hp_size),((uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.sent])+HCI_PKT_SIZE+HCI_ACL_HDR____dlen); - hp_size=hp_size+HCI_ACL_HDR_SIZE+HCI_PKT_SIZE; - if(!(bth_send_packet(bth_pole_adrr_comm_packet[bth_com_buf_info.sent],hp_size))) + switch(*(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.sent]) + { + case HCI_ACLDATA_PKT: + __bthtomc16((uint8_t*)&(hp_size),((uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.sent])+HCI_PKT_SIZE+HCI_ACL_HDR____dlen); + hp_size=hp_size+HCI_ACL_HDR_SIZE+HCI_PKT_SIZE; + if(!(bth_send_packet(bth_array_adrr_comm_packet[bth_com_buf_info.sent],hp_size))) + { + free(bth_array_adrr_comm_packet[bth_com_buf_info.sent]); + bth_array_adrr_comm_packet[bth_com_buf_info.sent]=NULL; + if(bth_com_buf_info.sent<(LENCOMMAND-2)){bth_com_buf_info.sent++;} + else{ bth_com_buf_info.sent=0;}; + return(0); + }; + free(bth_array_adrr_comm_packet[bth_com_buf_info.sent]); + bth_array_adrr_comm_packet[bth_com_buf_info.sent]=NULL; + return (-6); + case HCI_COMMAND_PKT: + hp_size=((uint16_t)*(((uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.sent])+HCI_PKT_SIZE+2)+HCI_COMMAND_HDR_SIZE+HCI_PKT_SIZE); + if(!(bth_send_packet(bth_array_adrr_comm_packet[bth_com_buf_info.sent],hp_size))) + {/*sent - add the command to allow confirmation*/ + for(i=0; i>4; #ifdef BTH_LX + uint8_t map_leters[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; sci_rs232_sendch(map_leters[val],sci_rs232_chan_default); val=(zn&0x0f); sci_rs232_sendch(map_leters[val],sci_rs232_chan_default); @@ -163,41 +162,11 @@ void bth_conv_char_text(uint8_t zn) -/** - //FIXME - *Sends data of the size hp_size from address hp to the bluetooth device (UART) - */ -int bth_send_packet(uint8_t *hp, uint16_t hp_size) -{ - int zn,i; - /*is bluetooth device free, or is it busy by the previous command?*/ - if(bth_local_info.busy==0) - { -#ifndef BTH_LX - VypisHexa(hp,hp_size); -#else - - for(i=0; iip; //FIXME set us to the actual position in the file @@ -397,8 +366,8 @@ int bth_recieve_packet(int c) { case HCI_EVENT_PKT: /*fill in structure "hci_event_hdr" from the queue (bye by byte)*/ - store16(bth_event_packet.evt, *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE)); - store16(bth_event_packet.plen, *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+1)); + store8(bth_event_packet.evt, *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE)); + store8(bth_event_packet.plen, *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+1)); if(bth_rs232_que_in.ip-bth_rs232_que_in.buf_beg>3) { @@ -451,7 +420,7 @@ int bth_recieve_packet(int c) bth_acl_packet.handle=bth_acl_packet.handle & 0x0fff; /*variable 'char_acl_pkt' stores the properties of the packet, if it is point to point or broadcast, or char. L2CAP*/ - store16(char_acl_pkt, (0xf0&*(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+HCI_ACL_HDR____handle+1))); + store8(char_acl_pkt, (0xf0&*(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+HCI_ACL_HDR____handle+1))); /*decide which packet is this (PtP,Piconet,broat...) and the type of communication (L2CAP, HCI)*/ data_ad=(uint8_t*)bth_rs232_que_in.buf_beg+HCI_PKT_SIZE+HCI_ACL_HDR_SIZE; @@ -513,11 +482,12 @@ void bth_start(void) */ void bth_init(void) { + static uint8_t bth_array_char_in[70]; // bth_check_command_for_send=NULL; - bth_rs232_que_in.buf_end=(uint8_t*)bth_pole_char_in+SCI_RS232_BUF_LEN; - bth_rs232_que_in.buf_beg=bth_pole_char_in; - bth_rs232_que_in.ip=bth_pole_char_in; + bth_rs232_que_in.buf_end=(uint8_t*)bth_array_char_in+BTH_BUF_LEN; + bth_rs232_que_in.buf_beg=bth_array_char_in; + bth_rs232_que_in.ip=bth_array_char_in; }; /****************************************************************************/ diff --git a/bluetooth/bth_receive.h b/bluetooth/bth_receive.h index cd30f36..0064dcc 100644 --- a/bluetooth/bth_receive.h +++ b/bluetooth/bth_receive.h @@ -10,7 +10,6 @@ #ifndef BTH_RECEIVE_H #define BTH_RECEIVE_H -#define SCI_BTH_BUF_LEN 70 typedef struct{ uint8_t *buf_beg; //start of adress structur uint8_t *buf_end; //end of adress structur - beg+sizeof(struct) diff --git a/bluetooth/fake_pkt_controll.c b/bluetooth/fake_pkt_controll.c new file mode 100644 index 0000000..05a80f1 --- /dev/null +++ b/bluetooth/fake_pkt_controll.c @@ -0,0 +1,63 @@ +/******************************************************************* + bluetooth library + + h2638_pkt_control.c - fce for TPU operation + + Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com + + *******************************************************************/ + +#include +#include "hci.h" +#include "bth_h8s2638.h" + + +long int timer; + +/** + * Starts TPU channel 1 +*/ +void bth_start_TPU_counter(void) +{ +}; + + +/** + * Stop TPU 1 + */ +void bth_stop_TPU_counter(void) +{ +}; + + +/** + * Reset TPU 1 + */ +void bth_clear_TPU_counter(void) +{ +}; + +/** + * Returns the number of timer interrupts + */ +long int bth_get_timer(void) +{ + return timer; +}; + +/** + * Zeroes the timer variable + */ +void bth_nul_timer(void) +{ + timer=0; +}; + + +/** + * Timer initialization - HW 1-timer overflow; 2-???Dosazeni citace hodnoty TIER1_TGIEAm + */ +void bth_init_pkt_controll(void) +{ +}; + diff --git a/bluetooth/hci.h b/bluetooth/hci.h index 9cab25f..70ce944 100644 --- a/bluetooth/hci.h +++ b/bluetooth/hci.h @@ -1,8 +1,8 @@ /******************************************************************* bluetooth library - hci.h - main structures for keeping an information about a queie, definition of global val, - and any macros and inline fce + hci.h - main structures for keeping an information about a queue, + definition of global val, and any macros and inline fce Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com @@ -14,6 +14,12 @@ #ifndef HCI_H_H #define HCI_H_H +#include +#include +#ifdef CONFIG_BLUETOOTH_LINUX +#include +#endif + /* Byte order conversions */ #if __BYTE_ORDER == __LITTLE_ENDIAN #define htobs(d) (d) @@ -51,7 +57,7 @@ typedef struct { // } /*pro typ char (nikoliv u16)*/ -#define store16(field, val) field=val; +#define store8(field, val) field=val; // Returns an offset of a field in a structure @@ -198,12 +204,12 @@ extern bths_dev_info bth_local_info; extern bths_connect_bluet *bth_connected[]; //extern void *bth_for_connecting[]; -/*---------------- queue prikazova a potvrzovaci-----------------------*/ -#define LENCOMMAND 10 -extern void *bth_pole_adrr_comm_packet[LENCOMMAND]; +/*---------------- command and acknowledge queues -----------------------*/ +#define LENCOMMAND 10 +extern void *bth_array_adrr_comm_packet[LENCOMMAND]; extern bths_command_buf_info bth_com_buf_info; -extern void *bth_pole_adrr_check_packet[LENCOMMAND]; +extern void *bth_array_adrr_check_packet[LENCOMMAND]; extern bths_command_buf_info bth_check_buf_info; extern uint8_t bth_controll_flag; diff --git a/bluetooth/hci_bluez.c b/bluetooth/hci_bluez.c new file mode 100644 index 0000000..e856c1c --- /dev/null +++ b/bluetooth/hci_bluez.c @@ -0,0 +1,21 @@ +#include "hci.h" +#include +int hci_socket; +/** + //FIXME + *Sends data of the size hp_size from address hp to the bluetooth device (UART) + */ +int bth_send_packet(uint8_t *hp, uint16_t hp_size) +{ + /*is bluetooth device free, or is it busy by the previous command?*/ + if(bth_local_info.busy==0) { + + write(hci_socket, hp, hp_size); + + bth_local_info.busy=1; + return(0); //everything sent ==== OK ===== + } else { + return 2; //busy + }; +}; + diff --git a/bluetooth/hci_sci.c b/bluetooth/hci_sci.c new file mode 100644 index 0000000..114b5e7 --- /dev/null +++ b/bluetooth/hci_sci.c @@ -0,0 +1,28 @@ +#include + +/** + //FIXME + *Sends data of the size hp_size from address hp to the bluetooth device (UART) + */ +int bth_send_packet(uint8_t *hp, uint16_t hp_size) +{ + /*is bluetooth device free, or is it busy by the previous command?*/ + if(bth_local_info.busy==0) { +#ifndef BTH_LX + VypisHexa(hp,hp_size); +#else + int zn,i; + + for(i=0; i #include -#ifdef BTH_LX #include +#ifdef BTH_LX #include #include #include #include - -#else -#include "types.h" #endif #include "hci.h" @@ -47,7 +44,7 @@ l2cap_code_fce_def l2cap_code_fce[]={ /** * Search the cannels of the connected device dev_num and search the channel dcid */ -inline int l2cap_find_dcid(int dcid, int dev_num ) +static inline int l2cap_find_dcid(int dcid, int dev_num ) { int i; for(i=1;i/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/bth_tests/Makefile.omk b/bth_tests/Makefile.omk new file mode 100644 index 0000000..6ee1f49 --- /dev/null +++ b/bth_tests/Makefile.omk @@ -0,0 +1,4 @@ +# -*- makefile -*- + +# All subdirectories (even linked) with Makefile.omk +SUBDIRS := $(shell find -L $(SOURCES_DIR) -maxdepth 2 -mindepth 2 -name Makefile.omk|sed 's!$(SOURCES_DIR)/\(.*\)/.*!\1!') diff --git a/bth_tests/Makefile.rules b/bth_tests/Makefile.rules new file mode 100644 index 0000000..0a50df9 --- /dev/null +++ b/bth_tests/Makefile.rules @@ -0,0 +1,1083 @@ +# Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base +# +# (C) Copyright 2003 by Pavel Pisa - OCERA team member +# (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE +# +# Version for Linux/RTLinux builds. #OMK@linux +# +# #OMK@base +# input variables +# V .. if set to 1, full command text is shown else short form is used +# SUBDIRS .. list of subdirectories intended for make from actual directory +# default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ... +# LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK@config_h +# of options defined in the current directory +# config_include_HEADERS .. names of global config files (possibly +# with subdirectories) +# xxx_DEFINES .. list of config directives to be included in +# config header file of the name /xxx.h +# LN_HEADERS .. if "y", header files are symbolicaly linked instead of copied. #OMK@include +# #OMK@linux +# input variables +# lib_LIBRARIES .. list of the user-space libraries +# shared_LIBRARIES .. list of the user-space shared libraries +# kernel_LIBRARIES .. list of the kernel-space libraries +# rtlinux_LIBRARIES.. list of the RT-Linux kernel-space libraries +# include_HEADERS .. list of the user-space public header files +# nobase_include_HEADERS .. public headers copied even with directory part +# renamed_include_HEADERS .. public headers copied to the different target name +# kernel_HEADERS .. list of the kernel-space public header files +# rtlinux_HEADERS .. list of the RT-Linux kernel-space public header files +# bin_PROGRAMS .. list of the require binary programs +# utils_PROGRAMS .. list of the development utility programs +# kernel_MODULES .. list of the kernel side modules/applications +# rtlinux_MODULES .. list of RT-Linux the kernel side modules/applications +# xxx_SOURCES .. list of specific target sources +# INCLUDES .. additional include directories and defines for user-space +# kernel_INCLUDES .. additional include directories and defines for kernel-space +# rtlinux_INCLUDES .. additional include directories and defines for RT-Linux +# OMIT_KERNEL_PASSES if defined, all kernel passes are omited +# +# LINUX_DIR .. location of Linux kernel sources +# RTL_DIR .. location of RT-Linux sources +# QT_SUBDIRS .. subdirectories where to build QT applications using qmake #OMK@qt +# QTDIR .. where QT resides +-include $(MAKERULES_DIR)/OCERA_TOP_DIR #OMK@linux-setup + +BUILD_DIR_NAME = _build +COMPILED_DIR_NAME = _compiled +ifndef GROUP_DIR_NAME +GROUP_DIR_NAME = nogroup +endif + +ifdef OCERA_DIR +ifeq ($(wildcard $(OCERA_DIR)/ocera.mk),) +$(warning "ocera.mk" file does not exist. Adapt Makefile.rules for standalone compilation) +$(warning (comment out definition of OCERA_DIR line and optionally select RTL_DIR) ) +$(error or go to the ocera/ directory and do 'make' to generate the "ocera.mk" file first, please) +endif +include $(OCERA_DIR)/ocera.mk +KERN_INCLUDE_DIR := $(OCERA_KERNEL_INCLUDES_DIR) +KERN_LIB_DIR := $(OCERA_KERNEL_LIBRARIES_DIR) +KERN_MODULES_DIR := $(OCERA_MODULES_DIR) +KERN_BUILD_DIR := $(BUILD_DIR)/kern/$(GROUP_DIR_NAME) +KERN_MODPOST_DIR := $(BUILD_DIR)/kern-modpost +USER_INCLUDE_DIR := $(OCERA_USER_INCLUDES_DIR) +USER_LIB_DIR := $(OCERA_USER_LIBRARIES_DIR) +USER_UTILS_DIR := $(TARGET_DIR)/usr/bin +USER_BIN_DIR := $(TARGET_DIR)/usr/bin +USER_BUILD_DIR := $(BUILD_DIR)/user/$(GROUP_DIR_NAME) +#LINUX_DIR := $(OCERA_DIR)/kernel/linux +#RTL_DIR := $(OCERA_DIR)/kernel/rtlinux +#CONFIG_FILE := $(OCERA_DIR)/emdebsys/.config +ifneq ($(wildcard $(CONFIG_FILE)),) +CONFIG_FILE_OK = y +endif +else # OCERA_DIR +KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern +KERN_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern +KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules +KERN_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern +KERN_MODPOST_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern-modpost +USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include +USER_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib +USER_UTILS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils +USER_BIN_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin +USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user + +ifndef LINUX_VERSION +LINUX_VERSION=$(shell uname -r) +endif +ifndef LINUX_DIR +LINUX_DIR=/lib/modules/$(LINUX_VERSION)/build +endif +endif # OCERA_DIR + +LOCAL_BUILD_DIR = $(USER_OBJS_DIR) + +# Local Variables: +# mode:makefile +# End: + #OMK@base +# We need to ensure definition of sources directory first +ifndef SOURCES_DIR +SOURCES_DIR := $(shell ( pwd -L ) ) +endif + +.PHONY: all default check-make-ver + +all: check-make-ver default + @echo "Compilation finished" + +#========================= +# Include the config file + +ifneq ($(CONFIG_FILE_OK),y) +ifndef CONFIG_FILE +CONFIG_FILE := $(MAKERULES_DIR)/config.omk +endif +ifneq ($(wildcard $(CONFIG_FILE)-default),) +-include $(CONFIG_FILE)-default +else +ifneq ($(MAKECMDGOALS),default-config) +$(warning Please, run "make default-config" first) +endif +endif + +ifneq ($(wildcard $(CONFIG_FILE)),) +include $(CONFIG_FILE) +CONFIG_FILE_OK = y +endif +endif #$(CONFIG_FILE_OK) + +export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR +export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT +# OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes +# must to be serialized only in the toplevel make. + +ifndef RELATIVE_DIR +RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) +endif +override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) +override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%) +#$(warning RELATIVE_DIR $(RELATIVE_DIR)) +override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__') +#$(warning BACK2TOP_DIR $(BACK2TOP_DIR)) + +#$(warning SOURCES_DIR = $(SOURCES_DIR)) +#$(warning MAKERULES_DIR = $(MAKERULES_DIR)) +#$(warning RELATIVE_DIR = $(RELATIVE_DIR)) + +#vpath %.c $(SOURCES_DIR) +#vpath %.cc $(SOURCES_DIR) +#vpath %.cxx $(SOURCES_DIR) + +VPATH = $(SOURCES_DIR) +srcdir = $(SOURCES_DIR) + +# Defines for quiet compilation +ifdef V + ifeq ("$(origin V)", "command line") + OMK_VERBOSE = $(V) + endif +endif +ifndef OMK_VERBOSE + OMK_VERBOSE = 0 +endif +ifeq ($(OMK_VERBOSE),1) + Q = +else + Q = @ +endif +ifneq ($(findstring s,$(MAKEFLAGS)),) + QUIET_CMD_ECHO = true + OMK_SILENT = 1 +else + QUIET_CMD_ECHO = echo +endif + +# =================================================================== +# We have set up all important variables, so we can check and include +# real OCERA style Makefile.omk now +ifndef OMK_INCLUDED +include $(SOURCES_DIR)/Makefile.omk +OMK_INCLUDED := 1 +endif + + +check-make-ver: + @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \ + if [ x$$GOOD_MAKE_VERSION != xy ] ; then \ + echo "Your make program version is too old and does not support OMK system." ; \ + echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \ + fi + +distclean dist-clean: + @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)" + @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME) + +# Common OMK templates +# ==================== + +# Syntax: $(call mkdir,) +define mkdir_def + [ -d $(1) ] || mkdir -p $(1) || exit 1 +endef + +ifneq ($(V),2) +NO_PRINT_DIRECTORY := --no-print-directory +endif + +# Syntax: $(call omk_pass_template,,,[],[]) +define omk_pass_template +.PHNOY: $(1) $(1)-local +$(1): + +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \ + $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \ + RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \ + -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true +ifneq ($(4),) + @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \ + $(call mkdir_def,$(2)); \ + $(MAKE) $(NO_PRINT_DIRECTORY) -C $(2) \ + -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local) +endif +endef + +# ======================= +# DEFAULT CONFIG PASS + +default-config: + @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default" + @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default" + @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default" + @echo >> "$(CONFIG_FILE)-default" + @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \ + RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \ + -f $(MAKERULES_DIR)/Makefile default-config-pass + +$(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always)) + +default-config-pass-local: +# @echo Default config for $(RELATIVE_DIR) + @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default" + @$(foreach x, $(default_CONFIG), echo $(x) | \ + sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; ) + #OMK@config_h +# Syntax: $(call BUILD_CONFIG_H_template,,,) +define BUILD_CONFIG_H_template + +$(1) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default) + @$(QUIET_CMD_ECHO) " CONFGEN $$(@:$(MAKERULES_DIR)/%=%)" + @if [ ! -d `dirname $(1).tmp` ] ; then \ + mkdir `dirname $(1).tmp` ; fi + @echo "/* Automatically generated from */" > "$(1).tmp" + @echo "/* config file: $$< */" >> "$(1).tmp" + @echo "#ifndef $(3)" >> "$(1).tmp" + @echo "#define $(3)" >> "$(1).tmp" + @( $(foreach x, $(shell echo '$($(2))' | sed -e 's/\<\([^ =]*\)\(=[^ ]\+\|\)\>/\1/g' ), \ + echo '$(x).$($(x))' ; ) echo ; ) | \ + sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \ + sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \ + >> "$(1).tmp" + @echo "#endif /*$(3)*/" >> "$(1).tmp" + @if cmp --quiet "$(1).tmp" "$(1)" ; then rm "$(1).tmp" ; \ + else mv "$(1).tmp" "$(1)" ; \ + echo Updated configuration "$(1)" ; fi + +endef + +ifdef LOCAL_CONFIG_H + +CFLAGS += -I. +$(eval $(call BUILD_CONFIG_H_template,$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) ) + +endif + +# Special rules for configuration exported headers + +#FIXME: The directory for headers should not be specified here. +$(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\ +_$(basename $(notdir $(confh)))_H \ +))) + +# Add some hooks to standard passes +include-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS)) + +clean-local: clean-local-config-h + +clean-local-config-h: + @$(foreach confh,$(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS)),\ + if [ -e $(confh) ] ; then touch -t 200001010101 $(confh) ; fi ; \ + ) + + +# Local Variables: +# mode:makefile +# End: +ifeq ($(OMK_VERBOSE),1) #OMK@include +CPHEADER_FLAGS += -v +LNHEADER_FLAGS += -v +endif + +ifneq ($(LN_HEADERS),y) +define cp_cmd +( echo " CP $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) ) +endef +else +define cp_cmd +( echo " LN $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; ln -sf $(LNHEADER_FLAGS) $(1) $(2) ) +endef +endif + +# TODO: Check modification date of changed header files. If it is +# newer that in source dir, show a warning. + +# Syntax: $(call include-pass-template,,) +define include-pass-template + @$(foreach f, $($(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(notdir $(f)) \ + || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(notdir $(f))) || exit 1 ; ) + @$(foreach f, $(nobase_$(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(f) \ + || ( mkdir -p $(1)/$(dir $(f)) && $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(f)) ) || exit 1 ; ) + @$(foreach f, $(renamed_$(2)_HEADERS), \ + srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \ + cmp --quiet $(SOURCES_DIR)/$${srcfname} $(1)/$${destfname} \ + || ( mkdir -p `dirname $(1)/$${destfname}` && $(call cp_cmd,$(SOURCES_DIR)/$${srcfname},$(1)/$${destfname}) ) || exit 1 ; ) +endef + +# Local Variables: +# mode:makefile +# End: + #OMK@linux +# Hack to check RT-Linux rules +#LINUX_DIR := /home/cvs/ocera/ocera-build/kernel/linux +#RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux +#CONFIG_RTLINUX = y +#OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) ) + +#CFLAGS += -ggdb +#CFLAGS += -O2 +CFLAGS += -Wall +#CXXFLAGS += -ggdb +CXXFLAGS += -O2 +CXXFLAGS += -Wall + + +CPPFLAGS += -I $(USER_INCLUDE_DIR) + +LOADLIBES += -L$(USER_LIB_DIR) + +LOADLIBES += $(lib_LOADLIBES:%=-l%) + +LIB_CPPFLAGS += $(CPPFLAGS) +LIB_CFLAGS += $(CFLAGS) + +ifeq ($(TARGET_OS),win32) + SOLIB_EXT = dll +else + SOLIB_EXT = so + SOLIB_PICFLAGS += -fpic +endif + +ifndef RELATIVE_DIR +RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) +endif +override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) +override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%) +#$(warning RELATIVE_DIR $(RELATIVE_DIR)) +override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__') +#$(warning BACK2TOP_DIR $(BACK2TOP_DIR)) + +#$(warning SOURCES_DIR = $(SOURCES_DIR)) +#$(warning MAKERULES_DIR = $(MAKERULES_DIR)) +#$(warning RELATIVE_DIR = $(RELATIVE_DIR)) + +override RELATIVE_PREFIX := $(RELATIVE_DIR)/ +override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%) + +#vpath %.c $(SOURCES_DIR) +#vpath %.cc $(SOURCES_DIR) +#vpath %.cxx $(SOURCES_DIR) + +VPATH = $(SOURCES_DIR) +srcdir = $(SOURCES_DIR) + +USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR) +KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR) + +.PHONY: dep subdirs clean clean-custom cleandepend + +# Some support to serialize some targets for parallel make +ifneq ($(OMK_SERIALIZE_INCLUDED),y) +include-pass: $(check-dir) +library-pass: include-pass +binary-pass: library-pass +kernel-lib-pass: include-pass +kernel-mod-pass: kernel-lib-pass +kernel-modpost-pass: kernel-mod-pass +kernel-pass: kernel-mod-pass kernel-modpost-pass + +OMK_SERIALIZE_INCLUDED = y +endif + +#===================================================================== +# User-space rules and templates to compile programs, libraries etc. + +ifdef USER_RULE_TEMPLATES + +ifdef CPP_ONLY +OBJ_EXT := .E +CC_STAGE_STOP := E +else +OBJ_EXT := .o +CC_STAGE_STOP := c +endif + +USER_SOURCES2OBJS = $(OBJ_EXT)/.c $(OBJ_EXT)/.cc $(OBJ_EXT)/.cxx $(OBJ_EXT)/$(OBJ_EXT) + +USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.lo + +#%.lo: %.c +# $(CC) -o $@ $(LCFLAGS) -c $< + +c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER + +cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER + +idl_COMPILE = $(IDL_COMPILER) + +# Check GCC version for user build +ifndef CC_MAJOR_VERSION +CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/') +endif +# Prepare suitable define for dependency building +ifeq ($(CC_MAJOR_VERSION),2) +CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp" +else +CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp" +endif + + +# Syntax: $(call COMPILE_c_o_template,,,) +define COMPILE_c_o_template +$(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) + @$(QUIET_CMD_ECHO) " CC $$@" + $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -$(CC_STAGE_STOP) $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d" ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +endef + + +# Syntax: $(call COMPILE_cc_o_template,,,) +define COMPILE_cc_o_template +$(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) + @$(QUIET_CMD_ECHO) " CXX $$@" + $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -$(CC_STAGE_STOP) $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d" ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +endef + + +# Syntax: $(call COMPILE_S_o_template,,,) +define COMPILE_S_o_template +$(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) + @$(QUIET_CMD_ECHO) " AS $$@" + $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -$(CC_STAGE_STOP) $$< ; \ + then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +endef + + +# Syntax: $(call CMETRIC_o_h_template,,) +define CMETRIC_o_h_template +$(2): $(1) + @$(QUIET_CMD_ECHO) " CMETRIC $$@" + $(Q)if [ -n `dirname $$@` ] ; then \ + if [ ! -e `dirname $$@` ] ; then \ + mkdir -p `dirname $$@` ; fi ; fi + $(Q)echo >$$@ '/* Automatically generated from $$< */' + $(Q)echo >>$$@ '/* Conditionals to control compilation */' + $(Q)set -o pipefail ; $(NM) $$< \ + | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@ + $(Q)echo >>$$@ '/* Defines from the values defined to symbols */' + $(Q)set -o pipefail ; $(NM) $$< \ + | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@ +endef + + + +define COMPILE_idl_template +$(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) + @$(QUIET_CMD_ECHO) " IDL $$@" + $(Q) $$(idl_COMPILE) $(1) +endef + + +# Syntax: $(call PROGRAM_template,,,,) +# FIXME: ???????? asi je tu blbej komentar +define PROGRAM_template + +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +USER_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(foreach x, $(USER_SOURCES2OBJS), +$(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\ + $$($(1)_SOURCES) $$($(1)_GEN_SOURCES))) +) +$(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%)) + +USER_OBJS += $$($(1)_OBJS) +USER_SOURCES += $$($(1)_SOURCES) + +$(2)/$(1): $$($(1)_OBJS) + @$(QUIET_CMD_ECHO) " LINK $$@" + $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES:%.cxx=%.cc))" ] ; then echo $$(CC) ; else echo $$(CXX) ; fi) \ + $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $(2)/$(1) + @echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d + @sed -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(USER_OBJS_DIR)/$(1).exe.map >>$(USER_OBJS_DIR)/$(1).exe.d + @echo >>$(USER_OBJS_DIR)/$(1).exe.d +endef + + +# Syntax: $(call LIBRARY_template,) +define LIBRARY_template + +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +USER_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(foreach x, $(USER_SOURCES2OBJS), +$(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\ + $$($(1)_SOURCES) $$($(1)_GEN_SOURCES))) +) +$(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%)) + +USER_OBJS += $$($(1)_OBJS) +USER_SOURCES += $$($(1)_SOURCES) + +$(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS) + @$(QUIET_CMD_ECHO) " AR $$@" + $(Q) $(AR) rcs $$@ $$^ +endef + + +# Syntax: $(call SOLIB_template,) +define SOLIB_template + +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(foreach x, $(USER_SOURCES2OBJSLO), +$(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\ + $$($(1)_SOURCES) $$($(1)_GEN_SOURCES))) +) +$(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%)) + +SOLIB_OBJS += $$($(1)_OBJSLO) +SOLIB_SOURCES += $$($(1)_SOURCES) + +$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_OBJSLO) + @$(QUIET_CMD_ECHO) " LINK $$@" + $(Q) $(LD) --shared --soname=lib$(1).$(SOLIB_EXT) -o $$@ $$^ +endef + + + +library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \ + $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT)) + +binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) + +# Special rules for CMETRIC generated headers + +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\ + $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%$(OBJ_EXT)),))) +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%$(OBJ_EXT)),\ + $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh))))) + +GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%) + +GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h)) + +# Generate rules for compilation of programs and libraries + +$(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR)))) + +$(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR)))) + +$(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib)))) + +$(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib)))) + +-include $(USER_OBJS_DIR)/*.d + +endif + +#===================================================================== +# Kernel-space rules and templates to compile modules, libraries etc. + +ifdef KERN_RULE_TEMPLATES + +$(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(MAKERULES_DIR)/kernelcfg2mk + @$(QUIET_CMD_ECHO) " KCFG2MK $$@" + $(Q) $(MAKERULES_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR) + +ifeq ($(CONFIG_RTLINUX),y) +include $(RTL_DIR)/rtl.mk + +KERN_CC = $(CC) +kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' ) +INCLUDES := -I $(KERN_INCLUDE_DIR) $(INCLUDE) $(rtlinux_INCLUDES) $(kernel_INCLUDES) +#-DEXPORT_NO_SYMBOLS +c_o_kern_COMPILE = $(KERN_CC) -idirafter $(kern_GCCLIB_DIR)/include $(INCLUDES) $(CFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc +cc_o_kern_COMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB +KERN_EXE_SUFFIX := .o +KERN_ARCH = $(ARCH) +KERN_LD = $(LD) +KERN_AR = $(AR) + +else # CONFIG_RTLINUX + +include $(KERN_LIB_DIR)/kernel.mk + +ifeq ($(LINUX_SRC),) +LINUX_SRC = $(LINUX_DIR) +endif +kernel_INCLUDES += -I $(LINUX_DIR) -idirafter $(LINUX_SRC)/include/linux + +ifdef LINUX_CC +KERN_CC = $(LINUX_CC) +kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(LINUX_CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' ) +else +KERN_CC = echo KERN_CC not defined - compilation skipped +endif +c_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc +cc_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB +KERN_EXE_SUFFIX := $(LINUX_MODULE_EXT) +KERN_LDFLAGS = $(LINUX_LDFLAGS) +ifdef LINUX_ARCH +KERN_ARCH = $(LINUX_ARCH) +else +KERN_ARCH = echo KERN_ARCH not defined - skipped +endif +ifdef LINUX_LD +KERN_LD = $(LINUX_LD) +else +KERN_LD = echo KERN_LD not defined - skipped +endif +ifneq ($(LINUX_AR),) +KERN_AR = $(LINUX_AR) +else +KERN_AR = $(AR) +endif +ifeq ($(LINUX_QUOTE_MODNAME),y) +KERN_MQ=\" +endif +endif # CONFIG_RTLINUX + +KERN_LOADLIBES += -L$(KERN_LIB_DIR) + +KERN_LOADLIBES += $(rtlinux_LOADLIBES:%=-l%) +KERN_LOADLIBES += $(kernel_LOADLIBES:%=-l%) + + + +# Check GCC version for kernel part of build +ifndef kern_CC_MAJOR_VERSION +kern_CC_MAJOR_VERSION := $(shell $(KERN_CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/') +endif +# Prepare suitable define for dependency building +ifeq ($(kern_CC_MAJOR_VERSION),2) +kern_CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp" +else +kern_CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp" +endif + +ifeq ($(KERN_EXE_SUFFIX),.ko) +ifeq ($(wildcard $(LINUX_DIR)/scripts/mod/modpost),) +KERN_MODPOST = $(LINUX_DIR)/scripts/modpost +else +KERN_MODPOST = $(LINUX_DIR)/scripts/mod/modpost +endif +KERN_MODULES_LINK_DIR = $(KERN_MODPOST_DIR) +KERN_LINK_SUFFIX = .o +else +KERN_MODULES_LINK_DIR = $(KERN_MODULES_DIR) +KERN_LINK_SUFFIX = $(KERN_EXE_SUFFIX) +endif + +define COMPILE_c_o_kern_template + +$(2): $(1) $(LOCAL_CONFIG_H) + @$(QUIET_CMD_ECHO) " CC [K] $$@" + $(Q) if $$(c_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) -D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \ + -o $$@ -$(CC_STAGE_STOP) $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d" ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +endef + + + +define COMPILE_cc_o_kern_template + +$(2): $(1) $(LOCAL_CONFIG_H) + @$(QUIET_CMD_ECHO) " CXX [K] $$@" + $(Q) if $$(cc_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) -D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \ + -o $$@ -$(CC_STAGE_STOP) $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d" ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +endef + + + +define MODULE_kern_template +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o)) +$(1)_OBJS := $$(sort $$($(1)_OBJS)) + +KERN_OBJS += $$($(1)_OBJS) +KERN_SOURCES += $$($(1)_SOURCES) + +# this is hack to build "__this_module" structure for 2.6.x kernels +# modpost is used for that purpose now + +#$(1).mod.c: +# echo "\ +# #include @\ +# #include @\ +# #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,5))@\ +# #include @\ +# #include @\ +# @\ +# MODULE_INFO(vermagic, VERMAGIC_STRING);@\ +# @\ +# #undef unix@\ +# struct module __this_module@\ +# __attribute__((section(\".gnu.linkonce.this_module\"))) = {@\ +# .name = __stringify(KBUILD_MODNAME),@\ +# .init = init_module,@\ +# #ifdef CONFIG_MODULE_UNLOAD@\ +# .exit = cleanup_module,@\ +# #endif@\ +# };@\ +# #endif@\ +# " | tr @ \\n >$$@ + + +#$(eval $(call COMPILE_c_o_kern_template,$(1).mod.c,$(1).mod.o,-DKBUILD_MODNAME=$(1))) + +$(2)/$(1)$(KERN_LINK_SUFFIX): $$($(1)_OBJS) + @$(QUIET_CMD_ECHO) " LD [K] $$@" + $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) -r $$($(1)_OBJS) -L$$(kern_GCCLIB_DIR) $$($(1)_LIBS:%=-l%) $$(KERN_LOADLIBES) -Map $(KERN_OBJS_DIR)/$(1).mod.map -o $$@ + @echo "$(2)/$(1)$(KERN_LINK_SUFFIX): \\" >$(KERN_OBJS_DIR)/$(1).mod.d + @sed -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(KERN_OBJS_DIR)/$(1).mod.map >>$(KERN_OBJS_DIR)/$(1).mod.d + @echo >>$(KERN_OBJS_DIR)/$(1).mod.d + @if [ "$(KERN_EXE_SUFFIX)" == ".ko" ] ; then \ + echo $(1) >>$(KERN_MODPOST_DIR)/module-changes ; \ + echo $(1) >>$(KERN_MODPOST_DIR)/$(1).mod.stamp ; \ + fi + +endef + + + +define LIBRARY_kern_template +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o)) +$(1)_OBJS := $$(sort $$($(1)_OBJS)) + +KERN_OBJS += $$($(1)_OBJS) +KERN_SOURCES += $$($(1)_SOURCES) + +$(KERN_LIB_DIR)/lib$(1).a: $$($(1)_OBJS) + @$(QUIET_CMD_ECHO) " AR [K] $$@" + $(Q) $(KERN_AR) rcs $$@ $$^ +endef + + +ifdef LINUX_DIR + +kernel-lib-pass-local: $(kernel_LIBRARIES:%=$(KERN_LIB_DIR)/lib%.a) + +kernel-mod-pass-local: $(kernel_MODULES:%=$(KERN_MODULES_LINK_DIR)/%$(KERN_LINK_SUFFIX)) + +$(foreach module,$(kernel_MODULES),$(eval $(call MODULE_kern_template,$(module),$(KERN_MODULES_LINK_DIR)))) + +$(foreach lib,$(kernel_LIBRARIES),$(eval $(call LIBRARY_kern_template,$(lib)))) + +endif + + +ifeq ($(CONFIG_RTLINUX),y) + +kernel-mod-pass-local: $(rtlinux_MODULES:%=$(KERN_MODULES_LINK_DIR)/%$(KERN_LINK_SUFFIX)) + +kernel-lib-pass-local: $(rtlinux_LIBRARIES:%=$(KERN_LIB_DIR)/lib%.a) + +$(foreach module,$(rtlinux_MODULES),$(eval $(call MODULE_kern_template,$(module),$(KERN_MODULES_LINK_DIR)))) + +$(foreach lib,$(rtlinux_LIBRARIES),$(eval $(call LIBRARY_kern_template,$(lib)))) + +endif + +ifeq ($(KERN_MODPOST_PASS),y) + +MODULES_LIST := $(wildcard *.mod.stamp) +MODULES_LIST := $(MODULES_LIST:%.mod.stamp=%) + +define MODPOST_kern_template +$(2) : $(1)$(KERN_LINK_SUFFIX) $(1).mod.c + @$(QUIET_CMD_ECHO) " LD [M] $$@" + $(Q) $$(cc_o_kern_COMPILE) -D"KBUILD_BASENAME=$(KERN_MQ)$(1)$(KERN_MQ)" \ + -D"KBUILD_MODNAME=$(KERN_MQ)$(1)$(KERN_MQ)" \ + -o $(1).mod.o -c $(1).mod.c + $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) $(1)$(KERN_LINK_SUFFIX) $(1).mod.o -r -o $$@ +endef + +kernel-modpost-versions: $(wildcard $(LINUX_DIR)/Module.symvers) + @$(QUIET_CMD_ECHO) " MODPOST $(KERN_MODPOST_DIR)" + @echo >$(KERN_MODPOST_DIR)/modpost-running + @rm -f $(KERN_MODPOST_DIR)/module-changes + $(Q) $(KERN_MODPOST) $(MODULES_LIST:%=%$(KERN_LINK_SUFFIX)) $(^:%=-i %) + +$(MODULES_LIST:%=%.mod.c) : kernel-modpost-versions + +kernel-modpost-pass-local: $(MODULES_LIST:%=$(KERN_MODULES_DIR)/%$(KERN_EXE_SUFFIX)) + @rm -f $(KERN_MODPOST_DIR)/modpost-running + +$(foreach module,$(MODULES_LIST),$(eval $(call MODPOST_kern_template,$(module),$(module:%=$(KERN_MODULES_DIR)/%$(KERN_EXE_SUFFIX))))) + +endif + +-include $(KERN_OBJS_DIR)/*.d + +endif + +#===================================================================== + +$(eval $(call omk_pass_template, kernel-lib-pass,$(KERN_OBJS_DIR),KERN_RULE_TEMPLATES=y,$(kernel_LIBRARIES)$(rtlinux_LIBRARIES))) +$(eval $(call omk_pass_template, kernel-mod-pass,$(KERN_OBJS_DIR),KERN_RULE_TEMPLATES=y,$(kernel_MODULES)$(rtlinux_MODULES))) + +kernel-modpost-pass: + +@if [ -e "$(KERN_MODPOST_DIR)/module-changes" -o -e "$(KERN_MODPOST_DIR)/modpost-running" ] ; \ + then \ + $(MAKE) --no-print-directory -C $(KERN_MODPOST_DIR) \ + -f $(SOURCES_DIR)/Makefile KERN_RULE_TEMPLATES=y KERN_MODPOST_PASS=y $(@:%=%-local) ; \ + fi + +$(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES))) +$(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS))) + +OTHER_PASSES = clean install include-pass +$(eval $(call omk_pass_template,$(OTHER_PASSES),$(USER_OBJS_DIR),,always)) + +# Create directories only for the first time +ifndef CHECK_DIR_DONE +check-dir = check-dir +CHECK_DIR_DONE = y +endif +export CHECK_DIR_DONE + +check-dir: + @$(call mkdir_def,$(USER_BUILD_DIR)) + @$(call mkdir_def,$(KERN_BUILD_DIR)) + @$(call mkdir_def,$(USER_INCLUDE_DIR)) + @$(call mkdir_def,$(KERN_INCLUDE_DIR)) + @$(call mkdir_def,$(USER_LIB_DIR)) + @$(call mkdir_def,$(KERN_LIB_DIR)) + @$(call mkdir_def,$(USER_BIN_DIR)) + @$(call mkdir_def,$(USER_UTILS_DIR)) + @$(call mkdir_def,$(KERN_MODULES_DIR)) + @$(call mkdir_def,$(KERN_MODPOST_DIR)) + +install-local: # TODO + +include-pass-local: + $(call include-pass-template,$(USER_INCLUDE_DIR),include) + $(call include-pass-template,$(KERN_INCLUDE_DIR),kernel) + +ifdef USER_RULE_TEMPLATES + +# User-space static libraries and applications object files + +USER_SOURCES := $(sort $(USER_SOURCES)) + +USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES)) + +#$(warning USER_SOURCES = $(USER_SOURCES)) + +$(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),))) + +$(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),))) + +$(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),))) + +$(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%$(OBJ_EXT)),))) + +# User-space shared libraries object files + +SOLIB_SOURCES := $(sort $(SOLIB_SOURCES)) + +SOLIB_GEN_SOURCES := $(sort $(SOLIB_GEN_SOURCES)) + +#$(warning SOLIB_SOURCES = $(SOLIB_SOURCES)) +#$(warning SOLIB_GEN_SOURCES = $(SOLIB_GEN_SOURCES)) + +$(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS)))) + +$(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS)))) + +$(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS)))) + +$(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS)))) + +# IDL compilation + +USER_IDLS := $(sort $(USER_IDLS)) + +$(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%)))) + +endif + +ifdef KERN_RULE_TEMPLATES + +KERN_SOURCES := $(sort $(KERN_SOURCES)) + +#$(warning KERN_SOURCES = $(KERN_SOURCES)) + +$(foreach src,$(filter %.c,$(KERN_SOURCES)),$(eval $(call COMPILE_c_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),))) + +$(foreach src,$(filter %.cc,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),))) + +$(foreach src,$(filter %.cxx,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),))) + +endif + +clean-local: clean-custom + @echo Cleaning in $(KERN_OBJS_DIR) and $(USER_OBJS_DIR) + @rm -f $(KERN_OBJS_DIR)/*$(OBJ_EXT) $(USER_OBJS_DIR)/*$(OBJ_EXT) $(USER_OBJS_DIR)/*.lo \ + $(KERN_OBJS_DIR)/*.d $(USER_OBJS_DIR)/*.d \ + $(KERN_OBJS_DIR)/*.map $(USER_OBJS_DIR)/*.map \ + $(KERN_OBJS_DIR)/*.mod.c \ + $(kernel_MODULES:%=$(KERN_MODPOST_DIR)/%.*) \ + $(LOCAL_CONFIG_H:%=$(KERN_OBJS_DIR)/%) \ + $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) + @if [ -e $(KERN_LIB_DIR)/kernel.mk ] ; then \ + touch -t 200001010101 $(KERN_LIB_DIR)/kernel.mk ; \ + fi + +default: $(check-dir) include-pass library-pass binary-pass +ifndef OMIT_KERNEL_PASSES +# Also make kernel passes if not disabled +default: kernel-lib-pass kernel-pass +endif + +# Local Variables: +# mode:makefile +# End: + #OMK@qt +ifneq ($(QT_SUBDIRS),) + +.PHONY: qt-subpass +qt-subpass: + +@$(foreach dir, $(QT_SUBDIRS), $(call mkdir_def,$(USER_OBJS_DIR)/$(dir)) ; \ + if [ ! -e $(SOURCES_DIR)/$(dir)/Makefile ] ; then \ + ( cd $(SOURCES_DIR)/$(dir) ; $(QTDIR:%=%/bin/)qmake TOP_DIR=$(MAKERULES_DIR) \ + RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) $(QTDIR:%=QTDIR=%) CC=$(CC) \ + CXX=$(CXX) || exit 1 ;) ; fi ; \ + $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \ + RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \ + -f $(SOURCES_DIR)/$(dir)/Makefile || exit 1 ;) + +# Hook to binary pass +binary-pass: qt-subpass + +endif + +# Local Variables: +# mode:makefile +# End: + #OMK@sources-list +# Rules that creates the list of files which are used during +# compilation. The list reflects conditional compilation depending on +# config.omk and other variables. + +SOURCES_LIST_FN=sources.txt +ifndef SOURCES_LIST +SOURCES_LIST_DIR:=$(RELATIVE_DIR) +SOURCES_LIST:=$(MAKERULES_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN) +export SOURCES_LIST SOURCES_LIST_DIR +endif + +ifeq ($(MAKECMDGOALS),sources-list) +NEED_SOURCES_LIST=y +endif +ifeq ($(MAKECMDGOALS),TAGS) +NEED_SOURCES_LIST=y +endif +ifeq ($(MAKECMDGOALS),tags) +NEED_SOURCES_LIST=y +endif + +ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful +.PHONY: sources-list +sources-list: $(SOURCES_LIST) + +$(SOURCES_LIST): $(CONFIG_FILE) $(CONFIG_FILE)-default $(shell find -name Makefile.omk) + @echo -n "" > "$(SOURCES_LIST).tmp" + @$(MAKE) --no-print-directory sources-list-pass + @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2" + @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2" + @rm "$(SOURCES_LIST).tmp" + @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)" +endif + +$(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always)) + +sources-list-pass-local: + @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\ + echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)" >> "$(SOURCES_LIST).tmp";) + @$(foreach h,$(renamed_include_HEADERS),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)"|sed -e 's/\(.*\)->.*/\1/' >> "$(SOURCES_LIST).tmp";) + @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(utils_PROGRAMS) \ + $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\ + $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(src)" >> "$(SOURCES_LIST).tmp";)) + +############ TAGS ########### + +ifeq ($(MAKECMDGOALS),TAGS) +ETAGS=etags +TAGS_CMD = $(ETAGS) +endif +ifeq ($(MAKECMDGOALS),tags) +CTAGS=ctags -N +TAGS_CMD = $(CTAGS) +endif +export TAGS_CMD + +tags TAGS: $(SOURCES_LIST) + @$(MAKE) --no-print-directory do-tags + +ifeq ($(MAKECMDGOALS),do-tags) +.PHONY: do-tags +do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST)) + @$(QUIET_CMD_ECHO) " TAGS $(SOURCES_LIST_FN)" + $(Q)$(TAGS_CMD) $^ +endif + +############ CSCOPE ########### + +cscope: $(SOURCES_LIST) + @$(QUIET_CMD_ECHO) " CSCOPE < $(SOURCES_LIST_FN)" + $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i- +#FIXME: see doc to -i in cscope(1) + +# Local Variables: +# mode:makefile +# End: diff --git a/bth_tests/app/Makefile b/bth_tests/app/Makefile new file mode 100644 index 0000000..f595272 --- /dev/null +++ b/bth_tests/app/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/bth_tests/app/Makefile.omk b/bth_tests/app/Makefile.omk new file mode 100644 index 0000000..4959b35 --- /dev/null +++ b/bth_tests/app/Makefile.omk @@ -0,0 +1,5 @@ +# -*- makefile -*- + +bin_PROGRAMS = test +test_SOURCES = test.c +test_LIBS = bluetooth mirobt diff --git a/bth_tests/app/test.c b/bth_tests/app/test.c new file mode 100644 index 0000000..21dd710 --- /dev/null +++ b/bth_tests/app/test.c @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include +#include + +/* #include */ +/* #include "cmd_bth.h" */ +/* #include "cmd_pxmc.h" */ +#include + +#include +#include +#include +#include +#include + +static int open_socket(int dev, unsigned long flags) +{ + struct sockaddr_hci addr; + struct hci_filter flt; + struct hci_dev_info di; + int sk, dd, opt; + + if (dev != HCI_DEV_NONE) { + dd = hci_open_dev(dev); + if (dd < 0) { + perror("Can't open device"); + exit(1); + } + + if (hci_devinfo(dev, &di) < 0) { + perror("Can't get device info"); + exit(1); + } + + opt = hci_test_bit(HCI_RAW, &di.flags); + if (ioctl(dd, HCISETRAW, opt) < 0) { + if (errno == EACCES) { + perror("Can't access device"); + exit(1); + } + } + + hci_close_dev(dd); + } + + /* Create HCI socket */ + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + if (sk < 0) { + perror("Can't create raw socket"); + exit(1); + } + + opt = 1; + if (setsockopt(sk, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) { + perror("Can't enable data direction info"); + exit(1); + } + + opt = 1; + if (setsockopt(sk, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) { + perror("Can't enable time stamp"); + exit(1); + } + + /* Setup filter */ + hci_filter_clear(&flt); + hci_filter_all_ptypes(&flt); + hci_filter_all_events(&flt); + if (setsockopt(sk, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { + perror("Can't set filter"); + exit(1); + } + + /* Bind socket to the HCI device */ + addr.hci_family = AF_BLUETOOTH; + addr.hci_dev = dev; + if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + printf("Can't attach to device hci%d. %s(%d)\n", + dev, strerror(errno), errno); + exit(1); + } + + return sk; +} + + +int main() +{ + int zn_bth; + + printf("I'm here\n"); + + extern int hci_socket; + //hci_socket = open_socket(0, 0); + hci_socket = 1; + + bth_init(); /* bluetooth initialization */ + + /*inicializace komunikacnich datovych I/O bufferu */ + bth_inface_setup(0); + + /*TPU channel 1 - inicialize (kontrola paketu + pocatecni zpozdeni)*/ + bth_init_pkt_controll(); + + /*nastaveni zarizeni Bth do slave role*/ + bth_parametr_slave(); + + /*kratka cas. pouza pro bth zarizeni - mazani zasilanych dat*/ + sleep(1); +// bth_start_TPU_counter(); + bth_start(); + + /*nekonecna smycka obsluhujici bth, pc ...*/ + do { + int ret; + ret = read(hci_socket, &zn_bth, sizeof(zn_bth)); + if(ret > 0) + { + bth_recieve_packet(zn_bth); + }; + + l2cap_send_data(0, 0); + bth_send_queue(); /* send built packets if there are any */ + } while(1); + return 0; +}; diff --git a/bth_tests/config.omk b/bth_tests/config.omk new file mode 100644 index 0000000..626baa5 --- /dev/null +++ b/bth_tests/config.omk @@ -0,0 +1,4 @@ +CONFIG_BLUETOOTH_LINUX=y +LN_HEADERS=y + +DEFS+=-g -O0 -DBTH_LX \ No newline at end of file diff --git a/bth_tests/sys/Makefile b/bth_tests/sys/Makefile new file mode 100644 index 0000000..f595272 --- /dev/null +++ b/bth_tests/sys/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/bth_tests/sys/Makefile.omk b/bth_tests/sys/Makefile.omk new file mode 100644 index 0000000..709c3a5 --- /dev/null +++ b/bth_tests/sys/Makefile.omk @@ -0,0 +1,3 @@ +# -*- makefile -*- + +include_HEADERS = types.h diff --git a/bth_tests/sys/types.h b/bth_tests/sys/types.h new file mode 100644 index 0000000..f38be5b --- /dev/null +++ b/bth_tests/sys/types.h @@ -0,0 +1,4 @@ +#define __KERNEL__ +#include +#include + diff --git a/testapp/.emacs-dirvars b/testapp/.emacs-dirvars new file mode 100644 index 0000000..346c0d8 --- /dev/null +++ b/testapp/.emacs-dirvars @@ -0,0 +1,11 @@ +;; -*- emacs-lisp -*- +;; +;; This file is processed by the dirvars emacs package. Each variable +;; setting below is performed when this dirvars file is loaded. +;; +c-basic-offset: 2 +indent-tabs-mode: nil +tab-width: 2 +;show-trailing-whitespace: t +;indicate-empty-lines: t + diff --git a/testapp/Makefile.omk b/testapp/Makefile.omk index be40280..2362cb9 100644 --- a/testapp/Makefile.omk +++ b/testapp/Makefile.omk @@ -1,8 +1,8 @@ # -*- makefile -*- -bin_PROGRAMS = Main +bin_PROGRAMS = mirosot -Main_SOURCES = mirosot_main.c cmd_pxmc.c +mirosot_SOURCES = mirosot_main.c cmd_pxmc.c cmd_bth.c -Main_LIBS = boot_fn arch_drivers excptvec misc pxmc m sci_channels bluetooth -Main_MOREOBJS = $(USER_LIB_DIR)/system_stub.o +mirosot_LIBS = boot_fn arch_drivers excptvec misc pxmc m sci_channels mirobt +mirosot_MOREOBJS = $(USER_LIB_DIR)/system_stub.o diff --git a/testapp/cmd_bth.c b/testapp/cmd_bth.c new file mode 100644 index 0000000..348c411 --- /dev/null +++ b/testapp/cmd_bth.c @@ -0,0 +1,41 @@ +#include +#include +#include + +cmd_io_t cmd_io_bth; + + +int cmd_bth_processor_run(void) +{ + int val; + cmd_io_t* cmd_io; + + cmd_io=&cmd_io_bth; + if(cmd_bth_line_out(cmd_io)) + return 1; + + if(cmd_bth_line_in(cmd_io)<=0) + return 0; + + if(cmd_bth){ + val=proc_cmd_line(cmd_io, cmd_bth, cmd_io->priv.ed_line.in->buf); + }else{ + val=-CMDERR_BADCMD; + } + + if(cmd_io->priv.ed_line.out->inbuf){ + cmd_io_putc(cmd_io,'\r'); + cmd_io_putc(cmd_io,'\n'); + + }else if(val<0){ + char s[20]; + cmd_io_write(&cmd_io_bth,"ERROR ",6); + i2str(s,-val,0,0); + cmd_io_write(cmd_io,s,strlen(s)); + cmd_io_putc(cmd_io,'\r'); + cmd_io_putc(cmd_io,'\n'); + } + return 1; +} + + diff --git a/testapp/cmd_bth.h b/testapp/cmd_bth.h deleted file mode 100644 index fc45735..0000000 --- a/testapp/cmd_bth.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CMD_BTH_H -#define CMD_BTH_H - -/* Bluetooth specific */ - -cmd_des_t const **cmd_bth; - -cmd_io_t cmd_io_bth; - -int cmd_bth_line_out(cmd_io_t *cmd_io); - -int cmd_bth_line_in(cmd_io_t *cmd_io); - -char *cmd_bth_rdline(cmd_io_t *cmd_io, int mode); - -#endif diff --git a/testapp/cmd_pxmc.c b/testapp/cmd_pxmc.c index 9e0200c..844ea19 100644 --- a/testapp/cmd_pxmc.c +++ b/testapp/cmd_pxmc.c @@ -19,7 +19,7 @@ #include #include #include "cmd_pxmc.h" - +#include /** * cmd_opchar_getreg - selects the right axis @@ -286,7 +286,7 @@ int cmd_do_axis_mode(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) int val; pxmc_state_t *mcs; if(*param[2]!=':') return -CMDERR_OPCHAR; -// if((mcs=cmd_opchar_getreg(cmd_io,des,param))==NULL) return -CMDERR_BADREG; + if((mcs=cmd_opchar_getreg(cmd_io,des,param))==NULL) return -CMDERR_BADREG; if(mcs->pxms_flg&PXMS_BSY_m) return -CMDERR_BSYREG; val=atol(param[3]); val=pxmc_axis_mode(mcs,val); diff --git a/testapp/mirosot_main.c b/testapp/mirosot_main.c index 735132c..25e9615 100644 --- a/testapp/mirosot_main.c +++ b/testapp/mirosot_main.c @@ -7,7 +7,7 @@ * * Author: Petr Kovacik , (C) 2006 * -* Copyright: +* Copyright: * */ #define _USE_EXR_LEVELS 1 @@ -30,11 +30,13 @@ #include "cmd_pxmc.h" #include +/* SCI channel where Bluetooth is connected */ +#define SCI_CHAN_BTH 2 /*struktury prikazu cmd*/ cmd_des_t const cmd_des_help={0, 0,"HELP","prints help for commands", cmd_do_help,{(char*)&cmd_bth}}; - + cmd_des_t const *cmd_rs232_default[]={ &cmd_des_help, @@ -58,7 +60,7 @@ pxmc_state_t mcsX0={ pxms_rp:155l*256, pxms_rs:0, //pxms_subdiv:8, pxms_md:8000l<<8, pxms_ms:5000, pxms_ma:10, - pxms_inp_info:(long)TPU_TCNT1,//TPU_TCNT1 /*chanel TPU A,B*/ + pxms_inp_info:(long)TPU_TCNT1, //TPU_TCNT1 /*chanel TPU A,B*/ pxms_out_info:(long)PWM_PWBFR1A, /*chanel PWM A,B*/ pxms_ene:0, pxms_erc:0, pxms_p:40, pxms_i:0, pxms_d:1, pxms_s1:0, pxms_s2:0, @@ -99,11 +101,9 @@ pxmc_state_t mcsX1={ pxmc_state_t *pxmc_main_arr[] = {&mcsX0,&mcsX1}; -#define SUMMOTORS (sizeof(pxmc_main_arr)/sizeof(pxmc_main_arr[0])) - pxmc_state_list_t pxmc_main_list = { pxml_arr:pxmc_main_arr, - pxml_cnt:SUMMOTORS + pxml_cnt:sizeof(pxmc_main_arr)/sizeof(pxmc_main_arr[0]) }; @@ -111,18 +111,6 @@ pxmc_state_list_t pxmc_main_list = { //******************************************************* void unhandled_exception(void) __attribute__ ((interrupt_handler)); -/** - * init - shaddow registers, outputs.. - * - * Initializes P1 and P3 shaddow registers, - * sets PJ.1, PJ.2, PJ.3 LED as outputs, - * initialises interrupt vector. - */ -void init() -{ - /* initialises interrupt vector */ - excptvec_initfill(unhandled_exception, 0); -} /*Interrupt routines*/ void unhandled_exception(void) @@ -135,11 +123,11 @@ int cmd_rs232_processor_run(void) { int val; cmd_io_t* cmd_io; - + cmd_io=&cmd_io_rs232; if(cmd_rs232_line_out(cmd_io)) return 1; - + if(cmd_rs232_line_in(cmd_io)<=0) return 0; @@ -149,47 +137,13 @@ int cmd_rs232_processor_run(void) val=-CMDERR_BADCMD; } - if(cmd_io->priv.ed_line.out->inbuf){ - cmd_io_putc(cmd_io,'\r'); - cmd_io_putc(cmd_io,'\n'); - - }else if(val<0){ - char s[20]; - cmd_io_write(&cmd_io_rs232,"ERROR ",6); - i2str(s,-val,0,0); - cmd_io_write(cmd_io,s,strlen(s)); - cmd_io_putc(cmd_io,'\r'); - cmd_io_putc(cmd_io,'\n'); - } - return 1; -} - - -int cmd_bth_processor_run(void) -{ - int val; - cmd_io_t* cmd_io; - - cmd_io=&cmd_io_bth; - if(cmd_bth_line_out(cmd_io)) - return 1; - - if(cmd_bth_line_in(cmd_io)<=0) - return 0; - - if(cmd_bth){ - val=proc_cmd_line(cmd_io, cmd_bth, cmd_io->priv.ed_line.in->buf); - }else{ - val=-CMDERR_BADCMD; - } - if(cmd_io->priv.ed_line.out->inbuf){ cmd_io_putc(cmd_io,'\r'); cmd_io_putc(cmd_io,'\n'); }else if(val<0){ char s[20]; - cmd_io_write(&cmd_io_bth,"ERROR ",6); + cmd_io_write(&cmd_io_rs232,"ERROR ",6); i2str(s,-val,0,0); cmd_io_write(cmd_io,s,strlen(s)); cmd_io_putc(cmd_io,'\r'); @@ -208,33 +162,32 @@ int main() *DIO_PJDDR=0xff; /*output gate*/ *DIO_PEDDR=0xff; /*output gate*/ *DIO_PEDR=0x60; /*0x0-LED - light all; 0x6 -ENA,ENB=1, LE33CD=0*/ - *DIO_PJDR=0x00; //rozsviceni vsech diod na */ - + *DIO_PJDR=0x00; //switch on all the LEDs - TODO: Use generic macros fot this + /*priority preruseni - SCI > TPU*/ *SYS_SYSCR|=SYSCR_INTM1m; - *INT_IPRA=0x22; *INT_IPRB=0x22; *INT_IPRC=0x04; + *INT_IPRA=0x22; *INT_IPRB=0x22; *INT_IPRC=0x04; *INT_IPRD=0x40; *INT_IPRE=0x44; *INT_IPRF=0x55; *INT_IPRG=0x55; *INT_IPRH=0x55; *INT_IPRJ=0x06; *INT_IPRK=0x67; *INT_IPRM=0x66; - /*povoleni vsech preruseni atd...*/ + /* disable and initialize interrupts...*/ cli(); - init(); + excptvec_initfill(unhandled_exception, 0); /*nastaveni seriovych linek - Bth, PC*/ - sci_rs232_setmode(RS232_BAUD_RAW | 3, 0, 0, 2); // HCI - hardcoded 115200 + sci_rs232_setmode(RS232_BAUD_RAW | 3, 0, 0, SCI_CHAN_BTH); // HCI - hardcoded 115200 //sci_rs232_setmode(115200, 0, 0, 2); // HCI sci_rs232_setmode(19200, 0, 0, sci_rs232_chan_default); //PC - sti(); + sti(); /* enable interrupts */ - /*inicializace bluetooth*/ - bth_init(); + bth_init(); /* bluetooth initialization */ /*inicializace komunikacnich datovych I/O bufferu */ bth_inface_setup(0); - /*TPU kanal 1 - inicialize (kontrola paketu + pocatecni zpozdeni)*/ + /*TPU channel 1 - inicialize (kontrola paketu + pocatecni zpozdeni)*/ bth_init_pkt_controll(); /*nastaveni zarizeni Bth do slave role*/ @@ -243,32 +196,31 @@ int main() /*kratka cas. pouza pro bth zarizeni - mazani zasilanych dat*/ // bth_start_TPU_counter(); - do - { - zn_bth=sci_rs232_recch(2); - }while(bth_get_timer()<11); + do { + zn_bth=sci_rs232_recch(SCI_CHAN_BTH); + } while(bth_get_timer()<11); + bth_start(); - /*nastaveni HW (TPU, PWM)*/ - pxmc_set_pwm_tpu(SUMMOTORS); + /* HW setup (TPU, PWM)*/ + pxmc_set_pwm_tpu(); /*nastaveni DC motoru*/ pxmc_add_pservice_and_mode(4); /*Macro - mod=4 tj. all motors are DC*/ /*nekonecna smycka obsluhujici bth, pc ...*/ - do{ - zn_bth=sci_rs232_recch(2); + do { + zn_bth=sci_rs232_recch(SCI_CHAN_BTH); if(zn_bth!=-1) { bth_recieve_packet(zn_bth); }; l2cap_send_data(0, 0); - bth_send_queue(); /*odesli sestavene pakety, pokod jsou*/ - cmd_bth_processor_run(); /*sber + odesilani cmd prikazu bth*/ - cmd_rs232_processor_run(); /*sber + odesilani cmd prikazu PC*/ - - }while(1); + bth_send_queue(); /* send built packets if there are any */ + cmd_bth_processor_run(); /* run command processor on bluetooth */ + cmd_rs232_processor_run(); /* run command processor on serial line */ + } while(1); return 0; };