OpenCores
URL https://opencores.org/ocsvn/yac/yac/trunk

Subversion Repositories yac

[/] [yac/] [trunk/] [test_sys/] [sw/] [or32/] [main.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 feddischso
/***************************************************************************
2
*                                                                          *
3
*  File           : main.c                                                 *
4
*  Project        : YAC (Yet Another CORDIC Core)                          *
5
*  Creation       : Jun. 2015                                              *
6
*  Limitations    :                                                        *
7
*  Platform       : Linux                                                  *
8
*  Target         : Open Risc MCU (test-system)                            *
9
*                                                                          *
10
*  Author(s):     : Christian Haettich                                     *
11
*  Email          : feddischson@opencores.org                              *
12
*                                                                          *
13
*                                                                          *
14
**                                                                        **
15
*                                                                          *
16
*  Description                                                             *
17
*        C implementation for a test system: Or32 part.                    *
18
*        This implementation receives messages via serial line.            *
19
*        Each message contains a calculation request, and each answer      *
20
*        contains the calculation result                                   *
21
*        All messages have the same size, starting with a synchronization  *
22
*        byte and a header byte.                                           *
23
*                                                                          *
24
*                                                                          *
25
****************************************************************************
26
*                                                                          *
27
*                     Copyright Notice                                     *
28
*                                                                          *
29
*    This file is part of YAC - Yet Another CORDIC Core                    *
30
*    Copyright (c) 2015, Author(s), All rights reserved.                   *
31
*                                                                          *
32
*    YAC is free software; you can redistribute it and/or                  *
33
*    modify it under the terms of the GNU Lesser General Public            *
34
*    License as published by the Free Software Foundation; either          *
35
*    version 3.0 of the License, or (at your option) any later version.    *
36
*                                                                          *
37
*    YAC is distributed in the hope that it will be useful,                *
38
*    but WITHOUT ANY WARRANTY; without even the implied warranty of        *
39
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
40
*    Lesser General Public License for more details.                       *
41
*                                                                          *
42
*    You should have received a copy of the GNU Lesser General Public      *
43
*    License along with this library. If not, download it from             *
44
*    http://www.gnu.org/licenses/lgpl                                      *
45
*                                                                          *
46
***************************************************************************/
47
#include "interconnect.h"
48
#include "support.h"
49
#include "or1200.h"
50
 
51
#include "uart.h"
52
#include "board.h"
53
#include <stdint.h>
54
#include "msg.h"
55
#include "yac.h"
56
#include "crc.h"
57
 
58
 
59
static uint8_t byte_cnt;
60
static uint8_t in_sync;
61
static void update_buf( uint8_t c );
62
static void proceed_msg( Msg * m );
63
 
64
 
65
/* our yac instance */
66
static YAC yac;
67
 
68
 
69
 
70
int main()
71
{
72
  uart_init( UART_BASE );
73
  empty_RX( );
74
 
75
  in_sync  = 0;
76
  byte_cnt = 0;
77
 
78
  yac_init( &yac,
79
            YAC_BASE,
80
            YAC_XY_WIDTH,
81
            YAC_A_WIDTH,
82
            YAC_RM_GAIN,
83
            YAC_N_ENTRIES );
84
 
85
 
86
  while(1)
87
  {
88
    update_buf( uart_getc() );
89
  }
90
}
91
 
92
 
93
/* serial decoding and synchronization */
94
void update_buf( uint8_t c )
95
{
96
  /* input buffer */
97
  static Msg buf;
98
 
99
 
100
  if( 0 == in_sync && SYNC_BYTE == c )
101
  {
102
    in_sync = 1;
103
    byte_cnt = 1;
104
    buf.bytes[ 0 ] = c;
105
  }
106
  else
107
  if( 1 == in_sync && byte_cnt < sizeof( Msg ) )
108
  {
109
    buf.bytes[ byte_cnt ] = c;
110
    byte_cnt++;
111
  }
112
  else
113
  if( 1 == in_sync && 0 == byte_cnt )
114
  {
115
    byte_cnt++;
116
    if( SYNC_BYTE == c )
117
      buf.bytes[ 0 ] = c;
118
    else
119
      in_sync = 0;
120
  }
121
 
122
 
123
  /* we are synchronized and have a full message */
124
  if( in_sync && byte_cnt == sizeof( Msg ) )
125
  {
126
    byte_cnt = 0;
127
    proceed_msg( &buf );
128
  }
129
 
130
}
131
 
132
void proceed_msg( Msg * m )
133
{
134
  uint8_t crc_in = crc( m->bytes, sizeof( Msg )-1 );
135
  if( crc_in != m->fields.crc )
136
  {
137
    /* Ignore message!
138
     * The pc will handle the situation, that
139
     * he doesn't get a response!
140
     */
141
  }
142
  else
143
  if( CMD_NOP == m->fields.header )
144
  {
145
    /* simple echo */
146
    uart_write( (char*)m->bytes, sizeof( Msg ) );
147
  }
148
 
149
  else
150
  if( CMD_CALC == m->fields.header )
151
  {
152
 
153
    /* please note: we extract the message fields to the stack
154
     * because of some "Program received signal SIGBUS, Bus error. ... incomplete sequence"
155
     * problem. It seems there is some problem with the alignment
156
     * (or maybe something else, but the problem does not occur if there is no pragma pack in msg.h)
157
     *
158
     * */
159
    int32_t x, xx, y, yy, a, aa;
160
    uint8_t mode;
161
 
162
    /* extract */
163
    x    = m->fields.payload[0];
164
    y    = m->fields.payload[1];
165
    a    = m->fields.payload[3];
166
    mode = m->fields.mode;
167
 
168
    /* do the calculation */
169
    yac_single( &yac,
170
        &x, &y, &a, &xx, &yy, &aa, &mode );
171
 
172
    /* put back the result */
173
    m->fields.payload[ 0 ] = xx;
174
    m->fields.payload[ 1 ] = yy;
175
    m->fields.payload[ 2 ] = aa;
176
 
177
    /* calculate the crc*/
178
    m->fields.crc = crc( m->bytes, sizeof( Msg )-1 );
179
 
180
    /* write out the message */
181
    uart_write( (char*)&m->bytes[0], sizeof( Msg ) );
182
  }
183
 
184
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.