SHARE
TWEET

Untitled

a guest May 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Michal Sulewski 160557
  2. //Jakub Maciejewski 160775
  3. //sroda 13-16
  4.  
  5. //NCR - LOOPBACK
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9.  
  10. /*
  11.  *  intsimple.c
  12.  *
  13.  *  This module demonstrates will contain code for handling an
  14.  *  interrupt.
  15.  *
  16.  *  To test is, simply run it.  Note that you may have to do something
  17.  *  to cause the interrupts to be generated (e.g. press a key if
  18.  *  handling the keyboard interrupt).
  19.  *
  20.  *    intsimple
  21.  *
  22. */
  23.  
  24. #include <errno.h>
  25. #include <fcntl.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <unistd.h>
  30. #include <sys/neutrino.h>
  31. #include <sys/syspage.h>
  32. #include <hw/inout.h>
  33.  
  34.  
  35.  
  36. #define PORT1 0x2F8
  37. #define INT_RCV 0x01
  38. #define INT_DISABLE 0x00
  39. #define int_flag 4
  40. #define int_flag2 2
  41.  
  42. unsigned READ_RS232(unsigned char *dana);
  43. void SET_RS232();
  44. void SEND_COMMAND(unsigned char COMM_TRANS);
  45. void SET_INT_SRC(unsigned char INT_SOURCE);
  46. void CLR_INT_SRC(unsigned char INT_SOURCE);
  47.  
  48. char *progname = "COM_1";
  49.  
  50. char data_TAB_Rx[16] = {0};
  51. char data_TAB_Tx[16] = "probageneralna12";
  52. int  data_cnt_rx=0;
  53. int  data_cnt_tx=0;
  54. char data_tx='a';
  55. char data_rx=0xFF;
  56. unsigned char Rx_flag = 0;
  57. volatile int j = 0;
  58. volatile  int k = 0;
  59.  
  60. volatile int l = 0;
  61.  
  62.  
  63.  
  64.  
  65. struct sigevent rsint_event;  // the event to wake up the thread
  66.  
  67. const struct sigevent *com1_hdlr( void *blah, int id )
  68. {
  69.     unsigned char st = 0;
  70.  
  71.     st = in8(PORT1+2); //sprawdzenie źródła przerwania
  72.     if((st&int_flag)==int_flag){
  73.         data_TAB_Rx[k] = in8(PORT1);
  74.         k++;
  75.         //if (k > 15) k = 0;
  76.         //data_rx = in8(PORT1);
  77.         return &rsint_event;
  78.     }
  79.  
  80.     if((st&int_flag2)==int_flag2)
  81.     {
  82.  
  83.         out8(PORT1, data_TAB_Tx[l]);
  84.         l++;
  85.         if( l > 15){
  86.             out8(PORT1+1, 0x01);
  87.         }
  88.         return &rsint_event;
  89.     }
  90.     return NULL;
  91. }
  92.  
  93. int main (int argc, char **argv){
  94.     int id,i;
  95.     unsigned char c= 'a';
  96.     setvbuf (stdout, NULL, _IOLBF, 0);
  97.  
  98.     printf ("%s:  starting...\n", progname);
  99.  
  100.     // request I/O privity
  101.     ThreadCtl(_NTO_TCTL_IO, 0 );
  102.  
  103.     // set up an event for the handler or the kernel to use to wake up
  104.     // this thread.  Use whatever type of event and event handling you want
  105.     SIGEV_INTR_INIT( &rsint_event );
  106.     // either register an interrupt handler or the event
  107.     SET_RS232();
  108.  
  109.  
  110.     id = InterruptAttach(3, com1_hdlr, NULL, 0, _NTO_INTR_FLAGS_TRK_MSK );
  111.  
  112.     j = 0;
  113.     l = 0;
  114.     k = 0;
  115.  
  116.     SET_INT_SRC(0x03);
  117.     while (1) {
  118.  
  119.         // block here waiting for the event
  120.             //SEND_COMMAND(data_TAB_Tx[j]);
  121.         //SEND_COMMAND(c++);
  122.         InterruptWait(0, NULL );
  123.         // if using a high frequency interrupt, don't print every interrupt
  124.         //printf("odebrany znak: %c\n", data_rx);
  125.         if (k > 15)
  126.         {
  127.             l = 0;
  128.                 //j = 0;
  129.             k = 0;
  130.  
  131.             printf("odebrany znak: %s, %d, %d\n", data_TAB_Rx, l, k);
  132.  
  133.             sleep(1);
  134.             out8(PORT1+1, 0x03);
  135.  
  136.         }
  137.     }
  138.  
  139.  
  140. }
  141.  
  142. unsigned READ_RS232(unsigned char *dana){
  143.  
  144.   unsigned c = in8(PORT1+5);
  145.   if(c & 1){
  146.    *dana = in8(PORT1);
  147.    return 1;
  148.   }
  149.   else{
  150.    return 0;
  151.   }
  152. }
  153.  
  154. void SET_RS232(){
  155.   unsigned char temp,licz;
  156.  
  157.   out8(PORT1+1, 0x00); /* INTERRUPT DISABLED */
  158.   out8(PORT1+3, 0x80); /* SET DLAB ON */
  159.   out8(PORT1+0, 0x06); /* SET BAUND RATE - 19200 BPS */
  160.   out8(PORT1+1, 0x00); /* */
  161.   out8(PORT1+3, 0x1B); /* PARITY, 1 STOP BIT, 8 BITS */
  162.   //out8(PORT1+1, ); /* */
  163.   out8(PORT1+2, 0x00); /* FIFO CONTROL */
  164.   out8(PORT1+4, 0x1B); /* TURN ON DTR, RTS and OUT2 */
  165.   licz=16;
  166.   do{
  167.    licz--;
  168.    if(!licz) break;
  169.   }while(READ_RS232((unsigned char*)&temp));
  170. }
  171.  
  172. void SEND_COMMAND(unsigned char COMM_TRANS){
  173.    out8(PORT1, COMM_TRANS);
  174. }
  175.  
  176. void SET_INT_SRC(unsigned char INT_SOURCE){
  177.     out8(PORT1+1, INT_SOURCE);
  178. }
  179.  
  180. void CLR_INT_SRC(unsigned char INT_SOURCE){
  181.     out8(PORT1+1, INT_SOURCE);
  182. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top