Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Michal Sulewski 160557
- //Jakub Maciejewski 160775
- //sroda 13-16
- //NCR - LOOPBACK
- #include <stdlib.h>
- #include <stdio.h>
- /*
- * intsimple.c
- *
- * This module demonstrates will contain code for handling an
- * interrupt.
- *
- * To test is, simply run it. Note that you may have to do something
- * to cause the interrupts to be generated (e.g. press a key if
- * handling the keyboard interrupt).
- *
- * intsimple
- *
- */
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/neutrino.h>
- #include <sys/syspage.h>
- #include <hw/inout.h>
- #define PORT1 0x2F8
- #define INT_RCV 0x01
- #define INT_DISABLE 0x00
- #define int_flag 4
- #define int_flag2 2
- unsigned READ_RS232(unsigned char *dana);
- void SET_RS232();
- void SEND_COMMAND(unsigned char COMM_TRANS);
- void SET_INT_SRC(unsigned char INT_SOURCE);
- void CLR_INT_SRC(unsigned char INT_SOURCE);
- char *progname = "COM_1";
- char data_TAB_Rx[16] = {0};
- char data_TAB_Tx[16] = "probageneralna12";
- int data_cnt_rx=0;
- int data_cnt_tx=0;
- char data_tx='a';
- char data_rx=0xFF;
- unsigned char Rx_flag = 0;
- volatile int j = 0;
- volatile int k = 0;
- volatile int l = 0;
- struct sigevent rsint_event; // the event to wake up the thread
- const struct sigevent *com1_hdlr( void *blah, int id )
- {
- unsigned char st = 0;
- st = in8(PORT1+2); //sprawdzenie źródła przerwania
- if((st&int_flag)==int_flag){
- data_TAB_Rx[k] = in8(PORT1);
- k++;
- //if (k > 15) k = 0;
- //data_rx = in8(PORT1);
- return &rsint_event;
- }
- if((st&int_flag2)==int_flag2)
- {
- out8(PORT1, data_TAB_Tx[l]);
- l++;
- if( l > 15){
- out8(PORT1+1, 0x01);
- }
- return &rsint_event;
- }
- return NULL;
- }
- int main (int argc, char **argv){
- int id,i;
- unsigned char c= 'a';
- setvbuf (stdout, NULL, _IOLBF, 0);
- printf ("%s: starting...\n", progname);
- // request I/O privity
- ThreadCtl(_NTO_TCTL_IO, 0 );
- // set up an event for the handler or the kernel to use to wake up
- // this thread. Use whatever type of event and event handling you want
- SIGEV_INTR_INIT( &rsint_event );
- // either register an interrupt handler or the event
- SET_RS232();
- id = InterruptAttach(3, com1_hdlr, NULL, 0, _NTO_INTR_FLAGS_TRK_MSK );
- j = 0;
- l = 0;
- k = 0;
- SET_INT_SRC(0x03);
- while (1) {
- // block here waiting for the event
- //SEND_COMMAND(data_TAB_Tx[j]);
- //SEND_COMMAND(c++);
- InterruptWait(0, NULL );
- // if using a high frequency interrupt, don't print every interrupt
- //printf("odebrany znak: %c\n", data_rx);
- if (k > 15)
- {
- l = 0;
- //j = 0;
- k = 0;
- printf("odebrany znak: %s, %d, %d\n", data_TAB_Rx, l, k);
- sleep(1);
- out8(PORT1+1, 0x03);
- }
- }
- }
- unsigned READ_RS232(unsigned char *dana){
- unsigned c = in8(PORT1+5);
- if(c & 1){
- *dana = in8(PORT1);
- return 1;
- }
- else{
- return 0;
- }
- }
- void SET_RS232(){
- unsigned char temp,licz;
- out8(PORT1+1, 0x00); /* INTERRUPT DISABLED */
- out8(PORT1+3, 0x80); /* SET DLAB ON */
- out8(PORT1+0, 0x06); /* SET BAUND RATE - 19200 BPS */
- out8(PORT1+1, 0x00); /* */
- out8(PORT1+3, 0x1B); /* PARITY, 1 STOP BIT, 8 BITS */
- //out8(PORT1+1, ); /* */
- out8(PORT1+2, 0x00); /* FIFO CONTROL */
- out8(PORT1+4, 0x1B); /* TURN ON DTR, RTS and OUT2 */
- licz=16;
- do{
- licz--;
- if(!licz) break;
- }while(READ_RS232((unsigned char*)&temp));
- }
- void SEND_COMMAND(unsigned char COMM_TRANS){
- out8(PORT1, COMM_TRANS);
- }
- void SET_INT_SRC(unsigned char INT_SOURCE){
- out8(PORT1+1, INT_SOURCE);
- }
- void CLR_INT_SRC(unsigned char INT_SOURCE){
- out8(PORT1+1, INT_SOURCE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement