--- /dev/null
+/*
+* C Implementation: main_test
+*
+* Description:
+
+*
+*
+* Author: Petr Kovacik <kovacp1@feld.cvut.cz>, (C) 2006
+*
+* Copyright:
+*
+*/
+#define _USE_EXR_LEVELS 1
+#include <types.h>
+#include <cpu_def.h>
+#include <h8s2638h.h>
+#include <periph/sci_rs232.h>
+#include <system_def.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pxmc.h>
+#include <pxmc_h2638.h>
+
+#include <bth_fce_out.h>
+#include <bth_inface.h>
+
+#include <cmd_proc.h>
+#include "cmd_bth.h"
+#include "cmd_pxmc.h"
+#include <bth_h8s2638.h>
+
+
+/*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,
+ (cmd_des_t*)1,
+ (cmd_des_t*)cmd_stm_default,
+ NULL
+};
+cmd_des_t const **cmd_bth=cmd_rs232_default; /*cmd prikazy pro bth*/
+cmd_des_t const **cmd_rs232=cmd_rs232_default; /*cmd prikazy pro PC*/
+
+
+/*struktury charakterizujici motor 0*/
+pxmc_state_t mcsX0={
+ pxms_flg:0,
+ pxms_do_inp:0,
+ pxms_do_con:0,
+ pxms_do_out:0,
+ pxms_do_deb:0,
+ pxms_do_gen:0,
+ pxms_ap:0, pxms_as:0,
+ 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_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,
+ pxms_me:0x1800, //6144
+ pxms_ptirc:40, // 2000 irc per rev, 200/4 steps /
+ pxms_ptper:1,
+ pxms_ptptr1:NULL,
+ pxms_ptptr2:NULL,
+ pxms_cfg:PXMS_CFG_MD2E_m|PXMS_CFG_HLS_m|
+ PXMS_CFG_HPS_m|PXMS_CFG_HDIR_m|0x1
+};
+
+
+/*struktury charakterizujici motor 1*/
+pxmc_state_t mcsX1={
+ pxms_flg:0,
+ pxms_do_inp:0,
+ pxms_do_con:0,
+ pxms_do_out:0,
+ pxms_do_deb:0,
+ pxms_do_gen:0,
+ pxms_ap:0, pxms_as:0,
+ 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_TCNT2, /*chanel TPU C,D*/
+ pxms_out_info:(long)PWM_PWBFR1C, /*chanel PWM C,D*/
+ pxms_ene:0, pxms_erc:0,
+ pxms_p:40, pxms_i:0, pxms_d:1, pxms_s1:0, pxms_s2:0,
+ pxms_me:0x1800, //6144
+ pxms_ptirc:40, // 2000 irc per rev, 200/4 steps /
+ pxms_ptper:1,
+ pxms_ptptr1:NULL,
+ pxms_ptptr2:NULL,
+ pxms_cfg:PXMS_CFG_MD2E_m|PXMS_CFG_HLS_m| //FIXME: nastavit spravne priznaky pro dalsi motorove struktur
+ PXMS_CFG_HPS_m|PXMS_CFG_HDIR_m|0x1
+};
+
+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
+};
+
+
+
+//*******************************************************
+
+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)
+{
+};
+//********************************************************
+
+
+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;
+
+ if(cmd_rs232){
+ val=proc_cmd_line(cmd_io, cmd_rs232, 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_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);
+ 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 main()
+{
+ int zn_bth;
+
+ /********************************************************************************/
+ *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 */
+
+
+ /*priority preruseni - SCI > TPU*/
+ *SYS_SYSCR|=SYSCR_INTM1m;
+ *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...*/
+ cli();
+ init();
+
+ /*nastaveni seriovych linek - Bth, PC*/
+ sci_rs232_setmode(115200, 0, 0, 2); //bth
+ sci_rs232_setmode(19200, 0, 0, sci_rs232_chan_default); //PC
+ sti();
+
+ /*inicializace bluetooth*/
+ bth_init();
+
+ /*inicializace komunikacnich datovych I/O bufferu */
+ bth_inface_setup(0);
+
+ /*TPU kanal 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*/
+
+// bth_start_TPU_counter();
+ do
+ {
+ zn_bth=sci_rs232_recch(2);
+ }while(bth_get_timer()<11);
+ bth_start();
+
+ /*nastaveni HW (TPU, PWM)*/
+ pxmc_set_pwm_tpu(SUMMOTORS);
+
+ /*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);
+ 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);
+ return 0;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0 //male pohybove demo - pohyb robota
+//#include "timer.h"
+
+// init_timer3();
+
+// long int before = -1;
+// int a=1;
+ do{
+/* long int now = get_timer();
+
+ if (now != before)
+ switch (now % 10) {
+ case 0:
+ pxmc_spd(&mcsX0,a*400,0);
+ pxmc_spd(&mcsX1,-a*700,0);
+ break;
+ case 1:
+ pxmc_spd(&mcsX0,a*700,0);
+ pxmc_spd(&mcsX1,-a*400,0);
+ break;
+ case 2:
+ pxmc_spd(&mcsX0,a*2000,0);
+ pxmc_spd(&mcsX1,-a*1200,0);
+ break;
+ case 3:
+ pxmc_spd(&mcsX0,a*1200,0);
+ pxmc_spd(&mcsX1,-a*2000,0);
+ break;
+ case 4:
+ pxmc_spd(&mcsX0,a*1300,0);
+ pxmc_spd(&mcsX1,-a*1000,0);
+ break;
+ case 5:
+ pxmc_spd(&mcsX0,a*1300,0);
+ pxmc_spd(&mcsX1,-a*1000,0);
+ break;
+ case 6:
+ pxmc_spd(&mcsX0,a*100,0);
+ pxmc_spd(&mcsX1,-a*300,0);
+ break;
+ case 7:
+ pxmc_spd(&mcsX0,a*300,0);
+ pxmc_spd(&mcsX1,-a*100,0);
+ break;
+ case 8:
+ pxmc_spd(&mcsX0,a*2000,0);
+ pxmc_spd(&mcsX1,-a*100,0);
+ break;
+ case 9:
+ pxmc_spd(&mcsX0,a*4000,0);
+ pxmc_spd(&mcsX1,-a*4000,0);
+ if(a>0) a=-1;
+ else a=1;
+ break;
+
+ }
+ */
+#endif