But when I made a branch of the code and added an spi_master_2 (aside: full code at [1]. This code takes care of both CS and EN bits, so it uses masks instead of 1-bit ports) I saw the situation. It’s like this (below).
The first bit of a 4-bit port is compatible with the first 1-bit port of the 1-bit port array. But there it correctly stops: the second bit of a 4-bit port is not compatible with the second 1-bit port of the 1-bit port array. From this follows that it should not have been allowed to send the 4-bit port instead of the array of 1-bit ports.
The type checker should, as far as I can see, not have allowed the compilation below. It even works for that first bit!
The semantics of p_ss[0] <: 1; with XS1_PORT_4C outputs 0001 binary but then it’s completely undefined, as with p_ss[1] <: 1; (but this latter is not compilable as I am not able to initialise p_ss for NUM_SPI_SLAVES 2 in the XS1_PORT_4C case. That’s fine! What is not fine it compiles and runs for NUM_SPI_SLAVES 1 in the XS1_PORT_4C case.
Defining PORT_PARAM_2 makes sense!
Code: Select all
#include <platform.h>
#include <xs1.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <iso646.h>
#include <xccompat.h> // REFERENCE_PARAMs
// Example from lib_spi:
void spi_master (
out port p_ss[num_slaves],
static const size_t num_slaves)
{
for(unsigned i=0;i<num_slaves;i++)
p_ss[i] <: 1;
}
// #define XMOS_10848_PORT_PARAM_2
#ifdef XMOS_10848_PORT_PARAM_2
#define NUM_SPI_SLAVES 2
out port p_ss[NUM_SPI_SLAVES] = {XS1_PORT_1A, XS1_PORT_1B};
#else
#define NUM_SPI_SLAVES 1
out port p_ss[NUM_SPI_SLAVES] = {XS1_PORT_4C};
#endif
int main() {
par {
spi_master (p_ss, NUM_SPI_SLAVES);
}
return 0;
}
[1] http://www.teigfam.net/oyvind/home/wp-c ... d_teig.zip
[2] http://www.teigfam.net/oyvind/home/tech ... ent_manner